bnx2x_main.c 360 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388
  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. bnx2x_dcbx_pmf_update(bp);
  2064. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2065. if (bp->link_vars.link_up)
  2066. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2067. else
  2068. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2069. /* indicate link status */
  2070. bnx2x_link_report(bp);
  2071. }
  2072. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2073. u16 vlan_val, u8 allowed_prio)
  2074. {
  2075. struct bnx2x_func_state_params func_params = {0};
  2076. struct bnx2x_func_afex_update_params *f_update_params =
  2077. &func_params.params.afex_update;
  2078. func_params.f_obj = &bp->func_obj;
  2079. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2080. /* no need to wait for RAMROD completion, so don't
  2081. * set RAMROD_COMP_WAIT flag
  2082. */
  2083. f_update_params->vif_id = vifid;
  2084. f_update_params->afex_default_vlan = vlan_val;
  2085. f_update_params->allowed_priorities = allowed_prio;
  2086. /* if ramrod can not be sent, response to MCP immediately */
  2087. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2088. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2089. return 0;
  2090. }
  2091. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2092. u16 vif_index, u8 func_bit_map)
  2093. {
  2094. struct bnx2x_func_state_params func_params = {0};
  2095. struct bnx2x_func_afex_viflists_params *update_params =
  2096. &func_params.params.afex_viflists;
  2097. int rc;
  2098. u32 drv_msg_code;
  2099. /* validate only LIST_SET and LIST_GET are received from switch */
  2100. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2101. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2102. cmd_type);
  2103. func_params.f_obj = &bp->func_obj;
  2104. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2105. /* set parameters according to cmd_type */
  2106. update_params->afex_vif_list_command = cmd_type;
  2107. update_params->vif_list_index = cpu_to_le16(vif_index);
  2108. update_params->func_bit_map =
  2109. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2110. update_params->func_to_clear = 0;
  2111. drv_msg_code =
  2112. (cmd_type == VIF_LIST_RULE_GET) ?
  2113. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2114. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2115. /* if ramrod can not be sent, respond to MCP immediately for
  2116. * SET and GET requests (other are not triggered from MCP)
  2117. */
  2118. rc = bnx2x_func_state_change(bp, &func_params);
  2119. if (rc < 0)
  2120. bnx2x_fw_command(bp, drv_msg_code, 0);
  2121. return 0;
  2122. }
  2123. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2124. {
  2125. struct afex_stats afex_stats;
  2126. u32 func = BP_ABS_FUNC(bp);
  2127. u32 mf_config;
  2128. u16 vlan_val;
  2129. u32 vlan_prio;
  2130. u16 vif_id;
  2131. u8 allowed_prio;
  2132. u8 vlan_mode;
  2133. u32 addr_to_write, vifid, addrs, stats_type, i;
  2134. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2135. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2136. DP(BNX2X_MSG_MCP,
  2137. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2138. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2139. }
  2140. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2141. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2142. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2143. DP(BNX2X_MSG_MCP,
  2144. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2145. vifid, addrs);
  2146. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2147. addrs);
  2148. }
  2149. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2150. addr_to_write = SHMEM2_RD(bp,
  2151. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2152. stats_type = SHMEM2_RD(bp,
  2153. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2154. DP(BNX2X_MSG_MCP,
  2155. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2156. addr_to_write);
  2157. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2158. /* write response to scratchpad, for MCP */
  2159. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2160. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2161. *(((u32 *)(&afex_stats))+i));
  2162. /* send ack message to MCP */
  2163. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2164. }
  2165. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2166. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2167. bp->mf_config[BP_VN(bp)] = mf_config;
  2168. DP(BNX2X_MSG_MCP,
  2169. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2170. mf_config);
  2171. /* if VIF_SET is "enabled" */
  2172. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2173. /* set rate limit directly to internal RAM */
  2174. struct cmng_init_input cmng_input;
  2175. struct rate_shaping_vars_per_vn m_rs_vn;
  2176. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2177. u32 addr = BAR_XSTRORM_INTMEM +
  2178. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2179. bp->mf_config[BP_VN(bp)] = mf_config;
  2180. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2181. m_rs_vn.vn_counter.rate =
  2182. cmng_input.vnic_max_rate[BP_VN(bp)];
  2183. m_rs_vn.vn_counter.quota =
  2184. (m_rs_vn.vn_counter.rate *
  2185. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2186. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2187. /* read relevant values from mf_cfg struct in shmem */
  2188. vif_id =
  2189. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2190. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2191. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2192. vlan_val =
  2193. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2194. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2195. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2196. vlan_prio = (mf_config &
  2197. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2198. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2199. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2200. vlan_mode =
  2201. (MF_CFG_RD(bp,
  2202. func_mf_config[func].afex_config) &
  2203. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2204. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2205. allowed_prio =
  2206. (MF_CFG_RD(bp,
  2207. func_mf_config[func].afex_config) &
  2208. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2209. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2210. /* send ramrod to FW, return in case of failure */
  2211. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2212. allowed_prio))
  2213. return;
  2214. bp->afex_def_vlan_tag = vlan_val;
  2215. bp->afex_vlan_mode = vlan_mode;
  2216. } else {
  2217. /* notify link down because BP->flags is disabled */
  2218. bnx2x_link_report(bp);
  2219. /* send INVALID VIF ramrod to FW */
  2220. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2221. /* Reset the default afex VLAN */
  2222. bp->afex_def_vlan_tag = -1;
  2223. }
  2224. }
  2225. }
  2226. static void bnx2x_pmf_update(struct bnx2x *bp)
  2227. {
  2228. int port = BP_PORT(bp);
  2229. u32 val;
  2230. bp->port.pmf = 1;
  2231. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2232. /*
  2233. * We need the mb() to ensure the ordering between the writing to
  2234. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2235. */
  2236. smp_mb();
  2237. /* queue a periodic task */
  2238. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2239. bnx2x_dcbx_pmf_update(bp);
  2240. /* enable nig attention */
  2241. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2242. if (bp->common.int_block == INT_BLOCK_HC) {
  2243. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2244. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2245. } else if (!CHIP_IS_E1x(bp)) {
  2246. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2247. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2248. }
  2249. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2250. }
  2251. /* end of Link */
  2252. /* slow path */
  2253. /*
  2254. * General service functions
  2255. */
  2256. /* send the MCP a request, block until there is a reply */
  2257. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2258. {
  2259. int mb_idx = BP_FW_MB_IDX(bp);
  2260. u32 seq;
  2261. u32 rc = 0;
  2262. u32 cnt = 1;
  2263. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2264. mutex_lock(&bp->fw_mb_mutex);
  2265. seq = ++bp->fw_seq;
  2266. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2267. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2268. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2269. (command | seq), param);
  2270. do {
  2271. /* let the FW do it's magic ... */
  2272. msleep(delay);
  2273. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2274. /* Give the FW up to 5 second (500*10ms) */
  2275. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2276. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2277. cnt*delay, rc, seq);
  2278. /* is this a reply to our command? */
  2279. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2280. rc &= FW_MSG_CODE_MASK;
  2281. else {
  2282. /* FW BUG! */
  2283. BNX2X_ERR("FW failed to respond!\n");
  2284. bnx2x_fw_dump(bp);
  2285. rc = 0;
  2286. }
  2287. mutex_unlock(&bp->fw_mb_mutex);
  2288. return rc;
  2289. }
  2290. static void storm_memset_func_cfg(struct bnx2x *bp,
  2291. struct tstorm_eth_function_common_config *tcfg,
  2292. u16 abs_fid)
  2293. {
  2294. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2295. u32 addr = BAR_TSTRORM_INTMEM +
  2296. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2297. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2298. }
  2299. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2300. {
  2301. if (CHIP_IS_E1x(bp)) {
  2302. struct tstorm_eth_function_common_config tcfg = {0};
  2303. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2304. }
  2305. /* Enable the function in the FW */
  2306. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2307. storm_memset_func_en(bp, p->func_id, 1);
  2308. /* spq */
  2309. if (p->func_flgs & FUNC_FLG_SPQ) {
  2310. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2311. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2312. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2313. }
  2314. }
  2315. /**
  2316. * bnx2x_get_tx_only_flags - Return common flags
  2317. *
  2318. * @bp device handle
  2319. * @fp queue handle
  2320. * @zero_stats TRUE if statistics zeroing is needed
  2321. *
  2322. * Return the flags that are common for the Tx-only and not normal connections.
  2323. */
  2324. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2325. struct bnx2x_fastpath *fp,
  2326. bool zero_stats)
  2327. {
  2328. unsigned long flags = 0;
  2329. /* PF driver will always initialize the Queue to an ACTIVE state */
  2330. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2331. /* tx only connections collect statistics (on the same index as the
  2332. * parent connection). The statistics are zeroed when the parent
  2333. * connection is initialized.
  2334. */
  2335. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2336. if (zero_stats)
  2337. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2338. return flags;
  2339. }
  2340. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2341. struct bnx2x_fastpath *fp,
  2342. bool leading)
  2343. {
  2344. unsigned long flags = 0;
  2345. /* calculate other queue flags */
  2346. if (IS_MF_SD(bp))
  2347. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2348. if (IS_FCOE_FP(fp)) {
  2349. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2350. /* For FCoE - force usage of default priority (for afex) */
  2351. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2352. }
  2353. if (!fp->disable_tpa) {
  2354. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2355. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2356. if (fp->mode == TPA_MODE_GRO)
  2357. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2358. }
  2359. if (leading) {
  2360. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2361. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2362. }
  2363. /* Always set HW VLAN stripping */
  2364. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2365. /* configure silent vlan removal */
  2366. if (IS_MF_AFEX(bp))
  2367. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2368. return flags | bnx2x_get_common_flags(bp, fp, true);
  2369. }
  2370. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2371. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2372. u8 cos)
  2373. {
  2374. gen_init->stat_id = bnx2x_stats_id(fp);
  2375. gen_init->spcl_id = fp->cl_id;
  2376. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2377. if (IS_FCOE_FP(fp))
  2378. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2379. else
  2380. gen_init->mtu = bp->dev->mtu;
  2381. gen_init->cos = cos;
  2382. }
  2383. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2384. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2385. struct bnx2x_rxq_setup_params *rxq_init)
  2386. {
  2387. u8 max_sge = 0;
  2388. u16 sge_sz = 0;
  2389. u16 tpa_agg_size = 0;
  2390. if (!fp->disable_tpa) {
  2391. pause->sge_th_lo = SGE_TH_LO(bp);
  2392. pause->sge_th_hi = SGE_TH_HI(bp);
  2393. /* validate SGE ring has enough to cross high threshold */
  2394. WARN_ON(bp->dropless_fc &&
  2395. pause->sge_th_hi + FW_PREFETCH_CNT >
  2396. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2397. tpa_agg_size = min_t(u32,
  2398. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2399. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2400. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2401. SGE_PAGE_SHIFT;
  2402. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2403. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2404. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2405. 0xffff);
  2406. }
  2407. /* pause - not for e1 */
  2408. if (!CHIP_IS_E1(bp)) {
  2409. pause->bd_th_lo = BD_TH_LO(bp);
  2410. pause->bd_th_hi = BD_TH_HI(bp);
  2411. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2412. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2413. /*
  2414. * validate that rings have enough entries to cross
  2415. * high thresholds
  2416. */
  2417. WARN_ON(bp->dropless_fc &&
  2418. pause->bd_th_hi + FW_PREFETCH_CNT >
  2419. bp->rx_ring_size);
  2420. WARN_ON(bp->dropless_fc &&
  2421. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2422. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2423. pause->pri_map = 1;
  2424. }
  2425. /* rxq setup */
  2426. rxq_init->dscr_map = fp->rx_desc_mapping;
  2427. rxq_init->sge_map = fp->rx_sge_mapping;
  2428. rxq_init->rcq_map = fp->rx_comp_mapping;
  2429. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2430. /* This should be a maximum number of data bytes that may be
  2431. * placed on the BD (not including paddings).
  2432. */
  2433. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2434. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2435. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2436. rxq_init->tpa_agg_sz = tpa_agg_size;
  2437. rxq_init->sge_buf_sz = sge_sz;
  2438. rxq_init->max_sges_pkt = max_sge;
  2439. rxq_init->rss_engine_id = BP_FUNC(bp);
  2440. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2441. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2442. *
  2443. * For PF Clients it should be the maximum avaliable number.
  2444. * VF driver(s) may want to define it to a smaller value.
  2445. */
  2446. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2447. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2448. rxq_init->fw_sb_id = fp->fw_sb_id;
  2449. if (IS_FCOE_FP(fp))
  2450. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2451. else
  2452. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2453. /* configure silent vlan removal
  2454. * if multi function mode is afex, then mask default vlan
  2455. */
  2456. if (IS_MF_AFEX(bp)) {
  2457. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2458. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2459. }
  2460. }
  2461. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2462. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2463. u8 cos)
  2464. {
  2465. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2466. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2467. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2468. txq_init->fw_sb_id = fp->fw_sb_id;
  2469. /*
  2470. * set the tss leading client id for TX classfication ==
  2471. * leading RSS client id
  2472. */
  2473. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2474. if (IS_FCOE_FP(fp)) {
  2475. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2476. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2477. }
  2478. }
  2479. static void bnx2x_pf_init(struct bnx2x *bp)
  2480. {
  2481. struct bnx2x_func_init_params func_init = {0};
  2482. struct event_ring_data eq_data = { {0} };
  2483. u16 flags;
  2484. if (!CHIP_IS_E1x(bp)) {
  2485. /* reset IGU PF statistics: MSIX + ATTN */
  2486. /* PF */
  2487. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2488. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2489. (CHIP_MODE_IS_4_PORT(bp) ?
  2490. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2491. /* ATTN */
  2492. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2493. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2494. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2495. (CHIP_MODE_IS_4_PORT(bp) ?
  2496. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2497. }
  2498. /* function setup flags */
  2499. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2500. /* This flag is relevant for E1x only.
  2501. * E2 doesn't have a TPA configuration in a function level.
  2502. */
  2503. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2504. func_init.func_flgs = flags;
  2505. func_init.pf_id = BP_FUNC(bp);
  2506. func_init.func_id = BP_FUNC(bp);
  2507. func_init.spq_map = bp->spq_mapping;
  2508. func_init.spq_prod = bp->spq_prod_idx;
  2509. bnx2x_func_init(bp, &func_init);
  2510. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2511. /*
  2512. * Congestion management values depend on the link rate
  2513. * There is no active link so initial link rate is set to 10 Gbps.
  2514. * When the link comes up The congestion management values are
  2515. * re-calculated according to the actual link rate.
  2516. */
  2517. bp->link_vars.line_speed = SPEED_10000;
  2518. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2519. /* Only the PMF sets the HW */
  2520. if (bp->port.pmf)
  2521. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2522. /* init Event Queue */
  2523. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2524. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2525. eq_data.producer = bp->eq_prod;
  2526. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2527. eq_data.sb_id = DEF_SB_ID;
  2528. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2529. }
  2530. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2531. {
  2532. int port = BP_PORT(bp);
  2533. bnx2x_tx_disable(bp);
  2534. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2535. }
  2536. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2537. {
  2538. int port = BP_PORT(bp);
  2539. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2540. /* Tx queue should be only reenabled */
  2541. netif_tx_wake_all_queues(bp->dev);
  2542. /*
  2543. * Should not call netif_carrier_on since it will be called if the link
  2544. * is up when checking for link state
  2545. */
  2546. }
  2547. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2548. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2549. {
  2550. struct eth_stats_info *ether_stat =
  2551. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2552. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2553. ETH_STAT_INFO_VERSION_LEN);
  2554. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2555. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2556. ether_stat->mac_local);
  2557. ether_stat->mtu_size = bp->dev->mtu;
  2558. if (bp->dev->features & NETIF_F_RXCSUM)
  2559. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2560. if (bp->dev->features & NETIF_F_TSO)
  2561. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2562. ether_stat->feature_flags |= bp->common.boot_mode;
  2563. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2564. ether_stat->txq_size = bp->tx_ring_size;
  2565. ether_stat->rxq_size = bp->rx_ring_size;
  2566. }
  2567. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2568. {
  2569. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2570. struct fcoe_stats_info *fcoe_stat =
  2571. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2572. if (!CNIC_LOADED(bp))
  2573. return;
  2574. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2575. bp->fip_mac, ETH_ALEN);
  2576. fcoe_stat->qos_priority =
  2577. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2578. /* insert FCoE stats from ramrod response */
  2579. if (!NO_FCOE(bp)) {
  2580. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2581. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2582. tstorm_queue_statistics;
  2583. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2584. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2585. xstorm_queue_statistics;
  2586. struct fcoe_statistics_params *fw_fcoe_stat =
  2587. &bp->fw_stats_data->fcoe;
  2588. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2589. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2590. ADD_64(fcoe_stat->rx_bytes_hi,
  2591. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2592. fcoe_stat->rx_bytes_lo,
  2593. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2594. ADD_64(fcoe_stat->rx_bytes_hi,
  2595. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2596. fcoe_stat->rx_bytes_lo,
  2597. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2598. ADD_64(fcoe_stat->rx_bytes_hi,
  2599. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2600. fcoe_stat->rx_bytes_lo,
  2601. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2602. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2603. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2604. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2605. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2606. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2607. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2608. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2609. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2610. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2611. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2612. ADD_64(fcoe_stat->tx_bytes_hi,
  2613. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2614. fcoe_stat->tx_bytes_lo,
  2615. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2616. ADD_64(fcoe_stat->tx_bytes_hi,
  2617. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2618. fcoe_stat->tx_bytes_lo,
  2619. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2620. ADD_64(fcoe_stat->tx_bytes_hi,
  2621. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2622. fcoe_stat->tx_bytes_lo,
  2623. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2624. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2625. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2626. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2627. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2628. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2629. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2630. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2631. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2632. }
  2633. /* ask L5 driver to add data to the struct */
  2634. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2635. }
  2636. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2637. {
  2638. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2639. struct iscsi_stats_info *iscsi_stat =
  2640. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2641. if (!CNIC_LOADED(bp))
  2642. return;
  2643. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2644. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2645. iscsi_stat->qos_priority =
  2646. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2647. /* ask L5 driver to add data to the struct */
  2648. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2649. }
  2650. /* called due to MCP event (on pmf):
  2651. * reread new bandwidth configuration
  2652. * configure FW
  2653. * notify others function about the change
  2654. */
  2655. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2656. {
  2657. if (bp->link_vars.link_up) {
  2658. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2659. bnx2x_link_sync_notify(bp);
  2660. }
  2661. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2662. }
  2663. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2664. {
  2665. bnx2x_config_mf_bw(bp);
  2666. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2667. }
  2668. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2669. {
  2670. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2671. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2672. }
  2673. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2674. {
  2675. enum drv_info_opcode op_code;
  2676. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2677. /* if drv_info version supported by MFW doesn't match - send NACK */
  2678. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2679. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2680. return;
  2681. }
  2682. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2683. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2684. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2685. sizeof(union drv_info_to_mcp));
  2686. switch (op_code) {
  2687. case ETH_STATS_OPCODE:
  2688. bnx2x_drv_info_ether_stat(bp);
  2689. break;
  2690. case FCOE_STATS_OPCODE:
  2691. bnx2x_drv_info_fcoe_stat(bp);
  2692. break;
  2693. case ISCSI_STATS_OPCODE:
  2694. bnx2x_drv_info_iscsi_stat(bp);
  2695. break;
  2696. default:
  2697. /* if op code isn't supported - send NACK */
  2698. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2699. return;
  2700. }
  2701. /* if we got drv_info attn from MFW then these fields are defined in
  2702. * shmem2 for sure
  2703. */
  2704. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2705. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2706. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2707. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2708. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2709. }
  2710. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2711. {
  2712. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2713. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2714. /*
  2715. * This is the only place besides the function initialization
  2716. * where the bp->flags can change so it is done without any
  2717. * locks
  2718. */
  2719. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2720. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2721. bp->flags |= MF_FUNC_DIS;
  2722. bnx2x_e1h_disable(bp);
  2723. } else {
  2724. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2725. bp->flags &= ~MF_FUNC_DIS;
  2726. bnx2x_e1h_enable(bp);
  2727. }
  2728. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2729. }
  2730. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2731. bnx2x_config_mf_bw(bp);
  2732. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2733. }
  2734. /* Report results to MCP */
  2735. if (dcc_event)
  2736. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2737. else
  2738. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2739. }
  2740. /* must be called under the spq lock */
  2741. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2742. {
  2743. struct eth_spe *next_spe = bp->spq_prod_bd;
  2744. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2745. bp->spq_prod_bd = bp->spq;
  2746. bp->spq_prod_idx = 0;
  2747. DP(BNX2X_MSG_SP, "end of spq\n");
  2748. } else {
  2749. bp->spq_prod_bd++;
  2750. bp->spq_prod_idx++;
  2751. }
  2752. return next_spe;
  2753. }
  2754. /* must be called under the spq lock */
  2755. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2756. {
  2757. int func = BP_FUNC(bp);
  2758. /*
  2759. * Make sure that BD data is updated before writing the producer:
  2760. * BD data is written to the memory, the producer is read from the
  2761. * memory, thus we need a full memory barrier to ensure the ordering.
  2762. */
  2763. mb();
  2764. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2765. bp->spq_prod_idx);
  2766. mmiowb();
  2767. }
  2768. /**
  2769. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2770. *
  2771. * @cmd: command to check
  2772. * @cmd_type: command type
  2773. */
  2774. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2775. {
  2776. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2777. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2778. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2779. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2780. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2781. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2782. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2783. return true;
  2784. else
  2785. return false;
  2786. }
  2787. /**
  2788. * bnx2x_sp_post - place a single command on an SP ring
  2789. *
  2790. * @bp: driver handle
  2791. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2792. * @cid: SW CID the command is related to
  2793. * @data_hi: command private data address (high 32 bits)
  2794. * @data_lo: command private data address (low 32 bits)
  2795. * @cmd_type: command type (e.g. NONE, ETH)
  2796. *
  2797. * SP data is handled as if it's always an address pair, thus data fields are
  2798. * not swapped to little endian in upper functions. Instead this function swaps
  2799. * data as if it's two u32 fields.
  2800. */
  2801. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2802. u32 data_hi, u32 data_lo, int cmd_type)
  2803. {
  2804. struct eth_spe *spe;
  2805. u16 type;
  2806. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2807. #ifdef BNX2X_STOP_ON_ERROR
  2808. if (unlikely(bp->panic)) {
  2809. BNX2X_ERR("Can't post SP when there is panic\n");
  2810. return -EIO;
  2811. }
  2812. #endif
  2813. spin_lock_bh(&bp->spq_lock);
  2814. if (common) {
  2815. if (!atomic_read(&bp->eq_spq_left)) {
  2816. BNX2X_ERR("BUG! EQ ring full!\n");
  2817. spin_unlock_bh(&bp->spq_lock);
  2818. bnx2x_panic();
  2819. return -EBUSY;
  2820. }
  2821. } else if (!atomic_read(&bp->cq_spq_left)) {
  2822. BNX2X_ERR("BUG! SPQ ring full!\n");
  2823. spin_unlock_bh(&bp->spq_lock);
  2824. bnx2x_panic();
  2825. return -EBUSY;
  2826. }
  2827. spe = bnx2x_sp_get_next(bp);
  2828. /* CID needs port number to be encoded int it */
  2829. spe->hdr.conn_and_cmd_data =
  2830. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2831. HW_CID(bp, cid));
  2832. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2833. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2834. SPE_HDR_FUNCTION_ID);
  2835. spe->hdr.type = cpu_to_le16(type);
  2836. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2837. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2838. /*
  2839. * It's ok if the actual decrement is issued towards the memory
  2840. * somewhere between the spin_lock and spin_unlock. Thus no
  2841. * more explict memory barrier is needed.
  2842. */
  2843. if (common)
  2844. atomic_dec(&bp->eq_spq_left);
  2845. else
  2846. atomic_dec(&bp->cq_spq_left);
  2847. DP(BNX2X_MSG_SP,
  2848. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2849. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2850. (u32)(U64_LO(bp->spq_mapping) +
  2851. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2852. HW_CID(bp, cid), data_hi, data_lo, type,
  2853. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2854. bnx2x_sp_prod_update(bp);
  2855. spin_unlock_bh(&bp->spq_lock);
  2856. return 0;
  2857. }
  2858. /* acquire split MCP access lock register */
  2859. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2860. {
  2861. u32 j, val;
  2862. int rc = 0;
  2863. might_sleep();
  2864. for (j = 0; j < 1000; j++) {
  2865. val = (1UL << 31);
  2866. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2867. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2868. if (val & (1L << 31))
  2869. break;
  2870. msleep(5);
  2871. }
  2872. if (!(val & (1L << 31))) {
  2873. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2874. rc = -EBUSY;
  2875. }
  2876. return rc;
  2877. }
  2878. /* release split MCP access lock register */
  2879. static void bnx2x_release_alr(struct bnx2x *bp)
  2880. {
  2881. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2882. }
  2883. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2884. #define BNX2X_DEF_SB_IDX 0x0002
  2885. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2886. {
  2887. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2888. u16 rc = 0;
  2889. barrier(); /* status block is written to by the chip */
  2890. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2891. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2892. rc |= BNX2X_DEF_SB_ATT_IDX;
  2893. }
  2894. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2895. bp->def_idx = def_sb->sp_sb.running_index;
  2896. rc |= BNX2X_DEF_SB_IDX;
  2897. }
  2898. /* Do not reorder: indecies reading should complete before handling */
  2899. barrier();
  2900. return rc;
  2901. }
  2902. /*
  2903. * slow path service functions
  2904. */
  2905. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2906. {
  2907. int port = BP_PORT(bp);
  2908. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2909. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2910. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2911. NIG_REG_MASK_INTERRUPT_PORT0;
  2912. u32 aeu_mask;
  2913. u32 nig_mask = 0;
  2914. u32 reg_addr;
  2915. if (bp->attn_state & asserted)
  2916. BNX2X_ERR("IGU ERROR\n");
  2917. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2918. aeu_mask = REG_RD(bp, aeu_addr);
  2919. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2920. aeu_mask, asserted);
  2921. aeu_mask &= ~(asserted & 0x3ff);
  2922. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2923. REG_WR(bp, aeu_addr, aeu_mask);
  2924. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2925. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2926. bp->attn_state |= asserted;
  2927. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2928. if (asserted & ATTN_HARD_WIRED_MASK) {
  2929. if (asserted & ATTN_NIG_FOR_FUNC) {
  2930. bnx2x_acquire_phy_lock(bp);
  2931. /* save nig interrupt mask */
  2932. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2933. /* If nig_mask is not set, no need to call the update
  2934. * function.
  2935. */
  2936. if (nig_mask) {
  2937. REG_WR(bp, nig_int_mask_addr, 0);
  2938. bnx2x_link_attn(bp);
  2939. }
  2940. /* handle unicore attn? */
  2941. }
  2942. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2943. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2944. if (asserted & GPIO_2_FUNC)
  2945. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2946. if (asserted & GPIO_3_FUNC)
  2947. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2948. if (asserted & GPIO_4_FUNC)
  2949. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2950. if (port == 0) {
  2951. if (asserted & ATTN_GENERAL_ATTN_1) {
  2952. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2953. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2954. }
  2955. if (asserted & ATTN_GENERAL_ATTN_2) {
  2956. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2957. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2958. }
  2959. if (asserted & ATTN_GENERAL_ATTN_3) {
  2960. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2961. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2962. }
  2963. } else {
  2964. if (asserted & ATTN_GENERAL_ATTN_4) {
  2965. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2966. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2967. }
  2968. if (asserted & ATTN_GENERAL_ATTN_5) {
  2969. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2970. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2971. }
  2972. if (asserted & ATTN_GENERAL_ATTN_6) {
  2973. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2974. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2975. }
  2976. }
  2977. } /* if hardwired */
  2978. if (bp->common.int_block == INT_BLOCK_HC)
  2979. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2980. COMMAND_REG_ATTN_BITS_SET);
  2981. else
  2982. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2983. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2984. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2985. REG_WR(bp, reg_addr, asserted);
  2986. /* now set back the mask */
  2987. if (asserted & ATTN_NIG_FOR_FUNC) {
  2988. /* Verify that IGU ack through BAR was written before restoring
  2989. * NIG mask. This loop should exit after 2-3 iterations max.
  2990. */
  2991. if (bp->common.int_block != INT_BLOCK_HC) {
  2992. u32 cnt = 0, igu_acked;
  2993. do {
  2994. igu_acked = REG_RD(bp,
  2995. IGU_REG_ATTENTION_ACK_BITS);
  2996. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  2997. (++cnt < MAX_IGU_ATTN_ACK_TO));
  2998. if (!igu_acked)
  2999. DP(NETIF_MSG_HW,
  3000. "Failed to verify IGU ack on time\n");
  3001. barrier();
  3002. }
  3003. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3004. bnx2x_release_phy_lock(bp);
  3005. }
  3006. }
  3007. static void bnx2x_fan_failure(struct bnx2x *bp)
  3008. {
  3009. int port = BP_PORT(bp);
  3010. u32 ext_phy_config;
  3011. /* mark the failure */
  3012. ext_phy_config =
  3013. SHMEM_RD(bp,
  3014. dev_info.port_hw_config[port].external_phy_config);
  3015. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3016. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3017. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3018. ext_phy_config);
  3019. /* log the failure */
  3020. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3021. "Please contact OEM Support for assistance\n");
  3022. /*
  3023. * Scheudle device reset (unload)
  3024. * This is due to some boards consuming sufficient power when driver is
  3025. * up to overheat if fan fails.
  3026. */
  3027. smp_mb__before_clear_bit();
  3028. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3029. smp_mb__after_clear_bit();
  3030. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3031. }
  3032. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3033. {
  3034. int port = BP_PORT(bp);
  3035. int reg_offset;
  3036. u32 val;
  3037. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3038. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3039. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3040. val = REG_RD(bp, reg_offset);
  3041. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3042. REG_WR(bp, reg_offset, val);
  3043. BNX2X_ERR("SPIO5 hw attention\n");
  3044. /* Fan failure attention */
  3045. bnx2x_hw_reset_phy(&bp->link_params);
  3046. bnx2x_fan_failure(bp);
  3047. }
  3048. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3049. bnx2x_acquire_phy_lock(bp);
  3050. bnx2x_handle_module_detect_int(&bp->link_params);
  3051. bnx2x_release_phy_lock(bp);
  3052. }
  3053. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3054. val = REG_RD(bp, reg_offset);
  3055. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3056. REG_WR(bp, reg_offset, val);
  3057. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3058. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3059. bnx2x_panic();
  3060. }
  3061. }
  3062. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3063. {
  3064. u32 val;
  3065. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3066. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3067. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3068. /* DORQ discard attention */
  3069. if (val & 0x2)
  3070. BNX2X_ERR("FATAL error from DORQ\n");
  3071. }
  3072. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3073. int port = BP_PORT(bp);
  3074. int reg_offset;
  3075. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3076. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3077. val = REG_RD(bp, reg_offset);
  3078. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3079. REG_WR(bp, reg_offset, val);
  3080. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3081. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3082. bnx2x_panic();
  3083. }
  3084. }
  3085. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3086. {
  3087. u32 val;
  3088. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3089. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3090. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3091. /* CFC error attention */
  3092. if (val & 0x2)
  3093. BNX2X_ERR("FATAL error from CFC\n");
  3094. }
  3095. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3096. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3097. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3098. /* RQ_USDMDP_FIFO_OVERFLOW */
  3099. if (val & 0x18000)
  3100. BNX2X_ERR("FATAL error from PXP\n");
  3101. if (!CHIP_IS_E1x(bp)) {
  3102. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3103. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3104. }
  3105. }
  3106. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3107. int port = BP_PORT(bp);
  3108. int reg_offset;
  3109. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3110. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3111. val = REG_RD(bp, reg_offset);
  3112. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3113. REG_WR(bp, reg_offset, val);
  3114. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3115. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3116. bnx2x_panic();
  3117. }
  3118. }
  3119. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3120. {
  3121. u32 val;
  3122. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3123. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3124. int func = BP_FUNC(bp);
  3125. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3126. bnx2x_read_mf_cfg(bp);
  3127. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3128. func_mf_config[BP_ABS_FUNC(bp)].config);
  3129. val = SHMEM_RD(bp,
  3130. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3131. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3132. bnx2x_dcc_event(bp,
  3133. (val & DRV_STATUS_DCC_EVENT_MASK));
  3134. if (val & DRV_STATUS_SET_MF_BW)
  3135. bnx2x_set_mf_bw(bp);
  3136. if (val & DRV_STATUS_DRV_INFO_REQ)
  3137. bnx2x_handle_drv_info_req(bp);
  3138. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3139. bnx2x_pmf_update(bp);
  3140. if (bp->port.pmf &&
  3141. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3142. bp->dcbx_enabled > 0)
  3143. /* start dcbx state machine */
  3144. bnx2x_dcbx_set_params(bp,
  3145. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3146. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3147. bnx2x_handle_afex_cmd(bp,
  3148. val & DRV_STATUS_AFEX_EVENT_MASK);
  3149. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3150. bnx2x_handle_eee_event(bp);
  3151. if (bp->link_vars.periodic_flags &
  3152. PERIODIC_FLAGS_LINK_EVENT) {
  3153. /* sync with link */
  3154. bnx2x_acquire_phy_lock(bp);
  3155. bp->link_vars.periodic_flags &=
  3156. ~PERIODIC_FLAGS_LINK_EVENT;
  3157. bnx2x_release_phy_lock(bp);
  3158. if (IS_MF(bp))
  3159. bnx2x_link_sync_notify(bp);
  3160. bnx2x_link_report(bp);
  3161. }
  3162. /* Always call it here: bnx2x_link_report() will
  3163. * prevent the link indication duplication.
  3164. */
  3165. bnx2x__link_status_update(bp);
  3166. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3167. BNX2X_ERR("MC assert!\n");
  3168. bnx2x_mc_assert(bp);
  3169. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3170. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3171. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3172. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3173. bnx2x_panic();
  3174. } else if (attn & BNX2X_MCP_ASSERT) {
  3175. BNX2X_ERR("MCP assert!\n");
  3176. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3177. bnx2x_fw_dump(bp);
  3178. } else
  3179. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3180. }
  3181. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3182. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3183. if (attn & BNX2X_GRC_TIMEOUT) {
  3184. val = CHIP_IS_E1(bp) ? 0 :
  3185. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3186. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3187. }
  3188. if (attn & BNX2X_GRC_RSV) {
  3189. val = CHIP_IS_E1(bp) ? 0 :
  3190. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3191. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3192. }
  3193. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3194. }
  3195. }
  3196. /*
  3197. * Bits map:
  3198. * 0-7 - Engine0 load counter.
  3199. * 8-15 - Engine1 load counter.
  3200. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3201. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3202. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3203. * on the engine
  3204. * 19 - Engine1 ONE_IS_LOADED.
  3205. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3206. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3207. * just the one belonging to its engine).
  3208. *
  3209. */
  3210. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3211. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3212. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3213. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3214. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3215. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3216. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3217. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3218. /*
  3219. * Set the GLOBAL_RESET bit.
  3220. *
  3221. * Should be run under rtnl lock
  3222. */
  3223. void bnx2x_set_reset_global(struct bnx2x *bp)
  3224. {
  3225. u32 val;
  3226. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3227. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3228. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3229. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3230. }
  3231. /*
  3232. * Clear the GLOBAL_RESET bit.
  3233. *
  3234. * Should be run under rtnl lock
  3235. */
  3236. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3237. {
  3238. u32 val;
  3239. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3240. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3241. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3242. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3243. }
  3244. /*
  3245. * Checks the GLOBAL_RESET bit.
  3246. *
  3247. * should be run under rtnl lock
  3248. */
  3249. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3250. {
  3251. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3252. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3253. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3254. }
  3255. /*
  3256. * Clear RESET_IN_PROGRESS bit for the current engine.
  3257. *
  3258. * Should be run under rtnl lock
  3259. */
  3260. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3261. {
  3262. u32 val;
  3263. u32 bit = BP_PATH(bp) ?
  3264. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3265. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3266. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3267. /* Clear the bit */
  3268. val &= ~bit;
  3269. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3270. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3271. }
  3272. /*
  3273. * Set RESET_IN_PROGRESS for the current engine.
  3274. *
  3275. * should be run under rtnl lock
  3276. */
  3277. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3278. {
  3279. u32 val;
  3280. u32 bit = BP_PATH(bp) ?
  3281. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3282. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3283. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3284. /* Set the bit */
  3285. val |= bit;
  3286. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3287. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3288. }
  3289. /*
  3290. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3291. * should be run under rtnl lock
  3292. */
  3293. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3294. {
  3295. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3296. u32 bit = engine ?
  3297. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3298. /* return false if bit is set */
  3299. return (val & bit) ? false : true;
  3300. }
  3301. /*
  3302. * set pf load for the current pf.
  3303. *
  3304. * should be run under rtnl lock
  3305. */
  3306. void bnx2x_set_pf_load(struct bnx2x *bp)
  3307. {
  3308. u32 val1, val;
  3309. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3310. BNX2X_PATH0_LOAD_CNT_MASK;
  3311. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3312. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3313. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3314. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3315. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3316. /* get the current counter value */
  3317. val1 = (val & mask) >> shift;
  3318. /* set bit of that PF */
  3319. val1 |= (1 << bp->pf_num);
  3320. /* clear the old value */
  3321. val &= ~mask;
  3322. /* set the new one */
  3323. val |= ((val1 << shift) & mask);
  3324. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3325. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3326. }
  3327. /**
  3328. * bnx2x_clear_pf_load - clear pf load mark
  3329. *
  3330. * @bp: driver handle
  3331. *
  3332. * Should be run under rtnl lock.
  3333. * Decrements the load counter for the current engine. Returns
  3334. * whether other functions are still loaded
  3335. */
  3336. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3337. {
  3338. u32 val1, val;
  3339. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3340. BNX2X_PATH0_LOAD_CNT_MASK;
  3341. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3342. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3343. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3344. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3345. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3346. /* get the current counter value */
  3347. val1 = (val & mask) >> shift;
  3348. /* clear bit of that PF */
  3349. val1 &= ~(1 << bp->pf_num);
  3350. /* clear the old value */
  3351. val &= ~mask;
  3352. /* set the new one */
  3353. val |= ((val1 << shift) & mask);
  3354. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3355. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3356. return val1 != 0;
  3357. }
  3358. /*
  3359. * Read the load status for the current engine.
  3360. *
  3361. * should be run under rtnl lock
  3362. */
  3363. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3364. {
  3365. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3366. BNX2X_PATH0_LOAD_CNT_MASK);
  3367. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3368. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3369. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3370. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3371. val = (val & mask) >> shift;
  3372. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3373. engine, val);
  3374. return val != 0;
  3375. }
  3376. static void _print_next_block(int idx, const char *blk)
  3377. {
  3378. pr_cont("%s%s", idx ? ", " : "", blk);
  3379. }
  3380. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3381. bool print)
  3382. {
  3383. int i = 0;
  3384. u32 cur_bit = 0;
  3385. for (i = 0; sig; i++) {
  3386. cur_bit = ((u32)0x1 << i);
  3387. if (sig & cur_bit) {
  3388. switch (cur_bit) {
  3389. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3390. if (print)
  3391. _print_next_block(par_num++, "BRB");
  3392. break;
  3393. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3394. if (print)
  3395. _print_next_block(par_num++, "PARSER");
  3396. break;
  3397. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3398. if (print)
  3399. _print_next_block(par_num++, "TSDM");
  3400. break;
  3401. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3402. if (print)
  3403. _print_next_block(par_num++,
  3404. "SEARCHER");
  3405. break;
  3406. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3407. if (print)
  3408. _print_next_block(par_num++, "TCM");
  3409. break;
  3410. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3411. if (print)
  3412. _print_next_block(par_num++, "TSEMI");
  3413. break;
  3414. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3415. if (print)
  3416. _print_next_block(par_num++, "XPB");
  3417. break;
  3418. }
  3419. /* Clear the bit */
  3420. sig &= ~cur_bit;
  3421. }
  3422. }
  3423. return par_num;
  3424. }
  3425. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3426. bool *global, bool print)
  3427. {
  3428. int i = 0;
  3429. u32 cur_bit = 0;
  3430. for (i = 0; sig; i++) {
  3431. cur_bit = ((u32)0x1 << i);
  3432. if (sig & cur_bit) {
  3433. switch (cur_bit) {
  3434. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3435. if (print)
  3436. _print_next_block(par_num++, "PBF");
  3437. break;
  3438. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3439. if (print)
  3440. _print_next_block(par_num++, "QM");
  3441. break;
  3442. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3443. if (print)
  3444. _print_next_block(par_num++, "TM");
  3445. break;
  3446. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3447. if (print)
  3448. _print_next_block(par_num++, "XSDM");
  3449. break;
  3450. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3451. if (print)
  3452. _print_next_block(par_num++, "XCM");
  3453. break;
  3454. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3455. if (print)
  3456. _print_next_block(par_num++, "XSEMI");
  3457. break;
  3458. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3459. if (print)
  3460. _print_next_block(par_num++,
  3461. "DOORBELLQ");
  3462. break;
  3463. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3464. if (print)
  3465. _print_next_block(par_num++, "NIG");
  3466. break;
  3467. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3468. if (print)
  3469. _print_next_block(par_num++,
  3470. "VAUX PCI CORE");
  3471. *global = true;
  3472. break;
  3473. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3474. if (print)
  3475. _print_next_block(par_num++, "DEBUG");
  3476. break;
  3477. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3478. if (print)
  3479. _print_next_block(par_num++, "USDM");
  3480. break;
  3481. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3482. if (print)
  3483. _print_next_block(par_num++, "UCM");
  3484. break;
  3485. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3486. if (print)
  3487. _print_next_block(par_num++, "USEMI");
  3488. break;
  3489. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3490. if (print)
  3491. _print_next_block(par_num++, "UPB");
  3492. break;
  3493. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3494. if (print)
  3495. _print_next_block(par_num++, "CSDM");
  3496. break;
  3497. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3498. if (print)
  3499. _print_next_block(par_num++, "CCM");
  3500. break;
  3501. }
  3502. /* Clear the bit */
  3503. sig &= ~cur_bit;
  3504. }
  3505. }
  3506. return par_num;
  3507. }
  3508. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3509. bool print)
  3510. {
  3511. int i = 0;
  3512. u32 cur_bit = 0;
  3513. for (i = 0; sig; i++) {
  3514. cur_bit = ((u32)0x1 << i);
  3515. if (sig & cur_bit) {
  3516. switch (cur_bit) {
  3517. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3518. if (print)
  3519. _print_next_block(par_num++, "CSEMI");
  3520. break;
  3521. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3522. if (print)
  3523. _print_next_block(par_num++, "PXP");
  3524. break;
  3525. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3526. if (print)
  3527. _print_next_block(par_num++,
  3528. "PXPPCICLOCKCLIENT");
  3529. break;
  3530. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3531. if (print)
  3532. _print_next_block(par_num++, "CFC");
  3533. break;
  3534. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3535. if (print)
  3536. _print_next_block(par_num++, "CDU");
  3537. break;
  3538. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3539. if (print)
  3540. _print_next_block(par_num++, "DMAE");
  3541. break;
  3542. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3543. if (print)
  3544. _print_next_block(par_num++, "IGU");
  3545. break;
  3546. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3547. if (print)
  3548. _print_next_block(par_num++, "MISC");
  3549. break;
  3550. }
  3551. /* Clear the bit */
  3552. sig &= ~cur_bit;
  3553. }
  3554. }
  3555. return par_num;
  3556. }
  3557. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3558. bool *global, bool print)
  3559. {
  3560. int i = 0;
  3561. u32 cur_bit = 0;
  3562. for (i = 0; sig; i++) {
  3563. cur_bit = ((u32)0x1 << i);
  3564. if (sig & cur_bit) {
  3565. switch (cur_bit) {
  3566. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3567. if (print)
  3568. _print_next_block(par_num++, "MCP ROM");
  3569. *global = true;
  3570. break;
  3571. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3572. if (print)
  3573. _print_next_block(par_num++,
  3574. "MCP UMP RX");
  3575. *global = true;
  3576. break;
  3577. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3578. if (print)
  3579. _print_next_block(par_num++,
  3580. "MCP UMP TX");
  3581. *global = true;
  3582. break;
  3583. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3584. if (print)
  3585. _print_next_block(par_num++,
  3586. "MCP SCPAD");
  3587. *global = true;
  3588. break;
  3589. }
  3590. /* Clear the bit */
  3591. sig &= ~cur_bit;
  3592. }
  3593. }
  3594. return par_num;
  3595. }
  3596. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3597. bool print)
  3598. {
  3599. int i = 0;
  3600. u32 cur_bit = 0;
  3601. for (i = 0; sig; i++) {
  3602. cur_bit = ((u32)0x1 << i);
  3603. if (sig & cur_bit) {
  3604. switch (cur_bit) {
  3605. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3606. if (print)
  3607. _print_next_block(par_num++, "PGLUE_B");
  3608. break;
  3609. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3610. if (print)
  3611. _print_next_block(par_num++, "ATC");
  3612. break;
  3613. }
  3614. /* Clear the bit */
  3615. sig &= ~cur_bit;
  3616. }
  3617. }
  3618. return par_num;
  3619. }
  3620. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3621. u32 *sig)
  3622. {
  3623. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3624. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3625. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3626. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3627. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3628. int par_num = 0;
  3629. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3630. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3631. sig[0] & HW_PRTY_ASSERT_SET_0,
  3632. sig[1] & HW_PRTY_ASSERT_SET_1,
  3633. sig[2] & HW_PRTY_ASSERT_SET_2,
  3634. sig[3] & HW_PRTY_ASSERT_SET_3,
  3635. sig[4] & HW_PRTY_ASSERT_SET_4);
  3636. if (print)
  3637. netdev_err(bp->dev,
  3638. "Parity errors detected in blocks: ");
  3639. par_num = bnx2x_check_blocks_with_parity0(
  3640. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3641. par_num = bnx2x_check_blocks_with_parity1(
  3642. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3643. par_num = bnx2x_check_blocks_with_parity2(
  3644. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3645. par_num = bnx2x_check_blocks_with_parity3(
  3646. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3647. par_num = bnx2x_check_blocks_with_parity4(
  3648. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3649. if (print)
  3650. pr_cont("\n");
  3651. return true;
  3652. } else
  3653. return false;
  3654. }
  3655. /**
  3656. * bnx2x_chk_parity_attn - checks for parity attentions.
  3657. *
  3658. * @bp: driver handle
  3659. * @global: true if there was a global attention
  3660. * @print: show parity attention in syslog
  3661. */
  3662. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3663. {
  3664. struct attn_route attn = { {0} };
  3665. int port = BP_PORT(bp);
  3666. attn.sig[0] = REG_RD(bp,
  3667. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3668. port*4);
  3669. attn.sig[1] = REG_RD(bp,
  3670. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3671. port*4);
  3672. attn.sig[2] = REG_RD(bp,
  3673. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3674. port*4);
  3675. attn.sig[3] = REG_RD(bp,
  3676. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3677. port*4);
  3678. if (!CHIP_IS_E1x(bp))
  3679. attn.sig[4] = REG_RD(bp,
  3680. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3681. port*4);
  3682. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3683. }
  3684. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3685. {
  3686. u32 val;
  3687. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3688. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3689. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3690. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3691. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3692. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3693. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3694. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3695. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3696. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3697. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3698. if (val &
  3699. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3700. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3701. if (val &
  3702. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3703. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3704. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3705. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3706. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3707. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3708. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3709. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3710. }
  3711. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3712. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3713. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3714. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3715. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3716. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3717. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3718. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3719. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3720. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3721. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3722. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3723. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3724. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3725. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3726. }
  3727. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3728. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3729. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3730. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3731. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3732. }
  3733. }
  3734. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3735. {
  3736. struct attn_route attn, *group_mask;
  3737. int port = BP_PORT(bp);
  3738. int index;
  3739. u32 reg_addr;
  3740. u32 val;
  3741. u32 aeu_mask;
  3742. bool global = false;
  3743. /* need to take HW lock because MCP or other port might also
  3744. try to handle this event */
  3745. bnx2x_acquire_alr(bp);
  3746. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3747. #ifndef BNX2X_STOP_ON_ERROR
  3748. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3749. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3750. /* Disable HW interrupts */
  3751. bnx2x_int_disable(bp);
  3752. /* In case of parity errors don't handle attentions so that
  3753. * other function would "see" parity errors.
  3754. */
  3755. #else
  3756. bnx2x_panic();
  3757. #endif
  3758. bnx2x_release_alr(bp);
  3759. return;
  3760. }
  3761. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3762. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3763. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3764. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3765. if (!CHIP_IS_E1x(bp))
  3766. attn.sig[4] =
  3767. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3768. else
  3769. attn.sig[4] = 0;
  3770. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3771. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3772. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3773. if (deasserted & (1 << index)) {
  3774. group_mask = &bp->attn_group[index];
  3775. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3776. index,
  3777. group_mask->sig[0], group_mask->sig[1],
  3778. group_mask->sig[2], group_mask->sig[3],
  3779. group_mask->sig[4]);
  3780. bnx2x_attn_int_deasserted4(bp,
  3781. attn.sig[4] & group_mask->sig[4]);
  3782. bnx2x_attn_int_deasserted3(bp,
  3783. attn.sig[3] & group_mask->sig[3]);
  3784. bnx2x_attn_int_deasserted1(bp,
  3785. attn.sig[1] & group_mask->sig[1]);
  3786. bnx2x_attn_int_deasserted2(bp,
  3787. attn.sig[2] & group_mask->sig[2]);
  3788. bnx2x_attn_int_deasserted0(bp,
  3789. attn.sig[0] & group_mask->sig[0]);
  3790. }
  3791. }
  3792. bnx2x_release_alr(bp);
  3793. if (bp->common.int_block == INT_BLOCK_HC)
  3794. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3795. COMMAND_REG_ATTN_BITS_CLR);
  3796. else
  3797. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3798. val = ~deasserted;
  3799. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3800. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3801. REG_WR(bp, reg_addr, val);
  3802. if (~bp->attn_state & deasserted)
  3803. BNX2X_ERR("IGU ERROR\n");
  3804. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3805. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3806. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3807. aeu_mask = REG_RD(bp, reg_addr);
  3808. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3809. aeu_mask, deasserted);
  3810. aeu_mask |= (deasserted & 0x3ff);
  3811. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3812. REG_WR(bp, reg_addr, aeu_mask);
  3813. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3814. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3815. bp->attn_state &= ~deasserted;
  3816. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3817. }
  3818. static void bnx2x_attn_int(struct bnx2x *bp)
  3819. {
  3820. /* read local copy of bits */
  3821. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3822. attn_bits);
  3823. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3824. attn_bits_ack);
  3825. u32 attn_state = bp->attn_state;
  3826. /* look for changed bits */
  3827. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3828. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3829. DP(NETIF_MSG_HW,
  3830. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3831. attn_bits, attn_ack, asserted, deasserted);
  3832. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3833. BNX2X_ERR("BAD attention state\n");
  3834. /* handle bits that were raised */
  3835. if (asserted)
  3836. bnx2x_attn_int_asserted(bp, asserted);
  3837. if (deasserted)
  3838. bnx2x_attn_int_deasserted(bp, deasserted);
  3839. }
  3840. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3841. u16 index, u8 op, u8 update)
  3842. {
  3843. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3844. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3845. igu_addr);
  3846. }
  3847. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3848. {
  3849. /* No memory barriers */
  3850. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3851. mmiowb(); /* keep prod updates ordered */
  3852. }
  3853. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3854. union event_ring_elem *elem)
  3855. {
  3856. u8 err = elem->message.error;
  3857. if (!bp->cnic_eth_dev.starting_cid ||
  3858. (cid < bp->cnic_eth_dev.starting_cid &&
  3859. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3860. return 1;
  3861. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3862. if (unlikely(err)) {
  3863. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3864. cid);
  3865. bnx2x_panic_dump(bp);
  3866. }
  3867. bnx2x_cnic_cfc_comp(bp, cid, err);
  3868. return 0;
  3869. }
  3870. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3871. {
  3872. struct bnx2x_mcast_ramrod_params rparam;
  3873. int rc;
  3874. memset(&rparam, 0, sizeof(rparam));
  3875. rparam.mcast_obj = &bp->mcast_obj;
  3876. netif_addr_lock_bh(bp->dev);
  3877. /* Clear pending state for the last command */
  3878. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3879. /* If there are pending mcast commands - send them */
  3880. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3881. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3882. if (rc < 0)
  3883. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3884. rc);
  3885. }
  3886. netif_addr_unlock_bh(bp->dev);
  3887. }
  3888. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3889. union event_ring_elem *elem)
  3890. {
  3891. unsigned long ramrod_flags = 0;
  3892. int rc = 0;
  3893. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3894. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3895. /* Always push next commands out, don't wait here */
  3896. __set_bit(RAMROD_CONT, &ramrod_flags);
  3897. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3898. case BNX2X_FILTER_MAC_PENDING:
  3899. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3900. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  3901. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3902. else
  3903. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  3904. break;
  3905. case BNX2X_FILTER_MCAST_PENDING:
  3906. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3907. /* This is only relevant for 57710 where multicast MACs are
  3908. * configured as unicast MACs using the same ramrod.
  3909. */
  3910. bnx2x_handle_mcast_eqe(bp);
  3911. return;
  3912. default:
  3913. BNX2X_ERR("Unsupported classification command: %d\n",
  3914. elem->message.data.eth_event.echo);
  3915. return;
  3916. }
  3917. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3918. if (rc < 0)
  3919. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3920. else if (rc > 0)
  3921. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3922. }
  3923. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3924. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3925. {
  3926. netif_addr_lock_bh(bp->dev);
  3927. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3928. /* Send rx_mode command again if was requested */
  3929. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3930. bnx2x_set_storm_rx_mode(bp);
  3931. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3932. &bp->sp_state))
  3933. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3934. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3935. &bp->sp_state))
  3936. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3937. netif_addr_unlock_bh(bp->dev);
  3938. }
  3939. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  3940. union event_ring_elem *elem)
  3941. {
  3942. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  3943. DP(BNX2X_MSG_SP,
  3944. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  3945. elem->message.data.vif_list_event.func_bit_map);
  3946. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  3947. elem->message.data.vif_list_event.func_bit_map);
  3948. } else if (elem->message.data.vif_list_event.echo ==
  3949. VIF_LIST_RULE_SET) {
  3950. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  3951. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  3952. }
  3953. }
  3954. /* called with rtnl_lock */
  3955. static void bnx2x_after_function_update(struct bnx2x *bp)
  3956. {
  3957. int q, rc;
  3958. struct bnx2x_fastpath *fp;
  3959. struct bnx2x_queue_state_params queue_params = {NULL};
  3960. struct bnx2x_queue_update_params *q_update_params =
  3961. &queue_params.params.update;
  3962. /* Send Q update command with afex vlan removal values for all Qs */
  3963. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  3964. /* set silent vlan removal values according to vlan mode */
  3965. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3966. &q_update_params->update_flags);
  3967. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  3968. &q_update_params->update_flags);
  3969. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3970. /* in access mode mark mask and value are 0 to strip all vlans */
  3971. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  3972. q_update_params->silent_removal_value = 0;
  3973. q_update_params->silent_removal_mask = 0;
  3974. } else {
  3975. q_update_params->silent_removal_value =
  3976. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  3977. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  3978. }
  3979. for_each_eth_queue(bp, q) {
  3980. /* Set the appropriate Queue object */
  3981. fp = &bp->fp[q];
  3982. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3983. /* send the ramrod */
  3984. rc = bnx2x_queue_state_change(bp, &queue_params);
  3985. if (rc < 0)
  3986. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3987. q);
  3988. }
  3989. if (!NO_FCOE(bp)) {
  3990. fp = &bp->fp[FCOE_IDX(bp)];
  3991. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3992. /* clear pending completion bit */
  3993. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3994. /* mark latest Q bit */
  3995. smp_mb__before_clear_bit();
  3996. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  3997. smp_mb__after_clear_bit();
  3998. /* send Q update ramrod for FCoE Q */
  3999. rc = bnx2x_queue_state_change(bp, &queue_params);
  4000. if (rc < 0)
  4001. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4002. q);
  4003. } else {
  4004. /* If no FCoE ring - ACK MCP now */
  4005. bnx2x_link_report(bp);
  4006. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4007. }
  4008. }
  4009. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4010. struct bnx2x *bp, u32 cid)
  4011. {
  4012. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4013. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4014. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4015. else
  4016. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4017. }
  4018. static void bnx2x_eq_int(struct bnx2x *bp)
  4019. {
  4020. u16 hw_cons, sw_cons, sw_prod;
  4021. union event_ring_elem *elem;
  4022. u8 echo;
  4023. u32 cid;
  4024. u8 opcode;
  4025. int spqe_cnt = 0;
  4026. struct bnx2x_queue_sp_obj *q_obj;
  4027. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4028. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4029. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4030. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4031. * when we get the the next-page we nned to adjust so the loop
  4032. * condition below will be met. The next element is the size of a
  4033. * regular element and hence incrementing by 1
  4034. */
  4035. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4036. hw_cons++;
  4037. /* This function may never run in parallel with itself for a
  4038. * specific bp, thus there is no need in "paired" read memory
  4039. * barrier here.
  4040. */
  4041. sw_cons = bp->eq_cons;
  4042. sw_prod = bp->eq_prod;
  4043. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4044. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4045. for (; sw_cons != hw_cons;
  4046. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4047. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4048. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4049. opcode = elem->message.opcode;
  4050. /* handle eq element */
  4051. switch (opcode) {
  4052. case EVENT_RING_OPCODE_STAT_QUERY:
  4053. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4054. "got statistics comp event %d\n",
  4055. bp->stats_comp++);
  4056. /* nothing to do with stats comp */
  4057. goto next_spqe;
  4058. case EVENT_RING_OPCODE_CFC_DEL:
  4059. /* handle according to cid range */
  4060. /*
  4061. * we may want to verify here that the bp state is
  4062. * HALTING
  4063. */
  4064. DP(BNX2X_MSG_SP,
  4065. "got delete ramrod for MULTI[%d]\n", cid);
  4066. if (CNIC_LOADED(bp) &&
  4067. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4068. goto next_spqe;
  4069. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4070. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4071. break;
  4072. goto next_spqe;
  4073. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4074. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4075. if (f_obj->complete_cmd(bp, f_obj,
  4076. BNX2X_F_CMD_TX_STOP))
  4077. break;
  4078. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4079. goto next_spqe;
  4080. case EVENT_RING_OPCODE_START_TRAFFIC:
  4081. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4082. if (f_obj->complete_cmd(bp, f_obj,
  4083. BNX2X_F_CMD_TX_START))
  4084. break;
  4085. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4086. goto next_spqe;
  4087. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4088. echo = elem->message.data.function_update_event.echo;
  4089. if (echo == SWITCH_UPDATE) {
  4090. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4091. "got FUNC_SWITCH_UPDATE ramrod\n");
  4092. if (f_obj->complete_cmd(
  4093. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4094. break;
  4095. } else {
  4096. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4097. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4098. f_obj->complete_cmd(bp, f_obj,
  4099. BNX2X_F_CMD_AFEX_UPDATE);
  4100. /* We will perform the Queues update from
  4101. * sp_rtnl task as all Queue SP operations
  4102. * should run under rtnl_lock.
  4103. */
  4104. smp_mb__before_clear_bit();
  4105. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4106. &bp->sp_rtnl_state);
  4107. smp_mb__after_clear_bit();
  4108. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4109. }
  4110. goto next_spqe;
  4111. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4112. f_obj->complete_cmd(bp, f_obj,
  4113. BNX2X_F_CMD_AFEX_VIFLISTS);
  4114. bnx2x_after_afex_vif_lists(bp, elem);
  4115. goto next_spqe;
  4116. case EVENT_RING_OPCODE_FUNCTION_START:
  4117. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4118. "got FUNC_START ramrod\n");
  4119. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4120. break;
  4121. goto next_spqe;
  4122. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4123. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4124. "got FUNC_STOP ramrod\n");
  4125. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4126. break;
  4127. goto next_spqe;
  4128. }
  4129. switch (opcode | bp->state) {
  4130. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4131. BNX2X_STATE_OPEN):
  4132. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4133. BNX2X_STATE_OPENING_WAIT4_PORT):
  4134. cid = elem->message.data.eth_event.echo &
  4135. BNX2X_SWCID_MASK;
  4136. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4137. cid);
  4138. rss_raw->clear_pending(rss_raw);
  4139. break;
  4140. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4141. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4142. case (EVENT_RING_OPCODE_SET_MAC |
  4143. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4144. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4145. BNX2X_STATE_OPEN):
  4146. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4147. BNX2X_STATE_DIAG):
  4148. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4149. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4150. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4151. bnx2x_handle_classification_eqe(bp, elem);
  4152. break;
  4153. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4154. BNX2X_STATE_OPEN):
  4155. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4156. BNX2X_STATE_DIAG):
  4157. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4158. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4159. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4160. bnx2x_handle_mcast_eqe(bp);
  4161. break;
  4162. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4163. BNX2X_STATE_OPEN):
  4164. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4165. BNX2X_STATE_DIAG):
  4166. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4167. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4168. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4169. bnx2x_handle_rx_mode_eqe(bp);
  4170. break;
  4171. default:
  4172. /* unknown event log error and continue */
  4173. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4174. elem->message.opcode, bp->state);
  4175. }
  4176. next_spqe:
  4177. spqe_cnt++;
  4178. } /* for */
  4179. smp_mb__before_atomic_inc();
  4180. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4181. bp->eq_cons = sw_cons;
  4182. bp->eq_prod = sw_prod;
  4183. /* Make sure that above mem writes were issued towards the memory */
  4184. smp_wmb();
  4185. /* update producer */
  4186. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4187. }
  4188. static void bnx2x_sp_task(struct work_struct *work)
  4189. {
  4190. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4191. u16 status;
  4192. status = bnx2x_update_dsb_idx(bp);
  4193. /* if (status == 0) */
  4194. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  4195. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  4196. /* HW attentions */
  4197. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4198. bnx2x_attn_int(bp);
  4199. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4200. }
  4201. /* SP events: STAT_QUERY and others */
  4202. if (status & BNX2X_DEF_SB_IDX) {
  4203. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4204. if (FCOE_INIT(bp) &&
  4205. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4206. /*
  4207. * Prevent local bottom-halves from running as
  4208. * we are going to change the local NAPI list.
  4209. */
  4210. local_bh_disable();
  4211. napi_schedule(&bnx2x_fcoe(bp, napi));
  4212. local_bh_enable();
  4213. }
  4214. /* Handle EQ completions */
  4215. bnx2x_eq_int(bp);
  4216. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4217. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4218. status &= ~BNX2X_DEF_SB_IDX;
  4219. }
  4220. if (unlikely(status))
  4221. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  4222. status);
  4223. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4224. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4225. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4226. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4227. &bp->sp_state)) {
  4228. bnx2x_link_report(bp);
  4229. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4230. }
  4231. }
  4232. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4233. {
  4234. struct net_device *dev = dev_instance;
  4235. struct bnx2x *bp = netdev_priv(dev);
  4236. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4237. IGU_INT_DISABLE, 0);
  4238. #ifdef BNX2X_STOP_ON_ERROR
  4239. if (unlikely(bp->panic))
  4240. return IRQ_HANDLED;
  4241. #endif
  4242. if (CNIC_LOADED(bp)) {
  4243. struct cnic_ops *c_ops;
  4244. rcu_read_lock();
  4245. c_ops = rcu_dereference(bp->cnic_ops);
  4246. if (c_ops)
  4247. c_ops->cnic_handler(bp->cnic_data, NULL);
  4248. rcu_read_unlock();
  4249. }
  4250. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  4251. return IRQ_HANDLED;
  4252. }
  4253. /* end of slow path */
  4254. void bnx2x_drv_pulse(struct bnx2x *bp)
  4255. {
  4256. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4257. bp->fw_drv_pulse_wr_seq);
  4258. }
  4259. static void bnx2x_timer(unsigned long data)
  4260. {
  4261. struct bnx2x *bp = (struct bnx2x *) data;
  4262. if (!netif_running(bp->dev))
  4263. return;
  4264. if (!BP_NOMCP(bp)) {
  4265. int mb_idx = BP_FW_MB_IDX(bp);
  4266. u32 drv_pulse;
  4267. u32 mcp_pulse;
  4268. ++bp->fw_drv_pulse_wr_seq;
  4269. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4270. /* TBD - add SYSTEM_TIME */
  4271. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4272. bnx2x_drv_pulse(bp);
  4273. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4274. MCP_PULSE_SEQ_MASK);
  4275. /* The delta between driver pulse and mcp response
  4276. * should be 1 (before mcp response) or 0 (after mcp response)
  4277. */
  4278. if ((drv_pulse != mcp_pulse) &&
  4279. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4280. /* someone lost a heartbeat... */
  4281. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4282. drv_pulse, mcp_pulse);
  4283. }
  4284. }
  4285. if (bp->state == BNX2X_STATE_OPEN)
  4286. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4287. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4288. }
  4289. /* end of Statistics */
  4290. /* nic init */
  4291. /*
  4292. * nic init service functions
  4293. */
  4294. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4295. {
  4296. u32 i;
  4297. if (!(len%4) && !(addr%4))
  4298. for (i = 0; i < len; i += 4)
  4299. REG_WR(bp, addr + i, fill);
  4300. else
  4301. for (i = 0; i < len; i++)
  4302. REG_WR8(bp, addr + i, fill);
  4303. }
  4304. /* helper: writes FP SP data to FW - data_size in dwords */
  4305. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4306. int fw_sb_id,
  4307. u32 *sb_data_p,
  4308. u32 data_size)
  4309. {
  4310. int index;
  4311. for (index = 0; index < data_size; index++)
  4312. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4313. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4314. sizeof(u32)*index,
  4315. *(sb_data_p + index));
  4316. }
  4317. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4318. {
  4319. u32 *sb_data_p;
  4320. u32 data_size = 0;
  4321. struct hc_status_block_data_e2 sb_data_e2;
  4322. struct hc_status_block_data_e1x sb_data_e1x;
  4323. /* disable the function first */
  4324. if (!CHIP_IS_E1x(bp)) {
  4325. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4326. sb_data_e2.common.state = SB_DISABLED;
  4327. sb_data_e2.common.p_func.vf_valid = false;
  4328. sb_data_p = (u32 *)&sb_data_e2;
  4329. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4330. } else {
  4331. memset(&sb_data_e1x, 0,
  4332. sizeof(struct hc_status_block_data_e1x));
  4333. sb_data_e1x.common.state = SB_DISABLED;
  4334. sb_data_e1x.common.p_func.vf_valid = false;
  4335. sb_data_p = (u32 *)&sb_data_e1x;
  4336. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4337. }
  4338. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4339. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4340. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4341. CSTORM_STATUS_BLOCK_SIZE);
  4342. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4343. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4344. CSTORM_SYNC_BLOCK_SIZE);
  4345. }
  4346. /* helper: writes SP SB data to FW */
  4347. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4348. struct hc_sp_status_block_data *sp_sb_data)
  4349. {
  4350. int func = BP_FUNC(bp);
  4351. int i;
  4352. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4353. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4354. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4355. i*sizeof(u32),
  4356. *((u32 *)sp_sb_data + i));
  4357. }
  4358. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4359. {
  4360. int func = BP_FUNC(bp);
  4361. struct hc_sp_status_block_data sp_sb_data;
  4362. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4363. sp_sb_data.state = SB_DISABLED;
  4364. sp_sb_data.p_func.vf_valid = false;
  4365. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4366. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4367. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4368. CSTORM_SP_STATUS_BLOCK_SIZE);
  4369. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4370. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4371. CSTORM_SP_SYNC_BLOCK_SIZE);
  4372. }
  4373. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4374. int igu_sb_id, int igu_seg_id)
  4375. {
  4376. hc_sm->igu_sb_id = igu_sb_id;
  4377. hc_sm->igu_seg_id = igu_seg_id;
  4378. hc_sm->timer_value = 0xFF;
  4379. hc_sm->time_to_expire = 0xFFFFFFFF;
  4380. }
  4381. /* allocates state machine ids. */
  4382. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4383. {
  4384. /* zero out state machine indices */
  4385. /* rx indices */
  4386. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4387. /* tx indices */
  4388. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4389. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4390. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4391. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4392. /* map indices */
  4393. /* rx indices */
  4394. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4395. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4396. /* tx indices */
  4397. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4398. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4399. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4400. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4401. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4402. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4403. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4404. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4405. }
  4406. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4407. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4408. {
  4409. int igu_seg_id;
  4410. struct hc_status_block_data_e2 sb_data_e2;
  4411. struct hc_status_block_data_e1x sb_data_e1x;
  4412. struct hc_status_block_sm *hc_sm_p;
  4413. int data_size;
  4414. u32 *sb_data_p;
  4415. if (CHIP_INT_MODE_IS_BC(bp))
  4416. igu_seg_id = HC_SEG_ACCESS_NORM;
  4417. else
  4418. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4419. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4420. if (!CHIP_IS_E1x(bp)) {
  4421. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4422. sb_data_e2.common.state = SB_ENABLED;
  4423. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4424. sb_data_e2.common.p_func.vf_id = vfid;
  4425. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4426. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4427. sb_data_e2.common.same_igu_sb_1b = true;
  4428. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4429. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4430. hc_sm_p = sb_data_e2.common.state_machine;
  4431. sb_data_p = (u32 *)&sb_data_e2;
  4432. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4433. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4434. } else {
  4435. memset(&sb_data_e1x, 0,
  4436. sizeof(struct hc_status_block_data_e1x));
  4437. sb_data_e1x.common.state = SB_ENABLED;
  4438. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4439. sb_data_e1x.common.p_func.vf_id = 0xff;
  4440. sb_data_e1x.common.p_func.vf_valid = false;
  4441. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4442. sb_data_e1x.common.same_igu_sb_1b = true;
  4443. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4444. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4445. hc_sm_p = sb_data_e1x.common.state_machine;
  4446. sb_data_p = (u32 *)&sb_data_e1x;
  4447. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4448. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4449. }
  4450. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4451. igu_sb_id, igu_seg_id);
  4452. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4453. igu_sb_id, igu_seg_id);
  4454. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4455. /* write indecies to HW */
  4456. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4457. }
  4458. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4459. u16 tx_usec, u16 rx_usec)
  4460. {
  4461. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4462. false, rx_usec);
  4463. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4464. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4465. tx_usec);
  4466. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4467. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4468. tx_usec);
  4469. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4470. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4471. tx_usec);
  4472. }
  4473. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4474. {
  4475. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4476. dma_addr_t mapping = bp->def_status_blk_mapping;
  4477. int igu_sp_sb_index;
  4478. int igu_seg_id;
  4479. int port = BP_PORT(bp);
  4480. int func = BP_FUNC(bp);
  4481. int reg_offset, reg_offset_en5;
  4482. u64 section;
  4483. int index;
  4484. struct hc_sp_status_block_data sp_sb_data;
  4485. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4486. if (CHIP_INT_MODE_IS_BC(bp)) {
  4487. igu_sp_sb_index = DEF_SB_IGU_ID;
  4488. igu_seg_id = HC_SEG_ACCESS_DEF;
  4489. } else {
  4490. igu_sp_sb_index = bp->igu_dsb_id;
  4491. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4492. }
  4493. /* ATTN */
  4494. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4495. atten_status_block);
  4496. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4497. bp->attn_state = 0;
  4498. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4499. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4500. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4501. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4502. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4503. int sindex;
  4504. /* take care of sig[0]..sig[4] */
  4505. for (sindex = 0; sindex < 4; sindex++)
  4506. bp->attn_group[index].sig[sindex] =
  4507. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4508. if (!CHIP_IS_E1x(bp))
  4509. /*
  4510. * enable5 is separate from the rest of the registers,
  4511. * and therefore the address skip is 4
  4512. * and not 16 between the different groups
  4513. */
  4514. bp->attn_group[index].sig[4] = REG_RD(bp,
  4515. reg_offset_en5 + 0x4*index);
  4516. else
  4517. bp->attn_group[index].sig[4] = 0;
  4518. }
  4519. if (bp->common.int_block == INT_BLOCK_HC) {
  4520. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4521. HC_REG_ATTN_MSG0_ADDR_L);
  4522. REG_WR(bp, reg_offset, U64_LO(section));
  4523. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4524. } else if (!CHIP_IS_E1x(bp)) {
  4525. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4526. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4527. }
  4528. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4529. sp_sb);
  4530. bnx2x_zero_sp_sb(bp);
  4531. sp_sb_data.state = SB_ENABLED;
  4532. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4533. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4534. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4535. sp_sb_data.igu_seg_id = igu_seg_id;
  4536. sp_sb_data.p_func.pf_id = func;
  4537. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4538. sp_sb_data.p_func.vf_id = 0xff;
  4539. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4540. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4541. }
  4542. void bnx2x_update_coalesce(struct bnx2x *bp)
  4543. {
  4544. int i;
  4545. for_each_eth_queue(bp, i)
  4546. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4547. bp->tx_ticks, bp->rx_ticks);
  4548. }
  4549. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4550. {
  4551. spin_lock_init(&bp->spq_lock);
  4552. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4553. bp->spq_prod_idx = 0;
  4554. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4555. bp->spq_prod_bd = bp->spq;
  4556. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4557. }
  4558. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4559. {
  4560. int i;
  4561. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4562. union event_ring_elem *elem =
  4563. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4564. elem->next_page.addr.hi =
  4565. cpu_to_le32(U64_HI(bp->eq_mapping +
  4566. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4567. elem->next_page.addr.lo =
  4568. cpu_to_le32(U64_LO(bp->eq_mapping +
  4569. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4570. }
  4571. bp->eq_cons = 0;
  4572. bp->eq_prod = NUM_EQ_DESC;
  4573. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4574. /* we want a warning message before it gets rought... */
  4575. atomic_set(&bp->eq_spq_left,
  4576. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4577. }
  4578. /* called with netif_addr_lock_bh() */
  4579. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4580. unsigned long rx_mode_flags,
  4581. unsigned long rx_accept_flags,
  4582. unsigned long tx_accept_flags,
  4583. unsigned long ramrod_flags)
  4584. {
  4585. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4586. int rc;
  4587. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4588. /* Prepare ramrod parameters */
  4589. ramrod_param.cid = 0;
  4590. ramrod_param.cl_id = cl_id;
  4591. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4592. ramrod_param.func_id = BP_FUNC(bp);
  4593. ramrod_param.pstate = &bp->sp_state;
  4594. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4595. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4596. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4597. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4598. ramrod_param.ramrod_flags = ramrod_flags;
  4599. ramrod_param.rx_mode_flags = rx_mode_flags;
  4600. ramrod_param.rx_accept_flags = rx_accept_flags;
  4601. ramrod_param.tx_accept_flags = tx_accept_flags;
  4602. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4603. if (rc < 0) {
  4604. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4605. return;
  4606. }
  4607. }
  4608. /* called with netif_addr_lock_bh() */
  4609. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4610. {
  4611. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4612. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4613. if (!NO_FCOE(bp))
  4614. /* Configure rx_mode of FCoE Queue */
  4615. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4616. switch (bp->rx_mode) {
  4617. case BNX2X_RX_MODE_NONE:
  4618. /*
  4619. * 'drop all' supersedes any accept flags that may have been
  4620. * passed to the function.
  4621. */
  4622. break;
  4623. case BNX2X_RX_MODE_NORMAL:
  4624. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4625. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4626. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4627. /* internal switching mode */
  4628. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4629. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4630. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4631. break;
  4632. case BNX2X_RX_MODE_ALLMULTI:
  4633. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4634. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4635. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4636. /* internal switching mode */
  4637. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4638. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4639. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4640. break;
  4641. case BNX2X_RX_MODE_PROMISC:
  4642. /* According to deffinition of SI mode, iface in promisc mode
  4643. * should receive matched and unmatched (in resolution of port)
  4644. * unicast packets.
  4645. */
  4646. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4647. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4648. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4649. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4650. /* internal switching mode */
  4651. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4652. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4653. if (IS_MF_SI(bp))
  4654. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4655. else
  4656. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4657. break;
  4658. default:
  4659. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4660. return;
  4661. }
  4662. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4663. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4664. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4665. }
  4666. __set_bit(RAMROD_RX, &ramrod_flags);
  4667. __set_bit(RAMROD_TX, &ramrod_flags);
  4668. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4669. tx_accept_flags, ramrod_flags);
  4670. }
  4671. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4672. {
  4673. int i;
  4674. if (IS_MF_SI(bp))
  4675. /*
  4676. * In switch independent mode, the TSTORM needs to accept
  4677. * packets that failed classification, since approximate match
  4678. * mac addresses aren't written to NIG LLH
  4679. */
  4680. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4681. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4682. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4683. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4684. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4685. /* Zero this manually as its initialization is
  4686. currently missing in the initTool */
  4687. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4688. REG_WR(bp, BAR_USTRORM_INTMEM +
  4689. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4690. if (!CHIP_IS_E1x(bp)) {
  4691. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4692. CHIP_INT_MODE_IS_BC(bp) ?
  4693. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4694. }
  4695. }
  4696. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4697. {
  4698. switch (load_code) {
  4699. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4700. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4701. bnx2x_init_internal_common(bp);
  4702. /* no break */
  4703. case FW_MSG_CODE_DRV_LOAD_PORT:
  4704. /* nothing to do */
  4705. /* no break */
  4706. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4707. /* internal memory per function is
  4708. initialized inside bnx2x_pf_init */
  4709. break;
  4710. default:
  4711. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4712. break;
  4713. }
  4714. }
  4715. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4716. {
  4717. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4718. }
  4719. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4720. {
  4721. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4722. }
  4723. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4724. {
  4725. if (CHIP_IS_E1x(fp->bp))
  4726. return BP_L_ID(fp->bp) + fp->index;
  4727. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4728. return bnx2x_fp_igu_sb_id(fp);
  4729. }
  4730. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4731. {
  4732. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4733. u8 cos;
  4734. unsigned long q_type = 0;
  4735. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4736. fp->rx_queue = fp_idx;
  4737. fp->cid = fp_idx;
  4738. fp->cl_id = bnx2x_fp_cl_id(fp);
  4739. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4740. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4741. /* qZone id equals to FW (per path) client id */
  4742. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4743. /* init shortcut */
  4744. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4745. /* Setup SB indicies */
  4746. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4747. /* Configure Queue State object */
  4748. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4749. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4750. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4751. /* init tx data */
  4752. for_each_cos_in_tx_queue(fp, cos) {
  4753. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4754. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4755. FP_COS_TO_TXQ(fp, cos, bp),
  4756. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4757. cids[cos] = fp->txdata_ptr[cos]->cid;
  4758. }
  4759. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4760. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4761. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4762. /**
  4763. * Configure classification DBs: Always enable Tx switching
  4764. */
  4765. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4766. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4767. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4768. fp->igu_sb_id);
  4769. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4770. fp->fw_sb_id, fp->igu_sb_id);
  4771. bnx2x_update_fpsb_idx(fp);
  4772. }
  4773. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4774. {
  4775. int i;
  4776. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4777. struct eth_tx_next_bd *tx_next_bd =
  4778. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4779. tx_next_bd->addr_hi =
  4780. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4781. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4782. tx_next_bd->addr_lo =
  4783. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4784. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4785. }
  4786. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4787. txdata->tx_db.data.zero_fill1 = 0;
  4788. txdata->tx_db.data.prod = 0;
  4789. txdata->tx_pkt_prod = 0;
  4790. txdata->tx_pkt_cons = 0;
  4791. txdata->tx_bd_prod = 0;
  4792. txdata->tx_bd_cons = 0;
  4793. txdata->tx_pkt = 0;
  4794. }
  4795. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  4796. {
  4797. int i;
  4798. for_each_tx_queue_cnic(bp, i)
  4799. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  4800. }
  4801. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4802. {
  4803. int i;
  4804. u8 cos;
  4805. for_each_eth_queue(bp, i)
  4806. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4807. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4808. }
  4809. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  4810. {
  4811. if (!NO_FCOE(bp))
  4812. bnx2x_init_fcoe_fp(bp);
  4813. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4814. BNX2X_VF_ID_INVALID, false,
  4815. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4816. /* ensure status block indices were read */
  4817. rmb();
  4818. bnx2x_init_rx_rings_cnic(bp);
  4819. bnx2x_init_tx_rings_cnic(bp);
  4820. /* flush all */
  4821. mb();
  4822. mmiowb();
  4823. }
  4824. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4825. {
  4826. int i;
  4827. for_each_eth_queue(bp, i)
  4828. bnx2x_init_eth_fp(bp, i);
  4829. /* Initialize MOD_ABS interrupts */
  4830. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4831. bp->common.shmem_base, bp->common.shmem2_base,
  4832. BP_PORT(bp));
  4833. /* ensure status block indices were read */
  4834. rmb();
  4835. bnx2x_init_def_sb(bp);
  4836. bnx2x_update_dsb_idx(bp);
  4837. bnx2x_init_rx_rings(bp);
  4838. bnx2x_init_tx_rings(bp);
  4839. bnx2x_init_sp_ring(bp);
  4840. bnx2x_init_eq_ring(bp);
  4841. bnx2x_init_internal(bp, load_code);
  4842. bnx2x_pf_init(bp);
  4843. bnx2x_stats_init(bp);
  4844. /* flush all before enabling interrupts */
  4845. mb();
  4846. mmiowb();
  4847. bnx2x_int_enable(bp);
  4848. /* Check for SPIO5 */
  4849. bnx2x_attn_int_deasserted0(bp,
  4850. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4851. AEU_INPUTS_ATTN_BITS_SPIO5);
  4852. }
  4853. /* end of nic init */
  4854. /*
  4855. * gzip service functions
  4856. */
  4857. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4858. {
  4859. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4860. &bp->gunzip_mapping, GFP_KERNEL);
  4861. if (bp->gunzip_buf == NULL)
  4862. goto gunzip_nomem1;
  4863. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4864. if (bp->strm == NULL)
  4865. goto gunzip_nomem2;
  4866. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4867. if (bp->strm->workspace == NULL)
  4868. goto gunzip_nomem3;
  4869. return 0;
  4870. gunzip_nomem3:
  4871. kfree(bp->strm);
  4872. bp->strm = NULL;
  4873. gunzip_nomem2:
  4874. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4875. bp->gunzip_mapping);
  4876. bp->gunzip_buf = NULL;
  4877. gunzip_nomem1:
  4878. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4879. return -ENOMEM;
  4880. }
  4881. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4882. {
  4883. if (bp->strm) {
  4884. vfree(bp->strm->workspace);
  4885. kfree(bp->strm);
  4886. bp->strm = NULL;
  4887. }
  4888. if (bp->gunzip_buf) {
  4889. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4890. bp->gunzip_mapping);
  4891. bp->gunzip_buf = NULL;
  4892. }
  4893. }
  4894. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4895. {
  4896. int n, rc;
  4897. /* check gzip header */
  4898. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4899. BNX2X_ERR("Bad gzip header\n");
  4900. return -EINVAL;
  4901. }
  4902. n = 10;
  4903. #define FNAME 0x8
  4904. if (zbuf[3] & FNAME)
  4905. while ((zbuf[n++] != 0) && (n < len));
  4906. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4907. bp->strm->avail_in = len - n;
  4908. bp->strm->next_out = bp->gunzip_buf;
  4909. bp->strm->avail_out = FW_BUF_SIZE;
  4910. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4911. if (rc != Z_OK)
  4912. return rc;
  4913. rc = zlib_inflate(bp->strm, Z_FINISH);
  4914. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4915. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4916. bp->strm->msg);
  4917. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4918. if (bp->gunzip_outlen & 0x3)
  4919. netdev_err(bp->dev,
  4920. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4921. bp->gunzip_outlen);
  4922. bp->gunzip_outlen >>= 2;
  4923. zlib_inflateEnd(bp->strm);
  4924. if (rc == Z_STREAM_END)
  4925. return 0;
  4926. return rc;
  4927. }
  4928. /* nic load/unload */
  4929. /*
  4930. * General service functions
  4931. */
  4932. /* send a NIG loopback debug packet */
  4933. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4934. {
  4935. u32 wb_write[3];
  4936. /* Ethernet source and destination addresses */
  4937. wb_write[0] = 0x55555555;
  4938. wb_write[1] = 0x55555555;
  4939. wb_write[2] = 0x20; /* SOP */
  4940. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4941. /* NON-IP protocol */
  4942. wb_write[0] = 0x09000000;
  4943. wb_write[1] = 0x55555555;
  4944. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4945. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4946. }
  4947. /* some of the internal memories
  4948. * are not directly readable from the driver
  4949. * to test them we send debug packets
  4950. */
  4951. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4952. {
  4953. int factor;
  4954. int count, i;
  4955. u32 val = 0;
  4956. if (CHIP_REV_IS_FPGA(bp))
  4957. factor = 120;
  4958. else if (CHIP_REV_IS_EMUL(bp))
  4959. factor = 200;
  4960. else
  4961. factor = 1;
  4962. /* Disable inputs of parser neighbor blocks */
  4963. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4964. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4965. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4966. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4967. /* Write 0 to parser credits for CFC search request */
  4968. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4969. /* send Ethernet packet */
  4970. bnx2x_lb_pckt(bp);
  4971. /* TODO do i reset NIG statistic? */
  4972. /* Wait until NIG register shows 1 packet of size 0x10 */
  4973. count = 1000 * factor;
  4974. while (count) {
  4975. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4976. val = *bnx2x_sp(bp, wb_data[0]);
  4977. if (val == 0x10)
  4978. break;
  4979. msleep(10);
  4980. count--;
  4981. }
  4982. if (val != 0x10) {
  4983. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4984. return -1;
  4985. }
  4986. /* Wait until PRS register shows 1 packet */
  4987. count = 1000 * factor;
  4988. while (count) {
  4989. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4990. if (val == 1)
  4991. break;
  4992. msleep(10);
  4993. count--;
  4994. }
  4995. if (val != 0x1) {
  4996. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4997. return -2;
  4998. }
  4999. /* Reset and init BRB, PRS */
  5000. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5001. msleep(50);
  5002. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5003. msleep(50);
  5004. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5005. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5006. DP(NETIF_MSG_HW, "part2\n");
  5007. /* Disable inputs of parser neighbor blocks */
  5008. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5009. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5010. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5011. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5012. /* Write 0 to parser credits for CFC search request */
  5013. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5014. /* send 10 Ethernet packets */
  5015. for (i = 0; i < 10; i++)
  5016. bnx2x_lb_pckt(bp);
  5017. /* Wait until NIG register shows 10 + 1
  5018. packets of size 11*0x10 = 0xb0 */
  5019. count = 1000 * factor;
  5020. while (count) {
  5021. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5022. val = *bnx2x_sp(bp, wb_data[0]);
  5023. if (val == 0xb0)
  5024. break;
  5025. msleep(10);
  5026. count--;
  5027. }
  5028. if (val != 0xb0) {
  5029. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5030. return -3;
  5031. }
  5032. /* Wait until PRS register shows 2 packets */
  5033. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5034. if (val != 2)
  5035. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5036. /* Write 1 to parser credits for CFC search request */
  5037. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5038. /* Wait until PRS register shows 3 packets */
  5039. msleep(10 * factor);
  5040. /* Wait until NIG register shows 1 packet of size 0x10 */
  5041. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5042. if (val != 3)
  5043. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5044. /* clear NIG EOP FIFO */
  5045. for (i = 0; i < 11; i++)
  5046. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5047. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5048. if (val != 1) {
  5049. BNX2X_ERR("clear of NIG failed\n");
  5050. return -4;
  5051. }
  5052. /* Reset and init BRB, PRS, NIG */
  5053. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5054. msleep(50);
  5055. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5056. msleep(50);
  5057. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5058. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5059. if (!CNIC_SUPPORT(bp))
  5060. /* set NIC mode */
  5061. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5062. /* Enable inputs of parser neighbor blocks */
  5063. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5064. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5065. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5066. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5067. DP(NETIF_MSG_HW, "done\n");
  5068. return 0; /* OK */
  5069. }
  5070. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5071. {
  5072. u32 val;
  5073. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5074. if (!CHIP_IS_E1x(bp))
  5075. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5076. else
  5077. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5078. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5079. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5080. /*
  5081. * mask read length error interrupts in brb for parser
  5082. * (parsing unit and 'checksum and crc' unit)
  5083. * these errors are legal (PU reads fixed length and CAC can cause
  5084. * read length error on truncated packets)
  5085. */
  5086. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5087. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5088. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5089. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5090. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5091. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5092. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5093. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5094. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5095. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5096. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5097. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5098. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5099. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5100. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5101. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5102. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5103. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5104. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5105. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5106. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5107. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5108. if (!CHIP_IS_E1x(bp))
  5109. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5110. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5111. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5112. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5113. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5114. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5115. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5116. if (!CHIP_IS_E1x(bp))
  5117. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5118. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5119. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5120. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5121. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5122. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5123. }
  5124. static void bnx2x_reset_common(struct bnx2x *bp)
  5125. {
  5126. u32 val = 0x1400;
  5127. /* reset_common */
  5128. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5129. 0xd3ffff7f);
  5130. if (CHIP_IS_E3(bp)) {
  5131. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5132. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5133. }
  5134. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5135. }
  5136. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5137. {
  5138. bp->dmae_ready = 0;
  5139. spin_lock_init(&bp->dmae_lock);
  5140. }
  5141. static void bnx2x_init_pxp(struct bnx2x *bp)
  5142. {
  5143. u16 devctl;
  5144. int r_order, w_order;
  5145. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5146. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5147. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5148. if (bp->mrrs == -1)
  5149. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5150. else {
  5151. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5152. r_order = bp->mrrs;
  5153. }
  5154. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5155. }
  5156. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5157. {
  5158. int is_required;
  5159. u32 val;
  5160. int port;
  5161. if (BP_NOMCP(bp))
  5162. return;
  5163. is_required = 0;
  5164. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5165. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5166. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5167. is_required = 1;
  5168. /*
  5169. * The fan failure mechanism is usually related to the PHY type since
  5170. * the power consumption of the board is affected by the PHY. Currently,
  5171. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5172. */
  5173. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5174. for (port = PORT_0; port < PORT_MAX; port++) {
  5175. is_required |=
  5176. bnx2x_fan_failure_det_req(
  5177. bp,
  5178. bp->common.shmem_base,
  5179. bp->common.shmem2_base,
  5180. port);
  5181. }
  5182. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5183. if (is_required == 0)
  5184. return;
  5185. /* Fan failure is indicated by SPIO 5 */
  5186. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5187. /* set to active low mode */
  5188. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5189. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5190. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5191. /* enable interrupt to signal the IGU */
  5192. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5193. val |= MISC_SPIO_SPIO5;
  5194. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5195. }
  5196. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  5197. {
  5198. u32 offset = 0;
  5199. if (CHIP_IS_E1(bp))
  5200. return;
  5201. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  5202. return;
  5203. switch (BP_ABS_FUNC(bp)) {
  5204. case 0:
  5205. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  5206. break;
  5207. case 1:
  5208. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  5209. break;
  5210. case 2:
  5211. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  5212. break;
  5213. case 3:
  5214. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  5215. break;
  5216. case 4:
  5217. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  5218. break;
  5219. case 5:
  5220. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  5221. break;
  5222. case 6:
  5223. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  5224. break;
  5225. case 7:
  5226. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  5227. break;
  5228. default:
  5229. return;
  5230. }
  5231. REG_WR(bp, offset, pretend_func_num);
  5232. REG_RD(bp, offset);
  5233. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  5234. }
  5235. void bnx2x_pf_disable(struct bnx2x *bp)
  5236. {
  5237. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5238. val &= ~IGU_PF_CONF_FUNC_EN;
  5239. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5240. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5241. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5242. }
  5243. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5244. {
  5245. u32 shmem_base[2], shmem2_base[2];
  5246. /* Avoid common init in case MFW supports LFA */
  5247. if (SHMEM2_RD(bp, size) >
  5248. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5249. return;
  5250. shmem_base[0] = bp->common.shmem_base;
  5251. shmem2_base[0] = bp->common.shmem2_base;
  5252. if (!CHIP_IS_E1x(bp)) {
  5253. shmem_base[1] =
  5254. SHMEM2_RD(bp, other_shmem_base_addr);
  5255. shmem2_base[1] =
  5256. SHMEM2_RD(bp, other_shmem2_base_addr);
  5257. }
  5258. bnx2x_acquire_phy_lock(bp);
  5259. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5260. bp->common.chip_id);
  5261. bnx2x_release_phy_lock(bp);
  5262. }
  5263. /**
  5264. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5265. *
  5266. * @bp: driver handle
  5267. */
  5268. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5269. {
  5270. u32 val;
  5271. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5272. /*
  5273. * take the UNDI lock to protect undi_unload flow from accessing
  5274. * registers while we're resetting the chip
  5275. */
  5276. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5277. bnx2x_reset_common(bp);
  5278. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5279. val = 0xfffc;
  5280. if (CHIP_IS_E3(bp)) {
  5281. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5282. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5283. }
  5284. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5285. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5286. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5287. if (!CHIP_IS_E1x(bp)) {
  5288. u8 abs_func_id;
  5289. /**
  5290. * 4-port mode or 2-port mode we need to turn of master-enable
  5291. * for everyone, after that, turn it back on for self.
  5292. * so, we disregard multi-function or not, and always disable
  5293. * for all functions on the given path, this means 0,2,4,6 for
  5294. * path 0 and 1,3,5,7 for path 1
  5295. */
  5296. for (abs_func_id = BP_PATH(bp);
  5297. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5298. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5299. REG_WR(bp,
  5300. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5301. 1);
  5302. continue;
  5303. }
  5304. bnx2x_pretend_func(bp, abs_func_id);
  5305. /* clear pf enable */
  5306. bnx2x_pf_disable(bp);
  5307. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5308. }
  5309. }
  5310. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5311. if (CHIP_IS_E1(bp)) {
  5312. /* enable HW interrupt from PXP on USDM overflow
  5313. bit 16 on INT_MASK_0 */
  5314. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5315. }
  5316. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5317. bnx2x_init_pxp(bp);
  5318. #ifdef __BIG_ENDIAN
  5319. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5320. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5321. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5322. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5323. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5324. /* make sure this value is 0 */
  5325. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5326. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5327. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5328. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5329. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5330. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5331. #endif
  5332. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5333. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5334. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5335. /* let the HW do it's magic ... */
  5336. msleep(100);
  5337. /* finish PXP init */
  5338. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5339. if (val != 1) {
  5340. BNX2X_ERR("PXP2 CFG failed\n");
  5341. return -EBUSY;
  5342. }
  5343. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5344. if (val != 1) {
  5345. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5346. return -EBUSY;
  5347. }
  5348. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5349. * have entries with value "0" and valid bit on.
  5350. * This needs to be done by the first PF that is loaded in a path
  5351. * (i.e. common phase)
  5352. */
  5353. if (!CHIP_IS_E1x(bp)) {
  5354. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5355. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5356. * This occurs when a different function (func2,3) is being marked
  5357. * as "scan-off". Real-life scenario for example: if a driver is being
  5358. * load-unloaded while func6,7 are down. This will cause the timer to access
  5359. * the ilt, translate to a logical address and send a request to read/write.
  5360. * Since the ilt for the function that is down is not valid, this will cause
  5361. * a translation error which is unrecoverable.
  5362. * The Workaround is intended to make sure that when this happens nothing fatal
  5363. * will occur. The workaround:
  5364. * 1. First PF driver which loads on a path will:
  5365. * a. After taking the chip out of reset, by using pretend,
  5366. * it will write "0" to the following registers of
  5367. * the other vnics.
  5368. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5369. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5370. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5371. * And for itself it will write '1' to
  5372. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5373. * dmae-operations (writing to pram for example.)
  5374. * note: can be done for only function 6,7 but cleaner this
  5375. * way.
  5376. * b. Write zero+valid to the entire ILT.
  5377. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5378. * VNIC3 (of that port). The range allocated will be the
  5379. * entire ILT. This is needed to prevent ILT range error.
  5380. * 2. Any PF driver load flow:
  5381. * a. ILT update with the physical addresses of the allocated
  5382. * logical pages.
  5383. * b. Wait 20msec. - note that this timeout is needed to make
  5384. * sure there are no requests in one of the PXP internal
  5385. * queues with "old" ILT addresses.
  5386. * c. PF enable in the PGLC.
  5387. * d. Clear the was_error of the PF in the PGLC. (could have
  5388. * occured while driver was down)
  5389. * e. PF enable in the CFC (WEAK + STRONG)
  5390. * f. Timers scan enable
  5391. * 3. PF driver unload flow:
  5392. * a. Clear the Timers scan_en.
  5393. * b. Polling for scan_on=0 for that PF.
  5394. * c. Clear the PF enable bit in the PXP.
  5395. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5396. * e. Write zero+valid to all ILT entries (The valid bit must
  5397. * stay set)
  5398. * f. If this is VNIC 3 of a port then also init
  5399. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5400. * to the last enrty in the ILT.
  5401. *
  5402. * Notes:
  5403. * Currently the PF error in the PGLC is non recoverable.
  5404. * In the future the there will be a recovery routine for this error.
  5405. * Currently attention is masked.
  5406. * Having an MCP lock on the load/unload process does not guarantee that
  5407. * there is no Timer disable during Func6/7 enable. This is because the
  5408. * Timers scan is currently being cleared by the MCP on FLR.
  5409. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5410. * there is error before clearing it. But the flow above is simpler and
  5411. * more general.
  5412. * All ILT entries are written by zero+valid and not just PF6/7
  5413. * ILT entries since in the future the ILT entries allocation for
  5414. * PF-s might be dynamic.
  5415. */
  5416. struct ilt_client_info ilt_cli;
  5417. struct bnx2x_ilt ilt;
  5418. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5419. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5420. /* initialize dummy TM client */
  5421. ilt_cli.start = 0;
  5422. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5423. ilt_cli.client_num = ILT_CLIENT_TM;
  5424. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5425. * Step 2: set the timers first/last ilt entry to point
  5426. * to the entire range to prevent ILT range error for 3rd/4th
  5427. * vnic (this code assumes existance of the vnic)
  5428. *
  5429. * both steps performed by call to bnx2x_ilt_client_init_op()
  5430. * with dummy TM client
  5431. *
  5432. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5433. * and his brother are split registers
  5434. */
  5435. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5436. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5437. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5438. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5439. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5440. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5441. }
  5442. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5443. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5444. if (!CHIP_IS_E1x(bp)) {
  5445. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5446. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5447. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5448. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5449. /* let the HW do it's magic ... */
  5450. do {
  5451. msleep(200);
  5452. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5453. } while (factor-- && (val != 1));
  5454. if (val != 1) {
  5455. BNX2X_ERR("ATC_INIT failed\n");
  5456. return -EBUSY;
  5457. }
  5458. }
  5459. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5460. /* clean the DMAE memory */
  5461. bp->dmae_ready = 1;
  5462. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5463. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5464. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5465. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5466. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5467. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5468. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5469. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5470. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5471. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5472. /* QM queues pointers table */
  5473. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5474. /* soft reset pulse */
  5475. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5476. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5477. if (CNIC_SUPPORT(bp))
  5478. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5479. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5480. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5481. if (!CHIP_REV_IS_SLOW(bp))
  5482. /* enable hw interrupt from doorbell Q */
  5483. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5484. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5485. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5486. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5487. if (!CHIP_IS_E1(bp))
  5488. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5489. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5490. if (IS_MF_AFEX(bp)) {
  5491. /* configure that VNTag and VLAN headers must be
  5492. * received in afex mode
  5493. */
  5494. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5495. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5496. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5497. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5498. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5499. } else {
  5500. /* Bit-map indicating which L2 hdrs may appear
  5501. * after the basic Ethernet header
  5502. */
  5503. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5504. bp->path_has_ovlan ? 7 : 6);
  5505. }
  5506. }
  5507. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5508. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5509. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5510. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5511. if (!CHIP_IS_E1x(bp)) {
  5512. /* reset VFC memories */
  5513. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5514. VFC_MEMORIES_RST_REG_CAM_RST |
  5515. VFC_MEMORIES_RST_REG_RAM_RST);
  5516. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5517. VFC_MEMORIES_RST_REG_CAM_RST |
  5518. VFC_MEMORIES_RST_REG_RAM_RST);
  5519. msleep(20);
  5520. }
  5521. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5522. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5523. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5524. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5525. /* sync semi rtc */
  5526. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5527. 0x80000000);
  5528. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5529. 0x80000000);
  5530. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5531. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5532. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5533. if (!CHIP_IS_E1x(bp)) {
  5534. if (IS_MF_AFEX(bp)) {
  5535. /* configure that VNTag and VLAN headers must be
  5536. * sent in afex mode
  5537. */
  5538. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5539. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5540. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5541. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5542. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5543. } else {
  5544. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5545. bp->path_has_ovlan ? 7 : 6);
  5546. }
  5547. }
  5548. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5549. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5550. if (CNIC_SUPPORT(bp)) {
  5551. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5552. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5553. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5554. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5555. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5556. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5557. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5558. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5559. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5560. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5561. }
  5562. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5563. if (sizeof(union cdu_context) != 1024)
  5564. /* we currently assume that a context is 1024 bytes */
  5565. dev_alert(&bp->pdev->dev,
  5566. "please adjust the size of cdu_context(%ld)\n",
  5567. (long)sizeof(union cdu_context));
  5568. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5569. val = (4 << 24) + (0 << 12) + 1024;
  5570. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5571. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5572. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5573. /* enable context validation interrupt from CFC */
  5574. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5575. /* set the thresholds to prevent CFC/CDU race */
  5576. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5577. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5578. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5579. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5580. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5581. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5582. /* Reset PCIE errors for debug */
  5583. REG_WR(bp, 0x2814, 0xffffffff);
  5584. REG_WR(bp, 0x3820, 0xffffffff);
  5585. if (!CHIP_IS_E1x(bp)) {
  5586. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5587. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5588. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5589. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5590. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5591. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5592. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5593. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5594. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5595. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5596. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5597. }
  5598. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5599. if (!CHIP_IS_E1(bp)) {
  5600. /* in E3 this done in per-port section */
  5601. if (!CHIP_IS_E3(bp))
  5602. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5603. }
  5604. if (CHIP_IS_E1H(bp))
  5605. /* not applicable for E2 (and above ...) */
  5606. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5607. if (CHIP_REV_IS_SLOW(bp))
  5608. msleep(200);
  5609. /* finish CFC init */
  5610. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5611. if (val != 1) {
  5612. BNX2X_ERR("CFC LL_INIT failed\n");
  5613. return -EBUSY;
  5614. }
  5615. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5616. if (val != 1) {
  5617. BNX2X_ERR("CFC AC_INIT failed\n");
  5618. return -EBUSY;
  5619. }
  5620. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5621. if (val != 1) {
  5622. BNX2X_ERR("CFC CAM_INIT failed\n");
  5623. return -EBUSY;
  5624. }
  5625. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5626. if (CHIP_IS_E1(bp)) {
  5627. /* read NIG statistic
  5628. to see if this is our first up since powerup */
  5629. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5630. val = *bnx2x_sp(bp, wb_data[0]);
  5631. /* do internal memory self test */
  5632. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5633. BNX2X_ERR("internal mem self test failed\n");
  5634. return -EBUSY;
  5635. }
  5636. }
  5637. bnx2x_setup_fan_failure_detection(bp);
  5638. /* clear PXP2 attentions */
  5639. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5640. bnx2x_enable_blocks_attention(bp);
  5641. bnx2x_enable_blocks_parity(bp);
  5642. if (!BP_NOMCP(bp)) {
  5643. if (CHIP_IS_E1x(bp))
  5644. bnx2x__common_init_phy(bp);
  5645. } else
  5646. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5647. return 0;
  5648. }
  5649. /**
  5650. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5651. *
  5652. * @bp: driver handle
  5653. */
  5654. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5655. {
  5656. int rc = bnx2x_init_hw_common(bp);
  5657. if (rc)
  5658. return rc;
  5659. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5660. if (!BP_NOMCP(bp))
  5661. bnx2x__common_init_phy(bp);
  5662. return 0;
  5663. }
  5664. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5665. {
  5666. int port = BP_PORT(bp);
  5667. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5668. u32 low, high;
  5669. u32 val;
  5670. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5671. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5672. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5673. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5674. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5675. /* Timers bug workaround: disables the pf_master bit in pglue at
  5676. * common phase, we need to enable it here before any dmae access are
  5677. * attempted. Therefore we manually added the enable-master to the
  5678. * port phase (it also happens in the function phase)
  5679. */
  5680. if (!CHIP_IS_E1x(bp))
  5681. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5682. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5683. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5684. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5685. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5686. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5687. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5688. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5689. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5690. /* QM cid (connection) count */
  5691. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5692. if (CNIC_SUPPORT(bp)) {
  5693. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5694. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5695. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5696. }
  5697. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5698. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5699. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5700. if (IS_MF(bp))
  5701. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5702. else if (bp->dev->mtu > 4096) {
  5703. if (bp->flags & ONE_PORT_FLAG)
  5704. low = 160;
  5705. else {
  5706. val = bp->dev->mtu;
  5707. /* (24*1024 + val*4)/256 */
  5708. low = 96 + (val/64) +
  5709. ((val % 64) ? 1 : 0);
  5710. }
  5711. } else
  5712. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5713. high = low + 56; /* 14*1024/256 */
  5714. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5715. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5716. }
  5717. if (CHIP_MODE_IS_4_PORT(bp))
  5718. REG_WR(bp, (BP_PORT(bp) ?
  5719. BRB1_REG_MAC_GUARANTIED_1 :
  5720. BRB1_REG_MAC_GUARANTIED_0), 40);
  5721. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5722. if (CHIP_IS_E3B0(bp)) {
  5723. if (IS_MF_AFEX(bp)) {
  5724. /* configure headers for AFEX mode */
  5725. REG_WR(bp, BP_PORT(bp) ?
  5726. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5727. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5728. REG_WR(bp, BP_PORT(bp) ?
  5729. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5730. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5731. REG_WR(bp, BP_PORT(bp) ?
  5732. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5733. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5734. } else {
  5735. /* Ovlan exists only if we are in multi-function +
  5736. * switch-dependent mode, in switch-independent there
  5737. * is no ovlan headers
  5738. */
  5739. REG_WR(bp, BP_PORT(bp) ?
  5740. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5741. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5742. (bp->path_has_ovlan ? 7 : 6));
  5743. }
  5744. }
  5745. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5746. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5747. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5748. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5749. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5750. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5751. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5752. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5753. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5754. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5755. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5756. if (CHIP_IS_E1x(bp)) {
  5757. /* configure PBF to work without PAUSE mtu 9000 */
  5758. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5759. /* update threshold */
  5760. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5761. /* update init credit */
  5762. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5763. /* probe changes */
  5764. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5765. udelay(50);
  5766. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5767. }
  5768. if (CNIC_SUPPORT(bp))
  5769. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5770. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5771. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5772. if (CHIP_IS_E1(bp)) {
  5773. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5774. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5775. }
  5776. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5777. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5778. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5779. /* init aeu_mask_attn_func_0/1:
  5780. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5781. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5782. * bits 4-7 are used for "per vn group attention" */
  5783. val = IS_MF(bp) ? 0xF7 : 0x7;
  5784. /* Enable DCBX attention for all but E1 */
  5785. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5786. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5787. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5788. if (!CHIP_IS_E1x(bp)) {
  5789. /* Bit-map indicating which L2 hdrs may appear after the
  5790. * basic Ethernet header
  5791. */
  5792. if (IS_MF_AFEX(bp))
  5793. REG_WR(bp, BP_PORT(bp) ?
  5794. NIG_REG_P1_HDRS_AFTER_BASIC :
  5795. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5796. else
  5797. REG_WR(bp, BP_PORT(bp) ?
  5798. NIG_REG_P1_HDRS_AFTER_BASIC :
  5799. NIG_REG_P0_HDRS_AFTER_BASIC,
  5800. IS_MF_SD(bp) ? 7 : 6);
  5801. if (CHIP_IS_E3(bp))
  5802. REG_WR(bp, BP_PORT(bp) ?
  5803. NIG_REG_LLH1_MF_MODE :
  5804. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5805. }
  5806. if (!CHIP_IS_E3(bp))
  5807. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5808. if (!CHIP_IS_E1(bp)) {
  5809. /* 0x2 disable mf_ov, 0x1 enable */
  5810. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5811. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5812. if (!CHIP_IS_E1x(bp)) {
  5813. val = 0;
  5814. switch (bp->mf_mode) {
  5815. case MULTI_FUNCTION_SD:
  5816. val = 1;
  5817. break;
  5818. case MULTI_FUNCTION_SI:
  5819. case MULTI_FUNCTION_AFEX:
  5820. val = 2;
  5821. break;
  5822. }
  5823. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5824. NIG_REG_LLH0_CLS_TYPE), val);
  5825. }
  5826. {
  5827. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5828. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5829. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5830. }
  5831. }
  5832. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5833. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5834. if (val & MISC_SPIO_SPIO5) {
  5835. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5836. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5837. val = REG_RD(bp, reg_addr);
  5838. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5839. REG_WR(bp, reg_addr, val);
  5840. }
  5841. return 0;
  5842. }
  5843. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5844. {
  5845. int reg;
  5846. u32 wb_write[2];
  5847. if (CHIP_IS_E1(bp))
  5848. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5849. else
  5850. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5851. wb_write[0] = ONCHIP_ADDR1(addr);
  5852. wb_write[1] = ONCHIP_ADDR2(addr);
  5853. REG_WR_DMAE(bp, reg, wb_write, 2);
  5854. }
  5855. static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
  5856. u8 idu_sb_id, bool is_Pf)
  5857. {
  5858. u32 data, ctl, cnt = 100;
  5859. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5860. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  5861. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  5862. u32 sb_bit = 1 << (idu_sb_id%32);
  5863. u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  5864. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  5865. /* Not supported in BC mode */
  5866. if (CHIP_INT_MODE_IS_BC(bp))
  5867. return;
  5868. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  5869. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  5870. IGU_REGULAR_CLEANUP_SET |
  5871. IGU_REGULAR_BCLEANUP;
  5872. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  5873. func_encode << IGU_CTRL_REG_FID_SHIFT |
  5874. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  5875. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5876. data, igu_addr_data);
  5877. REG_WR(bp, igu_addr_data, data);
  5878. mmiowb();
  5879. barrier();
  5880. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5881. ctl, igu_addr_ctl);
  5882. REG_WR(bp, igu_addr_ctl, ctl);
  5883. mmiowb();
  5884. barrier();
  5885. /* wait for clean up to finish */
  5886. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  5887. msleep(20);
  5888. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  5889. DP(NETIF_MSG_HW,
  5890. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  5891. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  5892. }
  5893. }
  5894. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5895. {
  5896. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5897. }
  5898. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5899. {
  5900. u32 i, base = FUNC_ILT_BASE(func);
  5901. for (i = base; i < base + ILT_PER_FUNC; i++)
  5902. bnx2x_ilt_wr(bp, i, 0);
  5903. }
  5904. static void bnx2x_init_searcher(struct bnx2x *bp)
  5905. {
  5906. int port = BP_PORT(bp);
  5907. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5908. /* T1 hash bits value determines the T1 number of entries */
  5909. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5910. }
  5911. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  5912. {
  5913. int rc;
  5914. struct bnx2x_func_state_params func_params = {NULL};
  5915. struct bnx2x_func_switch_update_params *switch_update_params =
  5916. &func_params.params.switch_update;
  5917. /* Prepare parameters for function state transitions */
  5918. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  5919. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  5920. func_params.f_obj = &bp->func_obj;
  5921. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  5922. /* Function parameters */
  5923. switch_update_params->suspend = suspend;
  5924. rc = bnx2x_func_state_change(bp, &func_params);
  5925. return rc;
  5926. }
  5927. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  5928. {
  5929. int rc, i, port = BP_PORT(bp);
  5930. int vlan_en = 0, mac_en[NUM_MACS];
  5931. /* Close input from network */
  5932. if (bp->mf_mode == SINGLE_FUNCTION) {
  5933. bnx2x_set_rx_filter(&bp->link_params, 0);
  5934. } else {
  5935. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5936. NIG_REG_LLH0_FUNC_EN);
  5937. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5938. NIG_REG_LLH0_FUNC_EN, 0);
  5939. for (i = 0; i < NUM_MACS; i++) {
  5940. mac_en[i] = REG_RD(bp, port ?
  5941. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5942. 4 * i) :
  5943. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  5944. 4 * i));
  5945. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5946. 4 * i) :
  5947. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  5948. }
  5949. }
  5950. /* Close BMC to host */
  5951. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  5952. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  5953. /* Suspend Tx switching to the PF. Completion of this ramrod
  5954. * further guarantees that all the packets of that PF / child
  5955. * VFs in BRB were processed by the Parser, so it is safe to
  5956. * change the NIC_MODE register.
  5957. */
  5958. rc = bnx2x_func_switch_update(bp, 1);
  5959. if (rc) {
  5960. BNX2X_ERR("Can't suspend tx-switching!\n");
  5961. return rc;
  5962. }
  5963. /* Change NIC_MODE register */
  5964. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  5965. /* Open input from network */
  5966. if (bp->mf_mode == SINGLE_FUNCTION) {
  5967. bnx2x_set_rx_filter(&bp->link_params, 1);
  5968. } else {
  5969. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5970. NIG_REG_LLH0_FUNC_EN, vlan_en);
  5971. for (i = 0; i < NUM_MACS; i++) {
  5972. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5973. 4 * i) :
  5974. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  5975. mac_en[i]);
  5976. }
  5977. }
  5978. /* Enable BMC to host */
  5979. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  5980. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  5981. /* Resume Tx switching to the PF */
  5982. rc = bnx2x_func_switch_update(bp, 0);
  5983. if (rc) {
  5984. BNX2X_ERR("Can't resume tx-switching!\n");
  5985. return rc;
  5986. }
  5987. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  5988. return 0;
  5989. }
  5990. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  5991. {
  5992. int rc;
  5993. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  5994. if (CONFIGURE_NIC_MODE(bp)) {
  5995. /* Configrue searcher as part of function hw init */
  5996. bnx2x_init_searcher(bp);
  5997. /* Reset NIC mode */
  5998. rc = bnx2x_reset_nic_mode(bp);
  5999. if (rc)
  6000. BNX2X_ERR("Can't change NIC mode!\n");
  6001. return rc;
  6002. }
  6003. return 0;
  6004. }
  6005. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6006. {
  6007. int port = BP_PORT(bp);
  6008. int func = BP_FUNC(bp);
  6009. int init_phase = PHASE_PF0 + func;
  6010. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6011. u16 cdu_ilt_start;
  6012. u32 addr, val;
  6013. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6014. int i, main_mem_width, rc;
  6015. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6016. /* FLR cleanup - hmmm */
  6017. if (!CHIP_IS_E1x(bp)) {
  6018. rc = bnx2x_pf_flr_clnup(bp);
  6019. if (rc)
  6020. return rc;
  6021. }
  6022. /* set MSI reconfigure capability */
  6023. if (bp->common.int_block == INT_BLOCK_HC) {
  6024. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6025. val = REG_RD(bp, addr);
  6026. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6027. REG_WR(bp, addr, val);
  6028. }
  6029. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6030. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6031. ilt = BP_ILT(bp);
  6032. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6033. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6034. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6035. ilt->lines[cdu_ilt_start + i].page_mapping =
  6036. bp->context[i].cxt_mapping;
  6037. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6038. }
  6039. bnx2x_ilt_init_op(bp, INITOP_SET);
  6040. if (!CONFIGURE_NIC_MODE(bp)) {
  6041. bnx2x_init_searcher(bp);
  6042. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6043. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6044. } else {
  6045. /* Set NIC mode */
  6046. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6047. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6048. }
  6049. if (!CHIP_IS_E1x(bp)) {
  6050. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6051. /* Turn on a single ISR mode in IGU if driver is going to use
  6052. * INT#x or MSI
  6053. */
  6054. if (!(bp->flags & USING_MSIX_FLAG))
  6055. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6056. /*
  6057. * Timers workaround bug: function init part.
  6058. * Need to wait 20msec after initializing ILT,
  6059. * needed to make sure there are no requests in
  6060. * one of the PXP internal queues with "old" ILT addresses
  6061. */
  6062. msleep(20);
  6063. /*
  6064. * Master enable - Due to WB DMAE writes performed before this
  6065. * register is re-initialized as part of the regular function
  6066. * init
  6067. */
  6068. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6069. /* Enable the function in IGU */
  6070. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6071. }
  6072. bp->dmae_ready = 1;
  6073. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6074. if (!CHIP_IS_E1x(bp))
  6075. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6076. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6077. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6078. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6079. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6080. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6081. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6082. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6083. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6084. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6085. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6086. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6087. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6088. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6089. if (!CHIP_IS_E1x(bp))
  6090. REG_WR(bp, QM_REG_PF_EN, 1);
  6091. if (!CHIP_IS_E1x(bp)) {
  6092. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6093. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6094. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6095. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6096. }
  6097. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6098. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6099. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6100. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6101. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6102. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6103. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6104. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6105. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6106. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6107. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6108. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6109. if (!CHIP_IS_E1x(bp))
  6110. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6111. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6112. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6113. if (!CHIP_IS_E1x(bp))
  6114. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6115. if (IS_MF(bp)) {
  6116. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6117. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6118. }
  6119. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6120. /* HC init per function */
  6121. if (bp->common.int_block == INT_BLOCK_HC) {
  6122. if (CHIP_IS_E1H(bp)) {
  6123. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6124. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6125. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6126. }
  6127. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6128. } else {
  6129. int num_segs, sb_idx, prod_offset;
  6130. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6131. if (!CHIP_IS_E1x(bp)) {
  6132. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6133. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6134. }
  6135. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6136. if (!CHIP_IS_E1x(bp)) {
  6137. int dsb_idx = 0;
  6138. /**
  6139. * Producer memory:
  6140. * E2 mode: address 0-135 match to the mapping memory;
  6141. * 136 - PF0 default prod; 137 - PF1 default prod;
  6142. * 138 - PF2 default prod; 139 - PF3 default prod;
  6143. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6144. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6145. * 144-147 reserved.
  6146. *
  6147. * E1.5 mode - In backward compatible mode;
  6148. * for non default SB; each even line in the memory
  6149. * holds the U producer and each odd line hold
  6150. * the C producer. The first 128 producers are for
  6151. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6152. * producers are for the DSB for each PF.
  6153. * Each PF has five segments: (the order inside each
  6154. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6155. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6156. * 144-147 attn prods;
  6157. */
  6158. /* non-default-status-blocks */
  6159. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6160. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6161. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6162. prod_offset = (bp->igu_base_sb + sb_idx) *
  6163. num_segs;
  6164. for (i = 0; i < num_segs; i++) {
  6165. addr = IGU_REG_PROD_CONS_MEMORY +
  6166. (prod_offset + i) * 4;
  6167. REG_WR(bp, addr, 0);
  6168. }
  6169. /* send consumer update with value 0 */
  6170. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6171. USTORM_ID, 0, IGU_INT_NOP, 1);
  6172. bnx2x_igu_clear_sb(bp,
  6173. bp->igu_base_sb + sb_idx);
  6174. }
  6175. /* default-status-blocks */
  6176. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6177. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6178. if (CHIP_MODE_IS_4_PORT(bp))
  6179. dsb_idx = BP_FUNC(bp);
  6180. else
  6181. dsb_idx = BP_VN(bp);
  6182. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6183. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6184. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6185. /*
  6186. * igu prods come in chunks of E1HVN_MAX (4) -
  6187. * does not matters what is the current chip mode
  6188. */
  6189. for (i = 0; i < (num_segs * E1HVN_MAX);
  6190. i += E1HVN_MAX) {
  6191. addr = IGU_REG_PROD_CONS_MEMORY +
  6192. (prod_offset + i)*4;
  6193. REG_WR(bp, addr, 0);
  6194. }
  6195. /* send consumer update with 0 */
  6196. if (CHIP_INT_MODE_IS_BC(bp)) {
  6197. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6198. USTORM_ID, 0, IGU_INT_NOP, 1);
  6199. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6200. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6201. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6202. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6203. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6204. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6205. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6206. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6207. } else {
  6208. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6209. USTORM_ID, 0, IGU_INT_NOP, 1);
  6210. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6211. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6212. }
  6213. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6214. /* !!! these should become driver const once
  6215. rf-tool supports split-68 const */
  6216. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6217. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6218. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6219. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6220. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6221. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6222. }
  6223. }
  6224. /* Reset PCIE errors for debug */
  6225. REG_WR(bp, 0x2114, 0xffffffff);
  6226. REG_WR(bp, 0x2120, 0xffffffff);
  6227. if (CHIP_IS_E1x(bp)) {
  6228. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6229. main_mem_base = HC_REG_MAIN_MEMORY +
  6230. BP_PORT(bp) * (main_mem_size * 4);
  6231. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6232. main_mem_width = 8;
  6233. val = REG_RD(bp, main_mem_prty_clr);
  6234. if (val)
  6235. DP(NETIF_MSG_HW,
  6236. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6237. val);
  6238. /* Clear "false" parity errors in MSI-X table */
  6239. for (i = main_mem_base;
  6240. i < main_mem_base + main_mem_size * 4;
  6241. i += main_mem_width) {
  6242. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6243. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6244. i, main_mem_width / 4);
  6245. }
  6246. /* Clear HC parity attention */
  6247. REG_RD(bp, main_mem_prty_clr);
  6248. }
  6249. #ifdef BNX2X_STOP_ON_ERROR
  6250. /* Enable STORMs SP logging */
  6251. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6252. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6253. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6254. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6255. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6256. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6257. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6258. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6259. #endif
  6260. bnx2x_phy_probe(&bp->link_params);
  6261. return 0;
  6262. }
  6263. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6264. {
  6265. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6266. if (!CHIP_IS_E1x(bp))
  6267. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6268. sizeof(struct host_hc_status_block_e2));
  6269. else
  6270. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6271. sizeof(struct host_hc_status_block_e1x));
  6272. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6273. }
  6274. void bnx2x_free_mem(struct bnx2x *bp)
  6275. {
  6276. int i;
  6277. /* fastpath */
  6278. bnx2x_free_fp_mem(bp);
  6279. /* end of fastpath */
  6280. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6281. sizeof(struct host_sp_status_block));
  6282. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6283. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6284. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6285. sizeof(struct bnx2x_slowpath));
  6286. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6287. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6288. bp->context[i].size);
  6289. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6290. BNX2X_FREE(bp->ilt->lines);
  6291. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6292. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6293. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6294. }
  6295. static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  6296. {
  6297. int num_groups;
  6298. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  6299. /* number of queues for statistics is number of eth queues + FCoE */
  6300. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  6301. /* Total number of FW statistics requests =
  6302. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  6303. * num of queues
  6304. */
  6305. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  6306. /* Request is built from stats_query_header and an array of
  6307. * stats_query_cmd_group each of which contains
  6308. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  6309. * configured in the stats_query_header.
  6310. */
  6311. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  6312. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  6313. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  6314. num_groups * sizeof(struct stats_query_cmd_group);
  6315. /* Data for statistics requests + stats_conter
  6316. *
  6317. * stats_counter holds per-STORM counters that are incremented
  6318. * when STORM has finished with the current request.
  6319. *
  6320. * memory for FCoE offloaded statistics are counted anyway,
  6321. * even if they will not be sent.
  6322. */
  6323. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  6324. sizeof(struct per_pf_stats) +
  6325. sizeof(struct fcoe_statistics_params) +
  6326. sizeof(struct per_queue_stats) * num_queue_stats +
  6327. sizeof(struct stats_counter);
  6328. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  6329. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6330. /* Set shortcuts */
  6331. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  6332. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  6333. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  6334. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  6335. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  6336. bp->fw_stats_req_sz;
  6337. return 0;
  6338. alloc_mem_err:
  6339. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6340. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6341. BNX2X_ERR("Can't allocate memory\n");
  6342. return -ENOMEM;
  6343. }
  6344. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6345. {
  6346. if (!CHIP_IS_E1x(bp))
  6347. /* size = the status block + ramrod buffers */
  6348. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6349. sizeof(struct host_hc_status_block_e2));
  6350. else
  6351. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6352. &bp->cnic_sb_mapping,
  6353. sizeof(struct
  6354. host_hc_status_block_e1x));
  6355. if (CONFIGURE_NIC_MODE(bp))
  6356. /* allocate searcher T2 table, as it wan't allocated before */
  6357. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6358. /* write address to which L5 should insert its values */
  6359. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6360. &bp->slowpath->drv_info_to_mcp;
  6361. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6362. goto alloc_mem_err;
  6363. return 0;
  6364. alloc_mem_err:
  6365. bnx2x_free_mem_cnic(bp);
  6366. BNX2X_ERR("Can't allocate memory\n");
  6367. return -ENOMEM;
  6368. }
  6369. int bnx2x_alloc_mem(struct bnx2x *bp)
  6370. {
  6371. int i, allocated, context_size;
  6372. if (!CONFIGURE_NIC_MODE(bp))
  6373. /* allocate searcher T2 table */
  6374. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6375. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6376. sizeof(struct host_sp_status_block));
  6377. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6378. sizeof(struct bnx2x_slowpath));
  6379. /* Allocated memory for FW statistics */
  6380. if (bnx2x_alloc_fw_stats_mem(bp))
  6381. goto alloc_mem_err;
  6382. /* Allocate memory for CDU context:
  6383. * This memory is allocated separately and not in the generic ILT
  6384. * functions because CDU differs in few aspects:
  6385. * 1. There are multiple entities allocating memory for context -
  6386. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6387. * its own ILT lines.
  6388. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6389. * for the other ILT clients), to be efficient we want to support
  6390. * allocation of sub-page-size in the last entry.
  6391. * 3. Context pointers are used by the driver to pass to FW / update
  6392. * the context (for the other ILT clients the pointers are used just to
  6393. * free the memory during unload).
  6394. */
  6395. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6396. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6397. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6398. (context_size - allocated));
  6399. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6400. &bp->context[i].cxt_mapping,
  6401. bp->context[i].size);
  6402. allocated += bp->context[i].size;
  6403. }
  6404. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6405. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6406. goto alloc_mem_err;
  6407. /* Slow path ring */
  6408. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6409. /* EQ */
  6410. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6411. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6412. /* fastpath */
  6413. /* need to be done at the end, since it's self adjusting to amount
  6414. * of memory available for RSS queues
  6415. */
  6416. if (bnx2x_alloc_fp_mem(bp))
  6417. goto alloc_mem_err;
  6418. return 0;
  6419. alloc_mem_err:
  6420. bnx2x_free_mem(bp);
  6421. BNX2X_ERR("Can't allocate memory\n");
  6422. return -ENOMEM;
  6423. }
  6424. /*
  6425. * Init service functions
  6426. */
  6427. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6428. struct bnx2x_vlan_mac_obj *obj, bool set,
  6429. int mac_type, unsigned long *ramrod_flags)
  6430. {
  6431. int rc;
  6432. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6433. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6434. /* Fill general parameters */
  6435. ramrod_param.vlan_mac_obj = obj;
  6436. ramrod_param.ramrod_flags = *ramrod_flags;
  6437. /* Fill a user request section if needed */
  6438. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6439. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6440. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6441. /* Set the command: ADD or DEL */
  6442. if (set)
  6443. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6444. else
  6445. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6446. }
  6447. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6448. if (rc == -EEXIST) {
  6449. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6450. /* do not treat adding same MAC as error */
  6451. rc = 0;
  6452. } else if (rc < 0)
  6453. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6454. return rc;
  6455. }
  6456. int bnx2x_del_all_macs(struct bnx2x *bp,
  6457. struct bnx2x_vlan_mac_obj *mac_obj,
  6458. int mac_type, bool wait_for_comp)
  6459. {
  6460. int rc;
  6461. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6462. /* Wait for completion of requested */
  6463. if (wait_for_comp)
  6464. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6465. /* Set the mac type of addresses we want to clear */
  6466. __set_bit(mac_type, &vlan_mac_flags);
  6467. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6468. if (rc < 0)
  6469. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6470. return rc;
  6471. }
  6472. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6473. {
  6474. unsigned long ramrod_flags = 0;
  6475. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6476. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6477. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6478. "Ignoring Zero MAC for STORAGE SD mode\n");
  6479. return 0;
  6480. }
  6481. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6482. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6483. /* Eth MAC is set on RSS leading client (fp[0]) */
  6484. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6485. set, BNX2X_ETH_MAC, &ramrod_flags);
  6486. }
  6487. int bnx2x_setup_leading(struct bnx2x *bp)
  6488. {
  6489. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6490. }
  6491. /**
  6492. * bnx2x_set_int_mode - configure interrupt mode
  6493. *
  6494. * @bp: driver handle
  6495. *
  6496. * In case of MSI-X it will also try to enable MSI-X.
  6497. */
  6498. int bnx2x_set_int_mode(struct bnx2x *bp)
  6499. {
  6500. int rc = 0;
  6501. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6502. return -EINVAL;
  6503. switch (int_mode) {
  6504. case BNX2X_INT_MODE_MSIX:
  6505. /* attempt to enable msix */
  6506. rc = bnx2x_enable_msix(bp);
  6507. /* msix attained */
  6508. if (!rc)
  6509. return 0;
  6510. /* vfs use only msix */
  6511. if (rc && IS_VF(bp))
  6512. return rc;
  6513. /* failed to enable multiple MSI-X */
  6514. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6515. bp->num_queues,
  6516. 1 + bp->num_cnic_queues);
  6517. /* falling through... */
  6518. case BNX2X_INT_MODE_MSI:
  6519. bnx2x_enable_msi(bp);
  6520. /* falling through... */
  6521. case BNX2X_INT_MODE_INTX:
  6522. bp->num_ethernet_queues = 1;
  6523. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6524. BNX2X_DEV_INFO("set number of queues to 1\n");
  6525. break;
  6526. default:
  6527. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6528. return -EINVAL;
  6529. }
  6530. return 0;
  6531. }
  6532. /* must be called prior to any HW initializations */
  6533. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6534. {
  6535. return L2_ILT_LINES(bp);
  6536. }
  6537. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6538. {
  6539. struct ilt_client_info *ilt_client;
  6540. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6541. u16 line = 0;
  6542. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6543. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6544. /* CDU */
  6545. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6546. ilt_client->client_num = ILT_CLIENT_CDU;
  6547. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6548. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6549. ilt_client->start = line;
  6550. line += bnx2x_cid_ilt_lines(bp);
  6551. if (CNIC_SUPPORT(bp))
  6552. line += CNIC_ILT_LINES;
  6553. ilt_client->end = line - 1;
  6554. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6555. ilt_client->start,
  6556. ilt_client->end,
  6557. ilt_client->page_size,
  6558. ilt_client->flags,
  6559. ilog2(ilt_client->page_size >> 12));
  6560. /* QM */
  6561. if (QM_INIT(bp->qm_cid_count)) {
  6562. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6563. ilt_client->client_num = ILT_CLIENT_QM;
  6564. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6565. ilt_client->flags = 0;
  6566. ilt_client->start = line;
  6567. /* 4 bytes for each cid */
  6568. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6569. QM_ILT_PAGE_SZ);
  6570. ilt_client->end = line - 1;
  6571. DP(NETIF_MSG_IFUP,
  6572. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6573. ilt_client->start,
  6574. ilt_client->end,
  6575. ilt_client->page_size,
  6576. ilt_client->flags,
  6577. ilog2(ilt_client->page_size >> 12));
  6578. }
  6579. if (CNIC_SUPPORT(bp)) {
  6580. /* SRC */
  6581. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6582. ilt_client->client_num = ILT_CLIENT_SRC;
  6583. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6584. ilt_client->flags = 0;
  6585. ilt_client->start = line;
  6586. line += SRC_ILT_LINES;
  6587. ilt_client->end = line - 1;
  6588. DP(NETIF_MSG_IFUP,
  6589. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6590. ilt_client->start,
  6591. ilt_client->end,
  6592. ilt_client->page_size,
  6593. ilt_client->flags,
  6594. ilog2(ilt_client->page_size >> 12));
  6595. /* TM */
  6596. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6597. ilt_client->client_num = ILT_CLIENT_TM;
  6598. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6599. ilt_client->flags = 0;
  6600. ilt_client->start = line;
  6601. line += TM_ILT_LINES;
  6602. ilt_client->end = line - 1;
  6603. DP(NETIF_MSG_IFUP,
  6604. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6605. ilt_client->start,
  6606. ilt_client->end,
  6607. ilt_client->page_size,
  6608. ilt_client->flags,
  6609. ilog2(ilt_client->page_size >> 12));
  6610. }
  6611. BUG_ON(line > ILT_MAX_LINES);
  6612. }
  6613. /**
  6614. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6615. *
  6616. * @bp: driver handle
  6617. * @fp: pointer to fastpath
  6618. * @init_params: pointer to parameters structure
  6619. *
  6620. * parameters configured:
  6621. * - HC configuration
  6622. * - Queue's CDU context
  6623. */
  6624. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6625. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6626. {
  6627. u8 cos;
  6628. int cxt_index, cxt_offset;
  6629. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6630. if (!IS_FCOE_FP(fp)) {
  6631. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6632. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6633. /* If HC is supporterd, enable host coalescing in the transition
  6634. * to INIT state.
  6635. */
  6636. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6637. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6638. /* HC rate */
  6639. init_params->rx.hc_rate = bp->rx_ticks ?
  6640. (1000000 / bp->rx_ticks) : 0;
  6641. init_params->tx.hc_rate = bp->tx_ticks ?
  6642. (1000000 / bp->tx_ticks) : 0;
  6643. /* FW SB ID */
  6644. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6645. fp->fw_sb_id;
  6646. /*
  6647. * CQ index among the SB indices: FCoE clients uses the default
  6648. * SB, therefore it's different.
  6649. */
  6650. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6651. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6652. }
  6653. /* set maximum number of COSs supported by this queue */
  6654. init_params->max_cos = fp->max_cos;
  6655. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6656. fp->index, init_params->max_cos);
  6657. /* set the context pointers queue object */
  6658. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6659. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6660. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6661. ILT_PAGE_CIDS);
  6662. init_params->cxts[cos] =
  6663. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6664. }
  6665. }
  6666. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6667. struct bnx2x_queue_state_params *q_params,
  6668. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6669. int tx_index, bool leading)
  6670. {
  6671. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6672. /* Set the command */
  6673. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6674. /* Set tx-only QUEUE flags: don't zero statistics */
  6675. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6676. /* choose the index of the cid to send the slow path on */
  6677. tx_only_params->cid_index = tx_index;
  6678. /* Set general TX_ONLY_SETUP parameters */
  6679. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6680. /* Set Tx TX_ONLY_SETUP parameters */
  6681. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6682. DP(NETIF_MSG_IFUP,
  6683. "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",
  6684. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6685. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6686. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6687. /* send the ramrod */
  6688. return bnx2x_queue_state_change(bp, q_params);
  6689. }
  6690. /**
  6691. * bnx2x_setup_queue - setup queue
  6692. *
  6693. * @bp: driver handle
  6694. * @fp: pointer to fastpath
  6695. * @leading: is leading
  6696. *
  6697. * This function performs 2 steps in a Queue state machine
  6698. * actually: 1) RESET->INIT 2) INIT->SETUP
  6699. */
  6700. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6701. bool leading)
  6702. {
  6703. struct bnx2x_queue_state_params q_params = {NULL};
  6704. struct bnx2x_queue_setup_params *setup_params =
  6705. &q_params.params.setup;
  6706. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6707. &q_params.params.tx_only;
  6708. int rc;
  6709. u8 tx_index;
  6710. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6711. /* reset IGU state skip FCoE L2 queue */
  6712. if (!IS_FCOE_FP(fp))
  6713. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6714. IGU_INT_ENABLE, 0);
  6715. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6716. /* We want to wait for completion in this context */
  6717. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6718. /* Prepare the INIT parameters */
  6719. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6720. /* Set the command */
  6721. q_params.cmd = BNX2X_Q_CMD_INIT;
  6722. /* Change the state to INIT */
  6723. rc = bnx2x_queue_state_change(bp, &q_params);
  6724. if (rc) {
  6725. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6726. return rc;
  6727. }
  6728. DP(NETIF_MSG_IFUP, "init complete\n");
  6729. /* Now move the Queue to the SETUP state... */
  6730. memset(setup_params, 0, sizeof(*setup_params));
  6731. /* Set QUEUE flags */
  6732. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6733. /* Set general SETUP parameters */
  6734. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6735. FIRST_TX_COS_INDEX);
  6736. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6737. &setup_params->rxq_params);
  6738. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6739. FIRST_TX_COS_INDEX);
  6740. /* Set the command */
  6741. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6742. if (IS_FCOE_FP(fp))
  6743. bp->fcoe_init = true;
  6744. /* Change the state to SETUP */
  6745. rc = bnx2x_queue_state_change(bp, &q_params);
  6746. if (rc) {
  6747. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6748. return rc;
  6749. }
  6750. /* loop through the relevant tx-only indices */
  6751. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6752. tx_index < fp->max_cos;
  6753. tx_index++) {
  6754. /* prepare and send tx-only ramrod*/
  6755. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6756. tx_only_params, tx_index, leading);
  6757. if (rc) {
  6758. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6759. fp->index, tx_index);
  6760. return rc;
  6761. }
  6762. }
  6763. return rc;
  6764. }
  6765. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6766. {
  6767. struct bnx2x_fastpath *fp = &bp->fp[index];
  6768. struct bnx2x_fp_txdata *txdata;
  6769. struct bnx2x_queue_state_params q_params = {NULL};
  6770. int rc, tx_index;
  6771. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6772. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6773. /* We want to wait for completion in this context */
  6774. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6775. /* close tx-only connections */
  6776. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6777. tx_index < fp->max_cos;
  6778. tx_index++){
  6779. /* ascertain this is a normal queue*/
  6780. txdata = fp->txdata_ptr[tx_index];
  6781. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6782. txdata->txq_index);
  6783. /* send halt terminate on tx-only connection */
  6784. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6785. memset(&q_params.params.terminate, 0,
  6786. sizeof(q_params.params.terminate));
  6787. q_params.params.terminate.cid_index = tx_index;
  6788. rc = bnx2x_queue_state_change(bp, &q_params);
  6789. if (rc)
  6790. return rc;
  6791. /* send halt terminate on tx-only connection */
  6792. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6793. memset(&q_params.params.cfc_del, 0,
  6794. sizeof(q_params.params.cfc_del));
  6795. q_params.params.cfc_del.cid_index = tx_index;
  6796. rc = bnx2x_queue_state_change(bp, &q_params);
  6797. if (rc)
  6798. return rc;
  6799. }
  6800. /* Stop the primary connection: */
  6801. /* ...halt the connection */
  6802. q_params.cmd = BNX2X_Q_CMD_HALT;
  6803. rc = bnx2x_queue_state_change(bp, &q_params);
  6804. if (rc)
  6805. return rc;
  6806. /* ...terminate the connection */
  6807. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6808. memset(&q_params.params.terminate, 0,
  6809. sizeof(q_params.params.terminate));
  6810. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6811. rc = bnx2x_queue_state_change(bp, &q_params);
  6812. if (rc)
  6813. return rc;
  6814. /* ...delete cfc entry */
  6815. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6816. memset(&q_params.params.cfc_del, 0,
  6817. sizeof(q_params.params.cfc_del));
  6818. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6819. return bnx2x_queue_state_change(bp, &q_params);
  6820. }
  6821. static void bnx2x_reset_func(struct bnx2x *bp)
  6822. {
  6823. int port = BP_PORT(bp);
  6824. int func = BP_FUNC(bp);
  6825. int i;
  6826. /* Disable the function in the FW */
  6827. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6828. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6829. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6830. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6831. /* FP SBs */
  6832. for_each_eth_queue(bp, i) {
  6833. struct bnx2x_fastpath *fp = &bp->fp[i];
  6834. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6835. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6836. SB_DISABLED);
  6837. }
  6838. if (CNIC_LOADED(bp))
  6839. /* CNIC SB */
  6840. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6841. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6842. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6843. /* SP SB */
  6844. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6845. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6846. SB_DISABLED);
  6847. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6848. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6849. 0);
  6850. /* Configure IGU */
  6851. if (bp->common.int_block == INT_BLOCK_HC) {
  6852. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6853. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6854. } else {
  6855. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6856. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6857. }
  6858. if (CNIC_LOADED(bp)) {
  6859. /* Disable Timer scan */
  6860. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6861. /*
  6862. * Wait for at least 10ms and up to 2 second for the timers
  6863. * scan to complete
  6864. */
  6865. for (i = 0; i < 200; i++) {
  6866. msleep(10);
  6867. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6868. break;
  6869. }
  6870. }
  6871. /* Clear ILT */
  6872. bnx2x_clear_func_ilt(bp, func);
  6873. /* Timers workaround bug for E2: if this is vnic-3,
  6874. * we need to set the entire ilt range for this timers.
  6875. */
  6876. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6877. struct ilt_client_info ilt_cli;
  6878. /* use dummy TM client */
  6879. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6880. ilt_cli.start = 0;
  6881. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6882. ilt_cli.client_num = ILT_CLIENT_TM;
  6883. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6884. }
  6885. /* this assumes that reset_port() called before reset_func()*/
  6886. if (!CHIP_IS_E1x(bp))
  6887. bnx2x_pf_disable(bp);
  6888. bp->dmae_ready = 0;
  6889. }
  6890. static void bnx2x_reset_port(struct bnx2x *bp)
  6891. {
  6892. int port = BP_PORT(bp);
  6893. u32 val;
  6894. /* Reset physical Link */
  6895. bnx2x__link_reset(bp);
  6896. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6897. /* Do not rcv packets to BRB */
  6898. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6899. /* Do not direct rcv packets that are not for MCP to the BRB */
  6900. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6901. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6902. /* Configure AEU */
  6903. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6904. msleep(100);
  6905. /* Check for BRB port occupancy */
  6906. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6907. if (val)
  6908. DP(NETIF_MSG_IFDOWN,
  6909. "BRB1 is not empty %d blocks are occupied\n", val);
  6910. /* TODO: Close Doorbell port? */
  6911. }
  6912. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6913. {
  6914. struct bnx2x_func_state_params func_params = {NULL};
  6915. /* Prepare parameters for function state transitions */
  6916. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6917. func_params.f_obj = &bp->func_obj;
  6918. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6919. func_params.params.hw_init.load_phase = load_code;
  6920. return bnx2x_func_state_change(bp, &func_params);
  6921. }
  6922. static int bnx2x_func_stop(struct bnx2x *bp)
  6923. {
  6924. struct bnx2x_func_state_params func_params = {NULL};
  6925. int rc;
  6926. /* Prepare parameters for function state transitions */
  6927. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6928. func_params.f_obj = &bp->func_obj;
  6929. func_params.cmd = BNX2X_F_CMD_STOP;
  6930. /*
  6931. * Try to stop the function the 'good way'. If fails (in case
  6932. * of a parity error during bnx2x_chip_cleanup()) and we are
  6933. * not in a debug mode, perform a state transaction in order to
  6934. * enable further HW_RESET transaction.
  6935. */
  6936. rc = bnx2x_func_state_change(bp, &func_params);
  6937. if (rc) {
  6938. #ifdef BNX2X_STOP_ON_ERROR
  6939. return rc;
  6940. #else
  6941. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6942. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6943. return bnx2x_func_state_change(bp, &func_params);
  6944. #endif
  6945. }
  6946. return 0;
  6947. }
  6948. /**
  6949. * bnx2x_send_unload_req - request unload mode from the MCP.
  6950. *
  6951. * @bp: driver handle
  6952. * @unload_mode: requested function's unload mode
  6953. *
  6954. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6955. */
  6956. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6957. {
  6958. u32 reset_code = 0;
  6959. int port = BP_PORT(bp);
  6960. /* Select the UNLOAD request mode */
  6961. if (unload_mode == UNLOAD_NORMAL)
  6962. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6963. else if (bp->flags & NO_WOL_FLAG)
  6964. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6965. else if (bp->wol) {
  6966. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6967. u8 *mac_addr = bp->dev->dev_addr;
  6968. u32 val;
  6969. u16 pmc;
  6970. /* The mac address is written to entries 1-4 to
  6971. * preserve entry 0 which is used by the PMF
  6972. */
  6973. u8 entry = (BP_VN(bp) + 1)*8;
  6974. val = (mac_addr[0] << 8) | mac_addr[1];
  6975. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6976. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6977. (mac_addr[4] << 8) | mac_addr[5];
  6978. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6979. /* Enable the PME and clear the status */
  6980. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6981. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6982. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6983. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6984. } else
  6985. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6986. /* Send the request to the MCP */
  6987. if (!BP_NOMCP(bp))
  6988. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6989. else {
  6990. int path = BP_PATH(bp);
  6991. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  6992. path, load_count[path][0], load_count[path][1],
  6993. load_count[path][2]);
  6994. load_count[path][0]--;
  6995. load_count[path][1 + port]--;
  6996. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  6997. path, load_count[path][0], load_count[path][1],
  6998. load_count[path][2]);
  6999. if (load_count[path][0] == 0)
  7000. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7001. else if (load_count[path][1 + port] == 0)
  7002. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7003. else
  7004. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7005. }
  7006. return reset_code;
  7007. }
  7008. /**
  7009. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7010. *
  7011. * @bp: driver handle
  7012. * @keep_link: true iff link should be kept up
  7013. */
  7014. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7015. {
  7016. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7017. /* Report UNLOAD_DONE to MCP */
  7018. if (!BP_NOMCP(bp))
  7019. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7020. }
  7021. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7022. {
  7023. int tout = 50;
  7024. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7025. if (!bp->port.pmf)
  7026. return 0;
  7027. /*
  7028. * (assumption: No Attention from MCP at this stage)
  7029. * PMF probably in the middle of TXdisable/enable transaction
  7030. * 1. Sync IRS for default SB
  7031. * 2. Sync SP queue - this guarantes us that attention handling started
  7032. * 3. Wait, that TXdisable/enable transaction completes
  7033. *
  7034. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7035. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7036. * received complettion for the transaction the state is TX_STOPPED.
  7037. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7038. * transaction.
  7039. */
  7040. /* make sure default SB ISR is done */
  7041. if (msix)
  7042. synchronize_irq(bp->msix_table[0].vector);
  7043. else
  7044. synchronize_irq(bp->pdev->irq);
  7045. flush_workqueue(bnx2x_wq);
  7046. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7047. BNX2X_F_STATE_STARTED && tout--)
  7048. msleep(20);
  7049. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7050. BNX2X_F_STATE_STARTED) {
  7051. #ifdef BNX2X_STOP_ON_ERROR
  7052. BNX2X_ERR("Wrong function state\n");
  7053. return -EBUSY;
  7054. #else
  7055. /*
  7056. * Failed to complete the transaction in a "good way"
  7057. * Force both transactions with CLR bit
  7058. */
  7059. struct bnx2x_func_state_params func_params = {NULL};
  7060. DP(NETIF_MSG_IFDOWN,
  7061. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7062. func_params.f_obj = &bp->func_obj;
  7063. __set_bit(RAMROD_DRV_CLR_ONLY,
  7064. &func_params.ramrod_flags);
  7065. /* STARTED-->TX_ST0PPED */
  7066. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7067. bnx2x_func_state_change(bp, &func_params);
  7068. /* TX_ST0PPED-->STARTED */
  7069. func_params.cmd = BNX2X_F_CMD_TX_START;
  7070. return bnx2x_func_state_change(bp, &func_params);
  7071. #endif
  7072. }
  7073. return 0;
  7074. }
  7075. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7076. {
  7077. int port = BP_PORT(bp);
  7078. int i, rc = 0;
  7079. u8 cos;
  7080. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7081. u32 reset_code;
  7082. /* Wait until tx fastpath tasks complete */
  7083. for_each_tx_queue(bp, i) {
  7084. struct bnx2x_fastpath *fp = &bp->fp[i];
  7085. for_each_cos_in_tx_queue(fp, cos)
  7086. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7087. #ifdef BNX2X_STOP_ON_ERROR
  7088. if (rc)
  7089. return;
  7090. #endif
  7091. }
  7092. /* Give HW time to discard old tx messages */
  7093. usleep_range(1000, 1000);
  7094. /* Clean all ETH MACs */
  7095. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7096. false);
  7097. if (rc < 0)
  7098. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7099. /* Clean up UC list */
  7100. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7101. true);
  7102. if (rc < 0)
  7103. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7104. rc);
  7105. /* Disable LLH */
  7106. if (!CHIP_IS_E1(bp))
  7107. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7108. /* Set "drop all" (stop Rx).
  7109. * We need to take a netif_addr_lock() here in order to prevent
  7110. * a race between the completion code and this code.
  7111. */
  7112. netif_addr_lock_bh(bp->dev);
  7113. /* Schedule the rx_mode command */
  7114. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7115. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7116. else
  7117. bnx2x_set_storm_rx_mode(bp);
  7118. /* Cleanup multicast configuration */
  7119. rparam.mcast_obj = &bp->mcast_obj;
  7120. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7121. if (rc < 0)
  7122. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7123. netif_addr_unlock_bh(bp->dev);
  7124. /*
  7125. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7126. * this function should perform FUNC, PORT or COMMON HW
  7127. * reset.
  7128. */
  7129. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7130. /*
  7131. * (assumption: No Attention from MCP at this stage)
  7132. * PMF probably in the middle of TXdisable/enable transaction
  7133. */
  7134. rc = bnx2x_func_wait_started(bp);
  7135. if (rc) {
  7136. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7137. #ifdef BNX2X_STOP_ON_ERROR
  7138. return;
  7139. #endif
  7140. }
  7141. /* Close multi and leading connections
  7142. * Completions for ramrods are collected in a synchronous way
  7143. */
  7144. for_each_eth_queue(bp, i)
  7145. if (bnx2x_stop_queue(bp, i))
  7146. #ifdef BNX2X_STOP_ON_ERROR
  7147. return;
  7148. #else
  7149. goto unload_error;
  7150. #endif
  7151. if (CNIC_LOADED(bp)) {
  7152. for_each_cnic_queue(bp, i)
  7153. if (bnx2x_stop_queue(bp, i))
  7154. #ifdef BNX2X_STOP_ON_ERROR
  7155. return;
  7156. #else
  7157. goto unload_error;
  7158. #endif
  7159. }
  7160. /* If SP settings didn't get completed so far - something
  7161. * very wrong has happen.
  7162. */
  7163. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7164. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7165. #ifndef BNX2X_STOP_ON_ERROR
  7166. unload_error:
  7167. #endif
  7168. rc = bnx2x_func_stop(bp);
  7169. if (rc) {
  7170. BNX2X_ERR("Function stop failed!\n");
  7171. #ifdef BNX2X_STOP_ON_ERROR
  7172. return;
  7173. #endif
  7174. }
  7175. /* Disable HW interrupts, NAPI */
  7176. bnx2x_netif_stop(bp, 1);
  7177. /* Delete all NAPI objects */
  7178. bnx2x_del_all_napi(bp);
  7179. if (CNIC_LOADED(bp))
  7180. bnx2x_del_all_napi_cnic(bp);
  7181. /* Release IRQs */
  7182. bnx2x_free_irq(bp);
  7183. /* Reset the chip */
  7184. rc = bnx2x_reset_hw(bp, reset_code);
  7185. if (rc)
  7186. BNX2X_ERR("HW_RESET failed\n");
  7187. /* Report UNLOAD_DONE to MCP */
  7188. bnx2x_send_unload_done(bp, keep_link);
  7189. }
  7190. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7191. {
  7192. u32 val;
  7193. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7194. if (CHIP_IS_E1(bp)) {
  7195. int port = BP_PORT(bp);
  7196. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7197. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7198. val = REG_RD(bp, addr);
  7199. val &= ~(0x300);
  7200. REG_WR(bp, addr, val);
  7201. } else {
  7202. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7203. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7204. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7205. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7206. }
  7207. }
  7208. /* Close gates #2, #3 and #4: */
  7209. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7210. {
  7211. u32 val;
  7212. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7213. if (!CHIP_IS_E1(bp)) {
  7214. /* #4 */
  7215. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7216. /* #2 */
  7217. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7218. }
  7219. /* #3 */
  7220. if (CHIP_IS_E1x(bp)) {
  7221. /* Prevent interrupts from HC on both ports */
  7222. val = REG_RD(bp, HC_REG_CONFIG_1);
  7223. REG_WR(bp, HC_REG_CONFIG_1,
  7224. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7225. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7226. val = REG_RD(bp, HC_REG_CONFIG_0);
  7227. REG_WR(bp, HC_REG_CONFIG_0,
  7228. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7229. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7230. } else {
  7231. /* Prevent incomming interrupts in IGU */
  7232. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7233. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7234. (!close) ?
  7235. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7236. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7237. }
  7238. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7239. close ? "closing" : "opening");
  7240. mmiowb();
  7241. }
  7242. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7243. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7244. {
  7245. /* Do some magic... */
  7246. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7247. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7248. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7249. }
  7250. /**
  7251. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7252. *
  7253. * @bp: driver handle
  7254. * @magic_val: old value of the `magic' bit.
  7255. */
  7256. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7257. {
  7258. /* Restore the `magic' bit value... */
  7259. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7260. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7261. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7262. }
  7263. /**
  7264. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7265. *
  7266. * @bp: driver handle
  7267. * @magic_val: old value of 'magic' bit.
  7268. *
  7269. * Takes care of CLP configurations.
  7270. */
  7271. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7272. {
  7273. u32 shmem;
  7274. u32 validity_offset;
  7275. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7276. /* Set `magic' bit in order to save MF config */
  7277. if (!CHIP_IS_E1(bp))
  7278. bnx2x_clp_reset_prep(bp, magic_val);
  7279. /* Get shmem offset */
  7280. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7281. validity_offset =
  7282. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7283. /* Clear validity map flags */
  7284. if (shmem > 0)
  7285. REG_WR(bp, shmem + validity_offset, 0);
  7286. }
  7287. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7288. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7289. /**
  7290. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7291. *
  7292. * @bp: driver handle
  7293. */
  7294. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7295. {
  7296. /* special handling for emulation and FPGA,
  7297. wait 10 times longer */
  7298. if (CHIP_REV_IS_SLOW(bp))
  7299. msleep(MCP_ONE_TIMEOUT*10);
  7300. else
  7301. msleep(MCP_ONE_TIMEOUT);
  7302. }
  7303. /*
  7304. * initializes bp->common.shmem_base and waits for validity signature to appear
  7305. */
  7306. static int bnx2x_init_shmem(struct bnx2x *bp)
  7307. {
  7308. int cnt = 0;
  7309. u32 val = 0;
  7310. do {
  7311. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7312. if (bp->common.shmem_base) {
  7313. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7314. if (val & SHR_MEM_VALIDITY_MB)
  7315. return 0;
  7316. }
  7317. bnx2x_mcp_wait_one(bp);
  7318. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7319. BNX2X_ERR("BAD MCP validity signature\n");
  7320. return -ENODEV;
  7321. }
  7322. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7323. {
  7324. int rc = bnx2x_init_shmem(bp);
  7325. /* Restore the `magic' bit value */
  7326. if (!CHIP_IS_E1(bp))
  7327. bnx2x_clp_reset_done(bp, magic_val);
  7328. return rc;
  7329. }
  7330. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7331. {
  7332. if (!CHIP_IS_E1(bp)) {
  7333. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7334. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7335. mmiowb();
  7336. }
  7337. }
  7338. /*
  7339. * Reset the whole chip except for:
  7340. * - PCIE core
  7341. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7342. * one reset bit)
  7343. * - IGU
  7344. * - MISC (including AEU)
  7345. * - GRC
  7346. * - RBCN, RBCP
  7347. */
  7348. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7349. {
  7350. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7351. u32 global_bits2, stay_reset2;
  7352. /*
  7353. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7354. * (per chip) blocks.
  7355. */
  7356. global_bits2 =
  7357. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7358. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7359. /* Don't reset the following blocks.
  7360. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7361. * reset, as in 4 port device they might still be owned
  7362. * by the MCP (there is only one leader per path).
  7363. */
  7364. not_reset_mask1 =
  7365. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7366. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7367. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7368. not_reset_mask2 =
  7369. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7370. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7371. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7372. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7373. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7374. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7375. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7376. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7377. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7378. MISC_REGISTERS_RESET_REG_2_PGLC |
  7379. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7380. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7381. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7382. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7383. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7384. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7385. /*
  7386. * Keep the following blocks in reset:
  7387. * - all xxMACs are handled by the bnx2x_link code.
  7388. */
  7389. stay_reset2 =
  7390. MISC_REGISTERS_RESET_REG_2_XMAC |
  7391. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7392. /* Full reset masks according to the chip */
  7393. reset_mask1 = 0xffffffff;
  7394. if (CHIP_IS_E1(bp))
  7395. reset_mask2 = 0xffff;
  7396. else if (CHIP_IS_E1H(bp))
  7397. reset_mask2 = 0x1ffff;
  7398. else if (CHIP_IS_E2(bp))
  7399. reset_mask2 = 0xfffff;
  7400. else /* CHIP_IS_E3 */
  7401. reset_mask2 = 0x3ffffff;
  7402. /* Don't reset global blocks unless we need to */
  7403. if (!global)
  7404. reset_mask2 &= ~global_bits2;
  7405. /*
  7406. * In case of attention in the QM, we need to reset PXP
  7407. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7408. * because otherwise QM reset would release 'close the gates' shortly
  7409. * before resetting the PXP, then the PSWRQ would send a write
  7410. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7411. * read the payload data from PSWWR, but PSWWR would not
  7412. * respond. The write queue in PGLUE would stuck, dmae commands
  7413. * would not return. Therefore it's important to reset the second
  7414. * reset register (containing the
  7415. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7416. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7417. * bit).
  7418. */
  7419. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7420. reset_mask2 & (~not_reset_mask2));
  7421. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7422. reset_mask1 & (~not_reset_mask1));
  7423. barrier();
  7424. mmiowb();
  7425. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7426. reset_mask2 & (~stay_reset2));
  7427. barrier();
  7428. mmiowb();
  7429. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7430. mmiowb();
  7431. }
  7432. /**
  7433. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7434. * It should get cleared in no more than 1s.
  7435. *
  7436. * @bp: driver handle
  7437. *
  7438. * It should get cleared in no more than 1s. Returns 0 if
  7439. * pending writes bit gets cleared.
  7440. */
  7441. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7442. {
  7443. u32 cnt = 1000;
  7444. u32 pend_bits = 0;
  7445. do {
  7446. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7447. if (pend_bits == 0)
  7448. break;
  7449. usleep_range(1000, 1000);
  7450. } while (cnt-- > 0);
  7451. if (cnt <= 0) {
  7452. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7453. pend_bits);
  7454. return -EBUSY;
  7455. }
  7456. return 0;
  7457. }
  7458. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7459. {
  7460. int cnt = 1000;
  7461. u32 val = 0;
  7462. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7463. u32 tags_63_32 = 0;
  7464. /* Empty the Tetris buffer, wait for 1s */
  7465. do {
  7466. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7467. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7468. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7469. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7470. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7471. if (CHIP_IS_E3(bp))
  7472. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7473. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7474. ((port_is_idle_0 & 0x1) == 0x1) &&
  7475. ((port_is_idle_1 & 0x1) == 0x1) &&
  7476. (pgl_exp_rom2 == 0xffffffff) &&
  7477. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7478. break;
  7479. usleep_range(1000, 1000);
  7480. } while (cnt-- > 0);
  7481. if (cnt <= 0) {
  7482. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7483. 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",
  7484. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7485. pgl_exp_rom2);
  7486. return -EAGAIN;
  7487. }
  7488. barrier();
  7489. /* Close gates #2, #3 and #4 */
  7490. bnx2x_set_234_gates(bp, true);
  7491. /* Poll for IGU VQs for 57712 and newer chips */
  7492. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7493. return -EAGAIN;
  7494. /* TBD: Indicate that "process kill" is in progress to MCP */
  7495. /* Clear "unprepared" bit */
  7496. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7497. barrier();
  7498. /* Make sure all is written to the chip before the reset */
  7499. mmiowb();
  7500. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7501. * PSWHST, GRC and PSWRD Tetris buffer.
  7502. */
  7503. usleep_range(1000, 1000);
  7504. /* Prepare to chip reset: */
  7505. /* MCP */
  7506. if (global)
  7507. bnx2x_reset_mcp_prep(bp, &val);
  7508. /* PXP */
  7509. bnx2x_pxp_prep(bp);
  7510. barrier();
  7511. /* reset the chip */
  7512. bnx2x_process_kill_chip_reset(bp, global);
  7513. barrier();
  7514. /* Recover after reset: */
  7515. /* MCP */
  7516. if (global && bnx2x_reset_mcp_comp(bp, val))
  7517. return -EAGAIN;
  7518. /* TBD: Add resetting the NO_MCP mode DB here */
  7519. /* Open the gates #2, #3 and #4 */
  7520. bnx2x_set_234_gates(bp, false);
  7521. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7522. * reset state, re-enable attentions. */
  7523. return 0;
  7524. }
  7525. static int bnx2x_leader_reset(struct bnx2x *bp)
  7526. {
  7527. int rc = 0;
  7528. bool global = bnx2x_reset_is_global(bp);
  7529. u32 load_code;
  7530. /* if not going to reset MCP - load "fake" driver to reset HW while
  7531. * driver is owner of the HW
  7532. */
  7533. if (!global && !BP_NOMCP(bp)) {
  7534. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7535. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7536. if (!load_code) {
  7537. BNX2X_ERR("MCP response failure, aborting\n");
  7538. rc = -EAGAIN;
  7539. goto exit_leader_reset;
  7540. }
  7541. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7542. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7543. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7544. rc = -EAGAIN;
  7545. goto exit_leader_reset2;
  7546. }
  7547. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7548. if (!load_code) {
  7549. BNX2X_ERR("MCP response failure, aborting\n");
  7550. rc = -EAGAIN;
  7551. goto exit_leader_reset2;
  7552. }
  7553. }
  7554. /* Try to recover after the failure */
  7555. if (bnx2x_process_kill(bp, global)) {
  7556. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7557. BP_PATH(bp));
  7558. rc = -EAGAIN;
  7559. goto exit_leader_reset2;
  7560. }
  7561. /*
  7562. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7563. * state.
  7564. */
  7565. bnx2x_set_reset_done(bp);
  7566. if (global)
  7567. bnx2x_clear_reset_global(bp);
  7568. exit_leader_reset2:
  7569. /* unload "fake driver" if it was loaded */
  7570. if (!global && !BP_NOMCP(bp)) {
  7571. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7572. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7573. }
  7574. exit_leader_reset:
  7575. bp->is_leader = 0;
  7576. bnx2x_release_leader_lock(bp);
  7577. smp_mb();
  7578. return rc;
  7579. }
  7580. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7581. {
  7582. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7583. /* Disconnect this device */
  7584. netif_device_detach(bp->dev);
  7585. /*
  7586. * Block ifup for all function on this engine until "process kill"
  7587. * or power cycle.
  7588. */
  7589. bnx2x_set_reset_in_progress(bp);
  7590. /* Shut down the power */
  7591. bnx2x_set_power_state(bp, PCI_D3hot);
  7592. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7593. smp_mb();
  7594. }
  7595. /*
  7596. * Assumption: runs under rtnl lock. This together with the fact
  7597. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7598. * will never be called when netif_running(bp->dev) is false.
  7599. */
  7600. static void bnx2x_parity_recover(struct bnx2x *bp)
  7601. {
  7602. bool global = false;
  7603. u32 error_recovered, error_unrecovered;
  7604. bool is_parity;
  7605. DP(NETIF_MSG_HW, "Handling parity\n");
  7606. while (1) {
  7607. switch (bp->recovery_state) {
  7608. case BNX2X_RECOVERY_INIT:
  7609. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7610. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7611. WARN_ON(!is_parity);
  7612. /* Try to get a LEADER_LOCK HW lock */
  7613. if (bnx2x_trylock_leader_lock(bp)) {
  7614. bnx2x_set_reset_in_progress(bp);
  7615. /*
  7616. * Check if there is a global attention and if
  7617. * there was a global attention, set the global
  7618. * reset bit.
  7619. */
  7620. if (global)
  7621. bnx2x_set_reset_global(bp);
  7622. bp->is_leader = 1;
  7623. }
  7624. /* Stop the driver */
  7625. /* If interface has been removed - break */
  7626. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7627. return;
  7628. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7629. /* Ensure "is_leader", MCP command sequence and
  7630. * "recovery_state" update values are seen on other
  7631. * CPUs.
  7632. */
  7633. smp_mb();
  7634. break;
  7635. case BNX2X_RECOVERY_WAIT:
  7636. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7637. if (bp->is_leader) {
  7638. int other_engine = BP_PATH(bp) ? 0 : 1;
  7639. bool other_load_status =
  7640. bnx2x_get_load_status(bp, other_engine);
  7641. bool load_status =
  7642. bnx2x_get_load_status(bp, BP_PATH(bp));
  7643. global = bnx2x_reset_is_global(bp);
  7644. /*
  7645. * In case of a parity in a global block, let
  7646. * the first leader that performs a
  7647. * leader_reset() reset the global blocks in
  7648. * order to clear global attentions. Otherwise
  7649. * the the gates will remain closed for that
  7650. * engine.
  7651. */
  7652. if (load_status ||
  7653. (global && other_load_status)) {
  7654. /* Wait until all other functions get
  7655. * down.
  7656. */
  7657. schedule_delayed_work(&bp->sp_rtnl_task,
  7658. HZ/10);
  7659. return;
  7660. } else {
  7661. /* If all other functions got down -
  7662. * try to bring the chip back to
  7663. * normal. In any case it's an exit
  7664. * point for a leader.
  7665. */
  7666. if (bnx2x_leader_reset(bp)) {
  7667. bnx2x_recovery_failed(bp);
  7668. return;
  7669. }
  7670. /* If we are here, means that the
  7671. * leader has succeeded and doesn't
  7672. * want to be a leader any more. Try
  7673. * to continue as a none-leader.
  7674. */
  7675. break;
  7676. }
  7677. } else { /* non-leader */
  7678. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7679. /* Try to get a LEADER_LOCK HW lock as
  7680. * long as a former leader may have
  7681. * been unloaded by the user or
  7682. * released a leadership by another
  7683. * reason.
  7684. */
  7685. if (bnx2x_trylock_leader_lock(bp)) {
  7686. /* I'm a leader now! Restart a
  7687. * switch case.
  7688. */
  7689. bp->is_leader = 1;
  7690. break;
  7691. }
  7692. schedule_delayed_work(&bp->sp_rtnl_task,
  7693. HZ/10);
  7694. return;
  7695. } else {
  7696. /*
  7697. * If there was a global attention, wait
  7698. * for it to be cleared.
  7699. */
  7700. if (bnx2x_reset_is_global(bp)) {
  7701. schedule_delayed_work(
  7702. &bp->sp_rtnl_task,
  7703. HZ/10);
  7704. return;
  7705. }
  7706. error_recovered =
  7707. bp->eth_stats.recoverable_error;
  7708. error_unrecovered =
  7709. bp->eth_stats.unrecoverable_error;
  7710. bp->recovery_state =
  7711. BNX2X_RECOVERY_NIC_LOADING;
  7712. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7713. error_unrecovered++;
  7714. netdev_err(bp->dev,
  7715. "Recovery failed. Power cycle needed\n");
  7716. /* Disconnect this device */
  7717. netif_device_detach(bp->dev);
  7718. /* Shut down the power */
  7719. bnx2x_set_power_state(
  7720. bp, PCI_D3hot);
  7721. smp_mb();
  7722. } else {
  7723. bp->recovery_state =
  7724. BNX2X_RECOVERY_DONE;
  7725. error_recovered++;
  7726. smp_mb();
  7727. }
  7728. bp->eth_stats.recoverable_error =
  7729. error_recovered;
  7730. bp->eth_stats.unrecoverable_error =
  7731. error_unrecovered;
  7732. return;
  7733. }
  7734. }
  7735. default:
  7736. return;
  7737. }
  7738. }
  7739. }
  7740. static int bnx2x_close(struct net_device *dev);
  7741. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7742. * scheduled on a general queue in order to prevent a dead lock.
  7743. */
  7744. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7745. {
  7746. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7747. rtnl_lock();
  7748. if (!netif_running(bp->dev))
  7749. goto sp_rtnl_exit;
  7750. /* if stop on error is defined no recovery flows should be executed */
  7751. #ifdef BNX2X_STOP_ON_ERROR
  7752. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7753. "you will need to reboot when done\n");
  7754. goto sp_rtnl_not_reset;
  7755. #endif
  7756. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7757. /*
  7758. * Clear all pending SP commands as we are going to reset the
  7759. * function anyway.
  7760. */
  7761. bp->sp_rtnl_state = 0;
  7762. smp_mb();
  7763. bnx2x_parity_recover(bp);
  7764. goto sp_rtnl_exit;
  7765. }
  7766. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7767. /*
  7768. * Clear all pending SP commands as we are going to reset the
  7769. * function anyway.
  7770. */
  7771. bp->sp_rtnl_state = 0;
  7772. smp_mb();
  7773. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7774. bnx2x_nic_load(bp, LOAD_NORMAL);
  7775. goto sp_rtnl_exit;
  7776. }
  7777. #ifdef BNX2X_STOP_ON_ERROR
  7778. sp_rtnl_not_reset:
  7779. #endif
  7780. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7781. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7782. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7783. bnx2x_after_function_update(bp);
  7784. /*
  7785. * in case of fan failure we need to reset id if the "stop on error"
  7786. * debug flag is set, since we trying to prevent permanent overheating
  7787. * damage
  7788. */
  7789. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7790. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7791. netif_device_detach(bp->dev);
  7792. bnx2x_close(bp->dev);
  7793. }
  7794. sp_rtnl_exit:
  7795. rtnl_unlock();
  7796. }
  7797. /* end of nic load/unload */
  7798. static void bnx2x_period_task(struct work_struct *work)
  7799. {
  7800. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7801. if (!netif_running(bp->dev))
  7802. goto period_task_exit;
  7803. if (CHIP_REV_IS_SLOW(bp)) {
  7804. BNX2X_ERR("period task called on emulation, ignoring\n");
  7805. goto period_task_exit;
  7806. }
  7807. bnx2x_acquire_phy_lock(bp);
  7808. /*
  7809. * The barrier is needed to ensure the ordering between the writing to
  7810. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7811. * the reading here.
  7812. */
  7813. smp_mb();
  7814. if (bp->port.pmf) {
  7815. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7816. /* Re-queue task in 1 sec */
  7817. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7818. }
  7819. bnx2x_release_phy_lock(bp);
  7820. period_task_exit:
  7821. return;
  7822. }
  7823. /*
  7824. * Init service functions
  7825. */
  7826. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7827. {
  7828. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7829. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7830. return base + (BP_ABS_FUNC(bp)) * stride;
  7831. }
  7832. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7833. {
  7834. u32 reg = bnx2x_get_pretend_reg(bp);
  7835. /* Flush all outstanding writes */
  7836. mmiowb();
  7837. /* Pretend to be function 0 */
  7838. REG_WR(bp, reg, 0);
  7839. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7840. /* From now we are in the "like-E1" mode */
  7841. bnx2x_int_disable(bp);
  7842. /* Flush all outstanding writes */
  7843. mmiowb();
  7844. /* Restore the original function */
  7845. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7846. REG_RD(bp, reg);
  7847. }
  7848. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7849. {
  7850. if (CHIP_IS_E1(bp))
  7851. bnx2x_int_disable(bp);
  7852. else
  7853. bnx2x_undi_int_disable_e1h(bp);
  7854. }
  7855. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp)
  7856. {
  7857. u32 val, base_addr, offset, mask, reset_reg;
  7858. bool mac_stopped = false;
  7859. u8 port = BP_PORT(bp);
  7860. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7861. if (!CHIP_IS_E3(bp)) {
  7862. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7863. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7864. if ((mask & reset_reg) && val) {
  7865. u32 wb_data[2];
  7866. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7867. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7868. : NIG_REG_INGRESS_BMAC0_MEM;
  7869. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7870. : BIGMAC_REGISTER_BMAC_CONTROL;
  7871. /*
  7872. * use rd/wr since we cannot use dmae. This is safe
  7873. * since MCP won't access the bus due to the request
  7874. * to unload, and no function on the path can be
  7875. * loaded at this time.
  7876. */
  7877. wb_data[0] = REG_RD(bp, base_addr + offset);
  7878. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  7879. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  7880. REG_WR(bp, base_addr + offset, wb_data[0]);
  7881. REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
  7882. }
  7883. BNX2X_DEV_INFO("Disable emac Rx\n");
  7884. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
  7885. mac_stopped = true;
  7886. } else {
  7887. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  7888. BNX2X_DEV_INFO("Disable xmac Rx\n");
  7889. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  7890. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  7891. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7892. val & ~(1 << 1));
  7893. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7894. val | (1 << 1));
  7895. REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
  7896. mac_stopped = true;
  7897. }
  7898. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  7899. if (mask & reset_reg) {
  7900. BNX2X_DEV_INFO("Disable umac Rx\n");
  7901. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  7902. REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
  7903. mac_stopped = true;
  7904. }
  7905. }
  7906. if (mac_stopped)
  7907. msleep(20);
  7908. }
  7909. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  7910. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  7911. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  7912. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  7913. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  7914. {
  7915. u16 rcq, bd;
  7916. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  7917. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  7918. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  7919. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  7920. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  7921. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  7922. port, bd, rcq);
  7923. }
  7924. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  7925. {
  7926. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  7927. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  7928. if (!rc) {
  7929. BNX2X_ERR("MCP response failure, aborting\n");
  7930. return -EBUSY;
  7931. }
  7932. return 0;
  7933. }
  7934. static struct bnx2x_prev_path_list *
  7935. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  7936. {
  7937. struct bnx2x_prev_path_list *tmp_list;
  7938. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  7939. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7940. bp->pdev->bus->number == tmp_list->bus &&
  7941. BP_PATH(bp) == tmp_list->path)
  7942. return tmp_list;
  7943. return NULL;
  7944. }
  7945. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  7946. {
  7947. struct bnx2x_prev_path_list *tmp_list;
  7948. int rc = false;
  7949. if (down_trylock(&bnx2x_prev_sem))
  7950. return false;
  7951. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  7952. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7953. bp->pdev->bus->number == tmp_list->bus &&
  7954. BP_PATH(bp) == tmp_list->path) {
  7955. rc = true;
  7956. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  7957. BP_PATH(bp));
  7958. break;
  7959. }
  7960. }
  7961. up(&bnx2x_prev_sem);
  7962. return rc;
  7963. }
  7964. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  7965. {
  7966. struct bnx2x_prev_path_list *tmp_list;
  7967. int rc;
  7968. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  7969. if (!tmp_list) {
  7970. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  7971. return -ENOMEM;
  7972. }
  7973. tmp_list->bus = bp->pdev->bus->number;
  7974. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  7975. tmp_list->path = BP_PATH(bp);
  7976. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  7977. rc = down_interruptible(&bnx2x_prev_sem);
  7978. if (rc) {
  7979. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  7980. kfree(tmp_list);
  7981. } else {
  7982. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  7983. BP_PATH(bp));
  7984. list_add(&tmp_list->list, &bnx2x_prev_list);
  7985. up(&bnx2x_prev_sem);
  7986. }
  7987. return rc;
  7988. }
  7989. static int bnx2x_do_flr(struct bnx2x *bp)
  7990. {
  7991. int i;
  7992. u16 status;
  7993. struct pci_dev *dev = bp->pdev;
  7994. if (CHIP_IS_E1x(bp)) {
  7995. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  7996. return -EINVAL;
  7997. }
  7998. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  7999. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8000. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8001. bp->common.bc_ver);
  8002. return -EINVAL;
  8003. }
  8004. /* Wait for Transaction Pending bit clean */
  8005. for (i = 0; i < 4; i++) {
  8006. if (i)
  8007. msleep((1 << (i - 1)) * 100);
  8008. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8009. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8010. goto clear;
  8011. }
  8012. dev_err(&dev->dev,
  8013. "transaction is not cleared; proceeding with reset anyway\n");
  8014. clear:
  8015. BNX2X_DEV_INFO("Initiating FLR\n");
  8016. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8017. return 0;
  8018. }
  8019. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8020. {
  8021. int rc;
  8022. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8023. /* Test if previous unload process was already finished for this path */
  8024. if (bnx2x_prev_is_path_marked(bp))
  8025. return bnx2x_prev_mcp_done(bp);
  8026. /* If function has FLR capabilities, and existing FW version matches
  8027. * the one required, then FLR will be sufficient to clean any residue
  8028. * left by previous driver
  8029. */
  8030. rc = bnx2x_test_firmware_version(bp, false);
  8031. if (!rc) {
  8032. /* fw version is good */
  8033. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8034. rc = bnx2x_do_flr(bp);
  8035. }
  8036. if (!rc) {
  8037. /* FLR was performed */
  8038. BNX2X_DEV_INFO("FLR successful\n");
  8039. return 0;
  8040. }
  8041. BNX2X_DEV_INFO("Could not FLR\n");
  8042. /* Close the MCP request, return failure*/
  8043. rc = bnx2x_prev_mcp_done(bp);
  8044. if (!rc)
  8045. rc = BNX2X_PREV_WAIT_NEEDED;
  8046. return rc;
  8047. }
  8048. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8049. {
  8050. u32 reset_reg, tmp_reg = 0, rc;
  8051. bool prev_undi = false;
  8052. /* It is possible a previous function received 'common' answer,
  8053. * but hasn't loaded yet, therefore creating a scenario of
  8054. * multiple functions receiving 'common' on the same path.
  8055. */
  8056. BNX2X_DEV_INFO("Common unload Flow\n");
  8057. if (bnx2x_prev_is_path_marked(bp))
  8058. return bnx2x_prev_mcp_done(bp);
  8059. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8060. /* Reset should be performed after BRB is emptied */
  8061. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8062. u32 timer_count = 1000;
  8063. /* Close the MAC Rx to prevent BRB from filling up */
  8064. bnx2x_prev_unload_close_mac(bp);
  8065. /* Check if the UNDI driver was previously loaded
  8066. * UNDI driver initializes CID offset for normal bell to 0x7
  8067. */
  8068. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8069. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8070. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8071. if (tmp_reg == 0x7) {
  8072. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8073. prev_undi = true;
  8074. /* clear the UNDI indication */
  8075. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8076. }
  8077. }
  8078. /* wait until BRB is empty */
  8079. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8080. while (timer_count) {
  8081. u32 prev_brb = tmp_reg;
  8082. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8083. if (!tmp_reg)
  8084. break;
  8085. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8086. /* reset timer as long as BRB actually gets emptied */
  8087. if (prev_brb > tmp_reg)
  8088. timer_count = 1000;
  8089. else
  8090. timer_count--;
  8091. /* If UNDI resides in memory, manually increment it */
  8092. if (prev_undi)
  8093. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8094. udelay(10);
  8095. }
  8096. if (!timer_count)
  8097. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8098. }
  8099. /* No packets are in the pipeline, path is ready for reset */
  8100. bnx2x_reset_common(bp);
  8101. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8102. if (rc) {
  8103. bnx2x_prev_mcp_done(bp);
  8104. return rc;
  8105. }
  8106. return bnx2x_prev_mcp_done(bp);
  8107. }
  8108. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8109. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8110. * the addresses of the transaction, resulting in was-error bit set in the pci
  8111. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8112. * to clear the interrupt which detected this from the pglueb and the was done
  8113. * bit
  8114. */
  8115. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8116. {
  8117. if (!CHIP_IS_E1x(bp)) {
  8118. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8119. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8120. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  8121. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8122. 1 << BP_FUNC(bp));
  8123. }
  8124. }
  8125. }
  8126. static int bnx2x_prev_unload(struct bnx2x *bp)
  8127. {
  8128. int time_counter = 10;
  8129. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8130. struct bnx2x_prev_path_list *prev_list;
  8131. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8132. /* clear hw from errors which may have resulted from an interrupted
  8133. * dmae transaction.
  8134. */
  8135. bnx2x_prev_interrupted_dmae(bp);
  8136. /* Release previously held locks */
  8137. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8138. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8139. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8140. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8141. if (hw_lock_val) {
  8142. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8143. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8144. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8145. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8146. }
  8147. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8148. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8149. } else
  8150. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8151. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8152. BNX2X_DEV_INFO("Release previously held alr\n");
  8153. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8154. }
  8155. do {
  8156. /* Lock MCP using an unload request */
  8157. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8158. if (!fw) {
  8159. BNX2X_ERR("MCP response failure, aborting\n");
  8160. rc = -EBUSY;
  8161. break;
  8162. }
  8163. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8164. rc = bnx2x_prev_unload_common(bp);
  8165. break;
  8166. }
  8167. /* non-common reply from MCP night require looping */
  8168. rc = bnx2x_prev_unload_uncommon(bp);
  8169. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8170. break;
  8171. msleep(20);
  8172. } while (--time_counter);
  8173. if (!time_counter || rc) {
  8174. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8175. rc = -EBUSY;
  8176. }
  8177. /* Mark function if its port was used to boot from SAN */
  8178. prev_list = bnx2x_prev_path_get_entry(bp);
  8179. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8180. bp->link_params.feature_config_flags |=
  8181. FEATURE_CONFIG_BOOT_FROM_SAN;
  8182. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8183. return rc;
  8184. }
  8185. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8186. {
  8187. u32 val, val2, val3, val4, id, boot_mode;
  8188. u16 pmc;
  8189. /* Get the chip revision id and number. */
  8190. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8191. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8192. id = ((val & 0xffff) << 16);
  8193. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8194. id |= ((val & 0xf) << 12);
  8195. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8196. id |= ((val & 0xff) << 4);
  8197. val = REG_RD(bp, MISC_REG_BOND_ID);
  8198. id |= (val & 0xf);
  8199. bp->common.chip_id = id;
  8200. /* force 57811 according to MISC register */
  8201. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8202. if (CHIP_IS_57810(bp))
  8203. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8204. (bp->common.chip_id & 0x0000FFFF);
  8205. else if (CHIP_IS_57810_MF(bp))
  8206. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8207. (bp->common.chip_id & 0x0000FFFF);
  8208. bp->common.chip_id |= 0x1;
  8209. }
  8210. /* Set doorbell size */
  8211. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8212. if (!CHIP_IS_E1x(bp)) {
  8213. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8214. if ((val & 1) == 0)
  8215. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8216. else
  8217. val = (val >> 1) & 1;
  8218. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8219. "2_PORT_MODE");
  8220. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8221. CHIP_2_PORT_MODE;
  8222. if (CHIP_MODE_IS_4_PORT(bp))
  8223. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8224. else
  8225. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8226. } else {
  8227. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8228. bp->pfid = bp->pf_num; /* 0..7 */
  8229. }
  8230. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8231. bp->link_params.chip_id = bp->common.chip_id;
  8232. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8233. val = (REG_RD(bp, 0x2874) & 0x55);
  8234. if ((bp->common.chip_id & 0x1) ||
  8235. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8236. bp->flags |= ONE_PORT_FLAG;
  8237. BNX2X_DEV_INFO("single port device\n");
  8238. }
  8239. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8240. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8241. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8242. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8243. bp->common.flash_size, bp->common.flash_size);
  8244. bnx2x_init_shmem(bp);
  8245. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8246. MISC_REG_GENERIC_CR_1 :
  8247. MISC_REG_GENERIC_CR_0));
  8248. bp->link_params.shmem_base = bp->common.shmem_base;
  8249. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8250. if (SHMEM2_RD(bp, size) >
  8251. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8252. bp->link_params.lfa_base =
  8253. REG_RD(bp, bp->common.shmem2_base +
  8254. (u32)offsetof(struct shmem2_region,
  8255. lfa_host_addr[BP_PORT(bp)]));
  8256. else
  8257. bp->link_params.lfa_base = 0;
  8258. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8259. bp->common.shmem_base, bp->common.shmem2_base);
  8260. if (!bp->common.shmem_base) {
  8261. BNX2X_DEV_INFO("MCP not active\n");
  8262. bp->flags |= NO_MCP_FLAG;
  8263. return;
  8264. }
  8265. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8266. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8267. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8268. SHARED_HW_CFG_LED_MODE_MASK) >>
  8269. SHARED_HW_CFG_LED_MODE_SHIFT);
  8270. bp->link_params.feature_config_flags = 0;
  8271. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8272. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8273. bp->link_params.feature_config_flags |=
  8274. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8275. else
  8276. bp->link_params.feature_config_flags &=
  8277. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8278. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8279. bp->common.bc_ver = val;
  8280. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8281. if (val < BNX2X_BC_VER) {
  8282. /* for now only warn
  8283. * later we might need to enforce this */
  8284. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8285. BNX2X_BC_VER, val);
  8286. }
  8287. bp->link_params.feature_config_flags |=
  8288. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8289. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8290. bp->link_params.feature_config_flags |=
  8291. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8292. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8293. bp->link_params.feature_config_flags |=
  8294. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8295. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8296. bp->link_params.feature_config_flags |=
  8297. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8298. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8299. bp->link_params.feature_config_flags |=
  8300. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8301. FEATURE_CONFIG_MT_SUPPORT : 0;
  8302. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8303. BC_SUPPORTS_PFC_STATS : 0;
  8304. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8305. BC_SUPPORTS_FCOE_FEATURES : 0;
  8306. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8307. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8308. boot_mode = SHMEM_RD(bp,
  8309. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8310. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8311. switch (boot_mode) {
  8312. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8313. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8314. break;
  8315. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8316. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8317. break;
  8318. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8319. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8320. break;
  8321. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8322. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8323. break;
  8324. }
  8325. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8326. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8327. BNX2X_DEV_INFO("%sWoL capable\n",
  8328. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8329. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8330. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8331. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8332. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8333. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8334. val, val2, val3, val4);
  8335. }
  8336. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8337. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8338. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8339. {
  8340. int pfid = BP_FUNC(bp);
  8341. int igu_sb_id;
  8342. u32 val;
  8343. u8 fid, igu_sb_cnt = 0;
  8344. bp->igu_base_sb = 0xff;
  8345. if (CHIP_INT_MODE_IS_BC(bp)) {
  8346. int vn = BP_VN(bp);
  8347. igu_sb_cnt = bp->igu_sb_cnt;
  8348. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8349. FP_SB_MAX_E1x;
  8350. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8351. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8352. return 0;
  8353. }
  8354. /* IGU in normal mode - read CAM */
  8355. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8356. igu_sb_id++) {
  8357. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8358. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8359. continue;
  8360. fid = IGU_FID(val);
  8361. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8362. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8363. continue;
  8364. if (IGU_VEC(val) == 0)
  8365. /* default status block */
  8366. bp->igu_dsb_id = igu_sb_id;
  8367. else {
  8368. if (bp->igu_base_sb == 0xff)
  8369. bp->igu_base_sb = igu_sb_id;
  8370. igu_sb_cnt++;
  8371. }
  8372. }
  8373. }
  8374. #ifdef CONFIG_PCI_MSI
  8375. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8376. * optional that number of CAM entries will not be equal to the value
  8377. * advertised in PCI.
  8378. * Driver should use the minimal value of both as the actual status
  8379. * block count
  8380. */
  8381. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8382. #endif
  8383. if (igu_sb_cnt == 0) {
  8384. BNX2X_ERR("CAM configuration error\n");
  8385. return -EINVAL;
  8386. }
  8387. return 0;
  8388. }
  8389. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8390. {
  8391. int cfg_size = 0, idx, port = BP_PORT(bp);
  8392. /* Aggregation of supported attributes of all external phys */
  8393. bp->port.supported[0] = 0;
  8394. bp->port.supported[1] = 0;
  8395. switch (bp->link_params.num_phys) {
  8396. case 1:
  8397. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8398. cfg_size = 1;
  8399. break;
  8400. case 2:
  8401. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8402. cfg_size = 1;
  8403. break;
  8404. case 3:
  8405. if (bp->link_params.multi_phy_config &
  8406. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8407. bp->port.supported[1] =
  8408. bp->link_params.phy[EXT_PHY1].supported;
  8409. bp->port.supported[0] =
  8410. bp->link_params.phy[EXT_PHY2].supported;
  8411. } else {
  8412. bp->port.supported[0] =
  8413. bp->link_params.phy[EXT_PHY1].supported;
  8414. bp->port.supported[1] =
  8415. bp->link_params.phy[EXT_PHY2].supported;
  8416. }
  8417. cfg_size = 2;
  8418. break;
  8419. }
  8420. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8421. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8422. SHMEM_RD(bp,
  8423. dev_info.port_hw_config[port].external_phy_config),
  8424. SHMEM_RD(bp,
  8425. dev_info.port_hw_config[port].external_phy_config2));
  8426. return;
  8427. }
  8428. if (CHIP_IS_E3(bp))
  8429. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8430. else {
  8431. switch (switch_cfg) {
  8432. case SWITCH_CFG_1G:
  8433. bp->port.phy_addr = REG_RD(
  8434. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8435. break;
  8436. case SWITCH_CFG_10G:
  8437. bp->port.phy_addr = REG_RD(
  8438. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8439. break;
  8440. default:
  8441. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8442. bp->port.link_config[0]);
  8443. return;
  8444. }
  8445. }
  8446. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8447. /* mask what we support according to speed_cap_mask per configuration */
  8448. for (idx = 0; idx < cfg_size; idx++) {
  8449. if (!(bp->link_params.speed_cap_mask[idx] &
  8450. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8451. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8452. if (!(bp->link_params.speed_cap_mask[idx] &
  8453. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8454. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8455. if (!(bp->link_params.speed_cap_mask[idx] &
  8456. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8457. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8458. if (!(bp->link_params.speed_cap_mask[idx] &
  8459. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8460. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8461. if (!(bp->link_params.speed_cap_mask[idx] &
  8462. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8463. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8464. SUPPORTED_1000baseT_Full);
  8465. if (!(bp->link_params.speed_cap_mask[idx] &
  8466. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8467. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8468. if (!(bp->link_params.speed_cap_mask[idx] &
  8469. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8470. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8471. }
  8472. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8473. bp->port.supported[1]);
  8474. }
  8475. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8476. {
  8477. u32 link_config, idx, cfg_size = 0;
  8478. bp->port.advertising[0] = 0;
  8479. bp->port.advertising[1] = 0;
  8480. switch (bp->link_params.num_phys) {
  8481. case 1:
  8482. case 2:
  8483. cfg_size = 1;
  8484. break;
  8485. case 3:
  8486. cfg_size = 2;
  8487. break;
  8488. }
  8489. for (idx = 0; idx < cfg_size; idx++) {
  8490. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8491. link_config = bp->port.link_config[idx];
  8492. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8493. case PORT_FEATURE_LINK_SPEED_AUTO:
  8494. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8495. bp->link_params.req_line_speed[idx] =
  8496. SPEED_AUTO_NEG;
  8497. bp->port.advertising[idx] |=
  8498. bp->port.supported[idx];
  8499. if (bp->link_params.phy[EXT_PHY1].type ==
  8500. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8501. bp->port.advertising[idx] |=
  8502. (SUPPORTED_100baseT_Half |
  8503. SUPPORTED_100baseT_Full);
  8504. } else {
  8505. /* force 10G, no AN */
  8506. bp->link_params.req_line_speed[idx] =
  8507. SPEED_10000;
  8508. bp->port.advertising[idx] |=
  8509. (ADVERTISED_10000baseT_Full |
  8510. ADVERTISED_FIBRE);
  8511. continue;
  8512. }
  8513. break;
  8514. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8515. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8516. bp->link_params.req_line_speed[idx] =
  8517. SPEED_10;
  8518. bp->port.advertising[idx] |=
  8519. (ADVERTISED_10baseT_Full |
  8520. ADVERTISED_TP);
  8521. } else {
  8522. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8523. link_config,
  8524. bp->link_params.speed_cap_mask[idx]);
  8525. return;
  8526. }
  8527. break;
  8528. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8529. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8530. bp->link_params.req_line_speed[idx] =
  8531. SPEED_10;
  8532. bp->link_params.req_duplex[idx] =
  8533. DUPLEX_HALF;
  8534. bp->port.advertising[idx] |=
  8535. (ADVERTISED_10baseT_Half |
  8536. ADVERTISED_TP);
  8537. } else {
  8538. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8539. link_config,
  8540. bp->link_params.speed_cap_mask[idx]);
  8541. return;
  8542. }
  8543. break;
  8544. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8545. if (bp->port.supported[idx] &
  8546. SUPPORTED_100baseT_Full) {
  8547. bp->link_params.req_line_speed[idx] =
  8548. SPEED_100;
  8549. bp->port.advertising[idx] |=
  8550. (ADVERTISED_100baseT_Full |
  8551. ADVERTISED_TP);
  8552. } else {
  8553. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8554. link_config,
  8555. bp->link_params.speed_cap_mask[idx]);
  8556. return;
  8557. }
  8558. break;
  8559. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8560. if (bp->port.supported[idx] &
  8561. SUPPORTED_100baseT_Half) {
  8562. bp->link_params.req_line_speed[idx] =
  8563. SPEED_100;
  8564. bp->link_params.req_duplex[idx] =
  8565. DUPLEX_HALF;
  8566. bp->port.advertising[idx] |=
  8567. (ADVERTISED_100baseT_Half |
  8568. ADVERTISED_TP);
  8569. } else {
  8570. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8571. link_config,
  8572. bp->link_params.speed_cap_mask[idx]);
  8573. return;
  8574. }
  8575. break;
  8576. case PORT_FEATURE_LINK_SPEED_1G:
  8577. if (bp->port.supported[idx] &
  8578. SUPPORTED_1000baseT_Full) {
  8579. bp->link_params.req_line_speed[idx] =
  8580. SPEED_1000;
  8581. bp->port.advertising[idx] |=
  8582. (ADVERTISED_1000baseT_Full |
  8583. ADVERTISED_TP);
  8584. } else {
  8585. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8586. link_config,
  8587. bp->link_params.speed_cap_mask[idx]);
  8588. return;
  8589. }
  8590. break;
  8591. case PORT_FEATURE_LINK_SPEED_2_5G:
  8592. if (bp->port.supported[idx] &
  8593. SUPPORTED_2500baseX_Full) {
  8594. bp->link_params.req_line_speed[idx] =
  8595. SPEED_2500;
  8596. bp->port.advertising[idx] |=
  8597. (ADVERTISED_2500baseX_Full |
  8598. ADVERTISED_TP);
  8599. } else {
  8600. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8601. link_config,
  8602. bp->link_params.speed_cap_mask[idx]);
  8603. return;
  8604. }
  8605. break;
  8606. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8607. if (bp->port.supported[idx] &
  8608. SUPPORTED_10000baseT_Full) {
  8609. bp->link_params.req_line_speed[idx] =
  8610. SPEED_10000;
  8611. bp->port.advertising[idx] |=
  8612. (ADVERTISED_10000baseT_Full |
  8613. ADVERTISED_FIBRE);
  8614. } else {
  8615. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8616. link_config,
  8617. bp->link_params.speed_cap_mask[idx]);
  8618. return;
  8619. }
  8620. break;
  8621. case PORT_FEATURE_LINK_SPEED_20G:
  8622. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8623. break;
  8624. default:
  8625. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8626. link_config);
  8627. bp->link_params.req_line_speed[idx] =
  8628. SPEED_AUTO_NEG;
  8629. bp->port.advertising[idx] =
  8630. bp->port.supported[idx];
  8631. break;
  8632. }
  8633. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8634. PORT_FEATURE_FLOW_CONTROL_MASK);
  8635. if (bp->link_params.req_flow_ctrl[idx] ==
  8636. BNX2X_FLOW_CTRL_AUTO) {
  8637. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8638. bp->link_params.req_flow_ctrl[idx] =
  8639. BNX2X_FLOW_CTRL_NONE;
  8640. else
  8641. bnx2x_set_requested_fc(bp);
  8642. }
  8643. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8644. bp->link_params.req_line_speed[idx],
  8645. bp->link_params.req_duplex[idx],
  8646. bp->link_params.req_flow_ctrl[idx],
  8647. bp->port.advertising[idx]);
  8648. }
  8649. }
  8650. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8651. {
  8652. mac_hi = cpu_to_be16(mac_hi);
  8653. mac_lo = cpu_to_be32(mac_lo);
  8654. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8655. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8656. }
  8657. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8658. {
  8659. int port = BP_PORT(bp);
  8660. u32 config;
  8661. u32 ext_phy_type, ext_phy_config, eee_mode;
  8662. bp->link_params.bp = bp;
  8663. bp->link_params.port = port;
  8664. bp->link_params.lane_config =
  8665. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8666. bp->link_params.speed_cap_mask[0] =
  8667. SHMEM_RD(bp,
  8668. dev_info.port_hw_config[port].speed_capability_mask);
  8669. bp->link_params.speed_cap_mask[1] =
  8670. SHMEM_RD(bp,
  8671. dev_info.port_hw_config[port].speed_capability_mask2);
  8672. bp->port.link_config[0] =
  8673. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8674. bp->port.link_config[1] =
  8675. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8676. bp->link_params.multi_phy_config =
  8677. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8678. /* If the device is capable of WoL, set the default state according
  8679. * to the HW
  8680. */
  8681. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8682. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8683. (config & PORT_FEATURE_WOL_ENABLED));
  8684. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8685. bp->link_params.lane_config,
  8686. bp->link_params.speed_cap_mask[0],
  8687. bp->port.link_config[0]);
  8688. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8689. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8690. bnx2x_phy_probe(&bp->link_params);
  8691. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8692. bnx2x_link_settings_requested(bp);
  8693. /*
  8694. * If connected directly, work with the internal PHY, otherwise, work
  8695. * with the external PHY
  8696. */
  8697. ext_phy_config =
  8698. SHMEM_RD(bp,
  8699. dev_info.port_hw_config[port].external_phy_config);
  8700. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8701. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8702. bp->mdio.prtad = bp->port.phy_addr;
  8703. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8704. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8705. bp->mdio.prtad =
  8706. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8707. /* Configure link feature according to nvram value */
  8708. eee_mode = (((SHMEM_RD(bp, dev_info.
  8709. port_feature_config[port].eee_power_mode)) &
  8710. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8711. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8712. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8713. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8714. EEE_MODE_ENABLE_LPI |
  8715. EEE_MODE_OUTPUT_TIME;
  8716. } else {
  8717. bp->link_params.eee_mode = 0;
  8718. }
  8719. }
  8720. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8721. {
  8722. u32 no_flags = NO_ISCSI_FLAG;
  8723. int port = BP_PORT(bp);
  8724. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8725. drv_lic_key[port].max_iscsi_conn);
  8726. if (!CNIC_SUPPORT(bp)) {
  8727. bp->flags |= no_flags;
  8728. return;
  8729. }
  8730. /* Get the number of maximum allowed iSCSI connections */
  8731. bp->cnic_eth_dev.max_iscsi_conn =
  8732. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8733. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8734. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8735. bp->cnic_eth_dev.max_iscsi_conn);
  8736. /*
  8737. * If maximum allowed number of connections is zero -
  8738. * disable the feature.
  8739. */
  8740. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8741. bp->flags |= no_flags;
  8742. }
  8743. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8744. {
  8745. /* Port info */
  8746. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8747. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8748. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8749. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8750. /* Node info */
  8751. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8752. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8753. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8754. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8755. }
  8756. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8757. {
  8758. int port = BP_PORT(bp);
  8759. int func = BP_ABS_FUNC(bp);
  8760. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8761. drv_lic_key[port].max_fcoe_conn);
  8762. if (!CNIC_SUPPORT(bp)) {
  8763. bp->flags |= NO_FCOE_FLAG;
  8764. return;
  8765. }
  8766. /* Get the number of maximum allowed FCoE connections */
  8767. bp->cnic_eth_dev.max_fcoe_conn =
  8768. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8769. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8770. /* Read the WWN: */
  8771. if (!IS_MF(bp)) {
  8772. /* Port info */
  8773. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8774. SHMEM_RD(bp,
  8775. dev_info.port_hw_config[port].
  8776. fcoe_wwn_port_name_upper);
  8777. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8778. SHMEM_RD(bp,
  8779. dev_info.port_hw_config[port].
  8780. fcoe_wwn_port_name_lower);
  8781. /* Node info */
  8782. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8783. SHMEM_RD(bp,
  8784. dev_info.port_hw_config[port].
  8785. fcoe_wwn_node_name_upper);
  8786. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8787. SHMEM_RD(bp,
  8788. dev_info.port_hw_config[port].
  8789. fcoe_wwn_node_name_lower);
  8790. } else if (!IS_MF_SD(bp)) {
  8791. /*
  8792. * Read the WWN info only if the FCoE feature is enabled for
  8793. * this function.
  8794. */
  8795. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8796. bnx2x_get_ext_wwn_info(bp, func);
  8797. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8798. bnx2x_get_ext_wwn_info(bp, func);
  8799. }
  8800. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8801. /*
  8802. * If maximum allowed number of connections is zero -
  8803. * disable the feature.
  8804. */
  8805. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8806. bp->flags |= NO_FCOE_FLAG;
  8807. }
  8808. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  8809. {
  8810. /*
  8811. * iSCSI may be dynamically disabled but reading
  8812. * info here we will decrease memory usage by driver
  8813. * if the feature is disabled for good
  8814. */
  8815. bnx2x_get_iscsi_info(bp);
  8816. bnx2x_get_fcoe_info(bp);
  8817. }
  8818. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8819. {
  8820. u32 val, val2;
  8821. int func = BP_ABS_FUNC(bp);
  8822. int port = BP_PORT(bp);
  8823. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8824. u8 *fip_mac = bp->fip_mac;
  8825. if (IS_MF(bp)) {
  8826. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8827. * FCoE MAC then the appropriate feature should be disabled.
  8828. * In non SD mode features configuration comes from struct
  8829. * func_ext_config.
  8830. */
  8831. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  8832. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8833. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8834. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8835. iscsi_mac_addr_upper);
  8836. val = MF_CFG_RD(bp, func_ext_config[func].
  8837. iscsi_mac_addr_lower);
  8838. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8839. BNX2X_DEV_INFO
  8840. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8841. } else {
  8842. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8843. }
  8844. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8845. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8846. fcoe_mac_addr_upper);
  8847. val = MF_CFG_RD(bp, func_ext_config[func].
  8848. fcoe_mac_addr_lower);
  8849. bnx2x_set_mac_buf(fip_mac, val, val2);
  8850. BNX2X_DEV_INFO
  8851. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  8852. } else {
  8853. bp->flags |= NO_FCOE_FLAG;
  8854. }
  8855. bp->mf_ext_config = cfg;
  8856. } else { /* SD MODE */
  8857. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8858. /* use primary mac as iscsi mac */
  8859. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  8860. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8861. BNX2X_DEV_INFO
  8862. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8863. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  8864. /* use primary mac as fip mac */
  8865. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  8866. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8867. BNX2X_DEV_INFO
  8868. ("Read FIP MAC: %pM\n", fip_mac);
  8869. }
  8870. }
  8871. if (IS_MF_STORAGE_SD(bp))
  8872. /* Zero primary MAC configuration */
  8873. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8874. if (IS_MF_FCOE_AFEX(bp))
  8875. /* use FIP MAC as primary MAC */
  8876. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  8877. } else {
  8878. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8879. iscsi_mac_upper);
  8880. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8881. iscsi_mac_lower);
  8882. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8883. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8884. fcoe_fip_mac_upper);
  8885. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8886. fcoe_fip_mac_lower);
  8887. bnx2x_set_mac_buf(fip_mac, val, val2);
  8888. }
  8889. /* Disable iSCSI OOO if MAC configuration is invalid. */
  8890. if (!is_valid_ether_addr(iscsi_mac)) {
  8891. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8892. memset(iscsi_mac, 0, ETH_ALEN);
  8893. }
  8894. /* Disable FCoE if MAC configuration is invalid. */
  8895. if (!is_valid_ether_addr(fip_mac)) {
  8896. bp->flags |= NO_FCOE_FLAG;
  8897. memset(bp->fip_mac, 0, ETH_ALEN);
  8898. }
  8899. }
  8900. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8901. {
  8902. u32 val, val2;
  8903. int func = BP_ABS_FUNC(bp);
  8904. int port = BP_PORT(bp);
  8905. /* Zero primary MAC configuration */
  8906. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8907. if (BP_NOMCP(bp)) {
  8908. BNX2X_ERROR("warning: random MAC workaround active\n");
  8909. eth_hw_addr_random(bp->dev);
  8910. } else if (IS_MF(bp)) {
  8911. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8912. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8913. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8914. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8915. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8916. if (CNIC_SUPPORT(bp))
  8917. bnx2x_get_cnic_mac_hwinfo(bp);
  8918. } else {
  8919. /* in SF read MACs from port configuration */
  8920. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8921. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8922. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8923. if (CNIC_SUPPORT(bp))
  8924. bnx2x_get_cnic_mac_hwinfo(bp);
  8925. }
  8926. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8927. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8928. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8929. dev_err(&bp->pdev->dev,
  8930. "bad Ethernet MAC address configuration: %pM\n"
  8931. "change it manually before bringing up the appropriate network interface\n",
  8932. bp->dev->dev_addr);
  8933. }
  8934. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  8935. {
  8936. int tmp;
  8937. u32 cfg;
  8938. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  8939. /* Take function: tmp = func */
  8940. tmp = BP_ABS_FUNC(bp);
  8941. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  8942. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  8943. } else {
  8944. /* Take port: tmp = port */
  8945. tmp = BP_PORT(bp);
  8946. cfg = SHMEM_RD(bp,
  8947. dev_info.port_hw_config[tmp].generic_features);
  8948. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  8949. }
  8950. return cfg;
  8951. }
  8952. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  8953. {
  8954. int /*abs*/func = BP_ABS_FUNC(bp);
  8955. int vn;
  8956. u32 val = 0;
  8957. int rc = 0;
  8958. bnx2x_get_common_hwinfo(bp);
  8959. /*
  8960. * initialize IGU parameters
  8961. */
  8962. if (CHIP_IS_E1x(bp)) {
  8963. bp->common.int_block = INT_BLOCK_HC;
  8964. bp->igu_dsb_id = DEF_SB_IGU_ID;
  8965. bp->igu_base_sb = 0;
  8966. } else {
  8967. bp->common.int_block = INT_BLOCK_IGU;
  8968. /* do not allow device reset during IGU info preocessing */
  8969. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8970. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  8971. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8972. int tout = 5000;
  8973. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  8974. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  8975. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  8976. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  8977. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8978. tout--;
  8979. usleep_range(1000, 1000);
  8980. }
  8981. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8982. dev_err(&bp->pdev->dev,
  8983. "FORCING Normal Mode failed!!!\n");
  8984. bnx2x_release_hw_lock(bp,
  8985. HW_LOCK_RESOURCE_RESET);
  8986. return -EPERM;
  8987. }
  8988. }
  8989. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8990. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  8991. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  8992. } else
  8993. BNX2X_DEV_INFO("IGU Normal Mode\n");
  8994. rc = bnx2x_get_igu_cam_info(bp);
  8995. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8996. if (rc)
  8997. return rc;
  8998. }
  8999. /*
  9000. * set base FW non-default (fast path) status block id, this value is
  9001. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9002. * determine the id used by the FW.
  9003. */
  9004. if (CHIP_IS_E1x(bp))
  9005. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9006. else /*
  9007. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9008. * the same queue are indicated on the same IGU SB). So we prefer
  9009. * FW and IGU SBs to be the same value.
  9010. */
  9011. bp->base_fw_ndsb = bp->igu_base_sb;
  9012. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9013. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9014. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9015. /*
  9016. * Initialize MF configuration
  9017. */
  9018. bp->mf_ov = 0;
  9019. bp->mf_mode = 0;
  9020. vn = BP_VN(bp);
  9021. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9022. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9023. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9024. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9025. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9026. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9027. else
  9028. bp->common.mf_cfg_base = bp->common.shmem_base +
  9029. offsetof(struct shmem_region, func_mb) +
  9030. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9031. /*
  9032. * get mf configuration:
  9033. * 1. existence of MF configuration
  9034. * 2. MAC address must be legal (check only upper bytes)
  9035. * for Switch-Independent mode;
  9036. * OVLAN must be legal for Switch-Dependent mode
  9037. * 3. SF_MODE configures specific MF mode
  9038. */
  9039. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9040. /* get mf configuration */
  9041. val = SHMEM_RD(bp,
  9042. dev_info.shared_feature_config.config);
  9043. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9044. switch (val) {
  9045. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9046. val = MF_CFG_RD(bp, func_mf_config[func].
  9047. mac_upper);
  9048. /* check for legal mac (upper bytes)*/
  9049. if (val != 0xffff) {
  9050. bp->mf_mode = MULTI_FUNCTION_SI;
  9051. bp->mf_config[vn] = MF_CFG_RD(bp,
  9052. func_mf_config[func].config);
  9053. } else
  9054. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9055. break;
  9056. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9057. if ((!CHIP_IS_E1x(bp)) &&
  9058. (MF_CFG_RD(bp, func_mf_config[func].
  9059. mac_upper) != 0xffff) &&
  9060. (SHMEM2_HAS(bp,
  9061. afex_driver_support))) {
  9062. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9063. bp->mf_config[vn] = MF_CFG_RD(bp,
  9064. func_mf_config[func].config);
  9065. } else {
  9066. BNX2X_DEV_INFO("can not configure afex mode\n");
  9067. }
  9068. break;
  9069. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9070. /* get OV configuration */
  9071. val = MF_CFG_RD(bp,
  9072. func_mf_config[FUNC_0].e1hov_tag);
  9073. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9074. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9075. bp->mf_mode = MULTI_FUNCTION_SD;
  9076. bp->mf_config[vn] = MF_CFG_RD(bp,
  9077. func_mf_config[func].config);
  9078. } else
  9079. BNX2X_DEV_INFO("illegal OV for SD\n");
  9080. break;
  9081. default:
  9082. /* Unknown configuration: reset mf_config */
  9083. bp->mf_config[vn] = 0;
  9084. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9085. }
  9086. }
  9087. BNX2X_DEV_INFO("%s function mode\n",
  9088. IS_MF(bp) ? "multi" : "single");
  9089. switch (bp->mf_mode) {
  9090. case MULTI_FUNCTION_SD:
  9091. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9092. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9093. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9094. bp->mf_ov = val;
  9095. bp->path_has_ovlan = true;
  9096. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9097. func, bp->mf_ov, bp->mf_ov);
  9098. } else {
  9099. dev_err(&bp->pdev->dev,
  9100. "No valid MF OV for func %d, aborting\n",
  9101. func);
  9102. return -EPERM;
  9103. }
  9104. break;
  9105. case MULTI_FUNCTION_AFEX:
  9106. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9107. break;
  9108. case MULTI_FUNCTION_SI:
  9109. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9110. func);
  9111. break;
  9112. default:
  9113. if (vn) {
  9114. dev_err(&bp->pdev->dev,
  9115. "VN %d is in a single function mode, aborting\n",
  9116. vn);
  9117. return -EPERM;
  9118. }
  9119. break;
  9120. }
  9121. /* check if other port on the path needs ovlan:
  9122. * Since MF configuration is shared between ports
  9123. * Possible mixed modes are only
  9124. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9125. */
  9126. if (CHIP_MODE_IS_4_PORT(bp) &&
  9127. !bp->path_has_ovlan &&
  9128. !IS_MF(bp) &&
  9129. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9130. u8 other_port = !BP_PORT(bp);
  9131. u8 other_func = BP_PATH(bp) + 2*other_port;
  9132. val = MF_CFG_RD(bp,
  9133. func_mf_config[other_func].e1hov_tag);
  9134. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9135. bp->path_has_ovlan = true;
  9136. }
  9137. }
  9138. /* adjust igu_sb_cnt to MF for E1x */
  9139. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9140. bp->igu_sb_cnt /= E1HVN_MAX;
  9141. /* port info */
  9142. bnx2x_get_port_hwinfo(bp);
  9143. /* Get MAC addresses */
  9144. bnx2x_get_mac_hwinfo(bp);
  9145. bnx2x_get_cnic_info(bp);
  9146. return rc;
  9147. }
  9148. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9149. {
  9150. int cnt, i, block_end, rodi;
  9151. char vpd_start[BNX2X_VPD_LEN+1];
  9152. char str_id_reg[VENDOR_ID_LEN+1];
  9153. char str_id_cap[VENDOR_ID_LEN+1];
  9154. char *vpd_data;
  9155. char *vpd_extended_data = NULL;
  9156. u8 len;
  9157. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9158. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9159. if (cnt < BNX2X_VPD_LEN)
  9160. goto out_not_found;
  9161. /* VPD RO tag should be first tag after identifier string, hence
  9162. * we should be able to find it in first BNX2X_VPD_LEN chars
  9163. */
  9164. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9165. PCI_VPD_LRDT_RO_DATA);
  9166. if (i < 0)
  9167. goto out_not_found;
  9168. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9169. pci_vpd_lrdt_size(&vpd_start[i]);
  9170. i += PCI_VPD_LRDT_TAG_SIZE;
  9171. if (block_end > BNX2X_VPD_LEN) {
  9172. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9173. if (vpd_extended_data == NULL)
  9174. goto out_not_found;
  9175. /* read rest of vpd image into vpd_extended_data */
  9176. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9177. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9178. block_end - BNX2X_VPD_LEN,
  9179. vpd_extended_data + BNX2X_VPD_LEN);
  9180. if (cnt < (block_end - BNX2X_VPD_LEN))
  9181. goto out_not_found;
  9182. vpd_data = vpd_extended_data;
  9183. } else
  9184. vpd_data = vpd_start;
  9185. /* now vpd_data holds full vpd content in both cases */
  9186. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9187. PCI_VPD_RO_KEYWORD_MFR_ID);
  9188. if (rodi < 0)
  9189. goto out_not_found;
  9190. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9191. if (len != VENDOR_ID_LEN)
  9192. goto out_not_found;
  9193. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9194. /* vendor specific info */
  9195. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9196. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9197. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9198. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9199. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9200. PCI_VPD_RO_KEYWORD_VENDOR0);
  9201. if (rodi >= 0) {
  9202. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9203. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9204. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9205. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9206. bp->fw_ver[len] = ' ';
  9207. }
  9208. }
  9209. kfree(vpd_extended_data);
  9210. return;
  9211. }
  9212. out_not_found:
  9213. kfree(vpd_extended_data);
  9214. return;
  9215. }
  9216. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9217. {
  9218. u32 flags = 0;
  9219. if (CHIP_REV_IS_FPGA(bp))
  9220. SET_FLAGS(flags, MODE_FPGA);
  9221. else if (CHIP_REV_IS_EMUL(bp))
  9222. SET_FLAGS(flags, MODE_EMUL);
  9223. else
  9224. SET_FLAGS(flags, MODE_ASIC);
  9225. if (CHIP_MODE_IS_4_PORT(bp))
  9226. SET_FLAGS(flags, MODE_PORT4);
  9227. else
  9228. SET_FLAGS(flags, MODE_PORT2);
  9229. if (CHIP_IS_E2(bp))
  9230. SET_FLAGS(flags, MODE_E2);
  9231. else if (CHIP_IS_E3(bp)) {
  9232. SET_FLAGS(flags, MODE_E3);
  9233. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9234. SET_FLAGS(flags, MODE_E3_A0);
  9235. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9236. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9237. }
  9238. if (IS_MF(bp)) {
  9239. SET_FLAGS(flags, MODE_MF);
  9240. switch (bp->mf_mode) {
  9241. case MULTI_FUNCTION_SD:
  9242. SET_FLAGS(flags, MODE_MF_SD);
  9243. break;
  9244. case MULTI_FUNCTION_SI:
  9245. SET_FLAGS(flags, MODE_MF_SI);
  9246. break;
  9247. case MULTI_FUNCTION_AFEX:
  9248. SET_FLAGS(flags, MODE_MF_AFEX);
  9249. break;
  9250. }
  9251. } else
  9252. SET_FLAGS(flags, MODE_SF);
  9253. #if defined(__LITTLE_ENDIAN)
  9254. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9255. #else /*(__BIG_ENDIAN)*/
  9256. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9257. #endif
  9258. INIT_MODE_FLAGS(bp) = flags;
  9259. }
  9260. static int bnx2x_init_bp(struct bnx2x *bp)
  9261. {
  9262. int func;
  9263. int rc;
  9264. mutex_init(&bp->port.phy_mutex);
  9265. mutex_init(&bp->fw_mb_mutex);
  9266. spin_lock_init(&bp->stats_lock);
  9267. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9268. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9269. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9270. if (IS_PF(bp)) {
  9271. rc = bnx2x_get_hwinfo(bp);
  9272. if (rc)
  9273. return rc;
  9274. } else {
  9275. random_ether_addr(bp->dev->dev_addr);
  9276. }
  9277. bnx2x_set_modes_bitmap(bp);
  9278. rc = bnx2x_alloc_mem_bp(bp);
  9279. if (rc)
  9280. return rc;
  9281. bnx2x_read_fwinfo(bp);
  9282. func = BP_FUNC(bp);
  9283. /* need to reset chip if undi was active */
  9284. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9285. /* init fw_seq */
  9286. bp->fw_seq =
  9287. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9288. DRV_MSG_SEQ_NUMBER_MASK;
  9289. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9290. bnx2x_prev_unload(bp);
  9291. }
  9292. if (CHIP_REV_IS_FPGA(bp))
  9293. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9294. if (BP_NOMCP(bp) && (func == 0))
  9295. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9296. bp->disable_tpa = disable_tpa;
  9297. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9298. /* Set TPA flags */
  9299. if (bp->disable_tpa) {
  9300. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9301. bp->dev->features &= ~NETIF_F_LRO;
  9302. } else {
  9303. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9304. bp->dev->features |= NETIF_F_LRO;
  9305. }
  9306. if (CHIP_IS_E1(bp))
  9307. bp->dropless_fc = 0;
  9308. else
  9309. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9310. bp->mrrs = mrrs;
  9311. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9312. if (IS_VF(bp))
  9313. bp->rx_ring_size = MAX_RX_AVAIL;
  9314. /* make sure that the numbers are in the right granularity */
  9315. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9316. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9317. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9318. init_timer(&bp->timer);
  9319. bp->timer.expires = jiffies + bp->current_interval;
  9320. bp->timer.data = (unsigned long) bp;
  9321. bp->timer.function = bnx2x_timer;
  9322. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9323. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9324. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9325. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9326. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9327. bnx2x_dcbx_init_params(bp);
  9328. } else {
  9329. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9330. }
  9331. if (CHIP_IS_E1x(bp))
  9332. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9333. else
  9334. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9335. /* multiple tx priority */
  9336. if (IS_VF(bp))
  9337. bp->max_cos = 1;
  9338. else if (CHIP_IS_E1x(bp))
  9339. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9340. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9341. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9342. else if (CHIP_IS_E3B0(bp))
  9343. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9344. else
  9345. BNX2X_ERR("unknown chip %x revision %x\n",
  9346. CHIP_NUM(bp), CHIP_REV(bp));
  9347. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9348. /* We need at least one default status block for slow-path events,
  9349. * second status block for the L2 queue, and a third status block for
  9350. * CNIC if supproted.
  9351. */
  9352. if (CNIC_SUPPORT(bp))
  9353. bp->min_msix_vec_cnt = 3;
  9354. else
  9355. bp->min_msix_vec_cnt = 2;
  9356. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9357. return rc;
  9358. }
  9359. /****************************************************************************
  9360. * General service functions
  9361. ****************************************************************************/
  9362. /*
  9363. * net_device service functions
  9364. */
  9365. /* called with rtnl_lock */
  9366. static int bnx2x_open(struct net_device *dev)
  9367. {
  9368. struct bnx2x *bp = netdev_priv(dev);
  9369. bool global = false;
  9370. int other_engine = BP_PATH(bp) ? 0 : 1;
  9371. bool other_load_status, load_status;
  9372. bp->stats_init = true;
  9373. netif_carrier_off(dev);
  9374. bnx2x_set_power_state(bp, PCI_D0);
  9375. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9376. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9377. /*
  9378. * If parity had happen during the unload, then attentions
  9379. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9380. * want the first function loaded on the current engine to
  9381. * complete the recovery.
  9382. */
  9383. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9384. bnx2x_chk_parity_attn(bp, &global, true))
  9385. do {
  9386. /*
  9387. * If there are attentions and they are in a global
  9388. * blocks, set the GLOBAL_RESET bit regardless whether
  9389. * it will be this function that will complete the
  9390. * recovery or not.
  9391. */
  9392. if (global)
  9393. bnx2x_set_reset_global(bp);
  9394. /*
  9395. * Only the first function on the current engine should
  9396. * try to recover in open. In case of attentions in
  9397. * global blocks only the first in the chip should try
  9398. * to recover.
  9399. */
  9400. if ((!load_status &&
  9401. (!global || !other_load_status)) &&
  9402. bnx2x_trylock_leader_lock(bp) &&
  9403. !bnx2x_leader_reset(bp)) {
  9404. netdev_info(bp->dev, "Recovered in open\n");
  9405. break;
  9406. }
  9407. /* recovery has failed... */
  9408. bnx2x_set_power_state(bp, PCI_D3hot);
  9409. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9410. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9411. "If you still see this message after a few retries then power cycle is required.\n");
  9412. return -EAGAIN;
  9413. } while (0);
  9414. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9415. return bnx2x_nic_load(bp, LOAD_OPEN);
  9416. }
  9417. /* called with rtnl_lock */
  9418. static int bnx2x_close(struct net_device *dev)
  9419. {
  9420. struct bnx2x *bp = netdev_priv(dev);
  9421. /* Unload the driver, release IRQs */
  9422. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9423. /* Power off */
  9424. bnx2x_set_power_state(bp, PCI_D3hot);
  9425. return 0;
  9426. }
  9427. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9428. struct bnx2x_mcast_ramrod_params *p)
  9429. {
  9430. int mc_count = netdev_mc_count(bp->dev);
  9431. struct bnx2x_mcast_list_elem *mc_mac =
  9432. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9433. struct netdev_hw_addr *ha;
  9434. if (!mc_mac)
  9435. return -ENOMEM;
  9436. INIT_LIST_HEAD(&p->mcast_list);
  9437. netdev_for_each_mc_addr(ha, bp->dev) {
  9438. mc_mac->mac = bnx2x_mc_addr(ha);
  9439. list_add_tail(&mc_mac->link, &p->mcast_list);
  9440. mc_mac++;
  9441. }
  9442. p->mcast_list_len = mc_count;
  9443. return 0;
  9444. }
  9445. static void bnx2x_free_mcast_macs_list(
  9446. struct bnx2x_mcast_ramrod_params *p)
  9447. {
  9448. struct bnx2x_mcast_list_elem *mc_mac =
  9449. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9450. link);
  9451. WARN_ON(!mc_mac);
  9452. kfree(mc_mac);
  9453. }
  9454. /**
  9455. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9456. *
  9457. * @bp: driver handle
  9458. *
  9459. * We will use zero (0) as a MAC type for these MACs.
  9460. */
  9461. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9462. {
  9463. int rc;
  9464. struct net_device *dev = bp->dev;
  9465. struct netdev_hw_addr *ha;
  9466. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9467. unsigned long ramrod_flags = 0;
  9468. /* First schedule a cleanup up of old configuration */
  9469. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9470. if (rc < 0) {
  9471. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9472. return rc;
  9473. }
  9474. netdev_for_each_uc_addr(ha, dev) {
  9475. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9476. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9477. if (rc == -EEXIST) {
  9478. DP(BNX2X_MSG_SP,
  9479. "Failed to schedule ADD operations: %d\n", rc);
  9480. /* do not treat adding same MAC as error */
  9481. rc = 0;
  9482. } else if (rc < 0) {
  9483. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9484. rc);
  9485. return rc;
  9486. }
  9487. }
  9488. /* Execute the pending commands */
  9489. __set_bit(RAMROD_CONT, &ramrod_flags);
  9490. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9491. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9492. }
  9493. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9494. {
  9495. struct net_device *dev = bp->dev;
  9496. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9497. int rc = 0;
  9498. rparam.mcast_obj = &bp->mcast_obj;
  9499. /* first, clear all configured multicast MACs */
  9500. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9501. if (rc < 0) {
  9502. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9503. return rc;
  9504. }
  9505. /* then, configure a new MACs list */
  9506. if (netdev_mc_count(dev)) {
  9507. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9508. if (rc) {
  9509. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9510. rc);
  9511. return rc;
  9512. }
  9513. /* Now add the new MACs */
  9514. rc = bnx2x_config_mcast(bp, &rparam,
  9515. BNX2X_MCAST_CMD_ADD);
  9516. if (rc < 0)
  9517. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9518. rc);
  9519. bnx2x_free_mcast_macs_list(&rparam);
  9520. }
  9521. return rc;
  9522. }
  9523. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9524. void bnx2x_set_rx_mode(struct net_device *dev)
  9525. {
  9526. struct bnx2x *bp = netdev_priv(dev);
  9527. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9528. if (bp->state != BNX2X_STATE_OPEN) {
  9529. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9530. return;
  9531. }
  9532. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9533. if (dev->flags & IFF_PROMISC)
  9534. rx_mode = BNX2X_RX_MODE_PROMISC;
  9535. else if ((dev->flags & IFF_ALLMULTI) ||
  9536. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9537. CHIP_IS_E1(bp)))
  9538. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9539. else {
  9540. /* some multicasts */
  9541. if (bnx2x_set_mc_list(bp) < 0)
  9542. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9543. if (bnx2x_set_uc_list(bp) < 0)
  9544. rx_mode = BNX2X_RX_MODE_PROMISC;
  9545. }
  9546. bp->rx_mode = rx_mode;
  9547. /* handle ISCSI SD mode */
  9548. if (IS_MF_ISCSI_SD(bp))
  9549. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9550. /* Schedule the rx_mode command */
  9551. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9552. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9553. return;
  9554. }
  9555. bnx2x_set_storm_rx_mode(bp);
  9556. }
  9557. /* called with rtnl_lock */
  9558. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9559. int devad, u16 addr)
  9560. {
  9561. struct bnx2x *bp = netdev_priv(netdev);
  9562. u16 value;
  9563. int rc;
  9564. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9565. prtad, devad, addr);
  9566. /* The HW expects different devad if CL22 is used */
  9567. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9568. bnx2x_acquire_phy_lock(bp);
  9569. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9570. bnx2x_release_phy_lock(bp);
  9571. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9572. if (!rc)
  9573. rc = value;
  9574. return rc;
  9575. }
  9576. /* called with rtnl_lock */
  9577. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9578. u16 addr, u16 value)
  9579. {
  9580. struct bnx2x *bp = netdev_priv(netdev);
  9581. int rc;
  9582. DP(NETIF_MSG_LINK,
  9583. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9584. prtad, devad, addr, value);
  9585. /* The HW expects different devad if CL22 is used */
  9586. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9587. bnx2x_acquire_phy_lock(bp);
  9588. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9589. bnx2x_release_phy_lock(bp);
  9590. return rc;
  9591. }
  9592. /* called with rtnl_lock */
  9593. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9594. {
  9595. struct bnx2x *bp = netdev_priv(dev);
  9596. struct mii_ioctl_data *mdio = if_mii(ifr);
  9597. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9598. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9599. if (!netif_running(dev))
  9600. return -EAGAIN;
  9601. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9602. }
  9603. #ifdef CONFIG_NET_POLL_CONTROLLER
  9604. static void poll_bnx2x(struct net_device *dev)
  9605. {
  9606. struct bnx2x *bp = netdev_priv(dev);
  9607. int i;
  9608. for_each_eth_queue(bp, i) {
  9609. struct bnx2x_fastpath *fp = &bp->fp[i];
  9610. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9611. }
  9612. }
  9613. #endif
  9614. static int bnx2x_validate_addr(struct net_device *dev)
  9615. {
  9616. struct bnx2x *bp = netdev_priv(dev);
  9617. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9618. BNX2X_ERR("Non-valid Ethernet address\n");
  9619. return -EADDRNOTAVAIL;
  9620. }
  9621. return 0;
  9622. }
  9623. static const struct net_device_ops bnx2x_netdev_ops = {
  9624. .ndo_open = bnx2x_open,
  9625. .ndo_stop = bnx2x_close,
  9626. .ndo_start_xmit = bnx2x_start_xmit,
  9627. .ndo_select_queue = bnx2x_select_queue,
  9628. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9629. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9630. .ndo_validate_addr = bnx2x_validate_addr,
  9631. .ndo_do_ioctl = bnx2x_ioctl,
  9632. .ndo_change_mtu = bnx2x_change_mtu,
  9633. .ndo_fix_features = bnx2x_fix_features,
  9634. .ndo_set_features = bnx2x_set_features,
  9635. .ndo_tx_timeout = bnx2x_tx_timeout,
  9636. #ifdef CONFIG_NET_POLL_CONTROLLER
  9637. .ndo_poll_controller = poll_bnx2x,
  9638. #endif
  9639. .ndo_setup_tc = bnx2x_setup_tc,
  9640. #ifdef NETDEV_FCOE_WWNN
  9641. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9642. #endif
  9643. };
  9644. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9645. {
  9646. struct device *dev = &bp->pdev->dev;
  9647. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9648. bp->flags |= USING_DAC_FLAG;
  9649. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9650. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9651. return -EIO;
  9652. }
  9653. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9654. dev_err(dev, "System does not support DMA, aborting\n");
  9655. return -EIO;
  9656. }
  9657. return 0;
  9658. }
  9659. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9660. struct net_device *dev, unsigned long board_type)
  9661. {
  9662. int rc;
  9663. u32 pci_cfg_dword;
  9664. bool chip_is_e1x = (board_type == BCM57710 ||
  9665. board_type == BCM57711 ||
  9666. board_type == BCM57711E);
  9667. SET_NETDEV_DEV(dev, &pdev->dev);
  9668. bp->dev = dev;
  9669. bp->pdev = pdev;
  9670. rc = pci_enable_device(pdev);
  9671. if (rc) {
  9672. dev_err(&bp->pdev->dev,
  9673. "Cannot enable PCI device, aborting\n");
  9674. goto err_out;
  9675. }
  9676. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9677. dev_err(&bp->pdev->dev,
  9678. "Cannot find PCI device base address, aborting\n");
  9679. rc = -ENODEV;
  9680. goto err_out_disable;
  9681. }
  9682. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9683. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9684. rc = -ENODEV;
  9685. goto err_out_disable;
  9686. }
  9687. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9688. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9689. PCICFG_REVESION_ID_ERROR_VAL) {
  9690. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9691. rc = -ENODEV;
  9692. goto err_out_disable;
  9693. }
  9694. if (atomic_read(&pdev->enable_cnt) == 1) {
  9695. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9696. if (rc) {
  9697. dev_err(&bp->pdev->dev,
  9698. "Cannot obtain PCI resources, aborting\n");
  9699. goto err_out_disable;
  9700. }
  9701. pci_set_master(pdev);
  9702. pci_save_state(pdev);
  9703. }
  9704. if (IS_PF(bp)) {
  9705. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9706. if (bp->pm_cap == 0) {
  9707. dev_err(&bp->pdev->dev,
  9708. "Cannot find power management capability, aborting\n");
  9709. rc = -EIO;
  9710. goto err_out_release;
  9711. }
  9712. }
  9713. if (!pci_is_pcie(pdev)) {
  9714. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9715. rc = -EIO;
  9716. goto err_out_release;
  9717. }
  9718. rc = bnx2x_set_coherency_mask(bp);
  9719. if (rc)
  9720. goto err_out_release;
  9721. dev->mem_start = pci_resource_start(pdev, 0);
  9722. dev->base_addr = dev->mem_start;
  9723. dev->mem_end = pci_resource_end(pdev, 0);
  9724. dev->irq = pdev->irq;
  9725. bp->regview = pci_ioremap_bar(pdev, 0);
  9726. if (!bp->regview) {
  9727. dev_err(&bp->pdev->dev,
  9728. "Cannot map register space, aborting\n");
  9729. rc = -ENOMEM;
  9730. goto err_out_release;
  9731. }
  9732. /* In E1/E1H use pci device function given by kernel.
  9733. * In E2/E3 read physical function from ME register since these chips
  9734. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9735. * (depending on hypervisor).
  9736. */
  9737. if (chip_is_e1x)
  9738. bp->pf_num = PCI_FUNC(pdev->devfn);
  9739. else {/* chip is E2/3*/
  9740. pci_read_config_dword(bp->pdev,
  9741. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9742. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9743. ME_REG_ABS_PF_NUM_SHIFT);
  9744. }
  9745. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9746. bnx2x_set_power_state(bp, PCI_D0);
  9747. /* clean indirect addresses */
  9748. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9749. PCICFG_VENDOR_ID_OFFSET);
  9750. /*
  9751. * Clean the following indirect addresses for all functions since it
  9752. * is not used by the driver.
  9753. */
  9754. if (IS_PF(bp)) {
  9755. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9756. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9757. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9758. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9759. if (chip_is_e1x) {
  9760. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9761. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9762. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9763. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9764. }
  9765. /* Enable internal target-read (in case we are probed after PF
  9766. * FLR). Must be done prior to any BAR read access. Only for
  9767. * 57712 and up
  9768. */
  9769. if (!chip_is_e1x)
  9770. REG_WR(bp,
  9771. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9772. }
  9773. dev->watchdog_timeo = TX_TIMEOUT;
  9774. dev->netdev_ops = &bnx2x_netdev_ops;
  9775. bnx2x_set_ethtool_ops(dev);
  9776. dev->priv_flags |= IFF_UNICAST_FLT;
  9777. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9778. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9779. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9780. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9781. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9782. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9783. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9784. if (bp->flags & USING_DAC_FLAG)
  9785. dev->features |= NETIF_F_HIGHDMA;
  9786. /* Add Loopback capability to the device */
  9787. dev->hw_features |= NETIF_F_LOOPBACK;
  9788. #ifdef BCM_DCBNL
  9789. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9790. #endif
  9791. /* get_port_hwinfo() will set prtad and mmds properly */
  9792. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9793. bp->mdio.mmds = 0;
  9794. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9795. bp->mdio.dev = dev;
  9796. bp->mdio.mdio_read = bnx2x_mdio_read;
  9797. bp->mdio.mdio_write = bnx2x_mdio_write;
  9798. return 0;
  9799. err_out_release:
  9800. if (atomic_read(&pdev->enable_cnt) == 1)
  9801. pci_release_regions(pdev);
  9802. err_out_disable:
  9803. pci_disable_device(pdev);
  9804. pci_set_drvdata(pdev, NULL);
  9805. err_out:
  9806. return rc;
  9807. }
  9808. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  9809. {
  9810. u32 val = 0;
  9811. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  9812. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9813. /* return value of 1=2.5GHz 2=5GHz */
  9814. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9815. }
  9816. static int bnx2x_check_firmware(struct bnx2x *bp)
  9817. {
  9818. const struct firmware *firmware = bp->firmware;
  9819. struct bnx2x_fw_file_hdr *fw_hdr;
  9820. struct bnx2x_fw_file_section *sections;
  9821. u32 offset, len, num_ops;
  9822. u16 *ops_offsets;
  9823. int i;
  9824. const u8 *fw_ver;
  9825. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9826. BNX2X_ERR("Wrong FW size\n");
  9827. return -EINVAL;
  9828. }
  9829. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9830. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9831. /* Make sure none of the offsets and sizes make us read beyond
  9832. * the end of the firmware data */
  9833. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9834. offset = be32_to_cpu(sections[i].offset);
  9835. len = be32_to_cpu(sections[i].len);
  9836. if (offset + len > firmware->size) {
  9837. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9838. return -EINVAL;
  9839. }
  9840. }
  9841. /* Likewise for the init_ops offsets */
  9842. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9843. ops_offsets = (u16 *)(firmware->data + offset);
  9844. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9845. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9846. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9847. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  9848. return -EINVAL;
  9849. }
  9850. }
  9851. /* Check FW version */
  9852. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9853. fw_ver = firmware->data + offset;
  9854. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9855. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9856. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9857. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9858. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  9859. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  9860. BCM_5710_FW_MAJOR_VERSION,
  9861. BCM_5710_FW_MINOR_VERSION,
  9862. BCM_5710_FW_REVISION_VERSION,
  9863. BCM_5710_FW_ENGINEERING_VERSION);
  9864. return -EINVAL;
  9865. }
  9866. return 0;
  9867. }
  9868. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9869. {
  9870. const __be32 *source = (const __be32 *)_source;
  9871. u32 *target = (u32 *)_target;
  9872. u32 i;
  9873. for (i = 0; i < n/4; i++)
  9874. target[i] = be32_to_cpu(source[i]);
  9875. }
  9876. /*
  9877. Ops array is stored in the following format:
  9878. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9879. */
  9880. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9881. {
  9882. const __be32 *source = (const __be32 *)_source;
  9883. struct raw_op *target = (struct raw_op *)_target;
  9884. u32 i, j, tmp;
  9885. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9886. tmp = be32_to_cpu(source[j]);
  9887. target[i].op = (tmp >> 24) & 0xff;
  9888. target[i].offset = tmp & 0xffffff;
  9889. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9890. }
  9891. }
  9892. /* IRO array is stored in the following format:
  9893. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9894. */
  9895. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9896. {
  9897. const __be32 *source = (const __be32 *)_source;
  9898. struct iro *target = (struct iro *)_target;
  9899. u32 i, j, tmp;
  9900. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9901. target[i].base = be32_to_cpu(source[j]);
  9902. j++;
  9903. tmp = be32_to_cpu(source[j]);
  9904. target[i].m1 = (tmp >> 16) & 0xffff;
  9905. target[i].m2 = tmp & 0xffff;
  9906. j++;
  9907. tmp = be32_to_cpu(source[j]);
  9908. target[i].m3 = (tmp >> 16) & 0xffff;
  9909. target[i].size = tmp & 0xffff;
  9910. j++;
  9911. }
  9912. }
  9913. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9914. {
  9915. const __be16 *source = (const __be16 *)_source;
  9916. u16 *target = (u16 *)_target;
  9917. u32 i;
  9918. for (i = 0; i < n/2; i++)
  9919. target[i] = be16_to_cpu(source[i]);
  9920. }
  9921. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9922. do { \
  9923. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9924. bp->arr = kmalloc(len, GFP_KERNEL); \
  9925. if (!bp->arr) \
  9926. goto lbl; \
  9927. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9928. (u8 *)bp->arr, len); \
  9929. } while (0)
  9930. static int bnx2x_init_firmware(struct bnx2x *bp)
  9931. {
  9932. const char *fw_file_name;
  9933. struct bnx2x_fw_file_hdr *fw_hdr;
  9934. int rc;
  9935. if (bp->firmware)
  9936. return 0;
  9937. if (CHIP_IS_E1(bp))
  9938. fw_file_name = FW_FILE_NAME_E1;
  9939. else if (CHIP_IS_E1H(bp))
  9940. fw_file_name = FW_FILE_NAME_E1H;
  9941. else if (!CHIP_IS_E1x(bp))
  9942. fw_file_name = FW_FILE_NAME_E2;
  9943. else {
  9944. BNX2X_ERR("Unsupported chip revision\n");
  9945. return -EINVAL;
  9946. }
  9947. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9948. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9949. if (rc) {
  9950. BNX2X_ERR("Can't load firmware file %s\n",
  9951. fw_file_name);
  9952. goto request_firmware_exit;
  9953. }
  9954. rc = bnx2x_check_firmware(bp);
  9955. if (rc) {
  9956. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9957. goto request_firmware_exit;
  9958. }
  9959. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  9960. /* Initialize the pointers to the init arrays */
  9961. /* Blob */
  9962. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  9963. /* Opcodes */
  9964. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  9965. /* Offsets */
  9966. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  9967. be16_to_cpu_n);
  9968. /* STORMs firmware */
  9969. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9970. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  9971. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  9972. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  9973. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9974. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  9975. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  9976. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  9977. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9978. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  9979. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  9980. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  9981. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9982. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  9983. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  9984. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  9985. /* IRO */
  9986. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  9987. return 0;
  9988. iro_alloc_err:
  9989. kfree(bp->init_ops_offsets);
  9990. init_offsets_alloc_err:
  9991. kfree(bp->init_ops);
  9992. init_ops_alloc_err:
  9993. kfree(bp->init_data);
  9994. request_firmware_exit:
  9995. release_firmware(bp->firmware);
  9996. bp->firmware = NULL;
  9997. return rc;
  9998. }
  9999. static void bnx2x_release_firmware(struct bnx2x *bp)
  10000. {
  10001. kfree(bp->init_ops_offsets);
  10002. kfree(bp->init_ops);
  10003. kfree(bp->init_data);
  10004. release_firmware(bp->firmware);
  10005. bp->firmware = NULL;
  10006. }
  10007. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10008. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10009. .init_hw_cmn = bnx2x_init_hw_common,
  10010. .init_hw_port = bnx2x_init_hw_port,
  10011. .init_hw_func = bnx2x_init_hw_func,
  10012. .reset_hw_cmn = bnx2x_reset_common,
  10013. .reset_hw_port = bnx2x_reset_port,
  10014. .reset_hw_func = bnx2x_reset_func,
  10015. .gunzip_init = bnx2x_gunzip_init,
  10016. .gunzip_end = bnx2x_gunzip_end,
  10017. .init_fw = bnx2x_init_firmware,
  10018. .release_fw = bnx2x_release_firmware,
  10019. };
  10020. void bnx2x__init_func_obj(struct bnx2x *bp)
  10021. {
  10022. /* Prepare DMAE related driver resources */
  10023. bnx2x_setup_dmae(bp);
  10024. bnx2x_init_func_obj(bp, &bp->func_obj,
  10025. bnx2x_sp(bp, func_rdata),
  10026. bnx2x_sp_mapping(bp, func_rdata),
  10027. bnx2x_sp(bp, func_afex_rdata),
  10028. bnx2x_sp_mapping(bp, func_afex_rdata),
  10029. &bnx2x_func_sp_drv);
  10030. }
  10031. /* must be called after sriov-enable */
  10032. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10033. {
  10034. int cid_count = BNX2X_L2_MAX_CID(bp);
  10035. if (CNIC_SUPPORT(bp))
  10036. cid_count += CNIC_CID_MAX;
  10037. return roundup(cid_count, QM_CID_ROUND);
  10038. }
  10039. /**
  10040. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10041. *
  10042. * @dev: pci device
  10043. *
  10044. */
  10045. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10046. int cnic_cnt, bool is_vf)
  10047. {
  10048. int pos, index;
  10049. u16 control = 0;
  10050. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10051. /*
  10052. * If MSI-X is not supported - return number of SBs needed to support
  10053. * one fast path queue: one FP queue + SB for CNIC
  10054. */
  10055. if (!pos) {
  10056. dev_info(&pdev->dev, "no msix capability found\n");
  10057. return 1 + cnic_cnt;
  10058. }
  10059. dev_info(&pdev->dev, "msix capability found\n");
  10060. /*
  10061. * The value in the PCI configuration space is the index of the last
  10062. * entry, namely one less than the actual size of the table, which is
  10063. * exactly what we want to return from this function: number of all SBs
  10064. * without the default SB.
  10065. * For VFs there is no default SB, then we return (index+1).
  10066. */
  10067. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10068. index = control & PCI_MSIX_FLAGS_QSIZE;
  10069. return is_vf ? index + 1 : index;
  10070. }
  10071. static int set_max_cos_est(int chip_id)
  10072. {
  10073. switch (chip_id) {
  10074. case BCM57710:
  10075. case BCM57711:
  10076. case BCM57711E:
  10077. return BNX2X_MULTI_TX_COS_E1X;
  10078. case BCM57712:
  10079. case BCM57712_MF:
  10080. case BCM57712_VF:
  10081. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10082. case BCM57800:
  10083. case BCM57800_MF:
  10084. case BCM57800_VF:
  10085. case BCM57810:
  10086. case BCM57810_MF:
  10087. case BCM57840_4_10:
  10088. case BCM57840_2_20:
  10089. case BCM57840_O:
  10090. case BCM57840_MFO:
  10091. case BCM57810_VF:
  10092. case BCM57840_MF:
  10093. case BCM57840_VF:
  10094. case BCM57811:
  10095. case BCM57811_MF:
  10096. case BCM57811_VF:
  10097. return BNX2X_MULTI_TX_COS_E3B0;
  10098. return 1;
  10099. default:
  10100. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10101. return -ENODEV;
  10102. }
  10103. }
  10104. static int set_is_vf(int chip_id)
  10105. {
  10106. switch (chip_id) {
  10107. case BCM57712_VF:
  10108. case BCM57800_VF:
  10109. case BCM57810_VF:
  10110. case BCM57840_VF:
  10111. case BCM57811_VF:
  10112. return true;
  10113. default:
  10114. return false;
  10115. }
  10116. }
  10117. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10118. static int bnx2x_init_one(struct pci_dev *pdev,
  10119. const struct pci_device_id *ent)
  10120. {
  10121. struct net_device *dev = NULL;
  10122. struct bnx2x *bp;
  10123. int pcie_width, pcie_speed;
  10124. int rc, max_non_def_sbs;
  10125. int rx_count, tx_count, rss_count, doorbell_size;
  10126. int max_cos_est;
  10127. bool is_vf;
  10128. int cnic_cnt;
  10129. /* An estimated maximum supported CoS number according to the chip
  10130. * version.
  10131. * We will try to roughly estimate the maximum number of CoSes this chip
  10132. * may support in order to minimize the memory allocated for Tx
  10133. * netdev_queue's. This number will be accurately calculated during the
  10134. * initialization of bp->max_cos based on the chip versions AND chip
  10135. * revision in the bnx2x_init_bp().
  10136. */
  10137. max_cos_est = set_max_cos_est(ent->driver_data);
  10138. if (max_cos_est < 0)
  10139. return max_cos_est;
  10140. is_vf = set_is_vf(ent->driver_data);
  10141. cnic_cnt = is_vf ? 0 : 1;
  10142. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10143. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10144. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10145. if (rss_count < 1)
  10146. return -EINVAL;
  10147. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10148. rx_count = rss_count + cnic_cnt;
  10149. /* Maximum number of netdev Tx queues:
  10150. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10151. */
  10152. tx_count = rss_count * max_cos_est + cnic_cnt;
  10153. /* dev zeroed in init_etherdev */
  10154. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10155. if (!dev)
  10156. return -ENOMEM;
  10157. bp = netdev_priv(dev);
  10158. bp->flags = 0;
  10159. if (is_vf)
  10160. bp->flags |= IS_VF_FLAG;
  10161. bp->igu_sb_cnt = max_non_def_sbs;
  10162. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10163. bp->msg_enable = debug;
  10164. bp->cnic_support = cnic_cnt;
  10165. bp->cnic_probe = bnx2x_cnic_probe;
  10166. pci_set_drvdata(pdev, dev);
  10167. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10168. if (rc < 0) {
  10169. free_netdev(dev);
  10170. return rc;
  10171. }
  10172. BNX2X_DEV_INFO("This is a %s function\n",
  10173. IS_PF(bp) ? "physical" : "virtual");
  10174. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10175. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10176. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10177. tx_count, rx_count);
  10178. rc = bnx2x_init_bp(bp);
  10179. if (rc)
  10180. goto init_one_exit;
  10181. /* Map doorbells here as we need the real value of bp->max_cos which
  10182. * is initialized in bnx2x_init_bp() to determine the number of
  10183. * l2 connections.
  10184. */
  10185. if (IS_VF(bp)) {
  10186. /* vf doorbells are embedded within the regview */
  10187. bp->doorbells = bp->regview + PXP_VF_ADDR_DB_START;
  10188. /* allocate vf2pf mailbox for vf to pf channel */
  10189. BNX2X_PCI_ALLOC(bp->vf2pf_mbox, &bp->vf2pf_mbox_mapping,
  10190. sizeof(struct bnx2x_vf_mbx_msg));
  10191. } else {
  10192. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10193. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10194. dev_err(&bp->pdev->dev,
  10195. "Cannot map doorbells, bar size too small, aborting\n");
  10196. rc = -ENOMEM;
  10197. goto init_one_exit;
  10198. }
  10199. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10200. doorbell_size);
  10201. }
  10202. if (!bp->doorbells) {
  10203. dev_err(&bp->pdev->dev,
  10204. "Cannot map doorbell space, aborting\n");
  10205. rc = -ENOMEM;
  10206. goto init_one_exit;
  10207. }
  10208. if (IS_VF(bp)) {
  10209. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10210. if (rc)
  10211. goto init_one_exit;
  10212. }
  10213. /* calc qm_cid_count */
  10214. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10215. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10216. /* disable FCOE L2 queue for E1x*/
  10217. if (CHIP_IS_E1x(bp))
  10218. bp->flags |= NO_FCOE_FLAG;
  10219. /* disable FCOE for 57840 device, until FW supports it */
  10220. switch (ent->driver_data) {
  10221. case BCM57840_O:
  10222. case BCM57840_4_10:
  10223. case BCM57840_2_20:
  10224. case BCM57840_MFO:
  10225. case BCM57840_MF:
  10226. bp->flags |= NO_FCOE_FLAG;
  10227. }
  10228. /* Set bp->num_queues for MSI-X mode*/
  10229. bnx2x_set_num_queues(bp);
  10230. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10231. * needed.
  10232. */
  10233. rc = bnx2x_set_int_mode(bp);
  10234. if (rc) {
  10235. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10236. goto init_one_exit;
  10237. }
  10238. /* register the net device */
  10239. rc = register_netdev(dev);
  10240. if (rc) {
  10241. dev_err(&pdev->dev, "Cannot register net device\n");
  10242. goto init_one_exit;
  10243. }
  10244. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10245. if (!NO_FCOE(bp)) {
  10246. /* Add storage MAC address */
  10247. rtnl_lock();
  10248. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10249. rtnl_unlock();
  10250. }
  10251. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10252. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10253. pcie_width, pcie_speed);
  10254. BNX2X_DEV_INFO(
  10255. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10256. board_info[ent->driver_data].name,
  10257. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10258. pcie_width,
  10259. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10260. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10261. "5GHz (Gen2)" : "2.5GHz",
  10262. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10263. return 0;
  10264. alloc_mem_err:
  10265. BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->vf2pf_mbox_mapping,
  10266. sizeof(struct bnx2x_vf_mbx_msg));
  10267. rc = -ENOMEM;
  10268. init_one_exit:
  10269. if (bp->regview)
  10270. iounmap(bp->regview);
  10271. if (IS_PF(bp) && bp->doorbells)
  10272. iounmap(bp->doorbells);
  10273. free_netdev(dev);
  10274. if (atomic_read(&pdev->enable_cnt) == 1)
  10275. pci_release_regions(pdev);
  10276. pci_disable_device(pdev);
  10277. pci_set_drvdata(pdev, NULL);
  10278. return rc;
  10279. }
  10280. static void bnx2x_remove_one(struct pci_dev *pdev)
  10281. {
  10282. struct net_device *dev = pci_get_drvdata(pdev);
  10283. struct bnx2x *bp;
  10284. if (!dev) {
  10285. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10286. return;
  10287. }
  10288. bp = netdev_priv(dev);
  10289. /* Delete storage MAC address */
  10290. if (!NO_FCOE(bp)) {
  10291. rtnl_lock();
  10292. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10293. rtnl_unlock();
  10294. }
  10295. #ifdef BCM_DCBNL
  10296. /* Delete app tlvs from dcbnl */
  10297. bnx2x_dcbnl_update_applist(bp, true);
  10298. #endif
  10299. unregister_netdev(dev);
  10300. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10301. if (IS_PF(bp))
  10302. bnx2x_set_power_state(bp, PCI_D0);
  10303. /* Disable MSI/MSI-X */
  10304. bnx2x_disable_msi(bp);
  10305. /* Power off */
  10306. if (IS_PF(bp))
  10307. bnx2x_set_power_state(bp, PCI_D3hot);
  10308. /* Make sure RESET task is not scheduled before continuing */
  10309. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10310. /* send message via vfpf channel to release the resources of this vf */
  10311. if (IS_VF(bp))
  10312. bnx2x_vfpf_release(bp);
  10313. if (bp->regview)
  10314. iounmap(bp->regview);
  10315. /* for vf doorbells are part of the regview and were unmapped along with
  10316. * it. FW is only loaded by PF.
  10317. */
  10318. if (IS_PF(bp)) {
  10319. if (bp->doorbells)
  10320. iounmap(bp->doorbells);
  10321. bnx2x_release_firmware(bp);
  10322. }
  10323. bnx2x_free_mem_bp(bp);
  10324. free_netdev(dev);
  10325. if (atomic_read(&pdev->enable_cnt) == 1)
  10326. pci_release_regions(pdev);
  10327. pci_disable_device(pdev);
  10328. pci_set_drvdata(pdev, NULL);
  10329. }
  10330. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10331. {
  10332. int i;
  10333. bp->state = BNX2X_STATE_ERROR;
  10334. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10335. if (CNIC_LOADED(bp))
  10336. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10337. /* Stop Tx */
  10338. bnx2x_tx_disable(bp);
  10339. bnx2x_netif_stop(bp, 0);
  10340. /* Delete all NAPI objects */
  10341. bnx2x_del_all_napi(bp);
  10342. if (CNIC_LOADED(bp))
  10343. bnx2x_del_all_napi_cnic(bp);
  10344. del_timer_sync(&bp->timer);
  10345. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10346. /* Release IRQs */
  10347. bnx2x_free_irq(bp);
  10348. /* Free SKBs, SGEs, TPA pool and driver internals */
  10349. bnx2x_free_skbs(bp);
  10350. for_each_rx_queue(bp, i)
  10351. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10352. bnx2x_free_mem(bp);
  10353. bp->state = BNX2X_STATE_CLOSED;
  10354. netif_carrier_off(bp->dev);
  10355. return 0;
  10356. }
  10357. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10358. {
  10359. u32 val;
  10360. mutex_init(&bp->port.phy_mutex);
  10361. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10362. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10363. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10364. BNX2X_ERR("BAD MCP validity signature\n");
  10365. }
  10366. /**
  10367. * bnx2x_io_error_detected - called when PCI error is detected
  10368. * @pdev: Pointer to PCI device
  10369. * @state: The current pci connection state
  10370. *
  10371. * This function is called after a PCI bus error affecting
  10372. * this device has been detected.
  10373. */
  10374. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10375. pci_channel_state_t state)
  10376. {
  10377. struct net_device *dev = pci_get_drvdata(pdev);
  10378. struct bnx2x *bp = netdev_priv(dev);
  10379. rtnl_lock();
  10380. netif_device_detach(dev);
  10381. if (state == pci_channel_io_perm_failure) {
  10382. rtnl_unlock();
  10383. return PCI_ERS_RESULT_DISCONNECT;
  10384. }
  10385. if (netif_running(dev))
  10386. bnx2x_eeh_nic_unload(bp);
  10387. pci_disable_device(pdev);
  10388. rtnl_unlock();
  10389. /* Request a slot reset */
  10390. return PCI_ERS_RESULT_NEED_RESET;
  10391. }
  10392. /**
  10393. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10394. * @pdev: Pointer to PCI device
  10395. *
  10396. * Restart the card from scratch, as if from a cold-boot.
  10397. */
  10398. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10399. {
  10400. struct net_device *dev = pci_get_drvdata(pdev);
  10401. struct bnx2x *bp = netdev_priv(dev);
  10402. rtnl_lock();
  10403. if (pci_enable_device(pdev)) {
  10404. dev_err(&pdev->dev,
  10405. "Cannot re-enable PCI device after reset\n");
  10406. rtnl_unlock();
  10407. return PCI_ERS_RESULT_DISCONNECT;
  10408. }
  10409. pci_set_master(pdev);
  10410. pci_restore_state(pdev);
  10411. if (netif_running(dev))
  10412. bnx2x_set_power_state(bp, PCI_D0);
  10413. rtnl_unlock();
  10414. return PCI_ERS_RESULT_RECOVERED;
  10415. }
  10416. /**
  10417. * bnx2x_io_resume - called when traffic can start flowing again
  10418. * @pdev: Pointer to PCI device
  10419. *
  10420. * This callback is called when the error recovery driver tells us that
  10421. * its OK to resume normal operation.
  10422. */
  10423. static void bnx2x_io_resume(struct pci_dev *pdev)
  10424. {
  10425. struct net_device *dev = pci_get_drvdata(pdev);
  10426. struct bnx2x *bp = netdev_priv(dev);
  10427. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10428. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10429. return;
  10430. }
  10431. rtnl_lock();
  10432. bnx2x_eeh_recover(bp);
  10433. if (netif_running(dev))
  10434. bnx2x_nic_load(bp, LOAD_NORMAL);
  10435. netif_device_attach(dev);
  10436. rtnl_unlock();
  10437. }
  10438. static const struct pci_error_handlers bnx2x_err_handler = {
  10439. .error_detected = bnx2x_io_error_detected,
  10440. .slot_reset = bnx2x_io_slot_reset,
  10441. .resume = bnx2x_io_resume,
  10442. };
  10443. static struct pci_driver bnx2x_pci_driver = {
  10444. .name = DRV_MODULE_NAME,
  10445. .id_table = bnx2x_pci_tbl,
  10446. .probe = bnx2x_init_one,
  10447. .remove = bnx2x_remove_one,
  10448. .suspend = bnx2x_suspend,
  10449. .resume = bnx2x_resume,
  10450. .err_handler = &bnx2x_err_handler,
  10451. };
  10452. static int __init bnx2x_init(void)
  10453. {
  10454. int ret;
  10455. pr_info("%s", version);
  10456. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10457. if (bnx2x_wq == NULL) {
  10458. pr_err("Cannot create workqueue\n");
  10459. return -ENOMEM;
  10460. }
  10461. ret = pci_register_driver(&bnx2x_pci_driver);
  10462. if (ret) {
  10463. pr_err("Cannot register driver\n");
  10464. destroy_workqueue(bnx2x_wq);
  10465. }
  10466. return ret;
  10467. }
  10468. static void __exit bnx2x_cleanup(void)
  10469. {
  10470. struct list_head *pos, *q;
  10471. pci_unregister_driver(&bnx2x_pci_driver);
  10472. destroy_workqueue(bnx2x_wq);
  10473. /* Free globablly allocated resources */
  10474. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10475. struct bnx2x_prev_path_list *tmp =
  10476. list_entry(pos, struct bnx2x_prev_path_list, list);
  10477. list_del(pos);
  10478. kfree(tmp);
  10479. }
  10480. }
  10481. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10482. {
  10483. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10484. }
  10485. module_init(bnx2x_init);
  10486. module_exit(bnx2x_cleanup);
  10487. /**
  10488. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10489. *
  10490. * @bp: driver handle
  10491. * @set: set or clear the CAM entry
  10492. *
  10493. * This function will wait until the ramdord completion returns.
  10494. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10495. */
  10496. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10497. {
  10498. unsigned long ramrod_flags = 0;
  10499. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10500. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10501. &bp->iscsi_l2_mac_obj, true,
  10502. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10503. }
  10504. /* count denotes the number of new completions we have seen */
  10505. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10506. {
  10507. struct eth_spe *spe;
  10508. int cxt_index, cxt_offset;
  10509. #ifdef BNX2X_STOP_ON_ERROR
  10510. if (unlikely(bp->panic))
  10511. return;
  10512. #endif
  10513. spin_lock_bh(&bp->spq_lock);
  10514. BUG_ON(bp->cnic_spq_pending < count);
  10515. bp->cnic_spq_pending -= count;
  10516. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10517. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10518. & SPE_HDR_CONN_TYPE) >>
  10519. SPE_HDR_CONN_TYPE_SHIFT;
  10520. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10521. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10522. /* Set validation for iSCSI L2 client before sending SETUP
  10523. * ramrod
  10524. */
  10525. if (type == ETH_CONNECTION_TYPE) {
  10526. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10527. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10528. ILT_PAGE_CIDS;
  10529. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10530. (cxt_index * ILT_PAGE_CIDS);
  10531. bnx2x_set_ctx_validation(bp,
  10532. &bp->context[cxt_index].
  10533. vcxt[cxt_offset].eth,
  10534. BNX2X_ISCSI_ETH_CID(bp));
  10535. }
  10536. }
  10537. /*
  10538. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10539. * and in the air. We also check that number of outstanding
  10540. * COMMON ramrods is not more than the EQ and SPQ can
  10541. * accommodate.
  10542. */
  10543. if (type == ETH_CONNECTION_TYPE) {
  10544. if (!atomic_read(&bp->cq_spq_left))
  10545. break;
  10546. else
  10547. atomic_dec(&bp->cq_spq_left);
  10548. } else if (type == NONE_CONNECTION_TYPE) {
  10549. if (!atomic_read(&bp->eq_spq_left))
  10550. break;
  10551. else
  10552. atomic_dec(&bp->eq_spq_left);
  10553. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10554. (type == FCOE_CONNECTION_TYPE)) {
  10555. if (bp->cnic_spq_pending >=
  10556. bp->cnic_eth_dev.max_kwqe_pending)
  10557. break;
  10558. else
  10559. bp->cnic_spq_pending++;
  10560. } else {
  10561. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10562. bnx2x_panic();
  10563. break;
  10564. }
  10565. spe = bnx2x_sp_get_next(bp);
  10566. *spe = *bp->cnic_kwq_cons;
  10567. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10568. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10569. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10570. bp->cnic_kwq_cons = bp->cnic_kwq;
  10571. else
  10572. bp->cnic_kwq_cons++;
  10573. }
  10574. bnx2x_sp_prod_update(bp);
  10575. spin_unlock_bh(&bp->spq_lock);
  10576. }
  10577. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10578. struct kwqe_16 *kwqes[], u32 count)
  10579. {
  10580. struct bnx2x *bp = netdev_priv(dev);
  10581. int i;
  10582. #ifdef BNX2X_STOP_ON_ERROR
  10583. if (unlikely(bp->panic)) {
  10584. BNX2X_ERR("Can't post to SP queue while panic\n");
  10585. return -EIO;
  10586. }
  10587. #endif
  10588. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10589. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10590. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10591. return -EAGAIN;
  10592. }
  10593. spin_lock_bh(&bp->spq_lock);
  10594. for (i = 0; i < count; i++) {
  10595. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10596. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10597. break;
  10598. *bp->cnic_kwq_prod = *spe;
  10599. bp->cnic_kwq_pending++;
  10600. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10601. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10602. spe->data.update_data_addr.hi,
  10603. spe->data.update_data_addr.lo,
  10604. bp->cnic_kwq_pending);
  10605. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10606. bp->cnic_kwq_prod = bp->cnic_kwq;
  10607. else
  10608. bp->cnic_kwq_prod++;
  10609. }
  10610. spin_unlock_bh(&bp->spq_lock);
  10611. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10612. bnx2x_cnic_sp_post(bp, 0);
  10613. return i;
  10614. }
  10615. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10616. {
  10617. struct cnic_ops *c_ops;
  10618. int rc = 0;
  10619. mutex_lock(&bp->cnic_mutex);
  10620. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10621. lockdep_is_held(&bp->cnic_mutex));
  10622. if (c_ops)
  10623. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10624. mutex_unlock(&bp->cnic_mutex);
  10625. return rc;
  10626. }
  10627. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10628. {
  10629. struct cnic_ops *c_ops;
  10630. int rc = 0;
  10631. rcu_read_lock();
  10632. c_ops = rcu_dereference(bp->cnic_ops);
  10633. if (c_ops)
  10634. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10635. rcu_read_unlock();
  10636. return rc;
  10637. }
  10638. /*
  10639. * for commands that have no data
  10640. */
  10641. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10642. {
  10643. struct cnic_ctl_info ctl = {0};
  10644. ctl.cmd = cmd;
  10645. return bnx2x_cnic_ctl_send(bp, &ctl);
  10646. }
  10647. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10648. {
  10649. struct cnic_ctl_info ctl = {0};
  10650. /* first we tell CNIC and only then we count this as a completion */
  10651. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10652. ctl.data.comp.cid = cid;
  10653. ctl.data.comp.error = err;
  10654. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10655. bnx2x_cnic_sp_post(bp, 0);
  10656. }
  10657. /* Called with netif_addr_lock_bh() taken.
  10658. * Sets an rx_mode config for an iSCSI ETH client.
  10659. * Doesn't block.
  10660. * Completion should be checked outside.
  10661. */
  10662. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10663. {
  10664. unsigned long accept_flags = 0, ramrod_flags = 0;
  10665. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10666. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10667. if (start) {
  10668. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10669. * because it's the only way for UIO Queue to accept
  10670. * multicasts (in non-promiscuous mode only one Queue per
  10671. * function will receive multicast packets (leading in our
  10672. * case).
  10673. */
  10674. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10675. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10676. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10677. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10678. /* Clear STOP_PENDING bit if START is requested */
  10679. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10680. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10681. } else
  10682. /* Clear START_PENDING bit if STOP is requested */
  10683. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10684. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10685. set_bit(sched_state, &bp->sp_state);
  10686. else {
  10687. __set_bit(RAMROD_RX, &ramrod_flags);
  10688. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10689. ramrod_flags);
  10690. }
  10691. }
  10692. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10693. {
  10694. struct bnx2x *bp = netdev_priv(dev);
  10695. int rc = 0;
  10696. switch (ctl->cmd) {
  10697. case DRV_CTL_CTXTBL_WR_CMD: {
  10698. u32 index = ctl->data.io.offset;
  10699. dma_addr_t addr = ctl->data.io.dma_addr;
  10700. bnx2x_ilt_wr(bp, index, addr);
  10701. break;
  10702. }
  10703. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10704. int count = ctl->data.credit.credit_count;
  10705. bnx2x_cnic_sp_post(bp, count);
  10706. break;
  10707. }
  10708. /* rtnl_lock is held. */
  10709. case DRV_CTL_START_L2_CMD: {
  10710. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10711. unsigned long sp_bits = 0;
  10712. /* Configure the iSCSI classification object */
  10713. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10714. cp->iscsi_l2_client_id,
  10715. cp->iscsi_l2_cid, BP_FUNC(bp),
  10716. bnx2x_sp(bp, mac_rdata),
  10717. bnx2x_sp_mapping(bp, mac_rdata),
  10718. BNX2X_FILTER_MAC_PENDING,
  10719. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10720. &bp->macs_pool);
  10721. /* Set iSCSI MAC address */
  10722. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10723. if (rc)
  10724. break;
  10725. mmiowb();
  10726. barrier();
  10727. /* Start accepting on iSCSI L2 ring */
  10728. netif_addr_lock_bh(dev);
  10729. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10730. netif_addr_unlock_bh(dev);
  10731. /* bits to wait on */
  10732. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10733. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10734. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10735. BNX2X_ERR("rx_mode completion timed out!\n");
  10736. break;
  10737. }
  10738. /* rtnl_lock is held. */
  10739. case DRV_CTL_STOP_L2_CMD: {
  10740. unsigned long sp_bits = 0;
  10741. /* Stop accepting on iSCSI L2 ring */
  10742. netif_addr_lock_bh(dev);
  10743. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10744. netif_addr_unlock_bh(dev);
  10745. /* bits to wait on */
  10746. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10747. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10748. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10749. BNX2X_ERR("rx_mode completion timed out!\n");
  10750. mmiowb();
  10751. barrier();
  10752. /* Unset iSCSI L2 MAC */
  10753. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10754. BNX2X_ISCSI_ETH_MAC, true);
  10755. break;
  10756. }
  10757. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10758. int count = ctl->data.credit.credit_count;
  10759. smp_mb__before_atomic_inc();
  10760. atomic_add(count, &bp->cq_spq_left);
  10761. smp_mb__after_atomic_inc();
  10762. break;
  10763. }
  10764. case DRV_CTL_ULP_REGISTER_CMD: {
  10765. int ulp_type = ctl->data.register_data.ulp_type;
  10766. if (CHIP_IS_E3(bp)) {
  10767. int idx = BP_FW_MB_IDX(bp);
  10768. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10769. int path = BP_PATH(bp);
  10770. int port = BP_PORT(bp);
  10771. int i;
  10772. u32 scratch_offset;
  10773. u32 *host_addr;
  10774. /* first write capability to shmem2 */
  10775. if (ulp_type == CNIC_ULP_ISCSI)
  10776. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10777. else if (ulp_type == CNIC_ULP_FCOE)
  10778. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10779. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10780. if ((ulp_type != CNIC_ULP_FCOE) ||
  10781. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  10782. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  10783. break;
  10784. /* if reached here - should write fcoe capabilities */
  10785. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  10786. if (!scratch_offset)
  10787. break;
  10788. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  10789. fcoe_features[path][port]);
  10790. host_addr = (u32 *) &(ctl->data.register_data.
  10791. fcoe_features);
  10792. for (i = 0; i < sizeof(struct fcoe_capabilities);
  10793. i += 4)
  10794. REG_WR(bp, scratch_offset + i,
  10795. *(host_addr + i/4));
  10796. }
  10797. break;
  10798. }
  10799. case DRV_CTL_ULP_UNREGISTER_CMD: {
  10800. int ulp_type = ctl->data.ulp_type;
  10801. if (CHIP_IS_E3(bp)) {
  10802. int idx = BP_FW_MB_IDX(bp);
  10803. u32 cap;
  10804. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10805. if (ulp_type == CNIC_ULP_ISCSI)
  10806. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10807. else if (ulp_type == CNIC_ULP_FCOE)
  10808. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10809. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10810. }
  10811. break;
  10812. }
  10813. default:
  10814. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10815. rc = -EINVAL;
  10816. }
  10817. return rc;
  10818. }
  10819. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10820. {
  10821. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10822. if (bp->flags & USING_MSIX_FLAG) {
  10823. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10824. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10825. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10826. } else {
  10827. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10828. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10829. }
  10830. if (!CHIP_IS_E1x(bp))
  10831. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  10832. else
  10833. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  10834. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  10835. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  10836. cp->irq_arr[1].status_blk = bp->def_status_blk;
  10837. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  10838. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  10839. cp->num_irq = 2;
  10840. }
  10841. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  10842. {
  10843. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10844. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10845. bnx2x_cid_ilt_lines(bp);
  10846. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10847. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10848. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10849. if (NO_ISCSI_OOO(bp))
  10850. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10851. }
  10852. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  10853. void *data)
  10854. {
  10855. struct bnx2x *bp = netdev_priv(dev);
  10856. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10857. int rc;
  10858. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  10859. if (ops == NULL) {
  10860. BNX2X_ERR("NULL ops received\n");
  10861. return -EINVAL;
  10862. }
  10863. if (!CNIC_SUPPORT(bp)) {
  10864. BNX2X_ERR("Can't register CNIC when not supported\n");
  10865. return -EOPNOTSUPP;
  10866. }
  10867. if (!CNIC_LOADED(bp)) {
  10868. rc = bnx2x_load_cnic(bp);
  10869. if (rc) {
  10870. BNX2X_ERR("CNIC-related load failed\n");
  10871. return rc;
  10872. }
  10873. }
  10874. bp->cnic_enabled = true;
  10875. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  10876. if (!bp->cnic_kwq)
  10877. return -ENOMEM;
  10878. bp->cnic_kwq_cons = bp->cnic_kwq;
  10879. bp->cnic_kwq_prod = bp->cnic_kwq;
  10880. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  10881. bp->cnic_spq_pending = 0;
  10882. bp->cnic_kwq_pending = 0;
  10883. bp->cnic_data = data;
  10884. cp->num_irq = 0;
  10885. cp->drv_state |= CNIC_DRV_STATE_REGD;
  10886. cp->iro_arr = bp->iro_arr;
  10887. bnx2x_setup_cnic_irq_info(bp);
  10888. rcu_assign_pointer(bp->cnic_ops, ops);
  10889. return 0;
  10890. }
  10891. static int bnx2x_unregister_cnic(struct net_device *dev)
  10892. {
  10893. struct bnx2x *bp = netdev_priv(dev);
  10894. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10895. mutex_lock(&bp->cnic_mutex);
  10896. cp->drv_state = 0;
  10897. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  10898. mutex_unlock(&bp->cnic_mutex);
  10899. synchronize_rcu();
  10900. kfree(bp->cnic_kwq);
  10901. bp->cnic_kwq = NULL;
  10902. return 0;
  10903. }
  10904. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  10905. {
  10906. struct bnx2x *bp = netdev_priv(dev);
  10907. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10908. /* If both iSCSI and FCoE are disabled - return NULL in
  10909. * order to indicate CNIC that it should not try to work
  10910. * with this device.
  10911. */
  10912. if (NO_ISCSI(bp) && NO_FCOE(bp))
  10913. return NULL;
  10914. cp->drv_owner = THIS_MODULE;
  10915. cp->chip_id = CHIP_ID(bp);
  10916. cp->pdev = bp->pdev;
  10917. cp->io_base = bp->regview;
  10918. cp->io_base2 = bp->doorbells;
  10919. cp->max_kwqe_pending = 8;
  10920. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  10921. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10922. bnx2x_cid_ilt_lines(bp);
  10923. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10924. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10925. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10926. cp->drv_ctl = bnx2x_drv_ctl;
  10927. cp->drv_register_cnic = bnx2x_register_cnic;
  10928. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10929. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10930. cp->iscsi_l2_client_id =
  10931. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10932. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10933. if (NO_ISCSI_OOO(bp))
  10934. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10935. if (NO_ISCSI(bp))
  10936. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  10937. if (NO_FCOE(bp))
  10938. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  10939. BNX2X_DEV_INFO(
  10940. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  10941. cp->ctx_blk_size,
  10942. cp->ctx_tbl_offset,
  10943. cp->ctx_tbl_len,
  10944. cp->starting_cid);
  10945. return cp;
  10946. }
  10947. int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
  10948. {
  10949. struct cstorm_vf_zone_data __iomem *zone_data =
  10950. REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
  10951. int tout = 600, interval = 100; /* wait for 60 seconds */
  10952. if (*done) {
  10953. BNX2X_ERR("done was non zero before message to pf was sent\n");
  10954. WARN_ON(true);
  10955. return -EINVAL;
  10956. }
  10957. /* Write message address */
  10958. writel(U64_LO(msg_mapping),
  10959. &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
  10960. writel(U64_HI(msg_mapping),
  10961. &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
  10962. /* make sure the address is written before FW accesses it */
  10963. wmb();
  10964. /* Trigger the PF FW */
  10965. writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
  10966. /* Wait for PF to complete */
  10967. while ((tout >= 0) && (!*done)) {
  10968. msleep(interval);
  10969. tout -= 1;
  10970. /* progress indicator - HV can take its own sweet time in
  10971. * answering VFs...
  10972. */
  10973. DP_CONT(BNX2X_MSG_IOV, ".");
  10974. }
  10975. if (!*done) {
  10976. BNX2X_ERR("PF response has timed out\n");
  10977. return -EAGAIN;
  10978. }
  10979. DP(BNX2X_MSG_SP, "Got a response from PF\n");
  10980. return 0;
  10981. }
  10982. int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
  10983. {
  10984. u32 me_reg;
  10985. int tout = 10, interval = 100; /* Wait for 1 sec */
  10986. do {
  10987. /* pxp traps vf read of doorbells and returns me reg value */
  10988. me_reg = readl(bp->doorbells);
  10989. if (GOOD_ME_REG(me_reg))
  10990. break;
  10991. msleep(interval);
  10992. BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
  10993. me_reg);
  10994. } while (tout-- > 0);
  10995. if (!GOOD_ME_REG(me_reg)) {
  10996. BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
  10997. return -EINVAL;
  10998. }
  10999. BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
  11000. *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
  11001. return 0;
  11002. }
  11003. int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
  11004. {
  11005. int rc = 0, attempts = 0;
  11006. struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
  11007. struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
  11008. u32 vf_id;
  11009. bool resources_acquired = false;
  11010. /* clear mailbox and prep first tlv */
  11011. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
  11012. if (bnx2x_get_vf_id(bp, &vf_id))
  11013. return -EAGAIN;
  11014. req->vfdev_info.vf_id = vf_id;
  11015. req->vfdev_info.vf_os = 0;
  11016. req->resc_request.num_rxqs = rx_count;
  11017. req->resc_request.num_txqs = tx_count;
  11018. req->resc_request.num_sbs = bp->igu_sb_cnt;
  11019. req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
  11020. req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
  11021. /* add list termination tlv */
  11022. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11023. sizeof(struct channel_list_end_tlv));
  11024. /* output tlvs list */
  11025. bnx2x_dp_tlv_list(bp, req);
  11026. while (!resources_acquired) {
  11027. DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
  11028. /* send acquire request */
  11029. rc = bnx2x_send_msg2pf(bp,
  11030. &resp->hdr.status,
  11031. bp->vf2pf_mbox_mapping);
  11032. /* PF timeout */
  11033. if (rc)
  11034. return rc;
  11035. /* copy acquire response from buffer to bp */
  11036. memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
  11037. attempts++;
  11038. /* test whether the PF accepted our request. If not, humble the
  11039. * the request and try again.
  11040. */
  11041. if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
  11042. DP(BNX2X_MSG_SP, "resources acquired\n");
  11043. resources_acquired = true;
  11044. } else if (bp->acquire_resp.hdr.status ==
  11045. PFVF_STATUS_NO_RESOURCE &&
  11046. attempts < VF_ACQUIRE_THRESH) {
  11047. DP(BNX2X_MSG_SP,
  11048. "PF unwilling to fulfill resource request. Try PF recommended amount\n");
  11049. /* humble our request */
  11050. req->resc_request.num_txqs =
  11051. bp->acquire_resp.resc.num_txqs;
  11052. req->resc_request.num_rxqs =
  11053. bp->acquire_resp.resc.num_rxqs;
  11054. req->resc_request.num_sbs =
  11055. bp->acquire_resp.resc.num_sbs;
  11056. req->resc_request.num_mac_filters =
  11057. bp->acquire_resp.resc.num_mac_filters;
  11058. req->resc_request.num_vlan_filters =
  11059. bp->acquire_resp.resc.num_vlan_filters;
  11060. req->resc_request.num_mc_filters =
  11061. bp->acquire_resp.resc.num_mc_filters;
  11062. /* Clear response buffer */
  11063. memset(&bp->vf2pf_mbox->resp, 0,
  11064. sizeof(union pfvf_tlvs));
  11065. } else {
  11066. /* PF reports error */
  11067. BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
  11068. bp->acquire_resp.hdr.status);
  11069. return -EAGAIN;
  11070. }
  11071. }
  11072. /* get HW info */
  11073. bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
  11074. bp->link_params.chip_id = bp->common.chip_id;
  11075. bp->db_size = bp->acquire_resp.pfdev_info.db_size;
  11076. bp->common.int_block = INT_BLOCK_IGU;
  11077. bp->common.chip_port_mode = CHIP_2_PORT_MODE;
  11078. bp->igu_dsb_id = -1;
  11079. bp->mf_ov = 0;
  11080. bp->mf_mode = 0;
  11081. bp->common.flash_size = 0;
  11082. bp->flags |=
  11083. NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
  11084. bp->igu_sb_cnt = 1;
  11085. bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
  11086. strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
  11087. sizeof(bp->fw_ver));
  11088. if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
  11089. memcpy(bp->dev->dev_addr,
  11090. bp->acquire_resp.resc.current_mac_addr,
  11091. ETH_ALEN);
  11092. return 0;
  11093. }
  11094. int bnx2x_vfpf_release(struct bnx2x *bp)
  11095. {
  11096. struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
  11097. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11098. u32 rc = 0, vf_id;
  11099. /* clear mailbox and prep first tlv */
  11100. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
  11101. if (bnx2x_get_vf_id(bp, &vf_id))
  11102. return -EAGAIN;
  11103. req->vf_id = vf_id;
  11104. /* add list termination tlv */
  11105. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11106. sizeof(struct channel_list_end_tlv));
  11107. /* output tlvs list */
  11108. bnx2x_dp_tlv_list(bp, req);
  11109. /* send release request */
  11110. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11111. if (rc)
  11112. /* PF timeout */
  11113. return rc;
  11114. if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
  11115. /* PF released us */
  11116. DP(BNX2X_MSG_SP, "vf released\n");
  11117. } else {
  11118. /* PF reports error */
  11119. BNX2X_ERR("PF failed our release request - are we out of sync? response status: %d\n",
  11120. resp->hdr.status);
  11121. return -EAGAIN;
  11122. }
  11123. return 0;
  11124. }