bnx2x_main.c 376 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937
  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. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  313. {
  314. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  315. switch (dmae->opcode & DMAE_COMMAND_DST) {
  316. case DMAE_CMD_DST_PCI:
  317. if (src_type == DMAE_CMD_SRC_PCI)
  318. DP(msglvl, "DMAE: opcode 0x%08x\n"
  319. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  320. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  321. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  322. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  323. dmae->comp_addr_hi, dmae->comp_addr_lo,
  324. dmae->comp_val);
  325. else
  326. DP(msglvl, "DMAE: opcode 0x%08x\n"
  327. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  328. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  329. dmae->opcode, dmae->src_addr_lo >> 2,
  330. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  331. dmae->comp_addr_hi, dmae->comp_addr_lo,
  332. dmae->comp_val);
  333. break;
  334. case DMAE_CMD_DST_GRC:
  335. if (src_type == DMAE_CMD_SRC_PCI)
  336. DP(msglvl, "DMAE: opcode 0x%08x\n"
  337. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  338. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  339. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  340. dmae->len, dmae->dst_addr_lo >> 2,
  341. dmae->comp_addr_hi, dmae->comp_addr_lo,
  342. dmae->comp_val);
  343. else
  344. DP(msglvl, "DMAE: opcode 0x%08x\n"
  345. "src [%08x], len [%d*4], dst [%08x]\n"
  346. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  347. dmae->opcode, dmae->src_addr_lo >> 2,
  348. dmae->len, dmae->dst_addr_lo >> 2,
  349. dmae->comp_addr_hi, dmae->comp_addr_lo,
  350. dmae->comp_val);
  351. break;
  352. default:
  353. if (src_type == DMAE_CMD_SRC_PCI)
  354. DP(msglvl, "DMAE: opcode 0x%08x\n"
  355. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  356. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  357. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  358. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  359. dmae->comp_val);
  360. else
  361. DP(msglvl, "DMAE: opcode 0x%08x\n"
  362. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  363. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  364. dmae->opcode, dmae->src_addr_lo >> 2,
  365. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  366. dmae->comp_val);
  367. break;
  368. }
  369. }
  370. /* copy command into DMAE command memory and set DMAE command go */
  371. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  372. {
  373. u32 cmd_offset;
  374. int i;
  375. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  376. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  377. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  378. }
  379. REG_WR(bp, dmae_reg_go_c[idx], 1);
  380. }
  381. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  382. {
  383. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  384. DMAE_CMD_C_ENABLE);
  385. }
  386. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  387. {
  388. return opcode & ~DMAE_CMD_SRC_RESET;
  389. }
  390. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  391. bool with_comp, u8 comp_type)
  392. {
  393. u32 opcode = 0;
  394. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  395. (dst_type << DMAE_COMMAND_DST_SHIFT));
  396. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  397. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  398. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  399. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  400. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  401. #ifdef __BIG_ENDIAN
  402. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  403. #else
  404. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  405. #endif
  406. if (with_comp)
  407. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  408. return opcode;
  409. }
  410. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  411. struct dmae_command *dmae,
  412. u8 src_type, u8 dst_type)
  413. {
  414. memset(dmae, 0, sizeof(struct dmae_command));
  415. /* set the opcode */
  416. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  417. true, DMAE_COMP_PCI);
  418. /* fill in the completion parameters */
  419. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  420. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  421. dmae->comp_val = DMAE_COMP_VAL;
  422. }
  423. /* issue a dmae command over the init-channel and wait for completion */
  424. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  425. {
  426. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  427. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  428. int rc = 0;
  429. /*
  430. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  431. * as long as this code is called both from syscall context and
  432. * from ndo_set_rx_mode() flow that may be called from BH.
  433. */
  434. spin_lock_bh(&bp->dmae_lock);
  435. /* reset completion */
  436. *wb_comp = 0;
  437. /* post the command on the channel used for initializations */
  438. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  439. /* wait for completion */
  440. udelay(5);
  441. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  442. if (!cnt ||
  443. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  444. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  445. BNX2X_ERR("DMAE timeout!\n");
  446. rc = DMAE_TIMEOUT;
  447. goto unlock;
  448. }
  449. cnt--;
  450. udelay(50);
  451. }
  452. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  453. BNX2X_ERR("DMAE PCI error!\n");
  454. rc = DMAE_PCI_ERROR;
  455. }
  456. unlock:
  457. spin_unlock_bh(&bp->dmae_lock);
  458. return rc;
  459. }
  460. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  461. u32 len32)
  462. {
  463. struct dmae_command dmae;
  464. if (!bp->dmae_ready) {
  465. u32 *data = bnx2x_sp(bp, wb_data[0]);
  466. if (CHIP_IS_E1(bp))
  467. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  468. else
  469. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  470. return;
  471. }
  472. /* set opcode and fixed command fields */
  473. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  474. /* fill in addresses and len */
  475. dmae.src_addr_lo = U64_LO(dma_addr);
  476. dmae.src_addr_hi = U64_HI(dma_addr);
  477. dmae.dst_addr_lo = dst_addr >> 2;
  478. dmae.dst_addr_hi = 0;
  479. dmae.len = len32;
  480. /* issue the command and wait for completion */
  481. bnx2x_issue_dmae_with_comp(bp, &dmae);
  482. }
  483. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  484. {
  485. struct dmae_command dmae;
  486. if (!bp->dmae_ready) {
  487. u32 *data = bnx2x_sp(bp, wb_data[0]);
  488. int i;
  489. if (CHIP_IS_E1(bp))
  490. for (i = 0; i < len32; i++)
  491. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  492. else
  493. for (i = 0; i < len32; i++)
  494. data[i] = REG_RD(bp, src_addr + i*4);
  495. return;
  496. }
  497. /* set opcode and fixed command fields */
  498. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  499. /* fill in addresses and len */
  500. dmae.src_addr_lo = src_addr >> 2;
  501. dmae.src_addr_hi = 0;
  502. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  503. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  504. dmae.len = len32;
  505. /* issue the command and wait for completion */
  506. bnx2x_issue_dmae_with_comp(bp, &dmae);
  507. }
  508. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  509. u32 addr, u32 len)
  510. {
  511. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  512. int offset = 0;
  513. while (len > dmae_wr_max) {
  514. bnx2x_write_dmae(bp, phys_addr + offset,
  515. addr + offset, dmae_wr_max);
  516. offset += dmae_wr_max * 4;
  517. len -= dmae_wr_max;
  518. }
  519. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  520. }
  521. static int bnx2x_mc_assert(struct bnx2x *bp)
  522. {
  523. char last_idx;
  524. int i, rc = 0;
  525. u32 row0, row1, row2, row3;
  526. /* XSTORM */
  527. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  528. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  529. if (last_idx)
  530. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  531. /* print the asserts */
  532. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  533. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  534. XSTORM_ASSERT_LIST_OFFSET(i));
  535. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  536. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  537. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  538. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  539. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  540. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  541. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  542. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  543. i, row3, row2, row1, row0);
  544. rc++;
  545. } else {
  546. break;
  547. }
  548. }
  549. /* TSTORM */
  550. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  551. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  552. if (last_idx)
  553. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  554. /* print the asserts */
  555. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  556. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  557. TSTORM_ASSERT_LIST_OFFSET(i));
  558. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  559. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  560. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  561. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  562. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  563. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  564. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  565. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  566. i, row3, row2, row1, row0);
  567. rc++;
  568. } else {
  569. break;
  570. }
  571. }
  572. /* CSTORM */
  573. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  574. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  575. if (last_idx)
  576. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  577. /* print the asserts */
  578. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  579. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  580. CSTORM_ASSERT_LIST_OFFSET(i));
  581. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  582. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  583. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  584. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  585. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  586. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  587. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  588. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  589. i, row3, row2, row1, row0);
  590. rc++;
  591. } else {
  592. break;
  593. }
  594. }
  595. /* USTORM */
  596. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  597. USTORM_ASSERT_LIST_INDEX_OFFSET);
  598. if (last_idx)
  599. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  600. /* print the asserts */
  601. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  602. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  603. USTORM_ASSERT_LIST_OFFSET(i));
  604. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  605. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  606. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  607. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  608. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  609. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  610. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  611. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  612. i, row3, row2, row1, row0);
  613. rc++;
  614. } else {
  615. break;
  616. }
  617. }
  618. return rc;
  619. }
  620. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  621. {
  622. u32 addr, val;
  623. u32 mark, offset;
  624. __be32 data[9];
  625. int word;
  626. u32 trace_shmem_base;
  627. if (BP_NOMCP(bp)) {
  628. BNX2X_ERR("NO MCP - can not dump\n");
  629. return;
  630. }
  631. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  632. (bp->common.bc_ver & 0xff0000) >> 16,
  633. (bp->common.bc_ver & 0xff00) >> 8,
  634. (bp->common.bc_ver & 0xff));
  635. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  636. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  637. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  638. if (BP_PATH(bp) == 0)
  639. trace_shmem_base = bp->common.shmem_base;
  640. else
  641. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  642. addr = trace_shmem_base - 0x800;
  643. /* validate TRCB signature */
  644. mark = REG_RD(bp, addr);
  645. if (mark != MFW_TRACE_SIGNATURE) {
  646. BNX2X_ERR("Trace buffer signature is missing.");
  647. return ;
  648. }
  649. /* read cyclic buffer pointer */
  650. addr += 4;
  651. mark = REG_RD(bp, addr);
  652. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  653. + ((mark + 0x3) & ~0x3) - 0x08000000;
  654. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  655. printk("%s", lvl);
  656. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  657. for (word = 0; word < 8; word++)
  658. data[word] = htonl(REG_RD(bp, offset + 4*word));
  659. data[8] = 0x0;
  660. pr_cont("%s", (char *)data);
  661. }
  662. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  663. for (word = 0; word < 8; word++)
  664. data[word] = htonl(REG_RD(bp, offset + 4*word));
  665. data[8] = 0x0;
  666. pr_cont("%s", (char *)data);
  667. }
  668. printk("%s" "end of fw dump\n", lvl);
  669. }
  670. static void bnx2x_fw_dump(struct bnx2x *bp)
  671. {
  672. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  673. }
  674. void bnx2x_panic_dump(struct bnx2x *bp)
  675. {
  676. int i;
  677. u16 j;
  678. struct hc_sp_status_block_data sp_sb_data;
  679. int func = BP_FUNC(bp);
  680. #ifdef BNX2X_STOP_ON_ERROR
  681. u16 start = 0, end = 0;
  682. u8 cos;
  683. #endif
  684. bp->stats_state = STATS_STATE_DISABLED;
  685. bp->eth_stats.unrecoverable_error++;
  686. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  687. BNX2X_ERR("begin crash dump -----------------\n");
  688. /* Indices */
  689. /* Common */
  690. 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",
  691. bp->def_idx, bp->def_att_idx, bp->attn_state,
  692. bp->spq_prod_idx, bp->stats_counter);
  693. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  694. bp->def_status_blk->atten_status_block.attn_bits,
  695. bp->def_status_blk->atten_status_block.attn_bits_ack,
  696. bp->def_status_blk->atten_status_block.status_block_id,
  697. bp->def_status_blk->atten_status_block.attn_bits_index);
  698. BNX2X_ERR(" def (");
  699. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  700. pr_cont("0x%x%s",
  701. bp->def_status_blk->sp_sb.index_values[i],
  702. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  703. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  704. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  705. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  706. i*sizeof(u32));
  707. 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",
  708. sp_sb_data.igu_sb_id,
  709. sp_sb_data.igu_seg_id,
  710. sp_sb_data.p_func.pf_id,
  711. sp_sb_data.p_func.vnic_id,
  712. sp_sb_data.p_func.vf_id,
  713. sp_sb_data.p_func.vf_valid,
  714. sp_sb_data.state);
  715. for_each_eth_queue(bp, i) {
  716. struct bnx2x_fastpath *fp = &bp->fp[i];
  717. int loop;
  718. struct hc_status_block_data_e2 sb_data_e2;
  719. struct hc_status_block_data_e1x sb_data_e1x;
  720. struct hc_status_block_sm *hc_sm_p =
  721. CHIP_IS_E1x(bp) ?
  722. sb_data_e1x.common.state_machine :
  723. sb_data_e2.common.state_machine;
  724. struct hc_index_data *hc_index_p =
  725. CHIP_IS_E1x(bp) ?
  726. sb_data_e1x.index_data :
  727. sb_data_e2.index_data;
  728. u8 data_size, cos;
  729. u32 *sb_data_p;
  730. struct bnx2x_fp_txdata txdata;
  731. /* Rx */
  732. 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",
  733. i, fp->rx_bd_prod, fp->rx_bd_cons,
  734. fp->rx_comp_prod,
  735. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  736. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  737. fp->rx_sge_prod, fp->last_max_sge,
  738. le16_to_cpu(fp->fp_hc_idx));
  739. /* Tx */
  740. for_each_cos_in_tx_queue(fp, cos)
  741. {
  742. txdata = *fp->txdata_ptr[cos];
  743. 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",
  744. i, txdata.tx_pkt_prod,
  745. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  746. txdata.tx_bd_cons,
  747. le16_to_cpu(*txdata.tx_cons_sb));
  748. }
  749. loop = CHIP_IS_E1x(bp) ?
  750. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  751. /* host sb data */
  752. if (IS_FCOE_FP(fp))
  753. continue;
  754. BNX2X_ERR(" run indexes (");
  755. for (j = 0; j < HC_SB_MAX_SM; j++)
  756. pr_cont("0x%x%s",
  757. fp->sb_running_index[j],
  758. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  759. BNX2X_ERR(" indexes (");
  760. for (j = 0; j < loop; j++)
  761. pr_cont("0x%x%s",
  762. fp->sb_index_values[j],
  763. (j == loop - 1) ? ")" : " ");
  764. /* fw sb data */
  765. data_size = CHIP_IS_E1x(bp) ?
  766. sizeof(struct hc_status_block_data_e1x) :
  767. sizeof(struct hc_status_block_data_e2);
  768. data_size /= sizeof(u32);
  769. sb_data_p = CHIP_IS_E1x(bp) ?
  770. (u32 *)&sb_data_e1x :
  771. (u32 *)&sb_data_e2;
  772. /* copy sb data in here */
  773. for (j = 0; j < data_size; j++)
  774. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  775. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  776. j * sizeof(u32));
  777. if (!CHIP_IS_E1x(bp)) {
  778. 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",
  779. sb_data_e2.common.p_func.pf_id,
  780. sb_data_e2.common.p_func.vf_id,
  781. sb_data_e2.common.p_func.vf_valid,
  782. sb_data_e2.common.p_func.vnic_id,
  783. sb_data_e2.common.same_igu_sb_1b,
  784. sb_data_e2.common.state);
  785. } else {
  786. 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",
  787. sb_data_e1x.common.p_func.pf_id,
  788. sb_data_e1x.common.p_func.vf_id,
  789. sb_data_e1x.common.p_func.vf_valid,
  790. sb_data_e1x.common.p_func.vnic_id,
  791. sb_data_e1x.common.same_igu_sb_1b,
  792. sb_data_e1x.common.state);
  793. }
  794. /* SB_SMs data */
  795. for (j = 0; j < HC_SB_MAX_SM; j++) {
  796. 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",
  797. j, hc_sm_p[j].__flags,
  798. hc_sm_p[j].igu_sb_id,
  799. hc_sm_p[j].igu_seg_id,
  800. hc_sm_p[j].time_to_expire,
  801. hc_sm_p[j].timer_value);
  802. }
  803. /* Indecies data */
  804. for (j = 0; j < loop; j++) {
  805. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  806. hc_index_p[j].flags,
  807. hc_index_p[j].timeout);
  808. }
  809. }
  810. #ifdef BNX2X_STOP_ON_ERROR
  811. /* Rings */
  812. /* Rx */
  813. for_each_valid_rx_queue(bp, i) {
  814. struct bnx2x_fastpath *fp = &bp->fp[i];
  815. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  816. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  817. for (j = start; j != end; j = RX_BD(j + 1)) {
  818. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  819. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  820. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  821. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  822. }
  823. start = RX_SGE(fp->rx_sge_prod);
  824. end = RX_SGE(fp->last_max_sge);
  825. for (j = start; j != end; j = RX_SGE(j + 1)) {
  826. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  827. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  828. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  829. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  830. }
  831. start = RCQ_BD(fp->rx_comp_cons - 10);
  832. end = RCQ_BD(fp->rx_comp_cons + 503);
  833. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  834. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  835. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  836. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  837. }
  838. }
  839. /* Tx */
  840. for_each_valid_tx_queue(bp, i) {
  841. struct bnx2x_fastpath *fp = &bp->fp[i];
  842. for_each_cos_in_tx_queue(fp, cos) {
  843. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  844. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  845. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  846. for (j = start; j != end; j = TX_BD(j + 1)) {
  847. struct sw_tx_bd *sw_bd =
  848. &txdata->tx_buf_ring[j];
  849. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  850. i, cos, j, sw_bd->skb,
  851. sw_bd->first_bd);
  852. }
  853. start = TX_BD(txdata->tx_bd_cons - 10);
  854. end = TX_BD(txdata->tx_bd_cons + 254);
  855. for (j = start; j != end; j = TX_BD(j + 1)) {
  856. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  857. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  858. i, cos, j, tx_bd[0], tx_bd[1],
  859. tx_bd[2], tx_bd[3]);
  860. }
  861. }
  862. }
  863. #endif
  864. bnx2x_fw_dump(bp);
  865. bnx2x_mc_assert(bp);
  866. BNX2X_ERR("end crash dump -----------------\n");
  867. }
  868. /*
  869. * FLR Support for E2
  870. *
  871. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  872. * initialization.
  873. */
  874. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  875. #define FLR_WAIT_INTERVAL 50 /* usec */
  876. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  877. struct pbf_pN_buf_regs {
  878. int pN;
  879. u32 init_crd;
  880. u32 crd;
  881. u32 crd_freed;
  882. };
  883. struct pbf_pN_cmd_regs {
  884. int pN;
  885. u32 lines_occup;
  886. u32 lines_freed;
  887. };
  888. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  889. struct pbf_pN_buf_regs *regs,
  890. u32 poll_count)
  891. {
  892. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  893. u32 cur_cnt = poll_count;
  894. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  895. crd = crd_start = REG_RD(bp, regs->crd);
  896. init_crd = REG_RD(bp, regs->init_crd);
  897. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  898. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  899. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  900. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  901. (init_crd - crd_start))) {
  902. if (cur_cnt--) {
  903. udelay(FLR_WAIT_INTERVAL);
  904. crd = REG_RD(bp, regs->crd);
  905. crd_freed = REG_RD(bp, regs->crd_freed);
  906. } else {
  907. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  908. regs->pN);
  909. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  910. regs->pN, crd);
  911. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  912. regs->pN, crd_freed);
  913. break;
  914. }
  915. }
  916. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  917. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  918. }
  919. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  920. struct pbf_pN_cmd_regs *regs,
  921. u32 poll_count)
  922. {
  923. u32 occup, to_free, freed, freed_start;
  924. u32 cur_cnt = poll_count;
  925. occup = to_free = REG_RD(bp, regs->lines_occup);
  926. freed = freed_start = REG_RD(bp, regs->lines_freed);
  927. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  928. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  929. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  930. if (cur_cnt--) {
  931. udelay(FLR_WAIT_INTERVAL);
  932. occup = REG_RD(bp, regs->lines_occup);
  933. freed = REG_RD(bp, regs->lines_freed);
  934. } else {
  935. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  936. regs->pN);
  937. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  938. regs->pN, occup);
  939. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  940. regs->pN, freed);
  941. break;
  942. }
  943. }
  944. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  945. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  946. }
  947. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  948. u32 expected, u32 poll_count)
  949. {
  950. u32 cur_cnt = poll_count;
  951. u32 val;
  952. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  953. udelay(FLR_WAIT_INTERVAL);
  954. return val;
  955. }
  956. static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  957. char *msg, u32 poll_cnt)
  958. {
  959. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  960. if (val != 0) {
  961. BNX2X_ERR("%s usage count=%d\n", msg, val);
  962. return 1;
  963. }
  964. return 0;
  965. }
  966. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  967. {
  968. /* adjust polling timeout */
  969. if (CHIP_REV_IS_EMUL(bp))
  970. return FLR_POLL_CNT * 2000;
  971. if (CHIP_REV_IS_FPGA(bp))
  972. return FLR_POLL_CNT * 120;
  973. return FLR_POLL_CNT;
  974. }
  975. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  976. {
  977. struct pbf_pN_cmd_regs cmd_regs[] = {
  978. {0, (CHIP_IS_E3B0(bp)) ?
  979. PBF_REG_TQ_OCCUPANCY_Q0 :
  980. PBF_REG_P0_TQ_OCCUPANCY,
  981. (CHIP_IS_E3B0(bp)) ?
  982. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  983. PBF_REG_P0_TQ_LINES_FREED_CNT},
  984. {1, (CHIP_IS_E3B0(bp)) ?
  985. PBF_REG_TQ_OCCUPANCY_Q1 :
  986. PBF_REG_P1_TQ_OCCUPANCY,
  987. (CHIP_IS_E3B0(bp)) ?
  988. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  989. PBF_REG_P1_TQ_LINES_FREED_CNT},
  990. {4, (CHIP_IS_E3B0(bp)) ?
  991. PBF_REG_TQ_OCCUPANCY_LB_Q :
  992. PBF_REG_P4_TQ_OCCUPANCY,
  993. (CHIP_IS_E3B0(bp)) ?
  994. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  995. PBF_REG_P4_TQ_LINES_FREED_CNT}
  996. };
  997. struct pbf_pN_buf_regs buf_regs[] = {
  998. {0, (CHIP_IS_E3B0(bp)) ?
  999. PBF_REG_INIT_CRD_Q0 :
  1000. PBF_REG_P0_INIT_CRD ,
  1001. (CHIP_IS_E3B0(bp)) ?
  1002. PBF_REG_CREDIT_Q0 :
  1003. PBF_REG_P0_CREDIT,
  1004. (CHIP_IS_E3B0(bp)) ?
  1005. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1006. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1007. {1, (CHIP_IS_E3B0(bp)) ?
  1008. PBF_REG_INIT_CRD_Q1 :
  1009. PBF_REG_P1_INIT_CRD,
  1010. (CHIP_IS_E3B0(bp)) ?
  1011. PBF_REG_CREDIT_Q1 :
  1012. PBF_REG_P1_CREDIT,
  1013. (CHIP_IS_E3B0(bp)) ?
  1014. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1015. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1016. {4, (CHIP_IS_E3B0(bp)) ?
  1017. PBF_REG_INIT_CRD_LB_Q :
  1018. PBF_REG_P4_INIT_CRD,
  1019. (CHIP_IS_E3B0(bp)) ?
  1020. PBF_REG_CREDIT_LB_Q :
  1021. PBF_REG_P4_CREDIT,
  1022. (CHIP_IS_E3B0(bp)) ?
  1023. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1024. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1025. };
  1026. int i;
  1027. /* Verify the command queues are flushed P0, P1, P4 */
  1028. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1029. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1030. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1031. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1032. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1033. }
  1034. #define OP_GEN_PARAM(param) \
  1035. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1036. #define OP_GEN_TYPE(type) \
  1037. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1038. #define OP_GEN_AGG_VECT(index) \
  1039. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1040. static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  1041. u32 poll_cnt)
  1042. {
  1043. struct sdm_op_gen op_gen = {0};
  1044. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1045. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1046. int ret = 0;
  1047. if (REG_RD(bp, comp_addr)) {
  1048. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1049. return 1;
  1050. }
  1051. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1052. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1053. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  1054. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1055. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1056. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1057. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1058. BNX2X_ERR("FW final cleanup did not succeed\n");
  1059. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1060. (REG_RD(bp, comp_addr)));
  1061. ret = 1;
  1062. }
  1063. /* Zero completion for nxt FLR */
  1064. REG_WR(bp, comp_addr, 0);
  1065. return ret;
  1066. }
  1067. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1068. {
  1069. u16 status;
  1070. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1071. return status & PCI_EXP_DEVSTA_TRPND;
  1072. }
  1073. /* PF FLR specific routines
  1074. */
  1075. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1076. {
  1077. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1078. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1079. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1080. "CFC PF usage counter timed out",
  1081. poll_cnt))
  1082. return 1;
  1083. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1084. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1085. DORQ_REG_PF_USAGE_CNT,
  1086. "DQ PF usage counter timed out",
  1087. poll_cnt))
  1088. return 1;
  1089. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1090. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1091. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1092. "QM PF usage counter timed out",
  1093. poll_cnt))
  1094. return 1;
  1095. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1096. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1097. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1098. "Timers VNIC usage counter timed out",
  1099. poll_cnt))
  1100. return 1;
  1101. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1102. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1103. "Timers NUM_SCANS usage counter timed out",
  1104. poll_cnt))
  1105. return 1;
  1106. /* Wait DMAE PF usage counter to zero */
  1107. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1108. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1109. "DMAE dommand register timed out",
  1110. poll_cnt))
  1111. return 1;
  1112. return 0;
  1113. }
  1114. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1115. {
  1116. u32 val;
  1117. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1118. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1119. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1120. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1121. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1122. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1123. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1124. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1125. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1126. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1127. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1128. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1129. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1130. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1131. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1132. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1133. val);
  1134. }
  1135. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1136. {
  1137. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1138. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1139. /* Re-enable PF target read access */
  1140. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1141. /* Poll HW usage counters */
  1142. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1143. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1144. return -EBUSY;
  1145. /* Zero the igu 'trailing edge' and 'leading edge' */
  1146. /* Send the FW cleanup command */
  1147. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1148. return -EBUSY;
  1149. /* ATC cleanup */
  1150. /* Verify TX hw is flushed */
  1151. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1152. /* Wait 100ms (not adjusted according to platform) */
  1153. msleep(100);
  1154. /* Verify no pending pci transactions */
  1155. if (bnx2x_is_pcie_pending(bp->pdev))
  1156. BNX2X_ERR("PCIE Transactions still pending\n");
  1157. /* Debug */
  1158. bnx2x_hw_enable_status(bp);
  1159. /*
  1160. * Master enable - Due to WB DMAE writes performed before this
  1161. * register is re-initialized as part of the regular function init
  1162. */
  1163. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1164. return 0;
  1165. }
  1166. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1167. {
  1168. int port = BP_PORT(bp);
  1169. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1170. u32 val = REG_RD(bp, addr);
  1171. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1172. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1173. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1174. if (msix) {
  1175. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1176. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1177. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1178. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1179. if (single_msix)
  1180. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1181. } else if (msi) {
  1182. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1183. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1184. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1185. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1186. } else {
  1187. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1188. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1189. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1190. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1191. if (!CHIP_IS_E1(bp)) {
  1192. DP(NETIF_MSG_IFUP,
  1193. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1194. REG_WR(bp, addr, val);
  1195. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1196. }
  1197. }
  1198. if (CHIP_IS_E1(bp))
  1199. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1200. DP(NETIF_MSG_IFUP,
  1201. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1202. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1203. REG_WR(bp, addr, val);
  1204. /*
  1205. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1206. */
  1207. mmiowb();
  1208. barrier();
  1209. if (!CHIP_IS_E1(bp)) {
  1210. /* init leading/trailing edge */
  1211. if (IS_MF(bp)) {
  1212. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1213. if (bp->port.pmf)
  1214. /* enable nig and gpio3 attention */
  1215. val |= 0x1100;
  1216. } else
  1217. val = 0xffff;
  1218. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1219. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1220. }
  1221. /* Make sure that interrupts are indeed enabled from here on */
  1222. mmiowb();
  1223. }
  1224. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1225. {
  1226. u32 val;
  1227. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1228. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1229. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1230. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1231. if (msix) {
  1232. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1233. IGU_PF_CONF_SINGLE_ISR_EN);
  1234. val |= (IGU_PF_CONF_FUNC_EN |
  1235. IGU_PF_CONF_MSI_MSIX_EN |
  1236. IGU_PF_CONF_ATTN_BIT_EN);
  1237. if (single_msix)
  1238. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1239. } else if (msi) {
  1240. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1241. val |= (IGU_PF_CONF_FUNC_EN |
  1242. IGU_PF_CONF_MSI_MSIX_EN |
  1243. IGU_PF_CONF_ATTN_BIT_EN |
  1244. IGU_PF_CONF_SINGLE_ISR_EN);
  1245. } else {
  1246. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1247. val |= (IGU_PF_CONF_FUNC_EN |
  1248. IGU_PF_CONF_INT_LINE_EN |
  1249. IGU_PF_CONF_ATTN_BIT_EN |
  1250. IGU_PF_CONF_SINGLE_ISR_EN);
  1251. }
  1252. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1253. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1254. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1255. if (val & IGU_PF_CONF_INT_LINE_EN)
  1256. pci_intx(bp->pdev, true);
  1257. barrier();
  1258. /* init leading/trailing edge */
  1259. if (IS_MF(bp)) {
  1260. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1261. if (bp->port.pmf)
  1262. /* enable nig and gpio3 attention */
  1263. val |= 0x1100;
  1264. } else
  1265. val = 0xffff;
  1266. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1267. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1268. /* Make sure that interrupts are indeed enabled from here on */
  1269. mmiowb();
  1270. }
  1271. void bnx2x_int_enable(struct bnx2x *bp)
  1272. {
  1273. if (bp->common.int_block == INT_BLOCK_HC)
  1274. bnx2x_hc_int_enable(bp);
  1275. else
  1276. bnx2x_igu_int_enable(bp);
  1277. }
  1278. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1279. {
  1280. int port = BP_PORT(bp);
  1281. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1282. u32 val = REG_RD(bp, addr);
  1283. /*
  1284. * in E1 we must use only PCI configuration space to disable
  1285. * MSI/MSIX capablility
  1286. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1287. */
  1288. if (CHIP_IS_E1(bp)) {
  1289. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1290. * Use mask register to prevent from HC sending interrupts
  1291. * after we exit the function
  1292. */
  1293. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1294. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1295. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1296. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1297. } else
  1298. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1299. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1300. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1301. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1302. DP(NETIF_MSG_IFDOWN,
  1303. "write %x to HC %d (addr 0x%x)\n",
  1304. val, port, addr);
  1305. /* flush all outstanding writes */
  1306. mmiowb();
  1307. REG_WR(bp, addr, val);
  1308. if (REG_RD(bp, addr) != val)
  1309. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1310. }
  1311. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1312. {
  1313. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1314. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1315. IGU_PF_CONF_INT_LINE_EN |
  1316. IGU_PF_CONF_ATTN_BIT_EN);
  1317. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1318. /* flush all outstanding writes */
  1319. mmiowb();
  1320. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1321. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1322. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1323. }
  1324. static void bnx2x_int_disable(struct bnx2x *bp)
  1325. {
  1326. if (bp->common.int_block == INT_BLOCK_HC)
  1327. bnx2x_hc_int_disable(bp);
  1328. else
  1329. bnx2x_igu_int_disable(bp);
  1330. }
  1331. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1332. {
  1333. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1334. int i, offset;
  1335. if (disable_hw)
  1336. /* prevent the HW from sending interrupts */
  1337. bnx2x_int_disable(bp);
  1338. /* make sure all ISRs are done */
  1339. if (msix) {
  1340. synchronize_irq(bp->msix_table[0].vector);
  1341. offset = 1;
  1342. if (CNIC_SUPPORT(bp))
  1343. offset++;
  1344. for_each_eth_queue(bp, i)
  1345. synchronize_irq(bp->msix_table[offset++].vector);
  1346. } else
  1347. synchronize_irq(bp->pdev->irq);
  1348. /* make sure sp_task is not running */
  1349. cancel_delayed_work(&bp->sp_task);
  1350. cancel_delayed_work(&bp->period_task);
  1351. flush_workqueue(bnx2x_wq);
  1352. }
  1353. /* fast path */
  1354. /*
  1355. * General service functions
  1356. */
  1357. /* Return true if succeeded to acquire the lock */
  1358. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1359. {
  1360. u32 lock_status;
  1361. u32 resource_bit = (1 << resource);
  1362. int func = BP_FUNC(bp);
  1363. u32 hw_lock_control_reg;
  1364. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1365. "Trying to take a lock on resource %d\n", resource);
  1366. /* Validating that the resource is within range */
  1367. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1368. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1369. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1370. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1371. return false;
  1372. }
  1373. if (func <= 5)
  1374. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1375. else
  1376. hw_lock_control_reg =
  1377. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1378. /* Try to acquire the lock */
  1379. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1380. lock_status = REG_RD(bp, hw_lock_control_reg);
  1381. if (lock_status & resource_bit)
  1382. return true;
  1383. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1384. "Failed to get a lock on resource %d\n", resource);
  1385. return false;
  1386. }
  1387. /**
  1388. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1389. *
  1390. * @bp: driver handle
  1391. *
  1392. * Returns the recovery leader resource id according to the engine this function
  1393. * belongs to. Currently only only 2 engines is supported.
  1394. */
  1395. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1396. {
  1397. if (BP_PATH(bp))
  1398. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1399. else
  1400. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1401. }
  1402. /**
  1403. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1404. *
  1405. * @bp: driver handle
  1406. *
  1407. * Tries to aquire a leader lock for current engine.
  1408. */
  1409. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1410. {
  1411. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1412. }
  1413. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1414. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1415. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1416. {
  1417. /* Set the interrupt occurred bit for the sp-task to recognize it
  1418. * must ack the interrupt and transition according to the IGU
  1419. * state machine.
  1420. */
  1421. atomic_set(&bp->interrupt_occurred, 1);
  1422. /* The sp_task must execute only after this bit
  1423. * is set, otherwise we will get out of sync and miss all
  1424. * further interrupts. Hence, the barrier.
  1425. */
  1426. smp_wmb();
  1427. /* schedule sp_task to workqueue */
  1428. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1429. }
  1430. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1431. {
  1432. struct bnx2x *bp = fp->bp;
  1433. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1434. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1435. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1436. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1437. DP(BNX2X_MSG_SP,
  1438. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1439. fp->index, cid, command, bp->state,
  1440. rr_cqe->ramrod_cqe.ramrod_type);
  1441. /* If cid is within VF range, replace the slowpath object with the
  1442. * one corresponding to this VF
  1443. */
  1444. if (cid >= BNX2X_FIRST_VF_CID &&
  1445. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1446. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1447. switch (command) {
  1448. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1449. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1450. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1451. break;
  1452. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1453. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1454. drv_cmd = BNX2X_Q_CMD_SETUP;
  1455. break;
  1456. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1457. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1458. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1459. break;
  1460. case (RAMROD_CMD_ID_ETH_HALT):
  1461. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1462. drv_cmd = BNX2X_Q_CMD_HALT;
  1463. break;
  1464. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1465. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1466. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1467. break;
  1468. case (RAMROD_CMD_ID_ETH_EMPTY):
  1469. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1470. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1471. break;
  1472. default:
  1473. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1474. command, fp->index);
  1475. return;
  1476. }
  1477. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1478. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1479. /* q_obj->complete_cmd() failure means that this was
  1480. * an unexpected completion.
  1481. *
  1482. * In this case we don't want to increase the bp->spq_left
  1483. * because apparently we haven't sent this command the first
  1484. * place.
  1485. */
  1486. #ifdef BNX2X_STOP_ON_ERROR
  1487. bnx2x_panic();
  1488. #else
  1489. return;
  1490. #endif
  1491. /* SRIOV: reschedule any 'in_progress' operations */
  1492. bnx2x_iov_sp_event(bp, cid, true);
  1493. smp_mb__before_atomic_inc();
  1494. atomic_inc(&bp->cq_spq_left);
  1495. /* push the change in bp->spq_left and towards the memory */
  1496. smp_mb__after_atomic_inc();
  1497. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1498. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1499. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1500. /* if Q update ramrod is completed for last Q in AFEX vif set
  1501. * flow, then ACK MCP at the end
  1502. *
  1503. * mark pending ACK to MCP bit.
  1504. * prevent case that both bits are cleared.
  1505. * At the end of load/unload driver checks that
  1506. * sp_state is cleaerd, and this order prevents
  1507. * races
  1508. */
  1509. smp_mb__before_clear_bit();
  1510. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1511. wmb();
  1512. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1513. smp_mb__after_clear_bit();
  1514. /* schedule the sp task as mcp ack is required */
  1515. bnx2x_schedule_sp_task(bp);
  1516. }
  1517. return;
  1518. }
  1519. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1520. {
  1521. struct bnx2x *bp = netdev_priv(dev_instance);
  1522. u16 status = bnx2x_ack_int(bp);
  1523. u16 mask;
  1524. int i;
  1525. u8 cos;
  1526. /* Return here if interrupt is shared and it's not for us */
  1527. if (unlikely(status == 0)) {
  1528. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1529. return IRQ_NONE;
  1530. }
  1531. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1532. #ifdef BNX2X_STOP_ON_ERROR
  1533. if (unlikely(bp->panic))
  1534. return IRQ_HANDLED;
  1535. #endif
  1536. for_each_eth_queue(bp, i) {
  1537. struct bnx2x_fastpath *fp = &bp->fp[i];
  1538. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1539. if (status & mask) {
  1540. /* Handle Rx or Tx according to SB id */
  1541. prefetch(fp->rx_cons_sb);
  1542. for_each_cos_in_tx_queue(fp, cos)
  1543. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1544. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1545. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1546. status &= ~mask;
  1547. }
  1548. }
  1549. if (CNIC_SUPPORT(bp)) {
  1550. mask = 0x2;
  1551. if (status & (mask | 0x1)) {
  1552. struct cnic_ops *c_ops = NULL;
  1553. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1554. rcu_read_lock();
  1555. c_ops = rcu_dereference(bp->cnic_ops);
  1556. if (c_ops)
  1557. c_ops->cnic_handler(bp->cnic_data,
  1558. NULL);
  1559. rcu_read_unlock();
  1560. }
  1561. status &= ~mask;
  1562. }
  1563. }
  1564. if (unlikely(status & 0x1)) {
  1565. /* schedule sp task to perform default status block work, ack
  1566. * attentions and enable interrupts.
  1567. */
  1568. bnx2x_schedule_sp_task(bp);
  1569. status &= ~0x1;
  1570. if (!status)
  1571. return IRQ_HANDLED;
  1572. }
  1573. if (unlikely(status))
  1574. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1575. status);
  1576. return IRQ_HANDLED;
  1577. }
  1578. /* Link */
  1579. /*
  1580. * General service functions
  1581. */
  1582. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1583. {
  1584. u32 lock_status;
  1585. u32 resource_bit = (1 << resource);
  1586. int func = BP_FUNC(bp);
  1587. u32 hw_lock_control_reg;
  1588. int cnt;
  1589. /* Validating that the resource is within range */
  1590. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1591. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1592. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1593. return -EINVAL;
  1594. }
  1595. if (func <= 5) {
  1596. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1597. } else {
  1598. hw_lock_control_reg =
  1599. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1600. }
  1601. /* Validating that the resource is not already taken */
  1602. lock_status = REG_RD(bp, hw_lock_control_reg);
  1603. if (lock_status & resource_bit) {
  1604. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1605. lock_status, resource_bit);
  1606. return -EEXIST;
  1607. }
  1608. /* Try for 5 second every 5ms */
  1609. for (cnt = 0; cnt < 1000; cnt++) {
  1610. /* Try to acquire the lock */
  1611. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1612. lock_status = REG_RD(bp, hw_lock_control_reg);
  1613. if (lock_status & resource_bit)
  1614. return 0;
  1615. msleep(5);
  1616. }
  1617. BNX2X_ERR("Timeout\n");
  1618. return -EAGAIN;
  1619. }
  1620. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1621. {
  1622. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1623. }
  1624. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1625. {
  1626. u32 lock_status;
  1627. u32 resource_bit = (1 << resource);
  1628. int func = BP_FUNC(bp);
  1629. u32 hw_lock_control_reg;
  1630. /* Validating that the resource is within range */
  1631. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1632. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1633. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1634. return -EINVAL;
  1635. }
  1636. if (func <= 5) {
  1637. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1638. } else {
  1639. hw_lock_control_reg =
  1640. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1641. }
  1642. /* Validating that the resource is currently taken */
  1643. lock_status = REG_RD(bp, hw_lock_control_reg);
  1644. if (!(lock_status & resource_bit)) {
  1645. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1646. lock_status, resource_bit);
  1647. return -EFAULT;
  1648. }
  1649. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1650. return 0;
  1651. }
  1652. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1653. {
  1654. /* The GPIO should be swapped if swap register is set and active */
  1655. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1656. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1657. int gpio_shift = gpio_num +
  1658. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1659. u32 gpio_mask = (1 << gpio_shift);
  1660. u32 gpio_reg;
  1661. int value;
  1662. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1663. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1664. return -EINVAL;
  1665. }
  1666. /* read GPIO value */
  1667. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1668. /* get the requested pin value */
  1669. if ((gpio_reg & gpio_mask) == gpio_mask)
  1670. value = 1;
  1671. else
  1672. value = 0;
  1673. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1674. return value;
  1675. }
  1676. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1677. {
  1678. /* The GPIO should be swapped if swap register is set and active */
  1679. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1680. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1681. int gpio_shift = gpio_num +
  1682. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1683. u32 gpio_mask = (1 << gpio_shift);
  1684. u32 gpio_reg;
  1685. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1686. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1687. return -EINVAL;
  1688. }
  1689. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1690. /* read GPIO and mask except the float bits */
  1691. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1692. switch (mode) {
  1693. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1694. DP(NETIF_MSG_LINK,
  1695. "Set GPIO %d (shift %d) -> output low\n",
  1696. gpio_num, gpio_shift);
  1697. /* clear FLOAT and set CLR */
  1698. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1699. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1700. break;
  1701. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1702. DP(NETIF_MSG_LINK,
  1703. "Set GPIO %d (shift %d) -> output high\n",
  1704. gpio_num, gpio_shift);
  1705. /* clear FLOAT and set SET */
  1706. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1707. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1708. break;
  1709. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1710. DP(NETIF_MSG_LINK,
  1711. "Set GPIO %d (shift %d) -> input\n",
  1712. gpio_num, gpio_shift);
  1713. /* set FLOAT */
  1714. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1715. break;
  1716. default:
  1717. break;
  1718. }
  1719. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1720. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1721. return 0;
  1722. }
  1723. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1724. {
  1725. u32 gpio_reg = 0;
  1726. int rc = 0;
  1727. /* Any port swapping should be handled by caller. */
  1728. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1729. /* read GPIO and mask except the float bits */
  1730. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1731. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1732. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1733. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1734. switch (mode) {
  1735. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1736. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1737. /* set CLR */
  1738. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1739. break;
  1740. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1741. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1742. /* set SET */
  1743. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1744. break;
  1745. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1746. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1747. /* set FLOAT */
  1748. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1749. break;
  1750. default:
  1751. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1752. rc = -EINVAL;
  1753. break;
  1754. }
  1755. if (rc == 0)
  1756. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1757. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1758. return rc;
  1759. }
  1760. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1761. {
  1762. /* The GPIO should be swapped if swap register is set and active */
  1763. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1764. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1765. int gpio_shift = gpio_num +
  1766. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1767. u32 gpio_mask = (1 << gpio_shift);
  1768. u32 gpio_reg;
  1769. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1770. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1771. return -EINVAL;
  1772. }
  1773. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1774. /* read GPIO int */
  1775. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1776. switch (mode) {
  1777. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1778. DP(NETIF_MSG_LINK,
  1779. "Clear GPIO INT %d (shift %d) -> output low\n",
  1780. gpio_num, gpio_shift);
  1781. /* clear SET and set CLR */
  1782. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1783. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1784. break;
  1785. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1786. DP(NETIF_MSG_LINK,
  1787. "Set GPIO INT %d (shift %d) -> output high\n",
  1788. gpio_num, gpio_shift);
  1789. /* clear CLR and set SET */
  1790. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1791. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1792. break;
  1793. default:
  1794. break;
  1795. }
  1796. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1797. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1798. return 0;
  1799. }
  1800. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1801. {
  1802. u32 spio_reg;
  1803. /* Only 2 SPIOs are configurable */
  1804. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1805. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1806. return -EINVAL;
  1807. }
  1808. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1809. /* read SPIO and mask except the float bits */
  1810. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1811. switch (mode) {
  1812. case MISC_SPIO_OUTPUT_LOW:
  1813. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1814. /* clear FLOAT and set CLR */
  1815. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1816. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1817. break;
  1818. case MISC_SPIO_OUTPUT_HIGH:
  1819. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1820. /* clear FLOAT and set SET */
  1821. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1822. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1823. break;
  1824. case MISC_SPIO_INPUT_HI_Z:
  1825. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1826. /* set FLOAT */
  1827. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1828. break;
  1829. default:
  1830. break;
  1831. }
  1832. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1833. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1834. return 0;
  1835. }
  1836. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1837. {
  1838. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1839. switch (bp->link_vars.ieee_fc &
  1840. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1841. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1842. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1843. ADVERTISED_Pause);
  1844. break;
  1845. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1846. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1847. ADVERTISED_Pause);
  1848. break;
  1849. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1850. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1851. break;
  1852. default:
  1853. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1854. ADVERTISED_Pause);
  1855. break;
  1856. }
  1857. }
  1858. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1859. {
  1860. /* Initialize link parameters structure variables
  1861. * It is recommended to turn off RX FC for jumbo frames
  1862. * for better performance
  1863. */
  1864. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1865. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1866. else
  1867. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1868. }
  1869. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1870. {
  1871. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1872. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1873. if (!BP_NOMCP(bp)) {
  1874. bnx2x_set_requested_fc(bp);
  1875. bnx2x_acquire_phy_lock(bp);
  1876. if (load_mode == LOAD_DIAG) {
  1877. struct link_params *lp = &bp->link_params;
  1878. lp->loopback_mode = LOOPBACK_XGXS;
  1879. /* do PHY loopback at 10G speed, if possible */
  1880. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1881. if (lp->speed_cap_mask[cfx_idx] &
  1882. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1883. lp->req_line_speed[cfx_idx] =
  1884. SPEED_10000;
  1885. else
  1886. lp->req_line_speed[cfx_idx] =
  1887. SPEED_1000;
  1888. }
  1889. }
  1890. if (load_mode == LOAD_LOOPBACK_EXT) {
  1891. struct link_params *lp = &bp->link_params;
  1892. lp->loopback_mode = LOOPBACK_EXT;
  1893. }
  1894. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1895. bnx2x_release_phy_lock(bp);
  1896. bnx2x_calc_fc_adv(bp);
  1897. if (bp->link_vars.link_up) {
  1898. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1899. bnx2x_link_report(bp);
  1900. }
  1901. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1902. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1903. return rc;
  1904. }
  1905. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1906. return -EINVAL;
  1907. }
  1908. void bnx2x_link_set(struct bnx2x *bp)
  1909. {
  1910. if (!BP_NOMCP(bp)) {
  1911. bnx2x_acquire_phy_lock(bp);
  1912. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1913. bnx2x_release_phy_lock(bp);
  1914. bnx2x_calc_fc_adv(bp);
  1915. } else
  1916. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1917. }
  1918. static void bnx2x__link_reset(struct bnx2x *bp)
  1919. {
  1920. if (!BP_NOMCP(bp)) {
  1921. bnx2x_acquire_phy_lock(bp);
  1922. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1923. bnx2x_release_phy_lock(bp);
  1924. } else
  1925. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1926. }
  1927. void bnx2x_force_link_reset(struct bnx2x *bp)
  1928. {
  1929. bnx2x_acquire_phy_lock(bp);
  1930. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1931. bnx2x_release_phy_lock(bp);
  1932. }
  1933. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1934. {
  1935. u8 rc = 0;
  1936. if (!BP_NOMCP(bp)) {
  1937. bnx2x_acquire_phy_lock(bp);
  1938. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1939. is_serdes);
  1940. bnx2x_release_phy_lock(bp);
  1941. } else
  1942. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1943. return rc;
  1944. }
  1945. /* Calculates the sum of vn_min_rates.
  1946. It's needed for further normalizing of the min_rates.
  1947. Returns:
  1948. sum of vn_min_rates.
  1949. or
  1950. 0 - if all the min_rates are 0.
  1951. In the later case fainess algorithm should be deactivated.
  1952. If not all min_rates are zero then those that are zeroes will be set to 1.
  1953. */
  1954. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1955. struct cmng_init_input *input)
  1956. {
  1957. int all_zero = 1;
  1958. int vn;
  1959. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1960. u32 vn_cfg = bp->mf_config[vn];
  1961. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1962. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1963. /* Skip hidden vns */
  1964. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1965. vn_min_rate = 0;
  1966. /* If min rate is zero - set it to 1 */
  1967. else if (!vn_min_rate)
  1968. vn_min_rate = DEF_MIN_RATE;
  1969. else
  1970. all_zero = 0;
  1971. input->vnic_min_rate[vn] = vn_min_rate;
  1972. }
  1973. /* if ETS or all min rates are zeros - disable fairness */
  1974. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1975. input->flags.cmng_enables &=
  1976. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1977. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1978. } else if (all_zero) {
  1979. input->flags.cmng_enables &=
  1980. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1981. DP(NETIF_MSG_IFUP,
  1982. "All MIN values are zeroes fairness will be disabled\n");
  1983. } else
  1984. input->flags.cmng_enables |=
  1985. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1986. }
  1987. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  1988. struct cmng_init_input *input)
  1989. {
  1990. u16 vn_max_rate;
  1991. u32 vn_cfg = bp->mf_config[vn];
  1992. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1993. vn_max_rate = 0;
  1994. else {
  1995. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1996. if (IS_MF_SI(bp)) {
  1997. /* maxCfg in percents of linkspeed */
  1998. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1999. } else /* SD modes */
  2000. /* maxCfg is absolute in 100Mb units */
  2001. vn_max_rate = maxCfg * 100;
  2002. }
  2003. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2004. input->vnic_max_rate[vn] = vn_max_rate;
  2005. }
  2006. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2007. {
  2008. if (CHIP_REV_IS_SLOW(bp))
  2009. return CMNG_FNS_NONE;
  2010. if (IS_MF(bp))
  2011. return CMNG_FNS_MINMAX;
  2012. return CMNG_FNS_NONE;
  2013. }
  2014. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2015. {
  2016. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2017. if (BP_NOMCP(bp))
  2018. return; /* what should be the default bvalue in this case */
  2019. /* For 2 port configuration the absolute function number formula
  2020. * is:
  2021. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2022. *
  2023. * and there are 4 functions per port
  2024. *
  2025. * For 4 port configuration it is
  2026. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2027. *
  2028. * and there are 2 functions per port
  2029. */
  2030. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2031. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2032. if (func >= E1H_FUNC_MAX)
  2033. break;
  2034. bp->mf_config[vn] =
  2035. MF_CFG_RD(bp, func_mf_config[func].config);
  2036. }
  2037. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2038. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2039. bp->flags |= MF_FUNC_DIS;
  2040. } else {
  2041. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2042. bp->flags &= ~MF_FUNC_DIS;
  2043. }
  2044. }
  2045. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2046. {
  2047. struct cmng_init_input input;
  2048. memset(&input, 0, sizeof(struct cmng_init_input));
  2049. input.port_rate = bp->link_vars.line_speed;
  2050. if (cmng_type == CMNG_FNS_MINMAX) {
  2051. int vn;
  2052. /* read mf conf from shmem */
  2053. if (read_cfg)
  2054. bnx2x_read_mf_cfg(bp);
  2055. /* vn_weight_sum and enable fairness if not 0 */
  2056. bnx2x_calc_vn_min(bp, &input);
  2057. /* calculate and set min-max rate for each vn */
  2058. if (bp->port.pmf)
  2059. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2060. bnx2x_calc_vn_max(bp, vn, &input);
  2061. /* always enable rate shaping and fairness */
  2062. input.flags.cmng_enables |=
  2063. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2064. bnx2x_init_cmng(&input, &bp->cmng);
  2065. return;
  2066. }
  2067. /* rate shaping and fairness are disabled */
  2068. DP(NETIF_MSG_IFUP,
  2069. "rate shaping and fairness are disabled\n");
  2070. }
  2071. static void storm_memset_cmng(struct bnx2x *bp,
  2072. struct cmng_init *cmng,
  2073. u8 port)
  2074. {
  2075. int vn;
  2076. size_t size = sizeof(struct cmng_struct_per_port);
  2077. u32 addr = BAR_XSTRORM_INTMEM +
  2078. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2079. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2080. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2081. int func = func_by_vn(bp, vn);
  2082. addr = BAR_XSTRORM_INTMEM +
  2083. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2084. size = sizeof(struct rate_shaping_vars_per_vn);
  2085. __storm_memset_struct(bp, addr, size,
  2086. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2087. addr = BAR_XSTRORM_INTMEM +
  2088. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2089. size = sizeof(struct fairness_vars_per_vn);
  2090. __storm_memset_struct(bp, addr, size,
  2091. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2092. }
  2093. }
  2094. /* This function is called upon link interrupt */
  2095. static void bnx2x_link_attn(struct bnx2x *bp)
  2096. {
  2097. /* Make sure that we are synced with the current statistics */
  2098. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2099. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2100. if (bp->link_vars.link_up) {
  2101. /* dropless flow control */
  2102. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2103. int port = BP_PORT(bp);
  2104. u32 pause_enabled = 0;
  2105. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2106. pause_enabled = 1;
  2107. REG_WR(bp, BAR_USTRORM_INTMEM +
  2108. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2109. pause_enabled);
  2110. }
  2111. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2112. struct host_port_stats *pstats;
  2113. pstats = bnx2x_sp(bp, port_stats);
  2114. /* reset old mac stats */
  2115. memset(&(pstats->mac_stx[0]), 0,
  2116. sizeof(struct mac_stx));
  2117. }
  2118. if (bp->state == BNX2X_STATE_OPEN)
  2119. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2120. }
  2121. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2122. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2123. if (cmng_fns != CMNG_FNS_NONE) {
  2124. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2125. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2126. } else
  2127. /* rate shaping and fairness are disabled */
  2128. DP(NETIF_MSG_IFUP,
  2129. "single function mode without fairness\n");
  2130. }
  2131. __bnx2x_link_report(bp);
  2132. if (IS_MF(bp))
  2133. bnx2x_link_sync_notify(bp);
  2134. }
  2135. void bnx2x__link_status_update(struct bnx2x *bp)
  2136. {
  2137. if (bp->state != BNX2X_STATE_OPEN)
  2138. return;
  2139. /* read updated dcb configuration */
  2140. if (IS_PF(bp)) {
  2141. bnx2x_dcbx_pmf_update(bp);
  2142. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2143. if (bp->link_vars.link_up)
  2144. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2145. else
  2146. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2147. /* indicate link status */
  2148. bnx2x_link_report(bp);
  2149. } else { /* VF */
  2150. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2151. SUPPORTED_10baseT_Full |
  2152. SUPPORTED_100baseT_Half |
  2153. SUPPORTED_100baseT_Full |
  2154. SUPPORTED_1000baseT_Full |
  2155. SUPPORTED_2500baseX_Full |
  2156. SUPPORTED_10000baseT_Full |
  2157. SUPPORTED_TP |
  2158. SUPPORTED_FIBRE |
  2159. SUPPORTED_Autoneg |
  2160. SUPPORTED_Pause |
  2161. SUPPORTED_Asym_Pause);
  2162. bp->port.advertising[0] = bp->port.supported[0];
  2163. bp->link_params.bp = bp;
  2164. bp->link_params.port = BP_PORT(bp);
  2165. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2166. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2167. bp->link_params.req_line_speed[0] = SPEED_10000;
  2168. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2169. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2170. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2171. bp->link_vars.line_speed = SPEED_10000;
  2172. bp->link_vars.link_status =
  2173. (LINK_STATUS_LINK_UP |
  2174. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2175. bp->link_vars.link_up = 1;
  2176. bp->link_vars.duplex = DUPLEX_FULL;
  2177. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2178. __bnx2x_link_report(bp);
  2179. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2180. }
  2181. }
  2182. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2183. u16 vlan_val, u8 allowed_prio)
  2184. {
  2185. struct bnx2x_func_state_params func_params = {0};
  2186. struct bnx2x_func_afex_update_params *f_update_params =
  2187. &func_params.params.afex_update;
  2188. func_params.f_obj = &bp->func_obj;
  2189. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2190. /* no need to wait for RAMROD completion, so don't
  2191. * set RAMROD_COMP_WAIT flag
  2192. */
  2193. f_update_params->vif_id = vifid;
  2194. f_update_params->afex_default_vlan = vlan_val;
  2195. f_update_params->allowed_priorities = allowed_prio;
  2196. /* if ramrod can not be sent, response to MCP immediately */
  2197. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2198. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2199. return 0;
  2200. }
  2201. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2202. u16 vif_index, u8 func_bit_map)
  2203. {
  2204. struct bnx2x_func_state_params func_params = {0};
  2205. struct bnx2x_func_afex_viflists_params *update_params =
  2206. &func_params.params.afex_viflists;
  2207. int rc;
  2208. u32 drv_msg_code;
  2209. /* validate only LIST_SET and LIST_GET are received from switch */
  2210. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2211. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2212. cmd_type);
  2213. func_params.f_obj = &bp->func_obj;
  2214. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2215. /* set parameters according to cmd_type */
  2216. update_params->afex_vif_list_command = cmd_type;
  2217. update_params->vif_list_index = cpu_to_le16(vif_index);
  2218. update_params->func_bit_map =
  2219. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2220. update_params->func_to_clear = 0;
  2221. drv_msg_code =
  2222. (cmd_type == VIF_LIST_RULE_GET) ?
  2223. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2224. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2225. /* if ramrod can not be sent, respond to MCP immediately for
  2226. * SET and GET requests (other are not triggered from MCP)
  2227. */
  2228. rc = bnx2x_func_state_change(bp, &func_params);
  2229. if (rc < 0)
  2230. bnx2x_fw_command(bp, drv_msg_code, 0);
  2231. return 0;
  2232. }
  2233. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2234. {
  2235. struct afex_stats afex_stats;
  2236. u32 func = BP_ABS_FUNC(bp);
  2237. u32 mf_config;
  2238. u16 vlan_val;
  2239. u32 vlan_prio;
  2240. u16 vif_id;
  2241. u8 allowed_prio;
  2242. u8 vlan_mode;
  2243. u32 addr_to_write, vifid, addrs, stats_type, i;
  2244. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2245. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2246. DP(BNX2X_MSG_MCP,
  2247. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2248. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2249. }
  2250. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2251. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2252. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2253. DP(BNX2X_MSG_MCP,
  2254. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2255. vifid, addrs);
  2256. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2257. addrs);
  2258. }
  2259. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2260. addr_to_write = SHMEM2_RD(bp,
  2261. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2262. stats_type = SHMEM2_RD(bp,
  2263. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2264. DP(BNX2X_MSG_MCP,
  2265. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2266. addr_to_write);
  2267. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2268. /* write response to scratchpad, for MCP */
  2269. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2270. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2271. *(((u32 *)(&afex_stats))+i));
  2272. /* send ack message to MCP */
  2273. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2274. }
  2275. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2276. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2277. bp->mf_config[BP_VN(bp)] = mf_config;
  2278. DP(BNX2X_MSG_MCP,
  2279. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2280. mf_config);
  2281. /* if VIF_SET is "enabled" */
  2282. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2283. /* set rate limit directly to internal RAM */
  2284. struct cmng_init_input cmng_input;
  2285. struct rate_shaping_vars_per_vn m_rs_vn;
  2286. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2287. u32 addr = BAR_XSTRORM_INTMEM +
  2288. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2289. bp->mf_config[BP_VN(bp)] = mf_config;
  2290. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2291. m_rs_vn.vn_counter.rate =
  2292. cmng_input.vnic_max_rate[BP_VN(bp)];
  2293. m_rs_vn.vn_counter.quota =
  2294. (m_rs_vn.vn_counter.rate *
  2295. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2296. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2297. /* read relevant values from mf_cfg struct in shmem */
  2298. vif_id =
  2299. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2300. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2301. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2302. vlan_val =
  2303. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2304. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2305. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2306. vlan_prio = (mf_config &
  2307. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2308. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2309. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2310. vlan_mode =
  2311. (MF_CFG_RD(bp,
  2312. func_mf_config[func].afex_config) &
  2313. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2314. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2315. allowed_prio =
  2316. (MF_CFG_RD(bp,
  2317. func_mf_config[func].afex_config) &
  2318. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2319. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2320. /* send ramrod to FW, return in case of failure */
  2321. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2322. allowed_prio))
  2323. return;
  2324. bp->afex_def_vlan_tag = vlan_val;
  2325. bp->afex_vlan_mode = vlan_mode;
  2326. } else {
  2327. /* notify link down because BP->flags is disabled */
  2328. bnx2x_link_report(bp);
  2329. /* send INVALID VIF ramrod to FW */
  2330. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2331. /* Reset the default afex VLAN */
  2332. bp->afex_def_vlan_tag = -1;
  2333. }
  2334. }
  2335. }
  2336. static void bnx2x_pmf_update(struct bnx2x *bp)
  2337. {
  2338. int port = BP_PORT(bp);
  2339. u32 val;
  2340. bp->port.pmf = 1;
  2341. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2342. /*
  2343. * We need the mb() to ensure the ordering between the writing to
  2344. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2345. */
  2346. smp_mb();
  2347. /* queue a periodic task */
  2348. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2349. bnx2x_dcbx_pmf_update(bp);
  2350. /* enable nig attention */
  2351. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2352. if (bp->common.int_block == INT_BLOCK_HC) {
  2353. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2354. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2355. } else if (!CHIP_IS_E1x(bp)) {
  2356. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2357. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2358. }
  2359. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2360. }
  2361. /* end of Link */
  2362. /* slow path */
  2363. /*
  2364. * General service functions
  2365. */
  2366. /* send the MCP a request, block until there is a reply */
  2367. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2368. {
  2369. int mb_idx = BP_FW_MB_IDX(bp);
  2370. u32 seq;
  2371. u32 rc = 0;
  2372. u32 cnt = 1;
  2373. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2374. mutex_lock(&bp->fw_mb_mutex);
  2375. seq = ++bp->fw_seq;
  2376. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2377. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2378. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2379. (command | seq), param);
  2380. do {
  2381. /* let the FW do it's magic ... */
  2382. msleep(delay);
  2383. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2384. /* Give the FW up to 5 second (500*10ms) */
  2385. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2386. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2387. cnt*delay, rc, seq);
  2388. /* is this a reply to our command? */
  2389. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2390. rc &= FW_MSG_CODE_MASK;
  2391. else {
  2392. /* FW BUG! */
  2393. BNX2X_ERR("FW failed to respond!\n");
  2394. bnx2x_fw_dump(bp);
  2395. rc = 0;
  2396. }
  2397. mutex_unlock(&bp->fw_mb_mutex);
  2398. return rc;
  2399. }
  2400. static void storm_memset_func_cfg(struct bnx2x *bp,
  2401. struct tstorm_eth_function_common_config *tcfg,
  2402. u16 abs_fid)
  2403. {
  2404. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2405. u32 addr = BAR_TSTRORM_INTMEM +
  2406. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2407. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2408. }
  2409. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2410. {
  2411. if (CHIP_IS_E1x(bp)) {
  2412. struct tstorm_eth_function_common_config tcfg = {0};
  2413. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2414. }
  2415. /* Enable the function in the FW */
  2416. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2417. storm_memset_func_en(bp, p->func_id, 1);
  2418. /* spq */
  2419. if (p->func_flgs & FUNC_FLG_SPQ) {
  2420. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2421. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2422. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2423. }
  2424. }
  2425. /**
  2426. * bnx2x_get_tx_only_flags - Return common flags
  2427. *
  2428. * @bp device handle
  2429. * @fp queue handle
  2430. * @zero_stats TRUE if statistics zeroing is needed
  2431. *
  2432. * Return the flags that are common for the Tx-only and not normal connections.
  2433. */
  2434. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2435. struct bnx2x_fastpath *fp,
  2436. bool zero_stats)
  2437. {
  2438. unsigned long flags = 0;
  2439. /* PF driver will always initialize the Queue to an ACTIVE state */
  2440. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2441. /* tx only connections collect statistics (on the same index as the
  2442. * parent connection). The statistics are zeroed when the parent
  2443. * connection is initialized.
  2444. */
  2445. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2446. if (zero_stats)
  2447. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2448. return flags;
  2449. }
  2450. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2451. struct bnx2x_fastpath *fp,
  2452. bool leading)
  2453. {
  2454. unsigned long flags = 0;
  2455. /* calculate other queue flags */
  2456. if (IS_MF_SD(bp))
  2457. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2458. if (IS_FCOE_FP(fp)) {
  2459. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2460. /* For FCoE - force usage of default priority (for afex) */
  2461. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2462. }
  2463. if (!fp->disable_tpa) {
  2464. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2465. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2466. if (fp->mode == TPA_MODE_GRO)
  2467. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2468. }
  2469. if (leading) {
  2470. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2471. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2472. }
  2473. /* Always set HW VLAN stripping */
  2474. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2475. /* configure silent vlan removal */
  2476. if (IS_MF_AFEX(bp))
  2477. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2478. return flags | bnx2x_get_common_flags(bp, fp, true);
  2479. }
  2480. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2481. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2482. u8 cos)
  2483. {
  2484. gen_init->stat_id = bnx2x_stats_id(fp);
  2485. gen_init->spcl_id = fp->cl_id;
  2486. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2487. if (IS_FCOE_FP(fp))
  2488. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2489. else
  2490. gen_init->mtu = bp->dev->mtu;
  2491. gen_init->cos = cos;
  2492. }
  2493. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2494. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2495. struct bnx2x_rxq_setup_params *rxq_init)
  2496. {
  2497. u8 max_sge = 0;
  2498. u16 sge_sz = 0;
  2499. u16 tpa_agg_size = 0;
  2500. if (!fp->disable_tpa) {
  2501. pause->sge_th_lo = SGE_TH_LO(bp);
  2502. pause->sge_th_hi = SGE_TH_HI(bp);
  2503. /* validate SGE ring has enough to cross high threshold */
  2504. WARN_ON(bp->dropless_fc &&
  2505. pause->sge_th_hi + FW_PREFETCH_CNT >
  2506. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2507. tpa_agg_size = min_t(u32,
  2508. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2509. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2510. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2511. SGE_PAGE_SHIFT;
  2512. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2513. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2514. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2515. 0xffff);
  2516. }
  2517. /* pause - not for e1 */
  2518. if (!CHIP_IS_E1(bp)) {
  2519. pause->bd_th_lo = BD_TH_LO(bp);
  2520. pause->bd_th_hi = BD_TH_HI(bp);
  2521. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2522. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2523. /*
  2524. * validate that rings have enough entries to cross
  2525. * high thresholds
  2526. */
  2527. WARN_ON(bp->dropless_fc &&
  2528. pause->bd_th_hi + FW_PREFETCH_CNT >
  2529. bp->rx_ring_size);
  2530. WARN_ON(bp->dropless_fc &&
  2531. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2532. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2533. pause->pri_map = 1;
  2534. }
  2535. /* rxq setup */
  2536. rxq_init->dscr_map = fp->rx_desc_mapping;
  2537. rxq_init->sge_map = fp->rx_sge_mapping;
  2538. rxq_init->rcq_map = fp->rx_comp_mapping;
  2539. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2540. /* This should be a maximum number of data bytes that may be
  2541. * placed on the BD (not including paddings).
  2542. */
  2543. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2544. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2545. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2546. rxq_init->tpa_agg_sz = tpa_agg_size;
  2547. rxq_init->sge_buf_sz = sge_sz;
  2548. rxq_init->max_sges_pkt = max_sge;
  2549. rxq_init->rss_engine_id = BP_FUNC(bp);
  2550. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2551. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2552. *
  2553. * For PF Clients it should be the maximum avaliable number.
  2554. * VF driver(s) may want to define it to a smaller value.
  2555. */
  2556. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2557. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2558. rxq_init->fw_sb_id = fp->fw_sb_id;
  2559. if (IS_FCOE_FP(fp))
  2560. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2561. else
  2562. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2563. /* configure silent vlan removal
  2564. * if multi function mode is afex, then mask default vlan
  2565. */
  2566. if (IS_MF_AFEX(bp)) {
  2567. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2568. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2569. }
  2570. }
  2571. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2572. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2573. u8 cos)
  2574. {
  2575. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2576. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2577. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2578. txq_init->fw_sb_id = fp->fw_sb_id;
  2579. /*
  2580. * set the tss leading client id for TX classfication ==
  2581. * leading RSS client id
  2582. */
  2583. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2584. if (IS_FCOE_FP(fp)) {
  2585. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2586. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2587. }
  2588. }
  2589. static void bnx2x_pf_init(struct bnx2x *bp)
  2590. {
  2591. struct bnx2x_func_init_params func_init = {0};
  2592. struct event_ring_data eq_data = { {0} };
  2593. u16 flags;
  2594. if (!CHIP_IS_E1x(bp)) {
  2595. /* reset IGU PF statistics: MSIX + ATTN */
  2596. /* PF */
  2597. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2598. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2599. (CHIP_MODE_IS_4_PORT(bp) ?
  2600. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2601. /* ATTN */
  2602. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2603. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2604. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2605. (CHIP_MODE_IS_4_PORT(bp) ?
  2606. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2607. }
  2608. /* function setup flags */
  2609. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2610. /* This flag is relevant for E1x only.
  2611. * E2 doesn't have a TPA configuration in a function level.
  2612. */
  2613. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2614. func_init.func_flgs = flags;
  2615. func_init.pf_id = BP_FUNC(bp);
  2616. func_init.func_id = BP_FUNC(bp);
  2617. func_init.spq_map = bp->spq_mapping;
  2618. func_init.spq_prod = bp->spq_prod_idx;
  2619. bnx2x_func_init(bp, &func_init);
  2620. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2621. /*
  2622. * Congestion management values depend on the link rate
  2623. * There is no active link so initial link rate is set to 10 Gbps.
  2624. * When the link comes up The congestion management values are
  2625. * re-calculated according to the actual link rate.
  2626. */
  2627. bp->link_vars.line_speed = SPEED_10000;
  2628. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2629. /* Only the PMF sets the HW */
  2630. if (bp->port.pmf)
  2631. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2632. /* init Event Queue */
  2633. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2634. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2635. eq_data.producer = bp->eq_prod;
  2636. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2637. eq_data.sb_id = DEF_SB_ID;
  2638. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2639. }
  2640. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2641. {
  2642. int port = BP_PORT(bp);
  2643. bnx2x_tx_disable(bp);
  2644. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2645. }
  2646. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2647. {
  2648. int port = BP_PORT(bp);
  2649. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2650. /* Tx queue should be only reenabled */
  2651. netif_tx_wake_all_queues(bp->dev);
  2652. /*
  2653. * Should not call netif_carrier_on since it will be called if the link
  2654. * is up when checking for link state
  2655. */
  2656. }
  2657. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2658. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2659. {
  2660. struct eth_stats_info *ether_stat =
  2661. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2662. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2663. ETH_STAT_INFO_VERSION_LEN);
  2664. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2665. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2666. ether_stat->mac_local);
  2667. ether_stat->mtu_size = bp->dev->mtu;
  2668. if (bp->dev->features & NETIF_F_RXCSUM)
  2669. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2670. if (bp->dev->features & NETIF_F_TSO)
  2671. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2672. ether_stat->feature_flags |= bp->common.boot_mode;
  2673. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2674. ether_stat->txq_size = bp->tx_ring_size;
  2675. ether_stat->rxq_size = bp->rx_ring_size;
  2676. }
  2677. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2678. {
  2679. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2680. struct fcoe_stats_info *fcoe_stat =
  2681. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2682. if (!CNIC_LOADED(bp))
  2683. return;
  2684. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2685. bp->fip_mac, ETH_ALEN);
  2686. fcoe_stat->qos_priority =
  2687. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2688. /* insert FCoE stats from ramrod response */
  2689. if (!NO_FCOE(bp)) {
  2690. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2691. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2692. tstorm_queue_statistics;
  2693. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2694. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2695. xstorm_queue_statistics;
  2696. struct fcoe_statistics_params *fw_fcoe_stat =
  2697. &bp->fw_stats_data->fcoe;
  2698. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2699. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2700. ADD_64(fcoe_stat->rx_bytes_hi,
  2701. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2702. fcoe_stat->rx_bytes_lo,
  2703. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2704. ADD_64(fcoe_stat->rx_bytes_hi,
  2705. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2706. fcoe_stat->rx_bytes_lo,
  2707. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2708. ADD_64(fcoe_stat->rx_bytes_hi,
  2709. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2710. fcoe_stat->rx_bytes_lo,
  2711. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2712. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2713. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2714. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2715. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2716. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2717. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2718. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2719. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2720. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2721. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2722. ADD_64(fcoe_stat->tx_bytes_hi,
  2723. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2724. fcoe_stat->tx_bytes_lo,
  2725. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2726. ADD_64(fcoe_stat->tx_bytes_hi,
  2727. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2728. fcoe_stat->tx_bytes_lo,
  2729. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2730. ADD_64(fcoe_stat->tx_bytes_hi,
  2731. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2732. fcoe_stat->tx_bytes_lo,
  2733. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2734. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2735. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2736. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2737. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2738. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2739. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2740. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2741. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2742. }
  2743. /* ask L5 driver to add data to the struct */
  2744. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2745. }
  2746. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2747. {
  2748. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2749. struct iscsi_stats_info *iscsi_stat =
  2750. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2751. if (!CNIC_LOADED(bp))
  2752. return;
  2753. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2754. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2755. iscsi_stat->qos_priority =
  2756. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2757. /* ask L5 driver to add data to the struct */
  2758. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2759. }
  2760. /* called due to MCP event (on pmf):
  2761. * reread new bandwidth configuration
  2762. * configure FW
  2763. * notify others function about the change
  2764. */
  2765. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2766. {
  2767. if (bp->link_vars.link_up) {
  2768. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2769. bnx2x_link_sync_notify(bp);
  2770. }
  2771. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2772. }
  2773. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2774. {
  2775. bnx2x_config_mf_bw(bp);
  2776. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2777. }
  2778. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2779. {
  2780. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2781. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2782. }
  2783. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2784. {
  2785. enum drv_info_opcode op_code;
  2786. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2787. /* if drv_info version supported by MFW doesn't match - send NACK */
  2788. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2789. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2790. return;
  2791. }
  2792. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2793. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2794. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2795. sizeof(union drv_info_to_mcp));
  2796. switch (op_code) {
  2797. case ETH_STATS_OPCODE:
  2798. bnx2x_drv_info_ether_stat(bp);
  2799. break;
  2800. case FCOE_STATS_OPCODE:
  2801. bnx2x_drv_info_fcoe_stat(bp);
  2802. break;
  2803. case ISCSI_STATS_OPCODE:
  2804. bnx2x_drv_info_iscsi_stat(bp);
  2805. break;
  2806. default:
  2807. /* if op code isn't supported - send NACK */
  2808. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2809. return;
  2810. }
  2811. /* if we got drv_info attn from MFW then these fields are defined in
  2812. * shmem2 for sure
  2813. */
  2814. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2815. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2816. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2817. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2818. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2819. }
  2820. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2821. {
  2822. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2823. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2824. /*
  2825. * This is the only place besides the function initialization
  2826. * where the bp->flags can change so it is done without any
  2827. * locks
  2828. */
  2829. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2830. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2831. bp->flags |= MF_FUNC_DIS;
  2832. bnx2x_e1h_disable(bp);
  2833. } else {
  2834. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2835. bp->flags &= ~MF_FUNC_DIS;
  2836. bnx2x_e1h_enable(bp);
  2837. }
  2838. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2839. }
  2840. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2841. bnx2x_config_mf_bw(bp);
  2842. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2843. }
  2844. /* Report results to MCP */
  2845. if (dcc_event)
  2846. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2847. else
  2848. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2849. }
  2850. /* must be called under the spq lock */
  2851. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2852. {
  2853. struct eth_spe *next_spe = bp->spq_prod_bd;
  2854. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2855. bp->spq_prod_bd = bp->spq;
  2856. bp->spq_prod_idx = 0;
  2857. DP(BNX2X_MSG_SP, "end of spq\n");
  2858. } else {
  2859. bp->spq_prod_bd++;
  2860. bp->spq_prod_idx++;
  2861. }
  2862. return next_spe;
  2863. }
  2864. /* must be called under the spq lock */
  2865. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2866. {
  2867. int func = BP_FUNC(bp);
  2868. /*
  2869. * Make sure that BD data is updated before writing the producer:
  2870. * BD data is written to the memory, the producer is read from the
  2871. * memory, thus we need a full memory barrier to ensure the ordering.
  2872. */
  2873. mb();
  2874. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2875. bp->spq_prod_idx);
  2876. mmiowb();
  2877. }
  2878. /**
  2879. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2880. *
  2881. * @cmd: command to check
  2882. * @cmd_type: command type
  2883. */
  2884. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2885. {
  2886. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2887. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2888. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2889. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2890. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2891. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2892. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2893. return true;
  2894. else
  2895. return false;
  2896. }
  2897. /**
  2898. * bnx2x_sp_post - place a single command on an SP ring
  2899. *
  2900. * @bp: driver handle
  2901. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2902. * @cid: SW CID the command is related to
  2903. * @data_hi: command private data address (high 32 bits)
  2904. * @data_lo: command private data address (low 32 bits)
  2905. * @cmd_type: command type (e.g. NONE, ETH)
  2906. *
  2907. * SP data is handled as if it's always an address pair, thus data fields are
  2908. * not swapped to little endian in upper functions. Instead this function swaps
  2909. * data as if it's two u32 fields.
  2910. */
  2911. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2912. u32 data_hi, u32 data_lo, int cmd_type)
  2913. {
  2914. struct eth_spe *spe;
  2915. u16 type;
  2916. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2917. #ifdef BNX2X_STOP_ON_ERROR
  2918. if (unlikely(bp->panic)) {
  2919. BNX2X_ERR("Can't post SP when there is panic\n");
  2920. return -EIO;
  2921. }
  2922. #endif
  2923. spin_lock_bh(&bp->spq_lock);
  2924. if (common) {
  2925. if (!atomic_read(&bp->eq_spq_left)) {
  2926. BNX2X_ERR("BUG! EQ ring full!\n");
  2927. spin_unlock_bh(&bp->spq_lock);
  2928. bnx2x_panic();
  2929. return -EBUSY;
  2930. }
  2931. } else if (!atomic_read(&bp->cq_spq_left)) {
  2932. BNX2X_ERR("BUG! SPQ ring full!\n");
  2933. spin_unlock_bh(&bp->spq_lock);
  2934. bnx2x_panic();
  2935. return -EBUSY;
  2936. }
  2937. spe = bnx2x_sp_get_next(bp);
  2938. /* CID needs port number to be encoded int it */
  2939. spe->hdr.conn_and_cmd_data =
  2940. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2941. HW_CID(bp, cid));
  2942. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2943. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2944. SPE_HDR_FUNCTION_ID);
  2945. spe->hdr.type = cpu_to_le16(type);
  2946. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2947. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2948. /*
  2949. * It's ok if the actual decrement is issued towards the memory
  2950. * somewhere between the spin_lock and spin_unlock. Thus no
  2951. * more explict memory barrier is needed.
  2952. */
  2953. if (common)
  2954. atomic_dec(&bp->eq_spq_left);
  2955. else
  2956. atomic_dec(&bp->cq_spq_left);
  2957. DP(BNX2X_MSG_SP,
  2958. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2959. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2960. (u32)(U64_LO(bp->spq_mapping) +
  2961. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2962. HW_CID(bp, cid), data_hi, data_lo, type,
  2963. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2964. bnx2x_sp_prod_update(bp);
  2965. spin_unlock_bh(&bp->spq_lock);
  2966. return 0;
  2967. }
  2968. /* acquire split MCP access lock register */
  2969. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2970. {
  2971. u32 j, val;
  2972. int rc = 0;
  2973. might_sleep();
  2974. for (j = 0; j < 1000; j++) {
  2975. val = (1UL << 31);
  2976. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2977. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2978. if (val & (1L << 31))
  2979. break;
  2980. msleep(5);
  2981. }
  2982. if (!(val & (1L << 31))) {
  2983. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2984. rc = -EBUSY;
  2985. }
  2986. return rc;
  2987. }
  2988. /* release split MCP access lock register */
  2989. static void bnx2x_release_alr(struct bnx2x *bp)
  2990. {
  2991. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2992. }
  2993. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2994. #define BNX2X_DEF_SB_IDX 0x0002
  2995. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2996. {
  2997. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2998. u16 rc = 0;
  2999. barrier(); /* status block is written to by the chip */
  3000. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3001. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3002. rc |= BNX2X_DEF_SB_ATT_IDX;
  3003. }
  3004. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3005. bp->def_idx = def_sb->sp_sb.running_index;
  3006. rc |= BNX2X_DEF_SB_IDX;
  3007. }
  3008. /* Do not reorder: indecies reading should complete before handling */
  3009. barrier();
  3010. return rc;
  3011. }
  3012. /*
  3013. * slow path service functions
  3014. */
  3015. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3016. {
  3017. int port = BP_PORT(bp);
  3018. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3019. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3020. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3021. NIG_REG_MASK_INTERRUPT_PORT0;
  3022. u32 aeu_mask;
  3023. u32 nig_mask = 0;
  3024. u32 reg_addr;
  3025. if (bp->attn_state & asserted)
  3026. BNX2X_ERR("IGU ERROR\n");
  3027. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3028. aeu_mask = REG_RD(bp, aeu_addr);
  3029. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3030. aeu_mask, asserted);
  3031. aeu_mask &= ~(asserted & 0x3ff);
  3032. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3033. REG_WR(bp, aeu_addr, aeu_mask);
  3034. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3035. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3036. bp->attn_state |= asserted;
  3037. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3038. if (asserted & ATTN_HARD_WIRED_MASK) {
  3039. if (asserted & ATTN_NIG_FOR_FUNC) {
  3040. bnx2x_acquire_phy_lock(bp);
  3041. /* save nig interrupt mask */
  3042. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3043. /* If nig_mask is not set, no need to call the update
  3044. * function.
  3045. */
  3046. if (nig_mask) {
  3047. REG_WR(bp, nig_int_mask_addr, 0);
  3048. bnx2x_link_attn(bp);
  3049. }
  3050. /* handle unicore attn? */
  3051. }
  3052. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3053. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3054. if (asserted & GPIO_2_FUNC)
  3055. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3056. if (asserted & GPIO_3_FUNC)
  3057. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3058. if (asserted & GPIO_4_FUNC)
  3059. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3060. if (port == 0) {
  3061. if (asserted & ATTN_GENERAL_ATTN_1) {
  3062. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3063. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3064. }
  3065. if (asserted & ATTN_GENERAL_ATTN_2) {
  3066. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3067. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3068. }
  3069. if (asserted & ATTN_GENERAL_ATTN_3) {
  3070. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3071. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3072. }
  3073. } else {
  3074. if (asserted & ATTN_GENERAL_ATTN_4) {
  3075. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3076. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3077. }
  3078. if (asserted & ATTN_GENERAL_ATTN_5) {
  3079. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3080. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3081. }
  3082. if (asserted & ATTN_GENERAL_ATTN_6) {
  3083. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3084. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3085. }
  3086. }
  3087. } /* if hardwired */
  3088. if (bp->common.int_block == INT_BLOCK_HC)
  3089. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3090. COMMAND_REG_ATTN_BITS_SET);
  3091. else
  3092. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3093. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3094. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3095. REG_WR(bp, reg_addr, asserted);
  3096. /* now set back the mask */
  3097. if (asserted & ATTN_NIG_FOR_FUNC) {
  3098. /* Verify that IGU ack through BAR was written before restoring
  3099. * NIG mask. This loop should exit after 2-3 iterations max.
  3100. */
  3101. if (bp->common.int_block != INT_BLOCK_HC) {
  3102. u32 cnt = 0, igu_acked;
  3103. do {
  3104. igu_acked = REG_RD(bp,
  3105. IGU_REG_ATTENTION_ACK_BITS);
  3106. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3107. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3108. if (!igu_acked)
  3109. DP(NETIF_MSG_HW,
  3110. "Failed to verify IGU ack on time\n");
  3111. barrier();
  3112. }
  3113. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3114. bnx2x_release_phy_lock(bp);
  3115. }
  3116. }
  3117. static void bnx2x_fan_failure(struct bnx2x *bp)
  3118. {
  3119. int port = BP_PORT(bp);
  3120. u32 ext_phy_config;
  3121. /* mark the failure */
  3122. ext_phy_config =
  3123. SHMEM_RD(bp,
  3124. dev_info.port_hw_config[port].external_phy_config);
  3125. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3126. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3127. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3128. ext_phy_config);
  3129. /* log the failure */
  3130. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3131. "Please contact OEM Support for assistance\n");
  3132. /*
  3133. * Scheudle device reset (unload)
  3134. * This is due to some boards consuming sufficient power when driver is
  3135. * up to overheat if fan fails.
  3136. */
  3137. smp_mb__before_clear_bit();
  3138. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3139. smp_mb__after_clear_bit();
  3140. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3141. }
  3142. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3143. {
  3144. int port = BP_PORT(bp);
  3145. int reg_offset;
  3146. u32 val;
  3147. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3148. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3149. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3150. val = REG_RD(bp, reg_offset);
  3151. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3152. REG_WR(bp, reg_offset, val);
  3153. BNX2X_ERR("SPIO5 hw attention\n");
  3154. /* Fan failure attention */
  3155. bnx2x_hw_reset_phy(&bp->link_params);
  3156. bnx2x_fan_failure(bp);
  3157. }
  3158. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3159. bnx2x_acquire_phy_lock(bp);
  3160. bnx2x_handle_module_detect_int(&bp->link_params);
  3161. bnx2x_release_phy_lock(bp);
  3162. }
  3163. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3164. val = REG_RD(bp, reg_offset);
  3165. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3166. REG_WR(bp, reg_offset, val);
  3167. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3168. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3169. bnx2x_panic();
  3170. }
  3171. }
  3172. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3173. {
  3174. u32 val;
  3175. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3176. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3177. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3178. /* DORQ discard attention */
  3179. if (val & 0x2)
  3180. BNX2X_ERR("FATAL error from DORQ\n");
  3181. }
  3182. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3183. int port = BP_PORT(bp);
  3184. int reg_offset;
  3185. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3186. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3187. val = REG_RD(bp, reg_offset);
  3188. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3189. REG_WR(bp, reg_offset, val);
  3190. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3191. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3192. bnx2x_panic();
  3193. }
  3194. }
  3195. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3196. {
  3197. u32 val;
  3198. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3199. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3200. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3201. /* CFC error attention */
  3202. if (val & 0x2)
  3203. BNX2X_ERR("FATAL error from CFC\n");
  3204. }
  3205. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3206. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3207. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3208. /* RQ_USDMDP_FIFO_OVERFLOW */
  3209. if (val & 0x18000)
  3210. BNX2X_ERR("FATAL error from PXP\n");
  3211. if (!CHIP_IS_E1x(bp)) {
  3212. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3213. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3214. }
  3215. }
  3216. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3217. int port = BP_PORT(bp);
  3218. int reg_offset;
  3219. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3220. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3221. val = REG_RD(bp, reg_offset);
  3222. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3223. REG_WR(bp, reg_offset, val);
  3224. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3225. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3226. bnx2x_panic();
  3227. }
  3228. }
  3229. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3230. {
  3231. u32 val;
  3232. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3233. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3234. int func = BP_FUNC(bp);
  3235. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3236. bnx2x_read_mf_cfg(bp);
  3237. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3238. func_mf_config[BP_ABS_FUNC(bp)].config);
  3239. val = SHMEM_RD(bp,
  3240. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3241. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3242. bnx2x_dcc_event(bp,
  3243. (val & DRV_STATUS_DCC_EVENT_MASK));
  3244. if (val & DRV_STATUS_SET_MF_BW)
  3245. bnx2x_set_mf_bw(bp);
  3246. if (val & DRV_STATUS_DRV_INFO_REQ)
  3247. bnx2x_handle_drv_info_req(bp);
  3248. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3249. bnx2x_pmf_update(bp);
  3250. if (bp->port.pmf &&
  3251. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3252. bp->dcbx_enabled > 0)
  3253. /* start dcbx state machine */
  3254. bnx2x_dcbx_set_params(bp,
  3255. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3256. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3257. bnx2x_handle_afex_cmd(bp,
  3258. val & DRV_STATUS_AFEX_EVENT_MASK);
  3259. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3260. bnx2x_handle_eee_event(bp);
  3261. if (bp->link_vars.periodic_flags &
  3262. PERIODIC_FLAGS_LINK_EVENT) {
  3263. /* sync with link */
  3264. bnx2x_acquire_phy_lock(bp);
  3265. bp->link_vars.periodic_flags &=
  3266. ~PERIODIC_FLAGS_LINK_EVENT;
  3267. bnx2x_release_phy_lock(bp);
  3268. if (IS_MF(bp))
  3269. bnx2x_link_sync_notify(bp);
  3270. bnx2x_link_report(bp);
  3271. }
  3272. /* Always call it here: bnx2x_link_report() will
  3273. * prevent the link indication duplication.
  3274. */
  3275. bnx2x__link_status_update(bp);
  3276. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3277. BNX2X_ERR("MC assert!\n");
  3278. bnx2x_mc_assert(bp);
  3279. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3280. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3281. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3282. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3283. bnx2x_panic();
  3284. } else if (attn & BNX2X_MCP_ASSERT) {
  3285. BNX2X_ERR("MCP assert!\n");
  3286. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3287. bnx2x_fw_dump(bp);
  3288. } else
  3289. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3290. }
  3291. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3292. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3293. if (attn & BNX2X_GRC_TIMEOUT) {
  3294. val = CHIP_IS_E1(bp) ? 0 :
  3295. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3296. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3297. }
  3298. if (attn & BNX2X_GRC_RSV) {
  3299. val = CHIP_IS_E1(bp) ? 0 :
  3300. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3301. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3302. }
  3303. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3304. }
  3305. }
  3306. /*
  3307. * Bits map:
  3308. * 0-7 - Engine0 load counter.
  3309. * 8-15 - Engine1 load counter.
  3310. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3311. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3312. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3313. * on the engine
  3314. * 19 - Engine1 ONE_IS_LOADED.
  3315. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3316. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3317. * just the one belonging to its engine).
  3318. *
  3319. */
  3320. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3321. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3322. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3323. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3324. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3325. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3326. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3327. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3328. /*
  3329. * Set the GLOBAL_RESET bit.
  3330. *
  3331. * Should be run under rtnl lock
  3332. */
  3333. void bnx2x_set_reset_global(struct bnx2x *bp)
  3334. {
  3335. u32 val;
  3336. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3337. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3338. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3339. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3340. }
  3341. /*
  3342. * Clear the GLOBAL_RESET bit.
  3343. *
  3344. * Should be run under rtnl lock
  3345. */
  3346. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3347. {
  3348. u32 val;
  3349. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3350. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3351. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3352. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3353. }
  3354. /*
  3355. * Checks the GLOBAL_RESET bit.
  3356. *
  3357. * should be run under rtnl lock
  3358. */
  3359. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3360. {
  3361. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3362. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3363. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3364. }
  3365. /*
  3366. * Clear RESET_IN_PROGRESS bit for the current engine.
  3367. *
  3368. * Should be run under rtnl lock
  3369. */
  3370. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3371. {
  3372. u32 val;
  3373. u32 bit = BP_PATH(bp) ?
  3374. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3375. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3376. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3377. /* Clear the bit */
  3378. val &= ~bit;
  3379. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3380. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3381. }
  3382. /*
  3383. * Set RESET_IN_PROGRESS for the current engine.
  3384. *
  3385. * should be run under rtnl lock
  3386. */
  3387. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3388. {
  3389. u32 val;
  3390. u32 bit = BP_PATH(bp) ?
  3391. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3392. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3393. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3394. /* Set the bit */
  3395. val |= bit;
  3396. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3397. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3398. }
  3399. /*
  3400. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3401. * should be run under rtnl lock
  3402. */
  3403. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3404. {
  3405. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3406. u32 bit = engine ?
  3407. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3408. /* return false if bit is set */
  3409. return (val & bit) ? false : true;
  3410. }
  3411. /*
  3412. * set pf load for the current pf.
  3413. *
  3414. * should be run under rtnl lock
  3415. */
  3416. void bnx2x_set_pf_load(struct bnx2x *bp)
  3417. {
  3418. u32 val1, val;
  3419. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3420. BNX2X_PATH0_LOAD_CNT_MASK;
  3421. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3422. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3423. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3424. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3425. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3426. /* get the current counter value */
  3427. val1 = (val & mask) >> shift;
  3428. /* set bit of that PF */
  3429. val1 |= (1 << bp->pf_num);
  3430. /* clear the old value */
  3431. val &= ~mask;
  3432. /* set the new one */
  3433. val |= ((val1 << shift) & mask);
  3434. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3435. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3436. }
  3437. /**
  3438. * bnx2x_clear_pf_load - clear pf load mark
  3439. *
  3440. * @bp: driver handle
  3441. *
  3442. * Should be run under rtnl lock.
  3443. * Decrements the load counter for the current engine. Returns
  3444. * whether other functions are still loaded
  3445. */
  3446. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3447. {
  3448. u32 val1, val;
  3449. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3450. BNX2X_PATH0_LOAD_CNT_MASK;
  3451. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3452. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3453. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3454. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3455. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3456. /* get the current counter value */
  3457. val1 = (val & mask) >> shift;
  3458. /* clear bit of that PF */
  3459. val1 &= ~(1 << bp->pf_num);
  3460. /* clear the old value */
  3461. val &= ~mask;
  3462. /* set the new one */
  3463. val |= ((val1 << shift) & mask);
  3464. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3465. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3466. return val1 != 0;
  3467. }
  3468. /*
  3469. * Read the load status for the current engine.
  3470. *
  3471. * should be run under rtnl lock
  3472. */
  3473. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3474. {
  3475. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3476. BNX2X_PATH0_LOAD_CNT_MASK);
  3477. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3478. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3479. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3480. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3481. val = (val & mask) >> shift;
  3482. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3483. engine, val);
  3484. return val != 0;
  3485. }
  3486. static void _print_next_block(int idx, const char *blk)
  3487. {
  3488. pr_cont("%s%s", idx ? ", " : "", blk);
  3489. }
  3490. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3491. bool print)
  3492. {
  3493. int i = 0;
  3494. u32 cur_bit = 0;
  3495. for (i = 0; sig; i++) {
  3496. cur_bit = ((u32)0x1 << i);
  3497. if (sig & cur_bit) {
  3498. switch (cur_bit) {
  3499. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3500. if (print)
  3501. _print_next_block(par_num++, "BRB");
  3502. break;
  3503. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3504. if (print)
  3505. _print_next_block(par_num++, "PARSER");
  3506. break;
  3507. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3508. if (print)
  3509. _print_next_block(par_num++, "TSDM");
  3510. break;
  3511. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3512. if (print)
  3513. _print_next_block(par_num++,
  3514. "SEARCHER");
  3515. break;
  3516. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3517. if (print)
  3518. _print_next_block(par_num++, "TCM");
  3519. break;
  3520. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3521. if (print)
  3522. _print_next_block(par_num++, "TSEMI");
  3523. break;
  3524. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3525. if (print)
  3526. _print_next_block(par_num++, "XPB");
  3527. break;
  3528. }
  3529. /* Clear the bit */
  3530. sig &= ~cur_bit;
  3531. }
  3532. }
  3533. return par_num;
  3534. }
  3535. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3536. bool *global, bool print)
  3537. {
  3538. int i = 0;
  3539. u32 cur_bit = 0;
  3540. for (i = 0; sig; i++) {
  3541. cur_bit = ((u32)0x1 << i);
  3542. if (sig & cur_bit) {
  3543. switch (cur_bit) {
  3544. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3545. if (print)
  3546. _print_next_block(par_num++, "PBF");
  3547. break;
  3548. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3549. if (print)
  3550. _print_next_block(par_num++, "QM");
  3551. break;
  3552. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3553. if (print)
  3554. _print_next_block(par_num++, "TM");
  3555. break;
  3556. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3557. if (print)
  3558. _print_next_block(par_num++, "XSDM");
  3559. break;
  3560. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3561. if (print)
  3562. _print_next_block(par_num++, "XCM");
  3563. break;
  3564. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3565. if (print)
  3566. _print_next_block(par_num++, "XSEMI");
  3567. break;
  3568. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3569. if (print)
  3570. _print_next_block(par_num++,
  3571. "DOORBELLQ");
  3572. break;
  3573. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3574. if (print)
  3575. _print_next_block(par_num++, "NIG");
  3576. break;
  3577. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3578. if (print)
  3579. _print_next_block(par_num++,
  3580. "VAUX PCI CORE");
  3581. *global = true;
  3582. break;
  3583. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3584. if (print)
  3585. _print_next_block(par_num++, "DEBUG");
  3586. break;
  3587. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3588. if (print)
  3589. _print_next_block(par_num++, "USDM");
  3590. break;
  3591. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3592. if (print)
  3593. _print_next_block(par_num++, "UCM");
  3594. break;
  3595. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3596. if (print)
  3597. _print_next_block(par_num++, "USEMI");
  3598. break;
  3599. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3600. if (print)
  3601. _print_next_block(par_num++, "UPB");
  3602. break;
  3603. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3604. if (print)
  3605. _print_next_block(par_num++, "CSDM");
  3606. break;
  3607. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3608. if (print)
  3609. _print_next_block(par_num++, "CCM");
  3610. break;
  3611. }
  3612. /* Clear the bit */
  3613. sig &= ~cur_bit;
  3614. }
  3615. }
  3616. return par_num;
  3617. }
  3618. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3619. bool print)
  3620. {
  3621. int i = 0;
  3622. u32 cur_bit = 0;
  3623. for (i = 0; sig; i++) {
  3624. cur_bit = ((u32)0x1 << i);
  3625. if (sig & cur_bit) {
  3626. switch (cur_bit) {
  3627. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3628. if (print)
  3629. _print_next_block(par_num++, "CSEMI");
  3630. break;
  3631. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3632. if (print)
  3633. _print_next_block(par_num++, "PXP");
  3634. break;
  3635. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3636. if (print)
  3637. _print_next_block(par_num++,
  3638. "PXPPCICLOCKCLIENT");
  3639. break;
  3640. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3641. if (print)
  3642. _print_next_block(par_num++, "CFC");
  3643. break;
  3644. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3645. if (print)
  3646. _print_next_block(par_num++, "CDU");
  3647. break;
  3648. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3649. if (print)
  3650. _print_next_block(par_num++, "DMAE");
  3651. break;
  3652. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3653. if (print)
  3654. _print_next_block(par_num++, "IGU");
  3655. break;
  3656. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3657. if (print)
  3658. _print_next_block(par_num++, "MISC");
  3659. break;
  3660. }
  3661. /* Clear the bit */
  3662. sig &= ~cur_bit;
  3663. }
  3664. }
  3665. return par_num;
  3666. }
  3667. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3668. bool *global, bool print)
  3669. {
  3670. int i = 0;
  3671. u32 cur_bit = 0;
  3672. for (i = 0; sig; i++) {
  3673. cur_bit = ((u32)0x1 << i);
  3674. if (sig & cur_bit) {
  3675. switch (cur_bit) {
  3676. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3677. if (print)
  3678. _print_next_block(par_num++, "MCP ROM");
  3679. *global = true;
  3680. break;
  3681. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3682. if (print)
  3683. _print_next_block(par_num++,
  3684. "MCP UMP RX");
  3685. *global = true;
  3686. break;
  3687. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3688. if (print)
  3689. _print_next_block(par_num++,
  3690. "MCP UMP TX");
  3691. *global = true;
  3692. break;
  3693. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3694. if (print)
  3695. _print_next_block(par_num++,
  3696. "MCP SCPAD");
  3697. *global = true;
  3698. break;
  3699. }
  3700. /* Clear the bit */
  3701. sig &= ~cur_bit;
  3702. }
  3703. }
  3704. return par_num;
  3705. }
  3706. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3707. bool print)
  3708. {
  3709. int i = 0;
  3710. u32 cur_bit = 0;
  3711. for (i = 0; sig; i++) {
  3712. cur_bit = ((u32)0x1 << i);
  3713. if (sig & cur_bit) {
  3714. switch (cur_bit) {
  3715. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3716. if (print)
  3717. _print_next_block(par_num++, "PGLUE_B");
  3718. break;
  3719. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3720. if (print)
  3721. _print_next_block(par_num++, "ATC");
  3722. break;
  3723. }
  3724. /* Clear the bit */
  3725. sig &= ~cur_bit;
  3726. }
  3727. }
  3728. return par_num;
  3729. }
  3730. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3731. u32 *sig)
  3732. {
  3733. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3734. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3735. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3736. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3737. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3738. int par_num = 0;
  3739. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3740. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3741. sig[0] & HW_PRTY_ASSERT_SET_0,
  3742. sig[1] & HW_PRTY_ASSERT_SET_1,
  3743. sig[2] & HW_PRTY_ASSERT_SET_2,
  3744. sig[3] & HW_PRTY_ASSERT_SET_3,
  3745. sig[4] & HW_PRTY_ASSERT_SET_4);
  3746. if (print)
  3747. netdev_err(bp->dev,
  3748. "Parity errors detected in blocks: ");
  3749. par_num = bnx2x_check_blocks_with_parity0(
  3750. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3751. par_num = bnx2x_check_blocks_with_parity1(
  3752. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3753. par_num = bnx2x_check_blocks_with_parity2(
  3754. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3755. par_num = bnx2x_check_blocks_with_parity3(
  3756. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3757. par_num = bnx2x_check_blocks_with_parity4(
  3758. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3759. if (print)
  3760. pr_cont("\n");
  3761. return true;
  3762. } else
  3763. return false;
  3764. }
  3765. /**
  3766. * bnx2x_chk_parity_attn - checks for parity attentions.
  3767. *
  3768. * @bp: driver handle
  3769. * @global: true if there was a global attention
  3770. * @print: show parity attention in syslog
  3771. */
  3772. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3773. {
  3774. struct attn_route attn = { {0} };
  3775. int port = BP_PORT(bp);
  3776. attn.sig[0] = REG_RD(bp,
  3777. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3778. port*4);
  3779. attn.sig[1] = REG_RD(bp,
  3780. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3781. port*4);
  3782. attn.sig[2] = REG_RD(bp,
  3783. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3784. port*4);
  3785. attn.sig[3] = REG_RD(bp,
  3786. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3787. port*4);
  3788. if (!CHIP_IS_E1x(bp))
  3789. attn.sig[4] = REG_RD(bp,
  3790. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3791. port*4);
  3792. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3793. }
  3794. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3795. {
  3796. u32 val;
  3797. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3798. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3799. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3800. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3801. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3802. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3803. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3804. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3805. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3806. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3807. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3808. if (val &
  3809. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3810. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3811. if (val &
  3812. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3813. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3814. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3815. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3816. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3817. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3818. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3819. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3820. }
  3821. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3822. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3823. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3824. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3825. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3826. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3827. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3828. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3829. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3830. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3831. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3832. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3833. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3834. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3835. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3836. }
  3837. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3838. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3839. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3840. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3841. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3842. }
  3843. }
  3844. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3845. {
  3846. struct attn_route attn, *group_mask;
  3847. int port = BP_PORT(bp);
  3848. int index;
  3849. u32 reg_addr;
  3850. u32 val;
  3851. u32 aeu_mask;
  3852. bool global = false;
  3853. /* need to take HW lock because MCP or other port might also
  3854. try to handle this event */
  3855. bnx2x_acquire_alr(bp);
  3856. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3857. #ifndef BNX2X_STOP_ON_ERROR
  3858. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3859. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3860. /* Disable HW interrupts */
  3861. bnx2x_int_disable(bp);
  3862. /* In case of parity errors don't handle attentions so that
  3863. * other function would "see" parity errors.
  3864. */
  3865. #else
  3866. bnx2x_panic();
  3867. #endif
  3868. bnx2x_release_alr(bp);
  3869. return;
  3870. }
  3871. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3872. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3873. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3874. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3875. if (!CHIP_IS_E1x(bp))
  3876. attn.sig[4] =
  3877. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3878. else
  3879. attn.sig[4] = 0;
  3880. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3881. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3882. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3883. if (deasserted & (1 << index)) {
  3884. group_mask = &bp->attn_group[index];
  3885. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3886. index,
  3887. group_mask->sig[0], group_mask->sig[1],
  3888. group_mask->sig[2], group_mask->sig[3],
  3889. group_mask->sig[4]);
  3890. bnx2x_attn_int_deasserted4(bp,
  3891. attn.sig[4] & group_mask->sig[4]);
  3892. bnx2x_attn_int_deasserted3(bp,
  3893. attn.sig[3] & group_mask->sig[3]);
  3894. bnx2x_attn_int_deasserted1(bp,
  3895. attn.sig[1] & group_mask->sig[1]);
  3896. bnx2x_attn_int_deasserted2(bp,
  3897. attn.sig[2] & group_mask->sig[2]);
  3898. bnx2x_attn_int_deasserted0(bp,
  3899. attn.sig[0] & group_mask->sig[0]);
  3900. }
  3901. }
  3902. bnx2x_release_alr(bp);
  3903. if (bp->common.int_block == INT_BLOCK_HC)
  3904. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3905. COMMAND_REG_ATTN_BITS_CLR);
  3906. else
  3907. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3908. val = ~deasserted;
  3909. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3910. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3911. REG_WR(bp, reg_addr, val);
  3912. if (~bp->attn_state & deasserted)
  3913. BNX2X_ERR("IGU ERROR\n");
  3914. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3915. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3916. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3917. aeu_mask = REG_RD(bp, reg_addr);
  3918. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3919. aeu_mask, deasserted);
  3920. aeu_mask |= (deasserted & 0x3ff);
  3921. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3922. REG_WR(bp, reg_addr, aeu_mask);
  3923. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3924. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3925. bp->attn_state &= ~deasserted;
  3926. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3927. }
  3928. static void bnx2x_attn_int(struct bnx2x *bp)
  3929. {
  3930. /* read local copy of bits */
  3931. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3932. attn_bits);
  3933. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3934. attn_bits_ack);
  3935. u32 attn_state = bp->attn_state;
  3936. /* look for changed bits */
  3937. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3938. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3939. DP(NETIF_MSG_HW,
  3940. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3941. attn_bits, attn_ack, asserted, deasserted);
  3942. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3943. BNX2X_ERR("BAD attention state\n");
  3944. /* handle bits that were raised */
  3945. if (asserted)
  3946. bnx2x_attn_int_asserted(bp, asserted);
  3947. if (deasserted)
  3948. bnx2x_attn_int_deasserted(bp, deasserted);
  3949. }
  3950. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3951. u16 index, u8 op, u8 update)
  3952. {
  3953. u32 igu_addr = bp->igu_base_addr;
  3954. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3955. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3956. igu_addr);
  3957. }
  3958. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3959. {
  3960. /* No memory barriers */
  3961. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3962. mmiowb(); /* keep prod updates ordered */
  3963. }
  3964. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3965. union event_ring_elem *elem)
  3966. {
  3967. u8 err = elem->message.error;
  3968. if (!bp->cnic_eth_dev.starting_cid ||
  3969. (cid < bp->cnic_eth_dev.starting_cid &&
  3970. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3971. return 1;
  3972. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3973. if (unlikely(err)) {
  3974. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3975. cid);
  3976. bnx2x_panic_dump(bp);
  3977. }
  3978. bnx2x_cnic_cfc_comp(bp, cid, err);
  3979. return 0;
  3980. }
  3981. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3982. {
  3983. struct bnx2x_mcast_ramrod_params rparam;
  3984. int rc;
  3985. memset(&rparam, 0, sizeof(rparam));
  3986. rparam.mcast_obj = &bp->mcast_obj;
  3987. netif_addr_lock_bh(bp->dev);
  3988. /* Clear pending state for the last command */
  3989. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3990. /* If there are pending mcast commands - send them */
  3991. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3992. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3993. if (rc < 0)
  3994. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3995. rc);
  3996. }
  3997. netif_addr_unlock_bh(bp->dev);
  3998. }
  3999. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4000. union event_ring_elem *elem)
  4001. {
  4002. unsigned long ramrod_flags = 0;
  4003. int rc = 0;
  4004. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4005. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4006. /* Always push next commands out, don't wait here */
  4007. __set_bit(RAMROD_CONT, &ramrod_flags);
  4008. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  4009. case BNX2X_FILTER_MAC_PENDING:
  4010. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4011. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4012. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4013. else
  4014. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4015. break;
  4016. case BNX2X_FILTER_MCAST_PENDING:
  4017. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4018. /* This is only relevant for 57710 where multicast MACs are
  4019. * configured as unicast MACs using the same ramrod.
  4020. */
  4021. bnx2x_handle_mcast_eqe(bp);
  4022. return;
  4023. default:
  4024. BNX2X_ERR("Unsupported classification command: %d\n",
  4025. elem->message.data.eth_event.echo);
  4026. return;
  4027. }
  4028. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4029. if (rc < 0)
  4030. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4031. else if (rc > 0)
  4032. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4033. }
  4034. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4035. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4036. {
  4037. netif_addr_lock_bh(bp->dev);
  4038. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4039. /* Send rx_mode command again if was requested */
  4040. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4041. bnx2x_set_storm_rx_mode(bp);
  4042. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4043. &bp->sp_state))
  4044. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4045. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4046. &bp->sp_state))
  4047. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4048. netif_addr_unlock_bh(bp->dev);
  4049. }
  4050. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4051. union event_ring_elem *elem)
  4052. {
  4053. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4054. DP(BNX2X_MSG_SP,
  4055. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4056. elem->message.data.vif_list_event.func_bit_map);
  4057. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4058. elem->message.data.vif_list_event.func_bit_map);
  4059. } else if (elem->message.data.vif_list_event.echo ==
  4060. VIF_LIST_RULE_SET) {
  4061. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4062. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4063. }
  4064. }
  4065. /* called with rtnl_lock */
  4066. static void bnx2x_after_function_update(struct bnx2x *bp)
  4067. {
  4068. int q, rc;
  4069. struct bnx2x_fastpath *fp;
  4070. struct bnx2x_queue_state_params queue_params = {NULL};
  4071. struct bnx2x_queue_update_params *q_update_params =
  4072. &queue_params.params.update;
  4073. /* Send Q update command with afex vlan removal values for all Qs */
  4074. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4075. /* set silent vlan removal values according to vlan mode */
  4076. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4077. &q_update_params->update_flags);
  4078. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4079. &q_update_params->update_flags);
  4080. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4081. /* in access mode mark mask and value are 0 to strip all vlans */
  4082. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4083. q_update_params->silent_removal_value = 0;
  4084. q_update_params->silent_removal_mask = 0;
  4085. } else {
  4086. q_update_params->silent_removal_value =
  4087. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4088. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4089. }
  4090. for_each_eth_queue(bp, q) {
  4091. /* Set the appropriate Queue object */
  4092. fp = &bp->fp[q];
  4093. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4094. /* send the ramrod */
  4095. rc = bnx2x_queue_state_change(bp, &queue_params);
  4096. if (rc < 0)
  4097. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4098. q);
  4099. }
  4100. if (!NO_FCOE(bp)) {
  4101. fp = &bp->fp[FCOE_IDX(bp)];
  4102. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4103. /* clear pending completion bit */
  4104. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4105. /* mark latest Q bit */
  4106. smp_mb__before_clear_bit();
  4107. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4108. smp_mb__after_clear_bit();
  4109. /* send Q update ramrod for FCoE Q */
  4110. rc = bnx2x_queue_state_change(bp, &queue_params);
  4111. if (rc < 0)
  4112. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4113. q);
  4114. } else {
  4115. /* If no FCoE ring - ACK MCP now */
  4116. bnx2x_link_report(bp);
  4117. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4118. }
  4119. }
  4120. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4121. struct bnx2x *bp, u32 cid)
  4122. {
  4123. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4124. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4125. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4126. else
  4127. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4128. }
  4129. static void bnx2x_eq_int(struct bnx2x *bp)
  4130. {
  4131. u16 hw_cons, sw_cons, sw_prod;
  4132. union event_ring_elem *elem;
  4133. u8 echo;
  4134. u32 cid;
  4135. u8 opcode;
  4136. int rc, spqe_cnt = 0;
  4137. struct bnx2x_queue_sp_obj *q_obj;
  4138. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4139. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4140. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4141. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4142. * when we get the the next-page we nned to adjust so the loop
  4143. * condition below will be met. The next element is the size of a
  4144. * regular element and hence incrementing by 1
  4145. */
  4146. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4147. hw_cons++;
  4148. /* This function may never run in parallel with itself for a
  4149. * specific bp, thus there is no need in "paired" read memory
  4150. * barrier here.
  4151. */
  4152. sw_cons = bp->eq_cons;
  4153. sw_prod = bp->eq_prod;
  4154. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4155. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4156. for (; sw_cons != hw_cons;
  4157. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4158. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4159. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4160. if (!rc) {
  4161. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4162. rc);
  4163. goto next_spqe;
  4164. }
  4165. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4166. opcode = elem->message.opcode;
  4167. /* handle eq element */
  4168. switch (opcode) {
  4169. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4170. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4171. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4172. continue;
  4173. case EVENT_RING_OPCODE_STAT_QUERY:
  4174. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4175. "got statistics comp event %d\n",
  4176. bp->stats_comp++);
  4177. /* nothing to do with stats comp */
  4178. goto next_spqe;
  4179. case EVENT_RING_OPCODE_CFC_DEL:
  4180. /* handle according to cid range */
  4181. /*
  4182. * we may want to verify here that the bp state is
  4183. * HALTING
  4184. */
  4185. DP(BNX2X_MSG_SP,
  4186. "got delete ramrod for MULTI[%d]\n", cid);
  4187. if (CNIC_LOADED(bp) &&
  4188. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4189. goto next_spqe;
  4190. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4191. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4192. break;
  4193. goto next_spqe;
  4194. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4195. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4196. if (f_obj->complete_cmd(bp, f_obj,
  4197. BNX2X_F_CMD_TX_STOP))
  4198. break;
  4199. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4200. goto next_spqe;
  4201. case EVENT_RING_OPCODE_START_TRAFFIC:
  4202. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4203. if (f_obj->complete_cmd(bp, f_obj,
  4204. BNX2X_F_CMD_TX_START))
  4205. break;
  4206. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4207. goto next_spqe;
  4208. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4209. echo = elem->message.data.function_update_event.echo;
  4210. if (echo == SWITCH_UPDATE) {
  4211. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4212. "got FUNC_SWITCH_UPDATE ramrod\n");
  4213. if (f_obj->complete_cmd(
  4214. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4215. break;
  4216. } else {
  4217. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4218. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4219. f_obj->complete_cmd(bp, f_obj,
  4220. BNX2X_F_CMD_AFEX_UPDATE);
  4221. /* We will perform the Queues update from
  4222. * sp_rtnl task as all Queue SP operations
  4223. * should run under rtnl_lock.
  4224. */
  4225. smp_mb__before_clear_bit();
  4226. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4227. &bp->sp_rtnl_state);
  4228. smp_mb__after_clear_bit();
  4229. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4230. }
  4231. goto next_spqe;
  4232. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4233. f_obj->complete_cmd(bp, f_obj,
  4234. BNX2X_F_CMD_AFEX_VIFLISTS);
  4235. bnx2x_after_afex_vif_lists(bp, elem);
  4236. goto next_spqe;
  4237. case EVENT_RING_OPCODE_FUNCTION_START:
  4238. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4239. "got FUNC_START ramrod\n");
  4240. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4241. break;
  4242. goto next_spqe;
  4243. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4244. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4245. "got FUNC_STOP ramrod\n");
  4246. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4247. break;
  4248. goto next_spqe;
  4249. }
  4250. switch (opcode | bp->state) {
  4251. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4252. BNX2X_STATE_OPEN):
  4253. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4254. BNX2X_STATE_OPENING_WAIT4_PORT):
  4255. cid = elem->message.data.eth_event.echo &
  4256. BNX2X_SWCID_MASK;
  4257. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4258. cid);
  4259. rss_raw->clear_pending(rss_raw);
  4260. break;
  4261. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4262. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4263. case (EVENT_RING_OPCODE_SET_MAC |
  4264. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4265. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4266. BNX2X_STATE_OPEN):
  4267. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4268. BNX2X_STATE_DIAG):
  4269. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4270. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4271. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4272. bnx2x_handle_classification_eqe(bp, elem);
  4273. break;
  4274. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4275. BNX2X_STATE_OPEN):
  4276. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4277. BNX2X_STATE_DIAG):
  4278. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4279. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4280. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4281. bnx2x_handle_mcast_eqe(bp);
  4282. break;
  4283. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4284. BNX2X_STATE_OPEN):
  4285. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4286. BNX2X_STATE_DIAG):
  4287. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4288. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4289. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4290. bnx2x_handle_rx_mode_eqe(bp);
  4291. break;
  4292. default:
  4293. /* unknown event log error and continue */
  4294. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4295. elem->message.opcode, bp->state);
  4296. }
  4297. next_spqe:
  4298. spqe_cnt++;
  4299. } /* for */
  4300. smp_mb__before_atomic_inc();
  4301. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4302. bp->eq_cons = sw_cons;
  4303. bp->eq_prod = sw_prod;
  4304. /* Make sure that above mem writes were issued towards the memory */
  4305. smp_wmb();
  4306. /* update producer */
  4307. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4308. }
  4309. static void bnx2x_sp_task(struct work_struct *work)
  4310. {
  4311. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4312. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4313. /* make sure the atomic interupt_occurred has been written */
  4314. smp_rmb();
  4315. if (atomic_read(&bp->interrupt_occurred)) {
  4316. /* what work needs to be performed? */
  4317. u16 status = bnx2x_update_dsb_idx(bp);
  4318. DP(BNX2X_MSG_SP, "status %x\n", status);
  4319. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4320. atomic_set(&bp->interrupt_occurred, 0);
  4321. /* HW attentions */
  4322. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4323. bnx2x_attn_int(bp);
  4324. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4325. }
  4326. /* SP events: STAT_QUERY and others */
  4327. if (status & BNX2X_DEF_SB_IDX) {
  4328. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4329. if (FCOE_INIT(bp) &&
  4330. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4331. /* Prevent local bottom-halves from running as
  4332. * we are going to change the local NAPI list.
  4333. */
  4334. local_bh_disable();
  4335. napi_schedule(&bnx2x_fcoe(bp, napi));
  4336. local_bh_enable();
  4337. }
  4338. /* Handle EQ completions */
  4339. bnx2x_eq_int(bp);
  4340. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4341. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4342. status &= ~BNX2X_DEF_SB_IDX;
  4343. }
  4344. /* if status is non zero then perhaps something went wrong */
  4345. if (unlikely(status))
  4346. DP(BNX2X_MSG_SP,
  4347. "got an unknown interrupt! (status 0x%x)\n", status);
  4348. /* ack status block only if something was actually handled */
  4349. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4350. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4351. }
  4352. /* must be called after the EQ processing (since eq leads to sriov
  4353. * ramrod completion flows).
  4354. * This flow may have been scheduled by the arrival of a ramrod
  4355. * completion, or by the sriov code rescheduling itself.
  4356. */
  4357. bnx2x_iov_sp_task(bp);
  4358. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4359. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4360. &bp->sp_state)) {
  4361. bnx2x_link_report(bp);
  4362. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4363. }
  4364. }
  4365. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4366. {
  4367. struct net_device *dev = dev_instance;
  4368. struct bnx2x *bp = netdev_priv(dev);
  4369. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4370. IGU_INT_DISABLE, 0);
  4371. #ifdef BNX2X_STOP_ON_ERROR
  4372. if (unlikely(bp->panic))
  4373. return IRQ_HANDLED;
  4374. #endif
  4375. if (CNIC_LOADED(bp)) {
  4376. struct cnic_ops *c_ops;
  4377. rcu_read_lock();
  4378. c_ops = rcu_dereference(bp->cnic_ops);
  4379. if (c_ops)
  4380. c_ops->cnic_handler(bp->cnic_data, NULL);
  4381. rcu_read_unlock();
  4382. }
  4383. /* schedule sp task to perform default status block work, ack
  4384. * attentions and enable interrupts.
  4385. */
  4386. bnx2x_schedule_sp_task(bp);
  4387. return IRQ_HANDLED;
  4388. }
  4389. /* end of slow path */
  4390. void bnx2x_drv_pulse(struct bnx2x *bp)
  4391. {
  4392. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4393. bp->fw_drv_pulse_wr_seq);
  4394. }
  4395. static void bnx2x_timer(unsigned long data)
  4396. {
  4397. struct bnx2x *bp = (struct bnx2x *) data;
  4398. if (!netif_running(bp->dev))
  4399. return;
  4400. if (!BP_NOMCP(bp)) {
  4401. int mb_idx = BP_FW_MB_IDX(bp);
  4402. u32 drv_pulse;
  4403. u32 mcp_pulse;
  4404. ++bp->fw_drv_pulse_wr_seq;
  4405. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4406. /* TBD - add SYSTEM_TIME */
  4407. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4408. bnx2x_drv_pulse(bp);
  4409. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4410. MCP_PULSE_SEQ_MASK);
  4411. /* The delta between driver pulse and mcp response
  4412. * should be 1 (before mcp response) or 0 (after mcp response)
  4413. */
  4414. if ((drv_pulse != mcp_pulse) &&
  4415. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4416. /* someone lost a heartbeat... */
  4417. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4418. drv_pulse, mcp_pulse);
  4419. }
  4420. }
  4421. if (bp->state == BNX2X_STATE_OPEN)
  4422. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4423. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4424. }
  4425. /* end of Statistics */
  4426. /* nic init */
  4427. /*
  4428. * nic init service functions
  4429. */
  4430. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4431. {
  4432. u32 i;
  4433. if (!(len%4) && !(addr%4))
  4434. for (i = 0; i < len; i += 4)
  4435. REG_WR(bp, addr + i, fill);
  4436. else
  4437. for (i = 0; i < len; i++)
  4438. REG_WR8(bp, addr + i, fill);
  4439. }
  4440. /* helper: writes FP SP data to FW - data_size in dwords */
  4441. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4442. int fw_sb_id,
  4443. u32 *sb_data_p,
  4444. u32 data_size)
  4445. {
  4446. int index;
  4447. for (index = 0; index < data_size; index++)
  4448. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4449. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4450. sizeof(u32)*index,
  4451. *(sb_data_p + index));
  4452. }
  4453. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4454. {
  4455. u32 *sb_data_p;
  4456. u32 data_size = 0;
  4457. struct hc_status_block_data_e2 sb_data_e2;
  4458. struct hc_status_block_data_e1x sb_data_e1x;
  4459. /* disable the function first */
  4460. if (!CHIP_IS_E1x(bp)) {
  4461. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4462. sb_data_e2.common.state = SB_DISABLED;
  4463. sb_data_e2.common.p_func.vf_valid = false;
  4464. sb_data_p = (u32 *)&sb_data_e2;
  4465. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4466. } else {
  4467. memset(&sb_data_e1x, 0,
  4468. sizeof(struct hc_status_block_data_e1x));
  4469. sb_data_e1x.common.state = SB_DISABLED;
  4470. sb_data_e1x.common.p_func.vf_valid = false;
  4471. sb_data_p = (u32 *)&sb_data_e1x;
  4472. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4473. }
  4474. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4475. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4476. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4477. CSTORM_STATUS_BLOCK_SIZE);
  4478. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4479. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4480. CSTORM_SYNC_BLOCK_SIZE);
  4481. }
  4482. /* helper: writes SP SB data to FW */
  4483. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4484. struct hc_sp_status_block_data *sp_sb_data)
  4485. {
  4486. int func = BP_FUNC(bp);
  4487. int i;
  4488. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4489. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4490. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4491. i*sizeof(u32),
  4492. *((u32 *)sp_sb_data + i));
  4493. }
  4494. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4495. {
  4496. int func = BP_FUNC(bp);
  4497. struct hc_sp_status_block_data sp_sb_data;
  4498. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4499. sp_sb_data.state = SB_DISABLED;
  4500. sp_sb_data.p_func.vf_valid = false;
  4501. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4502. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4503. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4504. CSTORM_SP_STATUS_BLOCK_SIZE);
  4505. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4506. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4507. CSTORM_SP_SYNC_BLOCK_SIZE);
  4508. }
  4509. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4510. int igu_sb_id, int igu_seg_id)
  4511. {
  4512. hc_sm->igu_sb_id = igu_sb_id;
  4513. hc_sm->igu_seg_id = igu_seg_id;
  4514. hc_sm->timer_value = 0xFF;
  4515. hc_sm->time_to_expire = 0xFFFFFFFF;
  4516. }
  4517. /* allocates state machine ids. */
  4518. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4519. {
  4520. /* zero out state machine indices */
  4521. /* rx indices */
  4522. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4523. /* tx indices */
  4524. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4525. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4526. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4527. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4528. /* map indices */
  4529. /* rx indices */
  4530. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4531. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4532. /* tx indices */
  4533. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4534. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4535. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4536. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4537. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4538. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4539. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4540. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4541. }
  4542. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4543. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4544. {
  4545. int igu_seg_id;
  4546. struct hc_status_block_data_e2 sb_data_e2;
  4547. struct hc_status_block_data_e1x sb_data_e1x;
  4548. struct hc_status_block_sm *hc_sm_p;
  4549. int data_size;
  4550. u32 *sb_data_p;
  4551. if (CHIP_INT_MODE_IS_BC(bp))
  4552. igu_seg_id = HC_SEG_ACCESS_NORM;
  4553. else
  4554. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4555. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4556. if (!CHIP_IS_E1x(bp)) {
  4557. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4558. sb_data_e2.common.state = SB_ENABLED;
  4559. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4560. sb_data_e2.common.p_func.vf_id = vfid;
  4561. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4562. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4563. sb_data_e2.common.same_igu_sb_1b = true;
  4564. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4565. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4566. hc_sm_p = sb_data_e2.common.state_machine;
  4567. sb_data_p = (u32 *)&sb_data_e2;
  4568. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4569. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4570. } else {
  4571. memset(&sb_data_e1x, 0,
  4572. sizeof(struct hc_status_block_data_e1x));
  4573. sb_data_e1x.common.state = SB_ENABLED;
  4574. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4575. sb_data_e1x.common.p_func.vf_id = 0xff;
  4576. sb_data_e1x.common.p_func.vf_valid = false;
  4577. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4578. sb_data_e1x.common.same_igu_sb_1b = true;
  4579. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4580. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4581. hc_sm_p = sb_data_e1x.common.state_machine;
  4582. sb_data_p = (u32 *)&sb_data_e1x;
  4583. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4584. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4585. }
  4586. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4587. igu_sb_id, igu_seg_id);
  4588. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4589. igu_sb_id, igu_seg_id);
  4590. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4591. /* write indecies to HW */
  4592. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4593. }
  4594. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4595. u16 tx_usec, u16 rx_usec)
  4596. {
  4597. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4598. false, rx_usec);
  4599. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4600. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4601. tx_usec);
  4602. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4603. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4604. tx_usec);
  4605. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4606. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4607. tx_usec);
  4608. }
  4609. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4610. {
  4611. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4612. dma_addr_t mapping = bp->def_status_blk_mapping;
  4613. int igu_sp_sb_index;
  4614. int igu_seg_id;
  4615. int port = BP_PORT(bp);
  4616. int func = BP_FUNC(bp);
  4617. int reg_offset, reg_offset_en5;
  4618. u64 section;
  4619. int index;
  4620. struct hc_sp_status_block_data sp_sb_data;
  4621. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4622. if (CHIP_INT_MODE_IS_BC(bp)) {
  4623. igu_sp_sb_index = DEF_SB_IGU_ID;
  4624. igu_seg_id = HC_SEG_ACCESS_DEF;
  4625. } else {
  4626. igu_sp_sb_index = bp->igu_dsb_id;
  4627. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4628. }
  4629. /* ATTN */
  4630. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4631. atten_status_block);
  4632. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4633. bp->attn_state = 0;
  4634. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4635. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4636. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4637. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4638. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4639. int sindex;
  4640. /* take care of sig[0]..sig[4] */
  4641. for (sindex = 0; sindex < 4; sindex++)
  4642. bp->attn_group[index].sig[sindex] =
  4643. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4644. if (!CHIP_IS_E1x(bp))
  4645. /*
  4646. * enable5 is separate from the rest of the registers,
  4647. * and therefore the address skip is 4
  4648. * and not 16 between the different groups
  4649. */
  4650. bp->attn_group[index].sig[4] = REG_RD(bp,
  4651. reg_offset_en5 + 0x4*index);
  4652. else
  4653. bp->attn_group[index].sig[4] = 0;
  4654. }
  4655. if (bp->common.int_block == INT_BLOCK_HC) {
  4656. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4657. HC_REG_ATTN_MSG0_ADDR_L);
  4658. REG_WR(bp, reg_offset, U64_LO(section));
  4659. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4660. } else if (!CHIP_IS_E1x(bp)) {
  4661. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4662. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4663. }
  4664. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4665. sp_sb);
  4666. bnx2x_zero_sp_sb(bp);
  4667. sp_sb_data.state = SB_ENABLED;
  4668. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4669. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4670. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4671. sp_sb_data.igu_seg_id = igu_seg_id;
  4672. sp_sb_data.p_func.pf_id = func;
  4673. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4674. sp_sb_data.p_func.vf_id = 0xff;
  4675. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4676. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4677. }
  4678. void bnx2x_update_coalesce(struct bnx2x *bp)
  4679. {
  4680. int i;
  4681. for_each_eth_queue(bp, i)
  4682. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4683. bp->tx_ticks, bp->rx_ticks);
  4684. }
  4685. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4686. {
  4687. spin_lock_init(&bp->spq_lock);
  4688. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4689. bp->spq_prod_idx = 0;
  4690. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4691. bp->spq_prod_bd = bp->spq;
  4692. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4693. }
  4694. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4695. {
  4696. int i;
  4697. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4698. union event_ring_elem *elem =
  4699. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4700. elem->next_page.addr.hi =
  4701. cpu_to_le32(U64_HI(bp->eq_mapping +
  4702. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4703. elem->next_page.addr.lo =
  4704. cpu_to_le32(U64_LO(bp->eq_mapping +
  4705. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4706. }
  4707. bp->eq_cons = 0;
  4708. bp->eq_prod = NUM_EQ_DESC;
  4709. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4710. /* we want a warning message before it gets rought... */
  4711. atomic_set(&bp->eq_spq_left,
  4712. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4713. }
  4714. /* called with netif_addr_lock_bh() */
  4715. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4716. unsigned long rx_mode_flags,
  4717. unsigned long rx_accept_flags,
  4718. unsigned long tx_accept_flags,
  4719. unsigned long ramrod_flags)
  4720. {
  4721. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4722. int rc;
  4723. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4724. /* Prepare ramrod parameters */
  4725. ramrod_param.cid = 0;
  4726. ramrod_param.cl_id = cl_id;
  4727. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4728. ramrod_param.func_id = BP_FUNC(bp);
  4729. ramrod_param.pstate = &bp->sp_state;
  4730. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4731. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4732. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4733. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4734. ramrod_param.ramrod_flags = ramrod_flags;
  4735. ramrod_param.rx_mode_flags = rx_mode_flags;
  4736. ramrod_param.rx_accept_flags = rx_accept_flags;
  4737. ramrod_param.tx_accept_flags = tx_accept_flags;
  4738. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4739. if (rc < 0) {
  4740. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4741. return;
  4742. }
  4743. }
  4744. /* called with netif_addr_lock_bh() */
  4745. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4746. {
  4747. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4748. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4749. if (!NO_FCOE(bp))
  4750. /* Configure rx_mode of FCoE Queue */
  4751. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4752. switch (bp->rx_mode) {
  4753. case BNX2X_RX_MODE_NONE:
  4754. /*
  4755. * 'drop all' supersedes any accept flags that may have been
  4756. * passed to the function.
  4757. */
  4758. break;
  4759. case BNX2X_RX_MODE_NORMAL:
  4760. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4761. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4762. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4763. /* internal switching mode */
  4764. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4765. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4766. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4767. break;
  4768. case BNX2X_RX_MODE_ALLMULTI:
  4769. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4770. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4771. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4772. /* internal switching mode */
  4773. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4774. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4775. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4776. break;
  4777. case BNX2X_RX_MODE_PROMISC:
  4778. /* According to deffinition of SI mode, iface in promisc mode
  4779. * should receive matched and unmatched (in resolution of port)
  4780. * unicast packets.
  4781. */
  4782. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4783. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4784. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4785. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4786. /* internal switching mode */
  4787. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4788. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4789. if (IS_MF_SI(bp))
  4790. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4791. else
  4792. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4793. break;
  4794. default:
  4795. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4796. return;
  4797. }
  4798. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4799. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4800. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4801. }
  4802. __set_bit(RAMROD_RX, &ramrod_flags);
  4803. __set_bit(RAMROD_TX, &ramrod_flags);
  4804. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4805. tx_accept_flags, ramrod_flags);
  4806. }
  4807. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4808. {
  4809. int i;
  4810. if (IS_MF_SI(bp))
  4811. /*
  4812. * In switch independent mode, the TSTORM needs to accept
  4813. * packets that failed classification, since approximate match
  4814. * mac addresses aren't written to NIG LLH
  4815. */
  4816. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4817. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4818. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4819. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4820. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4821. /* Zero this manually as its initialization is
  4822. currently missing in the initTool */
  4823. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4824. REG_WR(bp, BAR_USTRORM_INTMEM +
  4825. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4826. if (!CHIP_IS_E1x(bp)) {
  4827. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4828. CHIP_INT_MODE_IS_BC(bp) ?
  4829. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4830. }
  4831. }
  4832. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4833. {
  4834. switch (load_code) {
  4835. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4836. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4837. bnx2x_init_internal_common(bp);
  4838. /* no break */
  4839. case FW_MSG_CODE_DRV_LOAD_PORT:
  4840. /* nothing to do */
  4841. /* no break */
  4842. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4843. /* internal memory per function is
  4844. initialized inside bnx2x_pf_init */
  4845. break;
  4846. default:
  4847. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4848. break;
  4849. }
  4850. }
  4851. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4852. {
  4853. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4854. }
  4855. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4856. {
  4857. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4858. }
  4859. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4860. {
  4861. if (CHIP_IS_E1x(fp->bp))
  4862. return BP_L_ID(fp->bp) + fp->index;
  4863. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4864. return bnx2x_fp_igu_sb_id(fp);
  4865. }
  4866. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4867. {
  4868. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4869. u8 cos;
  4870. unsigned long q_type = 0;
  4871. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4872. fp->rx_queue = fp_idx;
  4873. fp->cid = fp_idx;
  4874. fp->cl_id = bnx2x_fp_cl_id(fp);
  4875. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4876. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4877. /* qZone id equals to FW (per path) client id */
  4878. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4879. /* init shortcut */
  4880. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4881. /* Setup SB indicies */
  4882. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4883. /* Configure Queue State object */
  4884. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4885. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4886. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4887. /* init tx data */
  4888. for_each_cos_in_tx_queue(fp, cos) {
  4889. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4890. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4891. FP_COS_TO_TXQ(fp, cos, bp),
  4892. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4893. cids[cos] = fp->txdata_ptr[cos]->cid;
  4894. }
  4895. /* nothing more for vf to do here */
  4896. if (IS_VF(bp))
  4897. return;
  4898. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4899. fp->fw_sb_id, fp->igu_sb_id);
  4900. bnx2x_update_fpsb_idx(fp);
  4901. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4902. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4903. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4904. /**
  4905. * Configure classification DBs: Always enable Tx switching
  4906. */
  4907. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4908. DP(NETIF_MSG_IFUP,
  4909. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4910. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4911. fp->igu_sb_id);
  4912. }
  4913. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4914. {
  4915. int i;
  4916. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4917. struct eth_tx_next_bd *tx_next_bd =
  4918. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4919. tx_next_bd->addr_hi =
  4920. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4921. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4922. tx_next_bd->addr_lo =
  4923. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4924. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4925. }
  4926. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4927. txdata->tx_db.data.zero_fill1 = 0;
  4928. txdata->tx_db.data.prod = 0;
  4929. txdata->tx_pkt_prod = 0;
  4930. txdata->tx_pkt_cons = 0;
  4931. txdata->tx_bd_prod = 0;
  4932. txdata->tx_bd_cons = 0;
  4933. txdata->tx_pkt = 0;
  4934. }
  4935. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  4936. {
  4937. int i;
  4938. for_each_tx_queue_cnic(bp, i)
  4939. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  4940. }
  4941. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4942. {
  4943. int i;
  4944. u8 cos;
  4945. for_each_eth_queue(bp, i)
  4946. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4947. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4948. }
  4949. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  4950. {
  4951. if (!NO_FCOE(bp))
  4952. bnx2x_init_fcoe_fp(bp);
  4953. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4954. BNX2X_VF_ID_INVALID, false,
  4955. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4956. /* ensure status block indices were read */
  4957. rmb();
  4958. bnx2x_init_rx_rings_cnic(bp);
  4959. bnx2x_init_tx_rings_cnic(bp);
  4960. /* flush all */
  4961. mb();
  4962. mmiowb();
  4963. }
  4964. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4965. {
  4966. int i;
  4967. for_each_eth_queue(bp, i)
  4968. bnx2x_init_eth_fp(bp, i);
  4969. /* ensure status block indices were read */
  4970. rmb();
  4971. bnx2x_init_rx_rings(bp);
  4972. bnx2x_init_tx_rings(bp);
  4973. if (IS_VF(bp))
  4974. return;
  4975. /* Initialize MOD_ABS interrupts */
  4976. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4977. bp->common.shmem_base, bp->common.shmem2_base,
  4978. BP_PORT(bp));
  4979. bnx2x_init_def_sb(bp);
  4980. bnx2x_update_dsb_idx(bp);
  4981. bnx2x_init_sp_ring(bp);
  4982. bnx2x_init_eq_ring(bp);
  4983. bnx2x_init_internal(bp, load_code);
  4984. bnx2x_pf_init(bp);
  4985. bnx2x_stats_init(bp);
  4986. /* flush all before enabling interrupts */
  4987. mb();
  4988. mmiowb();
  4989. bnx2x_int_enable(bp);
  4990. /* Check for SPIO5 */
  4991. bnx2x_attn_int_deasserted0(bp,
  4992. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4993. AEU_INPUTS_ATTN_BITS_SPIO5);
  4994. }
  4995. /* end of nic init */
  4996. /*
  4997. * gzip service functions
  4998. */
  4999. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5000. {
  5001. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5002. &bp->gunzip_mapping, GFP_KERNEL);
  5003. if (bp->gunzip_buf == NULL)
  5004. goto gunzip_nomem1;
  5005. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5006. if (bp->strm == NULL)
  5007. goto gunzip_nomem2;
  5008. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5009. if (bp->strm->workspace == NULL)
  5010. goto gunzip_nomem3;
  5011. return 0;
  5012. gunzip_nomem3:
  5013. kfree(bp->strm);
  5014. bp->strm = NULL;
  5015. gunzip_nomem2:
  5016. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5017. bp->gunzip_mapping);
  5018. bp->gunzip_buf = NULL;
  5019. gunzip_nomem1:
  5020. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5021. return -ENOMEM;
  5022. }
  5023. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5024. {
  5025. if (bp->strm) {
  5026. vfree(bp->strm->workspace);
  5027. kfree(bp->strm);
  5028. bp->strm = NULL;
  5029. }
  5030. if (bp->gunzip_buf) {
  5031. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5032. bp->gunzip_mapping);
  5033. bp->gunzip_buf = NULL;
  5034. }
  5035. }
  5036. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5037. {
  5038. int n, rc;
  5039. /* check gzip header */
  5040. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5041. BNX2X_ERR("Bad gzip header\n");
  5042. return -EINVAL;
  5043. }
  5044. n = 10;
  5045. #define FNAME 0x8
  5046. if (zbuf[3] & FNAME)
  5047. while ((zbuf[n++] != 0) && (n < len));
  5048. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5049. bp->strm->avail_in = len - n;
  5050. bp->strm->next_out = bp->gunzip_buf;
  5051. bp->strm->avail_out = FW_BUF_SIZE;
  5052. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5053. if (rc != Z_OK)
  5054. return rc;
  5055. rc = zlib_inflate(bp->strm, Z_FINISH);
  5056. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5057. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5058. bp->strm->msg);
  5059. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5060. if (bp->gunzip_outlen & 0x3)
  5061. netdev_err(bp->dev,
  5062. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5063. bp->gunzip_outlen);
  5064. bp->gunzip_outlen >>= 2;
  5065. zlib_inflateEnd(bp->strm);
  5066. if (rc == Z_STREAM_END)
  5067. return 0;
  5068. return rc;
  5069. }
  5070. /* nic load/unload */
  5071. /*
  5072. * General service functions
  5073. */
  5074. /* send a NIG loopback debug packet */
  5075. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5076. {
  5077. u32 wb_write[3];
  5078. /* Ethernet source and destination addresses */
  5079. wb_write[0] = 0x55555555;
  5080. wb_write[1] = 0x55555555;
  5081. wb_write[2] = 0x20; /* SOP */
  5082. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5083. /* NON-IP protocol */
  5084. wb_write[0] = 0x09000000;
  5085. wb_write[1] = 0x55555555;
  5086. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5087. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5088. }
  5089. /* some of the internal memories
  5090. * are not directly readable from the driver
  5091. * to test them we send debug packets
  5092. */
  5093. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5094. {
  5095. int factor;
  5096. int count, i;
  5097. u32 val = 0;
  5098. if (CHIP_REV_IS_FPGA(bp))
  5099. factor = 120;
  5100. else if (CHIP_REV_IS_EMUL(bp))
  5101. factor = 200;
  5102. else
  5103. factor = 1;
  5104. /* Disable inputs of parser neighbor blocks */
  5105. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5106. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5107. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5108. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5109. /* Write 0 to parser credits for CFC search request */
  5110. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5111. /* send Ethernet packet */
  5112. bnx2x_lb_pckt(bp);
  5113. /* TODO do i reset NIG statistic? */
  5114. /* Wait until NIG register shows 1 packet of size 0x10 */
  5115. count = 1000 * factor;
  5116. while (count) {
  5117. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5118. val = *bnx2x_sp(bp, wb_data[0]);
  5119. if (val == 0x10)
  5120. break;
  5121. msleep(10);
  5122. count--;
  5123. }
  5124. if (val != 0x10) {
  5125. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5126. return -1;
  5127. }
  5128. /* Wait until PRS register shows 1 packet */
  5129. count = 1000 * factor;
  5130. while (count) {
  5131. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5132. if (val == 1)
  5133. break;
  5134. msleep(10);
  5135. count--;
  5136. }
  5137. if (val != 0x1) {
  5138. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5139. return -2;
  5140. }
  5141. /* Reset and init BRB, PRS */
  5142. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5143. msleep(50);
  5144. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5145. msleep(50);
  5146. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5147. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5148. DP(NETIF_MSG_HW, "part2\n");
  5149. /* Disable inputs of parser neighbor blocks */
  5150. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5151. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5152. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5153. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5154. /* Write 0 to parser credits for CFC search request */
  5155. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5156. /* send 10 Ethernet packets */
  5157. for (i = 0; i < 10; i++)
  5158. bnx2x_lb_pckt(bp);
  5159. /* Wait until NIG register shows 10 + 1
  5160. packets of size 11*0x10 = 0xb0 */
  5161. count = 1000 * factor;
  5162. while (count) {
  5163. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5164. val = *bnx2x_sp(bp, wb_data[0]);
  5165. if (val == 0xb0)
  5166. break;
  5167. msleep(10);
  5168. count--;
  5169. }
  5170. if (val != 0xb0) {
  5171. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5172. return -3;
  5173. }
  5174. /* Wait until PRS register shows 2 packets */
  5175. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5176. if (val != 2)
  5177. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5178. /* Write 1 to parser credits for CFC search request */
  5179. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5180. /* Wait until PRS register shows 3 packets */
  5181. msleep(10 * factor);
  5182. /* Wait until NIG register shows 1 packet of size 0x10 */
  5183. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5184. if (val != 3)
  5185. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5186. /* clear NIG EOP FIFO */
  5187. for (i = 0; i < 11; i++)
  5188. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5189. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5190. if (val != 1) {
  5191. BNX2X_ERR("clear of NIG failed\n");
  5192. return -4;
  5193. }
  5194. /* Reset and init BRB, PRS, NIG */
  5195. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5196. msleep(50);
  5197. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5198. msleep(50);
  5199. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5200. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5201. if (!CNIC_SUPPORT(bp))
  5202. /* set NIC mode */
  5203. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5204. /* Enable inputs of parser neighbor blocks */
  5205. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5206. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5207. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5208. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5209. DP(NETIF_MSG_HW, "done\n");
  5210. return 0; /* OK */
  5211. }
  5212. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5213. {
  5214. u32 val;
  5215. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5216. if (!CHIP_IS_E1x(bp))
  5217. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5218. else
  5219. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5220. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5221. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5222. /*
  5223. * mask read length error interrupts in brb for parser
  5224. * (parsing unit and 'checksum and crc' unit)
  5225. * these errors are legal (PU reads fixed length and CAC can cause
  5226. * read length error on truncated packets)
  5227. */
  5228. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5229. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5230. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5231. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5232. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5233. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5234. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5235. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5236. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5237. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5238. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5239. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5240. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5241. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5242. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5243. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5244. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5245. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5246. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5247. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5248. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5249. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5250. if (!CHIP_IS_E1x(bp))
  5251. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5252. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5253. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5254. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5255. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5256. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5257. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5258. if (!CHIP_IS_E1x(bp))
  5259. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5260. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5261. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5262. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5263. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5264. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5265. }
  5266. static void bnx2x_reset_common(struct bnx2x *bp)
  5267. {
  5268. u32 val = 0x1400;
  5269. /* reset_common */
  5270. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5271. 0xd3ffff7f);
  5272. if (CHIP_IS_E3(bp)) {
  5273. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5274. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5275. }
  5276. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5277. }
  5278. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5279. {
  5280. bp->dmae_ready = 0;
  5281. spin_lock_init(&bp->dmae_lock);
  5282. }
  5283. static void bnx2x_init_pxp(struct bnx2x *bp)
  5284. {
  5285. u16 devctl;
  5286. int r_order, w_order;
  5287. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5288. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5289. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5290. if (bp->mrrs == -1)
  5291. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5292. else {
  5293. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5294. r_order = bp->mrrs;
  5295. }
  5296. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5297. }
  5298. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5299. {
  5300. int is_required;
  5301. u32 val;
  5302. int port;
  5303. if (BP_NOMCP(bp))
  5304. return;
  5305. is_required = 0;
  5306. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5307. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5308. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5309. is_required = 1;
  5310. /*
  5311. * The fan failure mechanism is usually related to the PHY type since
  5312. * the power consumption of the board is affected by the PHY. Currently,
  5313. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5314. */
  5315. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5316. for (port = PORT_0; port < PORT_MAX; port++) {
  5317. is_required |=
  5318. bnx2x_fan_failure_det_req(
  5319. bp,
  5320. bp->common.shmem_base,
  5321. bp->common.shmem2_base,
  5322. port);
  5323. }
  5324. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5325. if (is_required == 0)
  5326. return;
  5327. /* Fan failure is indicated by SPIO 5 */
  5328. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5329. /* set to active low mode */
  5330. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5331. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5332. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5333. /* enable interrupt to signal the IGU */
  5334. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5335. val |= MISC_SPIO_SPIO5;
  5336. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5337. }
  5338. void bnx2x_pf_disable(struct bnx2x *bp)
  5339. {
  5340. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5341. val &= ~IGU_PF_CONF_FUNC_EN;
  5342. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5343. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5344. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5345. }
  5346. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5347. {
  5348. u32 shmem_base[2], shmem2_base[2];
  5349. /* Avoid common init in case MFW supports LFA */
  5350. if (SHMEM2_RD(bp, size) >
  5351. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5352. return;
  5353. shmem_base[0] = bp->common.shmem_base;
  5354. shmem2_base[0] = bp->common.shmem2_base;
  5355. if (!CHIP_IS_E1x(bp)) {
  5356. shmem_base[1] =
  5357. SHMEM2_RD(bp, other_shmem_base_addr);
  5358. shmem2_base[1] =
  5359. SHMEM2_RD(bp, other_shmem2_base_addr);
  5360. }
  5361. bnx2x_acquire_phy_lock(bp);
  5362. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5363. bp->common.chip_id);
  5364. bnx2x_release_phy_lock(bp);
  5365. }
  5366. /**
  5367. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5368. *
  5369. * @bp: driver handle
  5370. */
  5371. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5372. {
  5373. u32 val;
  5374. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5375. /*
  5376. * take the UNDI lock to protect undi_unload flow from accessing
  5377. * registers while we're resetting the chip
  5378. */
  5379. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5380. bnx2x_reset_common(bp);
  5381. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5382. val = 0xfffc;
  5383. if (CHIP_IS_E3(bp)) {
  5384. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5385. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5386. }
  5387. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5388. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5389. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5390. if (!CHIP_IS_E1x(bp)) {
  5391. u8 abs_func_id;
  5392. /**
  5393. * 4-port mode or 2-port mode we need to turn of master-enable
  5394. * for everyone, after that, turn it back on for self.
  5395. * so, we disregard multi-function or not, and always disable
  5396. * for all functions on the given path, this means 0,2,4,6 for
  5397. * path 0 and 1,3,5,7 for path 1
  5398. */
  5399. for (abs_func_id = BP_PATH(bp);
  5400. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5401. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5402. REG_WR(bp,
  5403. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5404. 1);
  5405. continue;
  5406. }
  5407. bnx2x_pretend_func(bp, abs_func_id);
  5408. /* clear pf enable */
  5409. bnx2x_pf_disable(bp);
  5410. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5411. }
  5412. }
  5413. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5414. if (CHIP_IS_E1(bp)) {
  5415. /* enable HW interrupt from PXP on USDM overflow
  5416. bit 16 on INT_MASK_0 */
  5417. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5418. }
  5419. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5420. bnx2x_init_pxp(bp);
  5421. #ifdef __BIG_ENDIAN
  5422. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5423. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5424. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5425. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5426. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5427. /* make sure this value is 0 */
  5428. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5429. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5430. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5431. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5432. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5433. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5434. #endif
  5435. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5436. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5437. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5438. /* let the HW do it's magic ... */
  5439. msleep(100);
  5440. /* finish PXP init */
  5441. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5442. if (val != 1) {
  5443. BNX2X_ERR("PXP2 CFG failed\n");
  5444. return -EBUSY;
  5445. }
  5446. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5447. if (val != 1) {
  5448. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5449. return -EBUSY;
  5450. }
  5451. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5452. * have entries with value "0" and valid bit on.
  5453. * This needs to be done by the first PF that is loaded in a path
  5454. * (i.e. common phase)
  5455. */
  5456. if (!CHIP_IS_E1x(bp)) {
  5457. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5458. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5459. * This occurs when a different function (func2,3) is being marked
  5460. * as "scan-off". Real-life scenario for example: if a driver is being
  5461. * load-unloaded while func6,7 are down. This will cause the timer to access
  5462. * the ilt, translate to a logical address and send a request to read/write.
  5463. * Since the ilt for the function that is down is not valid, this will cause
  5464. * a translation error which is unrecoverable.
  5465. * The Workaround is intended to make sure that when this happens nothing fatal
  5466. * will occur. The workaround:
  5467. * 1. First PF driver which loads on a path will:
  5468. * a. After taking the chip out of reset, by using pretend,
  5469. * it will write "0" to the following registers of
  5470. * the other vnics.
  5471. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5472. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5473. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5474. * And for itself it will write '1' to
  5475. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5476. * dmae-operations (writing to pram for example.)
  5477. * note: can be done for only function 6,7 but cleaner this
  5478. * way.
  5479. * b. Write zero+valid to the entire ILT.
  5480. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5481. * VNIC3 (of that port). The range allocated will be the
  5482. * entire ILT. This is needed to prevent ILT range error.
  5483. * 2. Any PF driver load flow:
  5484. * a. ILT update with the physical addresses of the allocated
  5485. * logical pages.
  5486. * b. Wait 20msec. - note that this timeout is needed to make
  5487. * sure there are no requests in one of the PXP internal
  5488. * queues with "old" ILT addresses.
  5489. * c. PF enable in the PGLC.
  5490. * d. Clear the was_error of the PF in the PGLC. (could have
  5491. * occured while driver was down)
  5492. * e. PF enable in the CFC (WEAK + STRONG)
  5493. * f. Timers scan enable
  5494. * 3. PF driver unload flow:
  5495. * a. Clear the Timers scan_en.
  5496. * b. Polling for scan_on=0 for that PF.
  5497. * c. Clear the PF enable bit in the PXP.
  5498. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5499. * e. Write zero+valid to all ILT entries (The valid bit must
  5500. * stay set)
  5501. * f. If this is VNIC 3 of a port then also init
  5502. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5503. * to the last enrty in the ILT.
  5504. *
  5505. * Notes:
  5506. * Currently the PF error in the PGLC is non recoverable.
  5507. * In the future the there will be a recovery routine for this error.
  5508. * Currently attention is masked.
  5509. * Having an MCP lock on the load/unload process does not guarantee that
  5510. * there is no Timer disable during Func6/7 enable. This is because the
  5511. * Timers scan is currently being cleared by the MCP on FLR.
  5512. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5513. * there is error before clearing it. But the flow above is simpler and
  5514. * more general.
  5515. * All ILT entries are written by zero+valid and not just PF6/7
  5516. * ILT entries since in the future the ILT entries allocation for
  5517. * PF-s might be dynamic.
  5518. */
  5519. struct ilt_client_info ilt_cli;
  5520. struct bnx2x_ilt ilt;
  5521. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5522. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5523. /* initialize dummy TM client */
  5524. ilt_cli.start = 0;
  5525. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5526. ilt_cli.client_num = ILT_CLIENT_TM;
  5527. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5528. * Step 2: set the timers first/last ilt entry to point
  5529. * to the entire range to prevent ILT range error for 3rd/4th
  5530. * vnic (this code assumes existance of the vnic)
  5531. *
  5532. * both steps performed by call to bnx2x_ilt_client_init_op()
  5533. * with dummy TM client
  5534. *
  5535. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5536. * and his brother are split registers
  5537. */
  5538. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5539. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5540. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5541. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5542. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5543. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5544. }
  5545. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5546. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5547. if (!CHIP_IS_E1x(bp)) {
  5548. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5549. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5550. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5551. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5552. /* let the HW do it's magic ... */
  5553. do {
  5554. msleep(200);
  5555. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5556. } while (factor-- && (val != 1));
  5557. if (val != 1) {
  5558. BNX2X_ERR("ATC_INIT failed\n");
  5559. return -EBUSY;
  5560. }
  5561. }
  5562. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5563. bnx2x_iov_init_dmae(bp);
  5564. /* clean the DMAE memory */
  5565. bp->dmae_ready = 1;
  5566. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5567. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5568. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5569. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5570. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5571. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5572. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5573. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5574. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5575. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5576. /* QM queues pointers table */
  5577. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5578. /* soft reset pulse */
  5579. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5580. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5581. if (CNIC_SUPPORT(bp))
  5582. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5583. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5584. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5585. if (!CHIP_REV_IS_SLOW(bp))
  5586. /* enable hw interrupt from doorbell Q */
  5587. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5588. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5589. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5590. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5591. if (!CHIP_IS_E1(bp))
  5592. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5593. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5594. if (IS_MF_AFEX(bp)) {
  5595. /* configure that VNTag and VLAN headers must be
  5596. * received in afex mode
  5597. */
  5598. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5599. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5600. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5601. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5602. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5603. } else {
  5604. /* Bit-map indicating which L2 hdrs may appear
  5605. * after the basic Ethernet header
  5606. */
  5607. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5608. bp->path_has_ovlan ? 7 : 6);
  5609. }
  5610. }
  5611. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5612. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5613. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5614. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5615. if (!CHIP_IS_E1x(bp)) {
  5616. /* reset VFC memories */
  5617. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5618. VFC_MEMORIES_RST_REG_CAM_RST |
  5619. VFC_MEMORIES_RST_REG_RAM_RST);
  5620. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5621. VFC_MEMORIES_RST_REG_CAM_RST |
  5622. VFC_MEMORIES_RST_REG_RAM_RST);
  5623. msleep(20);
  5624. }
  5625. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5626. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5627. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5628. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5629. /* sync semi rtc */
  5630. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5631. 0x80000000);
  5632. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5633. 0x80000000);
  5634. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5635. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5636. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5637. if (!CHIP_IS_E1x(bp)) {
  5638. if (IS_MF_AFEX(bp)) {
  5639. /* configure that VNTag and VLAN headers must be
  5640. * sent in afex mode
  5641. */
  5642. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5643. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5644. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5645. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5646. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5647. } else {
  5648. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5649. bp->path_has_ovlan ? 7 : 6);
  5650. }
  5651. }
  5652. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5653. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5654. if (CNIC_SUPPORT(bp)) {
  5655. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5656. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5657. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5658. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5659. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5660. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5661. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5662. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5663. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5664. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5665. }
  5666. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5667. if (sizeof(union cdu_context) != 1024)
  5668. /* we currently assume that a context is 1024 bytes */
  5669. dev_alert(&bp->pdev->dev,
  5670. "please adjust the size of cdu_context(%ld)\n",
  5671. (long)sizeof(union cdu_context));
  5672. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5673. val = (4 << 24) + (0 << 12) + 1024;
  5674. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5675. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5676. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5677. /* enable context validation interrupt from CFC */
  5678. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5679. /* set the thresholds to prevent CFC/CDU race */
  5680. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5681. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5682. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5683. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5684. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5685. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5686. /* Reset PCIE errors for debug */
  5687. REG_WR(bp, 0x2814, 0xffffffff);
  5688. REG_WR(bp, 0x3820, 0xffffffff);
  5689. if (!CHIP_IS_E1x(bp)) {
  5690. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5691. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5692. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5693. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5694. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5695. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5696. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5697. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5698. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5699. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5700. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5701. }
  5702. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5703. if (!CHIP_IS_E1(bp)) {
  5704. /* in E3 this done in per-port section */
  5705. if (!CHIP_IS_E3(bp))
  5706. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5707. }
  5708. if (CHIP_IS_E1H(bp))
  5709. /* not applicable for E2 (and above ...) */
  5710. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5711. if (CHIP_REV_IS_SLOW(bp))
  5712. msleep(200);
  5713. /* finish CFC init */
  5714. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5715. if (val != 1) {
  5716. BNX2X_ERR("CFC LL_INIT failed\n");
  5717. return -EBUSY;
  5718. }
  5719. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5720. if (val != 1) {
  5721. BNX2X_ERR("CFC AC_INIT failed\n");
  5722. return -EBUSY;
  5723. }
  5724. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5725. if (val != 1) {
  5726. BNX2X_ERR("CFC CAM_INIT failed\n");
  5727. return -EBUSY;
  5728. }
  5729. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5730. if (CHIP_IS_E1(bp)) {
  5731. /* read NIG statistic
  5732. to see if this is our first up since powerup */
  5733. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5734. val = *bnx2x_sp(bp, wb_data[0]);
  5735. /* do internal memory self test */
  5736. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5737. BNX2X_ERR("internal mem self test failed\n");
  5738. return -EBUSY;
  5739. }
  5740. }
  5741. bnx2x_setup_fan_failure_detection(bp);
  5742. /* clear PXP2 attentions */
  5743. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5744. bnx2x_enable_blocks_attention(bp);
  5745. bnx2x_enable_blocks_parity(bp);
  5746. if (!BP_NOMCP(bp)) {
  5747. if (CHIP_IS_E1x(bp))
  5748. bnx2x__common_init_phy(bp);
  5749. } else
  5750. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5751. return 0;
  5752. }
  5753. /**
  5754. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5755. *
  5756. * @bp: driver handle
  5757. */
  5758. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5759. {
  5760. int rc = bnx2x_init_hw_common(bp);
  5761. if (rc)
  5762. return rc;
  5763. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5764. if (!BP_NOMCP(bp))
  5765. bnx2x__common_init_phy(bp);
  5766. return 0;
  5767. }
  5768. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5769. {
  5770. int port = BP_PORT(bp);
  5771. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5772. u32 low, high;
  5773. u32 val;
  5774. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5775. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5776. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5777. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5778. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5779. /* Timers bug workaround: disables the pf_master bit in pglue at
  5780. * common phase, we need to enable it here before any dmae access are
  5781. * attempted. Therefore we manually added the enable-master to the
  5782. * port phase (it also happens in the function phase)
  5783. */
  5784. if (!CHIP_IS_E1x(bp))
  5785. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5786. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5787. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5788. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5789. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5790. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5791. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5792. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5793. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5794. /* QM cid (connection) count */
  5795. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5796. if (CNIC_SUPPORT(bp)) {
  5797. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5798. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5799. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5800. }
  5801. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5802. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5803. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5804. if (IS_MF(bp))
  5805. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5806. else if (bp->dev->mtu > 4096) {
  5807. if (bp->flags & ONE_PORT_FLAG)
  5808. low = 160;
  5809. else {
  5810. val = bp->dev->mtu;
  5811. /* (24*1024 + val*4)/256 */
  5812. low = 96 + (val/64) +
  5813. ((val % 64) ? 1 : 0);
  5814. }
  5815. } else
  5816. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5817. high = low + 56; /* 14*1024/256 */
  5818. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5819. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5820. }
  5821. if (CHIP_MODE_IS_4_PORT(bp))
  5822. REG_WR(bp, (BP_PORT(bp) ?
  5823. BRB1_REG_MAC_GUARANTIED_1 :
  5824. BRB1_REG_MAC_GUARANTIED_0), 40);
  5825. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5826. if (CHIP_IS_E3B0(bp)) {
  5827. if (IS_MF_AFEX(bp)) {
  5828. /* configure headers for AFEX mode */
  5829. REG_WR(bp, BP_PORT(bp) ?
  5830. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5831. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5832. REG_WR(bp, BP_PORT(bp) ?
  5833. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5834. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5835. REG_WR(bp, BP_PORT(bp) ?
  5836. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5837. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5838. } else {
  5839. /* Ovlan exists only if we are in multi-function +
  5840. * switch-dependent mode, in switch-independent there
  5841. * is no ovlan headers
  5842. */
  5843. REG_WR(bp, BP_PORT(bp) ?
  5844. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5845. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5846. (bp->path_has_ovlan ? 7 : 6));
  5847. }
  5848. }
  5849. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5850. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5851. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5852. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5853. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5854. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5855. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5856. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5857. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5858. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5859. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5860. if (CHIP_IS_E1x(bp)) {
  5861. /* configure PBF to work without PAUSE mtu 9000 */
  5862. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5863. /* update threshold */
  5864. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5865. /* update init credit */
  5866. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5867. /* probe changes */
  5868. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5869. udelay(50);
  5870. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5871. }
  5872. if (CNIC_SUPPORT(bp))
  5873. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5874. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5875. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5876. if (CHIP_IS_E1(bp)) {
  5877. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5878. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5879. }
  5880. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5881. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5882. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5883. /* init aeu_mask_attn_func_0/1:
  5884. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5885. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5886. * bits 4-7 are used for "per vn group attention" */
  5887. val = IS_MF(bp) ? 0xF7 : 0x7;
  5888. /* Enable DCBX attention for all but E1 */
  5889. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5890. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5891. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5892. if (!CHIP_IS_E1x(bp)) {
  5893. /* Bit-map indicating which L2 hdrs may appear after the
  5894. * basic Ethernet header
  5895. */
  5896. if (IS_MF_AFEX(bp))
  5897. REG_WR(bp, BP_PORT(bp) ?
  5898. NIG_REG_P1_HDRS_AFTER_BASIC :
  5899. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5900. else
  5901. REG_WR(bp, BP_PORT(bp) ?
  5902. NIG_REG_P1_HDRS_AFTER_BASIC :
  5903. NIG_REG_P0_HDRS_AFTER_BASIC,
  5904. IS_MF_SD(bp) ? 7 : 6);
  5905. if (CHIP_IS_E3(bp))
  5906. REG_WR(bp, BP_PORT(bp) ?
  5907. NIG_REG_LLH1_MF_MODE :
  5908. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5909. }
  5910. if (!CHIP_IS_E3(bp))
  5911. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5912. if (!CHIP_IS_E1(bp)) {
  5913. /* 0x2 disable mf_ov, 0x1 enable */
  5914. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5915. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5916. if (!CHIP_IS_E1x(bp)) {
  5917. val = 0;
  5918. switch (bp->mf_mode) {
  5919. case MULTI_FUNCTION_SD:
  5920. val = 1;
  5921. break;
  5922. case MULTI_FUNCTION_SI:
  5923. case MULTI_FUNCTION_AFEX:
  5924. val = 2;
  5925. break;
  5926. }
  5927. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5928. NIG_REG_LLH0_CLS_TYPE), val);
  5929. }
  5930. {
  5931. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5932. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5933. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5934. }
  5935. }
  5936. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5937. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5938. if (val & MISC_SPIO_SPIO5) {
  5939. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5940. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5941. val = REG_RD(bp, reg_addr);
  5942. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5943. REG_WR(bp, reg_addr, val);
  5944. }
  5945. return 0;
  5946. }
  5947. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5948. {
  5949. int reg;
  5950. u32 wb_write[2];
  5951. if (CHIP_IS_E1(bp))
  5952. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5953. else
  5954. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5955. wb_write[0] = ONCHIP_ADDR1(addr);
  5956. wb_write[1] = ONCHIP_ADDR2(addr);
  5957. REG_WR_DMAE(bp, reg, wb_write, 2);
  5958. }
  5959. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  5960. {
  5961. u32 data, ctl, cnt = 100;
  5962. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5963. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  5964. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  5965. u32 sb_bit = 1 << (idu_sb_id%32);
  5966. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  5967. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  5968. /* Not supported in BC mode */
  5969. if (CHIP_INT_MODE_IS_BC(bp))
  5970. return;
  5971. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  5972. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  5973. IGU_REGULAR_CLEANUP_SET |
  5974. IGU_REGULAR_BCLEANUP;
  5975. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  5976. func_encode << IGU_CTRL_REG_FID_SHIFT |
  5977. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  5978. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5979. data, igu_addr_data);
  5980. REG_WR(bp, igu_addr_data, data);
  5981. mmiowb();
  5982. barrier();
  5983. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5984. ctl, igu_addr_ctl);
  5985. REG_WR(bp, igu_addr_ctl, ctl);
  5986. mmiowb();
  5987. barrier();
  5988. /* wait for clean up to finish */
  5989. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  5990. msleep(20);
  5991. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  5992. DP(NETIF_MSG_HW,
  5993. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  5994. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  5995. }
  5996. }
  5997. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5998. {
  5999. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6000. }
  6001. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6002. {
  6003. u32 i, base = FUNC_ILT_BASE(func);
  6004. for (i = base; i < base + ILT_PER_FUNC; i++)
  6005. bnx2x_ilt_wr(bp, i, 0);
  6006. }
  6007. static void bnx2x_init_searcher(struct bnx2x *bp)
  6008. {
  6009. int port = BP_PORT(bp);
  6010. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6011. /* T1 hash bits value determines the T1 number of entries */
  6012. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6013. }
  6014. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6015. {
  6016. int rc;
  6017. struct bnx2x_func_state_params func_params = {NULL};
  6018. struct bnx2x_func_switch_update_params *switch_update_params =
  6019. &func_params.params.switch_update;
  6020. /* Prepare parameters for function state transitions */
  6021. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6022. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6023. func_params.f_obj = &bp->func_obj;
  6024. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6025. /* Function parameters */
  6026. switch_update_params->suspend = suspend;
  6027. rc = bnx2x_func_state_change(bp, &func_params);
  6028. return rc;
  6029. }
  6030. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6031. {
  6032. int rc, i, port = BP_PORT(bp);
  6033. int vlan_en = 0, mac_en[NUM_MACS];
  6034. /* Close input from network */
  6035. if (bp->mf_mode == SINGLE_FUNCTION) {
  6036. bnx2x_set_rx_filter(&bp->link_params, 0);
  6037. } else {
  6038. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6039. NIG_REG_LLH0_FUNC_EN);
  6040. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6041. NIG_REG_LLH0_FUNC_EN, 0);
  6042. for (i = 0; i < NUM_MACS; i++) {
  6043. mac_en[i] = REG_RD(bp, port ?
  6044. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6045. 4 * i) :
  6046. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6047. 4 * i));
  6048. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6049. 4 * i) :
  6050. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6051. }
  6052. }
  6053. /* Close BMC to host */
  6054. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6055. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6056. /* Suspend Tx switching to the PF. Completion of this ramrod
  6057. * further guarantees that all the packets of that PF / child
  6058. * VFs in BRB were processed by the Parser, so it is safe to
  6059. * change the NIC_MODE register.
  6060. */
  6061. rc = bnx2x_func_switch_update(bp, 1);
  6062. if (rc) {
  6063. BNX2X_ERR("Can't suspend tx-switching!\n");
  6064. return rc;
  6065. }
  6066. /* Change NIC_MODE register */
  6067. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6068. /* Open input from network */
  6069. if (bp->mf_mode == SINGLE_FUNCTION) {
  6070. bnx2x_set_rx_filter(&bp->link_params, 1);
  6071. } else {
  6072. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6073. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6074. for (i = 0; i < NUM_MACS; i++) {
  6075. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6076. 4 * i) :
  6077. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6078. mac_en[i]);
  6079. }
  6080. }
  6081. /* Enable BMC to host */
  6082. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6083. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6084. /* Resume Tx switching to the PF */
  6085. rc = bnx2x_func_switch_update(bp, 0);
  6086. if (rc) {
  6087. BNX2X_ERR("Can't resume tx-switching!\n");
  6088. return rc;
  6089. }
  6090. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6091. return 0;
  6092. }
  6093. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6094. {
  6095. int rc;
  6096. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6097. if (CONFIGURE_NIC_MODE(bp)) {
  6098. /* Configrue searcher as part of function hw init */
  6099. bnx2x_init_searcher(bp);
  6100. /* Reset NIC mode */
  6101. rc = bnx2x_reset_nic_mode(bp);
  6102. if (rc)
  6103. BNX2X_ERR("Can't change NIC mode!\n");
  6104. return rc;
  6105. }
  6106. return 0;
  6107. }
  6108. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6109. {
  6110. int port = BP_PORT(bp);
  6111. int func = BP_FUNC(bp);
  6112. int init_phase = PHASE_PF0 + func;
  6113. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6114. u16 cdu_ilt_start;
  6115. u32 addr, val;
  6116. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6117. int i, main_mem_width, rc;
  6118. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6119. /* FLR cleanup - hmmm */
  6120. if (!CHIP_IS_E1x(bp)) {
  6121. rc = bnx2x_pf_flr_clnup(bp);
  6122. if (rc)
  6123. return rc;
  6124. }
  6125. /* set MSI reconfigure capability */
  6126. if (bp->common.int_block == INT_BLOCK_HC) {
  6127. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6128. val = REG_RD(bp, addr);
  6129. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6130. REG_WR(bp, addr, val);
  6131. }
  6132. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6133. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6134. ilt = BP_ILT(bp);
  6135. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6136. if (IS_SRIOV(bp))
  6137. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6138. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6139. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6140. * those of the VFs, so start line should be reset
  6141. */
  6142. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6143. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6144. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6145. ilt->lines[cdu_ilt_start + i].page_mapping =
  6146. bp->context[i].cxt_mapping;
  6147. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6148. }
  6149. bnx2x_ilt_init_op(bp, INITOP_SET);
  6150. if (!CONFIGURE_NIC_MODE(bp)) {
  6151. bnx2x_init_searcher(bp);
  6152. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6153. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6154. } else {
  6155. /* Set NIC mode */
  6156. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6157. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6158. }
  6159. if (!CHIP_IS_E1x(bp)) {
  6160. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6161. /* Turn on a single ISR mode in IGU if driver is going to use
  6162. * INT#x or MSI
  6163. */
  6164. if (!(bp->flags & USING_MSIX_FLAG))
  6165. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6166. /*
  6167. * Timers workaround bug: function init part.
  6168. * Need to wait 20msec after initializing ILT,
  6169. * needed to make sure there are no requests in
  6170. * one of the PXP internal queues with "old" ILT addresses
  6171. */
  6172. msleep(20);
  6173. /*
  6174. * Master enable - Due to WB DMAE writes performed before this
  6175. * register is re-initialized as part of the regular function
  6176. * init
  6177. */
  6178. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6179. /* Enable the function in IGU */
  6180. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6181. }
  6182. bp->dmae_ready = 1;
  6183. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6184. if (!CHIP_IS_E1x(bp))
  6185. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6186. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6187. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6188. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6189. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6190. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6191. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6192. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6193. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6194. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6195. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6196. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6197. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6198. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6199. if (!CHIP_IS_E1x(bp))
  6200. REG_WR(bp, QM_REG_PF_EN, 1);
  6201. if (!CHIP_IS_E1x(bp)) {
  6202. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6203. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6204. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6205. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6206. }
  6207. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6208. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6209. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6210. bnx2x_iov_init_dq(bp);
  6211. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6212. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6213. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6214. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6215. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6216. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6217. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6218. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6219. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6220. if (!CHIP_IS_E1x(bp))
  6221. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6222. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6223. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6224. if (!CHIP_IS_E1x(bp))
  6225. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6226. if (IS_MF(bp)) {
  6227. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6228. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6229. }
  6230. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6231. /* HC init per function */
  6232. if (bp->common.int_block == INT_BLOCK_HC) {
  6233. if (CHIP_IS_E1H(bp)) {
  6234. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6235. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6236. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6237. }
  6238. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6239. } else {
  6240. int num_segs, sb_idx, prod_offset;
  6241. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6242. if (!CHIP_IS_E1x(bp)) {
  6243. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6244. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6245. }
  6246. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6247. if (!CHIP_IS_E1x(bp)) {
  6248. int dsb_idx = 0;
  6249. /**
  6250. * Producer memory:
  6251. * E2 mode: address 0-135 match to the mapping memory;
  6252. * 136 - PF0 default prod; 137 - PF1 default prod;
  6253. * 138 - PF2 default prod; 139 - PF3 default prod;
  6254. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6255. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6256. * 144-147 reserved.
  6257. *
  6258. * E1.5 mode - In backward compatible mode;
  6259. * for non default SB; each even line in the memory
  6260. * holds the U producer and each odd line hold
  6261. * the C producer. The first 128 producers are for
  6262. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6263. * producers are for the DSB for each PF.
  6264. * Each PF has five segments: (the order inside each
  6265. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6266. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6267. * 144-147 attn prods;
  6268. */
  6269. /* non-default-status-blocks */
  6270. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6271. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6272. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6273. prod_offset = (bp->igu_base_sb + sb_idx) *
  6274. num_segs;
  6275. for (i = 0; i < num_segs; i++) {
  6276. addr = IGU_REG_PROD_CONS_MEMORY +
  6277. (prod_offset + i) * 4;
  6278. REG_WR(bp, addr, 0);
  6279. }
  6280. /* send consumer update with value 0 */
  6281. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6282. USTORM_ID, 0, IGU_INT_NOP, 1);
  6283. bnx2x_igu_clear_sb(bp,
  6284. bp->igu_base_sb + sb_idx);
  6285. }
  6286. /* default-status-blocks */
  6287. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6288. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6289. if (CHIP_MODE_IS_4_PORT(bp))
  6290. dsb_idx = BP_FUNC(bp);
  6291. else
  6292. dsb_idx = BP_VN(bp);
  6293. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6294. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6295. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6296. /*
  6297. * igu prods come in chunks of E1HVN_MAX (4) -
  6298. * does not matters what is the current chip mode
  6299. */
  6300. for (i = 0; i < (num_segs * E1HVN_MAX);
  6301. i += E1HVN_MAX) {
  6302. addr = IGU_REG_PROD_CONS_MEMORY +
  6303. (prod_offset + i)*4;
  6304. REG_WR(bp, addr, 0);
  6305. }
  6306. /* send consumer update with 0 */
  6307. if (CHIP_INT_MODE_IS_BC(bp)) {
  6308. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6309. USTORM_ID, 0, IGU_INT_NOP, 1);
  6310. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6311. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6312. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6313. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6314. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6315. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6316. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6317. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6318. } else {
  6319. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6320. USTORM_ID, 0, IGU_INT_NOP, 1);
  6321. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6322. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6323. }
  6324. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6325. /* !!! these should become driver const once
  6326. rf-tool supports split-68 const */
  6327. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6328. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6329. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6330. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6331. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6332. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6333. }
  6334. }
  6335. /* Reset PCIE errors for debug */
  6336. REG_WR(bp, 0x2114, 0xffffffff);
  6337. REG_WR(bp, 0x2120, 0xffffffff);
  6338. if (CHIP_IS_E1x(bp)) {
  6339. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6340. main_mem_base = HC_REG_MAIN_MEMORY +
  6341. BP_PORT(bp) * (main_mem_size * 4);
  6342. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6343. main_mem_width = 8;
  6344. val = REG_RD(bp, main_mem_prty_clr);
  6345. if (val)
  6346. DP(NETIF_MSG_HW,
  6347. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6348. val);
  6349. /* Clear "false" parity errors in MSI-X table */
  6350. for (i = main_mem_base;
  6351. i < main_mem_base + main_mem_size * 4;
  6352. i += main_mem_width) {
  6353. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6354. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6355. i, main_mem_width / 4);
  6356. }
  6357. /* Clear HC parity attention */
  6358. REG_RD(bp, main_mem_prty_clr);
  6359. }
  6360. #ifdef BNX2X_STOP_ON_ERROR
  6361. /* Enable STORMs SP logging */
  6362. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6363. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6364. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6365. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6366. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6367. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6368. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6369. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6370. #endif
  6371. bnx2x_phy_probe(&bp->link_params);
  6372. return 0;
  6373. }
  6374. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6375. {
  6376. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6377. if (!CHIP_IS_E1x(bp))
  6378. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6379. sizeof(struct host_hc_status_block_e2));
  6380. else
  6381. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6382. sizeof(struct host_hc_status_block_e1x));
  6383. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6384. }
  6385. void bnx2x_free_mem(struct bnx2x *bp)
  6386. {
  6387. int i;
  6388. /* fastpath */
  6389. bnx2x_free_fp_mem(bp);
  6390. /* end of fastpath */
  6391. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6392. sizeof(struct host_sp_status_block));
  6393. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6394. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6395. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6396. sizeof(struct bnx2x_slowpath));
  6397. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6398. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6399. bp->context[i].size);
  6400. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6401. BNX2X_FREE(bp->ilt->lines);
  6402. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6403. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6404. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6405. }
  6406. static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  6407. {
  6408. int num_groups;
  6409. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  6410. /* number of queues for statistics is number of eth queues + FCoE */
  6411. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  6412. /* Total number of FW statistics requests =
  6413. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  6414. * num of queues
  6415. */
  6416. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  6417. /* Request is built from stats_query_header and an array of
  6418. * stats_query_cmd_group each of which contains
  6419. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  6420. * configured in the stats_query_header.
  6421. */
  6422. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  6423. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  6424. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  6425. num_groups * sizeof(struct stats_query_cmd_group);
  6426. /* Data for statistics requests + stats_conter
  6427. *
  6428. * stats_counter holds per-STORM counters that are incremented
  6429. * when STORM has finished with the current request.
  6430. *
  6431. * memory for FCoE offloaded statistics are counted anyway,
  6432. * even if they will not be sent.
  6433. */
  6434. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  6435. sizeof(struct per_pf_stats) +
  6436. sizeof(struct fcoe_statistics_params) +
  6437. sizeof(struct per_queue_stats) * num_queue_stats +
  6438. sizeof(struct stats_counter);
  6439. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  6440. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6441. /* Set shortcuts */
  6442. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  6443. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  6444. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  6445. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  6446. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  6447. bp->fw_stats_req_sz;
  6448. return 0;
  6449. alloc_mem_err:
  6450. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6451. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6452. BNX2X_ERR("Can't allocate memory\n");
  6453. return -ENOMEM;
  6454. }
  6455. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6456. {
  6457. if (!CHIP_IS_E1x(bp))
  6458. /* size = the status block + ramrod buffers */
  6459. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6460. sizeof(struct host_hc_status_block_e2));
  6461. else
  6462. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6463. &bp->cnic_sb_mapping,
  6464. sizeof(struct
  6465. host_hc_status_block_e1x));
  6466. if (CONFIGURE_NIC_MODE(bp))
  6467. /* allocate searcher T2 table, as it wan't allocated before */
  6468. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6469. /* write address to which L5 should insert its values */
  6470. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6471. &bp->slowpath->drv_info_to_mcp;
  6472. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6473. goto alloc_mem_err;
  6474. return 0;
  6475. alloc_mem_err:
  6476. bnx2x_free_mem_cnic(bp);
  6477. BNX2X_ERR("Can't allocate memory\n");
  6478. return -ENOMEM;
  6479. }
  6480. int bnx2x_alloc_mem(struct bnx2x *bp)
  6481. {
  6482. int i, allocated, context_size;
  6483. if (!CONFIGURE_NIC_MODE(bp))
  6484. /* allocate searcher T2 table */
  6485. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6486. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6487. sizeof(struct host_sp_status_block));
  6488. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6489. sizeof(struct bnx2x_slowpath));
  6490. /* Allocated memory for FW statistics */
  6491. if (bnx2x_alloc_fw_stats_mem(bp))
  6492. goto alloc_mem_err;
  6493. /* Allocate memory for CDU context:
  6494. * This memory is allocated separately and not in the generic ILT
  6495. * functions because CDU differs in few aspects:
  6496. * 1. There are multiple entities allocating memory for context -
  6497. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6498. * its own ILT lines.
  6499. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6500. * for the other ILT clients), to be efficient we want to support
  6501. * allocation of sub-page-size in the last entry.
  6502. * 3. Context pointers are used by the driver to pass to FW / update
  6503. * the context (for the other ILT clients the pointers are used just to
  6504. * free the memory during unload).
  6505. */
  6506. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6507. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6508. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6509. (context_size - allocated));
  6510. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6511. &bp->context[i].cxt_mapping,
  6512. bp->context[i].size);
  6513. allocated += bp->context[i].size;
  6514. }
  6515. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6516. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6517. goto alloc_mem_err;
  6518. /* Slow path ring */
  6519. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6520. /* EQ */
  6521. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6522. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6523. /* fastpath */
  6524. /* need to be done at the end, since it's self adjusting to amount
  6525. * of memory available for RSS queues
  6526. */
  6527. if (bnx2x_alloc_fp_mem(bp))
  6528. goto alloc_mem_err;
  6529. return 0;
  6530. alloc_mem_err:
  6531. bnx2x_free_mem(bp);
  6532. BNX2X_ERR("Can't allocate memory\n");
  6533. return -ENOMEM;
  6534. }
  6535. /*
  6536. * Init service functions
  6537. */
  6538. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6539. struct bnx2x_vlan_mac_obj *obj, bool set,
  6540. int mac_type, unsigned long *ramrod_flags)
  6541. {
  6542. int rc;
  6543. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6544. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6545. /* Fill general parameters */
  6546. ramrod_param.vlan_mac_obj = obj;
  6547. ramrod_param.ramrod_flags = *ramrod_flags;
  6548. /* Fill a user request section if needed */
  6549. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6550. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6551. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6552. /* Set the command: ADD or DEL */
  6553. if (set)
  6554. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6555. else
  6556. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6557. }
  6558. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6559. if (rc == -EEXIST) {
  6560. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6561. /* do not treat adding same MAC as error */
  6562. rc = 0;
  6563. } else if (rc < 0)
  6564. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6565. return rc;
  6566. }
  6567. int bnx2x_del_all_macs(struct bnx2x *bp,
  6568. struct bnx2x_vlan_mac_obj *mac_obj,
  6569. int mac_type, bool wait_for_comp)
  6570. {
  6571. int rc;
  6572. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6573. /* Wait for completion of requested */
  6574. if (wait_for_comp)
  6575. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6576. /* Set the mac type of addresses we want to clear */
  6577. __set_bit(mac_type, &vlan_mac_flags);
  6578. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6579. if (rc < 0)
  6580. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6581. return rc;
  6582. }
  6583. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6584. {
  6585. unsigned long ramrod_flags = 0;
  6586. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6587. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6588. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6589. "Ignoring Zero MAC for STORAGE SD mode\n");
  6590. return 0;
  6591. }
  6592. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6593. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6594. /* Eth MAC is set on RSS leading client (fp[0]) */
  6595. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6596. set, BNX2X_ETH_MAC, &ramrod_flags);
  6597. }
  6598. int bnx2x_setup_leading(struct bnx2x *bp)
  6599. {
  6600. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6601. }
  6602. /**
  6603. * bnx2x_set_int_mode - configure interrupt mode
  6604. *
  6605. * @bp: driver handle
  6606. *
  6607. * In case of MSI-X it will also try to enable MSI-X.
  6608. */
  6609. int bnx2x_set_int_mode(struct bnx2x *bp)
  6610. {
  6611. int rc = 0;
  6612. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6613. return -EINVAL;
  6614. switch (int_mode) {
  6615. case BNX2X_INT_MODE_MSIX:
  6616. /* attempt to enable msix */
  6617. rc = bnx2x_enable_msix(bp);
  6618. /* msix attained */
  6619. if (!rc)
  6620. return 0;
  6621. /* vfs use only msix */
  6622. if (rc && IS_VF(bp))
  6623. return rc;
  6624. /* failed to enable multiple MSI-X */
  6625. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6626. bp->num_queues,
  6627. 1 + bp->num_cnic_queues);
  6628. /* falling through... */
  6629. case BNX2X_INT_MODE_MSI:
  6630. bnx2x_enable_msi(bp);
  6631. /* falling through... */
  6632. case BNX2X_INT_MODE_INTX:
  6633. bp->num_ethernet_queues = 1;
  6634. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6635. BNX2X_DEV_INFO("set number of queues to 1\n");
  6636. break;
  6637. default:
  6638. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6639. return -EINVAL;
  6640. }
  6641. return 0;
  6642. }
  6643. /* must be called prior to any HW initializations */
  6644. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6645. {
  6646. if (IS_SRIOV(bp))
  6647. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6648. return L2_ILT_LINES(bp);
  6649. }
  6650. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6651. {
  6652. struct ilt_client_info *ilt_client;
  6653. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6654. u16 line = 0;
  6655. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6656. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6657. /* CDU */
  6658. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6659. ilt_client->client_num = ILT_CLIENT_CDU;
  6660. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6661. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6662. ilt_client->start = line;
  6663. line += bnx2x_cid_ilt_lines(bp);
  6664. if (CNIC_SUPPORT(bp))
  6665. line += CNIC_ILT_LINES;
  6666. ilt_client->end = line - 1;
  6667. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6668. ilt_client->start,
  6669. ilt_client->end,
  6670. ilt_client->page_size,
  6671. ilt_client->flags,
  6672. ilog2(ilt_client->page_size >> 12));
  6673. /* QM */
  6674. if (QM_INIT(bp->qm_cid_count)) {
  6675. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6676. ilt_client->client_num = ILT_CLIENT_QM;
  6677. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6678. ilt_client->flags = 0;
  6679. ilt_client->start = line;
  6680. /* 4 bytes for each cid */
  6681. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6682. QM_ILT_PAGE_SZ);
  6683. ilt_client->end = line - 1;
  6684. DP(NETIF_MSG_IFUP,
  6685. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6686. ilt_client->start,
  6687. ilt_client->end,
  6688. ilt_client->page_size,
  6689. ilt_client->flags,
  6690. ilog2(ilt_client->page_size >> 12));
  6691. }
  6692. if (CNIC_SUPPORT(bp)) {
  6693. /* SRC */
  6694. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6695. ilt_client->client_num = ILT_CLIENT_SRC;
  6696. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6697. ilt_client->flags = 0;
  6698. ilt_client->start = line;
  6699. line += SRC_ILT_LINES;
  6700. ilt_client->end = line - 1;
  6701. DP(NETIF_MSG_IFUP,
  6702. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6703. ilt_client->start,
  6704. ilt_client->end,
  6705. ilt_client->page_size,
  6706. ilt_client->flags,
  6707. ilog2(ilt_client->page_size >> 12));
  6708. /* TM */
  6709. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6710. ilt_client->client_num = ILT_CLIENT_TM;
  6711. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6712. ilt_client->flags = 0;
  6713. ilt_client->start = line;
  6714. line += TM_ILT_LINES;
  6715. ilt_client->end = line - 1;
  6716. DP(NETIF_MSG_IFUP,
  6717. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6718. ilt_client->start,
  6719. ilt_client->end,
  6720. ilt_client->page_size,
  6721. ilt_client->flags,
  6722. ilog2(ilt_client->page_size >> 12));
  6723. }
  6724. BUG_ON(line > ILT_MAX_LINES);
  6725. }
  6726. /**
  6727. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6728. *
  6729. * @bp: driver handle
  6730. * @fp: pointer to fastpath
  6731. * @init_params: pointer to parameters structure
  6732. *
  6733. * parameters configured:
  6734. * - HC configuration
  6735. * - Queue's CDU context
  6736. */
  6737. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6738. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6739. {
  6740. u8 cos;
  6741. int cxt_index, cxt_offset;
  6742. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6743. if (!IS_FCOE_FP(fp)) {
  6744. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6745. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6746. /* If HC is supporterd, enable host coalescing in the transition
  6747. * to INIT state.
  6748. */
  6749. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6750. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6751. /* HC rate */
  6752. init_params->rx.hc_rate = bp->rx_ticks ?
  6753. (1000000 / bp->rx_ticks) : 0;
  6754. init_params->tx.hc_rate = bp->tx_ticks ?
  6755. (1000000 / bp->tx_ticks) : 0;
  6756. /* FW SB ID */
  6757. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6758. fp->fw_sb_id;
  6759. /*
  6760. * CQ index among the SB indices: FCoE clients uses the default
  6761. * SB, therefore it's different.
  6762. */
  6763. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6764. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6765. }
  6766. /* set maximum number of COSs supported by this queue */
  6767. init_params->max_cos = fp->max_cos;
  6768. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6769. fp->index, init_params->max_cos);
  6770. /* set the context pointers queue object */
  6771. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6772. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6773. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6774. ILT_PAGE_CIDS);
  6775. init_params->cxts[cos] =
  6776. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6777. }
  6778. }
  6779. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6780. struct bnx2x_queue_state_params *q_params,
  6781. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6782. int tx_index, bool leading)
  6783. {
  6784. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6785. /* Set the command */
  6786. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6787. /* Set tx-only QUEUE flags: don't zero statistics */
  6788. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6789. /* choose the index of the cid to send the slow path on */
  6790. tx_only_params->cid_index = tx_index;
  6791. /* Set general TX_ONLY_SETUP parameters */
  6792. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6793. /* Set Tx TX_ONLY_SETUP parameters */
  6794. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6795. DP(NETIF_MSG_IFUP,
  6796. "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",
  6797. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6798. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6799. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6800. /* send the ramrod */
  6801. return bnx2x_queue_state_change(bp, q_params);
  6802. }
  6803. /**
  6804. * bnx2x_setup_queue - setup queue
  6805. *
  6806. * @bp: driver handle
  6807. * @fp: pointer to fastpath
  6808. * @leading: is leading
  6809. *
  6810. * This function performs 2 steps in a Queue state machine
  6811. * actually: 1) RESET->INIT 2) INIT->SETUP
  6812. */
  6813. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6814. bool leading)
  6815. {
  6816. struct bnx2x_queue_state_params q_params = {NULL};
  6817. struct bnx2x_queue_setup_params *setup_params =
  6818. &q_params.params.setup;
  6819. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6820. &q_params.params.tx_only;
  6821. int rc;
  6822. u8 tx_index;
  6823. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6824. /* reset IGU state skip FCoE L2 queue */
  6825. if (!IS_FCOE_FP(fp))
  6826. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6827. IGU_INT_ENABLE, 0);
  6828. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6829. /* We want to wait for completion in this context */
  6830. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6831. /* Prepare the INIT parameters */
  6832. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6833. /* Set the command */
  6834. q_params.cmd = BNX2X_Q_CMD_INIT;
  6835. /* Change the state to INIT */
  6836. rc = bnx2x_queue_state_change(bp, &q_params);
  6837. if (rc) {
  6838. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6839. return rc;
  6840. }
  6841. DP(NETIF_MSG_IFUP, "init complete\n");
  6842. /* Now move the Queue to the SETUP state... */
  6843. memset(setup_params, 0, sizeof(*setup_params));
  6844. /* Set QUEUE flags */
  6845. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6846. /* Set general SETUP parameters */
  6847. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6848. FIRST_TX_COS_INDEX);
  6849. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6850. &setup_params->rxq_params);
  6851. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6852. FIRST_TX_COS_INDEX);
  6853. /* Set the command */
  6854. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6855. if (IS_FCOE_FP(fp))
  6856. bp->fcoe_init = true;
  6857. /* Change the state to SETUP */
  6858. rc = bnx2x_queue_state_change(bp, &q_params);
  6859. if (rc) {
  6860. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6861. return rc;
  6862. }
  6863. /* loop through the relevant tx-only indices */
  6864. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6865. tx_index < fp->max_cos;
  6866. tx_index++) {
  6867. /* prepare and send tx-only ramrod*/
  6868. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6869. tx_only_params, tx_index, leading);
  6870. if (rc) {
  6871. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6872. fp->index, tx_index);
  6873. return rc;
  6874. }
  6875. }
  6876. return rc;
  6877. }
  6878. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6879. {
  6880. struct bnx2x_fastpath *fp = &bp->fp[index];
  6881. struct bnx2x_fp_txdata *txdata;
  6882. struct bnx2x_queue_state_params q_params = {NULL};
  6883. int rc, tx_index;
  6884. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6885. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6886. /* We want to wait for completion in this context */
  6887. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6888. /* close tx-only connections */
  6889. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6890. tx_index < fp->max_cos;
  6891. tx_index++){
  6892. /* ascertain this is a normal queue*/
  6893. txdata = fp->txdata_ptr[tx_index];
  6894. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6895. txdata->txq_index);
  6896. /* send halt terminate on tx-only connection */
  6897. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6898. memset(&q_params.params.terminate, 0,
  6899. sizeof(q_params.params.terminate));
  6900. q_params.params.terminate.cid_index = tx_index;
  6901. rc = bnx2x_queue_state_change(bp, &q_params);
  6902. if (rc)
  6903. return rc;
  6904. /* send halt terminate on tx-only connection */
  6905. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6906. memset(&q_params.params.cfc_del, 0,
  6907. sizeof(q_params.params.cfc_del));
  6908. q_params.params.cfc_del.cid_index = tx_index;
  6909. rc = bnx2x_queue_state_change(bp, &q_params);
  6910. if (rc)
  6911. return rc;
  6912. }
  6913. /* Stop the primary connection: */
  6914. /* ...halt the connection */
  6915. q_params.cmd = BNX2X_Q_CMD_HALT;
  6916. rc = bnx2x_queue_state_change(bp, &q_params);
  6917. if (rc)
  6918. return rc;
  6919. /* ...terminate the connection */
  6920. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6921. memset(&q_params.params.terminate, 0,
  6922. sizeof(q_params.params.terminate));
  6923. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6924. rc = bnx2x_queue_state_change(bp, &q_params);
  6925. if (rc)
  6926. return rc;
  6927. /* ...delete cfc entry */
  6928. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6929. memset(&q_params.params.cfc_del, 0,
  6930. sizeof(q_params.params.cfc_del));
  6931. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6932. return bnx2x_queue_state_change(bp, &q_params);
  6933. }
  6934. static void bnx2x_reset_func(struct bnx2x *bp)
  6935. {
  6936. int port = BP_PORT(bp);
  6937. int func = BP_FUNC(bp);
  6938. int i;
  6939. /* Disable the function in the FW */
  6940. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6941. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6942. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6943. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6944. /* FP SBs */
  6945. for_each_eth_queue(bp, i) {
  6946. struct bnx2x_fastpath *fp = &bp->fp[i];
  6947. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6948. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6949. SB_DISABLED);
  6950. }
  6951. if (CNIC_LOADED(bp))
  6952. /* CNIC SB */
  6953. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6954. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6955. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6956. /* SP SB */
  6957. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6958. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6959. SB_DISABLED);
  6960. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6961. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6962. 0);
  6963. /* Configure IGU */
  6964. if (bp->common.int_block == INT_BLOCK_HC) {
  6965. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6966. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6967. } else {
  6968. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6969. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6970. }
  6971. if (CNIC_LOADED(bp)) {
  6972. /* Disable Timer scan */
  6973. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6974. /*
  6975. * Wait for at least 10ms and up to 2 second for the timers
  6976. * scan to complete
  6977. */
  6978. for (i = 0; i < 200; i++) {
  6979. msleep(10);
  6980. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6981. break;
  6982. }
  6983. }
  6984. /* Clear ILT */
  6985. bnx2x_clear_func_ilt(bp, func);
  6986. /* Timers workaround bug for E2: if this is vnic-3,
  6987. * we need to set the entire ilt range for this timers.
  6988. */
  6989. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6990. struct ilt_client_info ilt_cli;
  6991. /* use dummy TM client */
  6992. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6993. ilt_cli.start = 0;
  6994. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6995. ilt_cli.client_num = ILT_CLIENT_TM;
  6996. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6997. }
  6998. /* this assumes that reset_port() called before reset_func()*/
  6999. if (!CHIP_IS_E1x(bp))
  7000. bnx2x_pf_disable(bp);
  7001. bp->dmae_ready = 0;
  7002. }
  7003. static void bnx2x_reset_port(struct bnx2x *bp)
  7004. {
  7005. int port = BP_PORT(bp);
  7006. u32 val;
  7007. /* Reset physical Link */
  7008. bnx2x__link_reset(bp);
  7009. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7010. /* Do not rcv packets to BRB */
  7011. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7012. /* Do not direct rcv packets that are not for MCP to the BRB */
  7013. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7014. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7015. /* Configure AEU */
  7016. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7017. msleep(100);
  7018. /* Check for BRB port occupancy */
  7019. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7020. if (val)
  7021. DP(NETIF_MSG_IFDOWN,
  7022. "BRB1 is not empty %d blocks are occupied\n", val);
  7023. /* TODO: Close Doorbell port? */
  7024. }
  7025. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7026. {
  7027. struct bnx2x_func_state_params func_params = {NULL};
  7028. /* Prepare parameters for function state transitions */
  7029. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7030. func_params.f_obj = &bp->func_obj;
  7031. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7032. func_params.params.hw_init.load_phase = load_code;
  7033. return bnx2x_func_state_change(bp, &func_params);
  7034. }
  7035. static int bnx2x_func_stop(struct bnx2x *bp)
  7036. {
  7037. struct bnx2x_func_state_params func_params = {NULL};
  7038. int rc;
  7039. /* Prepare parameters for function state transitions */
  7040. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7041. func_params.f_obj = &bp->func_obj;
  7042. func_params.cmd = BNX2X_F_CMD_STOP;
  7043. /*
  7044. * Try to stop the function the 'good way'. If fails (in case
  7045. * of a parity error during bnx2x_chip_cleanup()) and we are
  7046. * not in a debug mode, perform a state transaction in order to
  7047. * enable further HW_RESET transaction.
  7048. */
  7049. rc = bnx2x_func_state_change(bp, &func_params);
  7050. if (rc) {
  7051. #ifdef BNX2X_STOP_ON_ERROR
  7052. return rc;
  7053. #else
  7054. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7055. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7056. return bnx2x_func_state_change(bp, &func_params);
  7057. #endif
  7058. }
  7059. return 0;
  7060. }
  7061. /**
  7062. * bnx2x_send_unload_req - request unload mode from the MCP.
  7063. *
  7064. * @bp: driver handle
  7065. * @unload_mode: requested function's unload mode
  7066. *
  7067. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7068. */
  7069. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7070. {
  7071. u32 reset_code = 0;
  7072. int port = BP_PORT(bp);
  7073. /* Select the UNLOAD request mode */
  7074. if (unload_mode == UNLOAD_NORMAL)
  7075. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7076. else if (bp->flags & NO_WOL_FLAG)
  7077. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7078. else if (bp->wol) {
  7079. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7080. u8 *mac_addr = bp->dev->dev_addr;
  7081. u32 val;
  7082. u16 pmc;
  7083. /* The mac address is written to entries 1-4 to
  7084. * preserve entry 0 which is used by the PMF
  7085. */
  7086. u8 entry = (BP_VN(bp) + 1)*8;
  7087. val = (mac_addr[0] << 8) | mac_addr[1];
  7088. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7089. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7090. (mac_addr[4] << 8) | mac_addr[5];
  7091. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7092. /* Enable the PME and clear the status */
  7093. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7094. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7095. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7096. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7097. } else
  7098. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7099. /* Send the request to the MCP */
  7100. if (!BP_NOMCP(bp))
  7101. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7102. else {
  7103. int path = BP_PATH(bp);
  7104. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7105. path, load_count[path][0], load_count[path][1],
  7106. load_count[path][2]);
  7107. load_count[path][0]--;
  7108. load_count[path][1 + port]--;
  7109. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7110. path, load_count[path][0], load_count[path][1],
  7111. load_count[path][2]);
  7112. if (load_count[path][0] == 0)
  7113. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7114. else if (load_count[path][1 + port] == 0)
  7115. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7116. else
  7117. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7118. }
  7119. return reset_code;
  7120. }
  7121. /**
  7122. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7123. *
  7124. * @bp: driver handle
  7125. * @keep_link: true iff link should be kept up
  7126. */
  7127. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7128. {
  7129. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7130. /* Report UNLOAD_DONE to MCP */
  7131. if (!BP_NOMCP(bp))
  7132. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7133. }
  7134. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7135. {
  7136. int tout = 50;
  7137. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7138. if (!bp->port.pmf)
  7139. return 0;
  7140. /*
  7141. * (assumption: No Attention from MCP at this stage)
  7142. * PMF probably in the middle of TXdisable/enable transaction
  7143. * 1. Sync IRS for default SB
  7144. * 2. Sync SP queue - this guarantes us that attention handling started
  7145. * 3. Wait, that TXdisable/enable transaction completes
  7146. *
  7147. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7148. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7149. * received complettion for the transaction the state is TX_STOPPED.
  7150. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7151. * transaction.
  7152. */
  7153. /* make sure default SB ISR is done */
  7154. if (msix)
  7155. synchronize_irq(bp->msix_table[0].vector);
  7156. else
  7157. synchronize_irq(bp->pdev->irq);
  7158. flush_workqueue(bnx2x_wq);
  7159. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7160. BNX2X_F_STATE_STARTED && tout--)
  7161. msleep(20);
  7162. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7163. BNX2X_F_STATE_STARTED) {
  7164. #ifdef BNX2X_STOP_ON_ERROR
  7165. BNX2X_ERR("Wrong function state\n");
  7166. return -EBUSY;
  7167. #else
  7168. /*
  7169. * Failed to complete the transaction in a "good way"
  7170. * Force both transactions with CLR bit
  7171. */
  7172. struct bnx2x_func_state_params func_params = {NULL};
  7173. DP(NETIF_MSG_IFDOWN,
  7174. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7175. func_params.f_obj = &bp->func_obj;
  7176. __set_bit(RAMROD_DRV_CLR_ONLY,
  7177. &func_params.ramrod_flags);
  7178. /* STARTED-->TX_ST0PPED */
  7179. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7180. bnx2x_func_state_change(bp, &func_params);
  7181. /* TX_ST0PPED-->STARTED */
  7182. func_params.cmd = BNX2X_F_CMD_TX_START;
  7183. return bnx2x_func_state_change(bp, &func_params);
  7184. #endif
  7185. }
  7186. return 0;
  7187. }
  7188. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7189. {
  7190. int port = BP_PORT(bp);
  7191. int i, rc = 0;
  7192. u8 cos;
  7193. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7194. u32 reset_code;
  7195. /* Wait until tx fastpath tasks complete */
  7196. for_each_tx_queue(bp, i) {
  7197. struct bnx2x_fastpath *fp = &bp->fp[i];
  7198. for_each_cos_in_tx_queue(fp, cos)
  7199. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7200. #ifdef BNX2X_STOP_ON_ERROR
  7201. if (rc)
  7202. return;
  7203. #endif
  7204. }
  7205. /* Give HW time to discard old tx messages */
  7206. usleep_range(1000, 1000);
  7207. /* Clean all ETH MACs */
  7208. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7209. false);
  7210. if (rc < 0)
  7211. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7212. /* Clean up UC list */
  7213. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7214. true);
  7215. if (rc < 0)
  7216. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7217. rc);
  7218. /* Disable LLH */
  7219. if (!CHIP_IS_E1(bp))
  7220. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7221. /* Set "drop all" (stop Rx).
  7222. * We need to take a netif_addr_lock() here in order to prevent
  7223. * a race between the completion code and this code.
  7224. */
  7225. netif_addr_lock_bh(bp->dev);
  7226. /* Schedule the rx_mode command */
  7227. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7228. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7229. else
  7230. bnx2x_set_storm_rx_mode(bp);
  7231. /* Cleanup multicast configuration */
  7232. rparam.mcast_obj = &bp->mcast_obj;
  7233. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7234. if (rc < 0)
  7235. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7236. netif_addr_unlock_bh(bp->dev);
  7237. /*
  7238. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7239. * this function should perform FUNC, PORT or COMMON HW
  7240. * reset.
  7241. */
  7242. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7243. /*
  7244. * (assumption: No Attention from MCP at this stage)
  7245. * PMF probably in the middle of TXdisable/enable transaction
  7246. */
  7247. rc = bnx2x_func_wait_started(bp);
  7248. if (rc) {
  7249. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7250. #ifdef BNX2X_STOP_ON_ERROR
  7251. return;
  7252. #endif
  7253. }
  7254. /* Close multi and leading connections
  7255. * Completions for ramrods are collected in a synchronous way
  7256. */
  7257. for_each_eth_queue(bp, i)
  7258. if (bnx2x_stop_queue(bp, i))
  7259. #ifdef BNX2X_STOP_ON_ERROR
  7260. return;
  7261. #else
  7262. goto unload_error;
  7263. #endif
  7264. if (CNIC_LOADED(bp)) {
  7265. for_each_cnic_queue(bp, i)
  7266. if (bnx2x_stop_queue(bp, i))
  7267. #ifdef BNX2X_STOP_ON_ERROR
  7268. return;
  7269. #else
  7270. goto unload_error;
  7271. #endif
  7272. }
  7273. /* If SP settings didn't get completed so far - something
  7274. * very wrong has happen.
  7275. */
  7276. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7277. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7278. #ifndef BNX2X_STOP_ON_ERROR
  7279. unload_error:
  7280. #endif
  7281. rc = bnx2x_func_stop(bp);
  7282. if (rc) {
  7283. BNX2X_ERR("Function stop failed!\n");
  7284. #ifdef BNX2X_STOP_ON_ERROR
  7285. return;
  7286. #endif
  7287. }
  7288. /* Disable HW interrupts, NAPI */
  7289. bnx2x_netif_stop(bp, 1);
  7290. /* Delete all NAPI objects */
  7291. bnx2x_del_all_napi(bp);
  7292. if (CNIC_LOADED(bp))
  7293. bnx2x_del_all_napi_cnic(bp);
  7294. /* Release IRQs */
  7295. bnx2x_free_irq(bp);
  7296. /* Reset the chip */
  7297. rc = bnx2x_reset_hw(bp, reset_code);
  7298. if (rc)
  7299. BNX2X_ERR("HW_RESET failed\n");
  7300. /* Report UNLOAD_DONE to MCP */
  7301. bnx2x_send_unload_done(bp, keep_link);
  7302. }
  7303. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7304. {
  7305. u32 val;
  7306. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7307. if (CHIP_IS_E1(bp)) {
  7308. int port = BP_PORT(bp);
  7309. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7310. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7311. val = REG_RD(bp, addr);
  7312. val &= ~(0x300);
  7313. REG_WR(bp, addr, val);
  7314. } else {
  7315. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7316. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7317. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7318. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7319. }
  7320. }
  7321. /* Close gates #2, #3 and #4: */
  7322. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7323. {
  7324. u32 val;
  7325. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7326. if (!CHIP_IS_E1(bp)) {
  7327. /* #4 */
  7328. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7329. /* #2 */
  7330. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7331. }
  7332. /* #3 */
  7333. if (CHIP_IS_E1x(bp)) {
  7334. /* Prevent interrupts from HC on both ports */
  7335. val = REG_RD(bp, HC_REG_CONFIG_1);
  7336. REG_WR(bp, HC_REG_CONFIG_1,
  7337. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7338. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7339. val = REG_RD(bp, HC_REG_CONFIG_0);
  7340. REG_WR(bp, HC_REG_CONFIG_0,
  7341. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7342. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7343. } else {
  7344. /* Prevent incomming interrupts in IGU */
  7345. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7346. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7347. (!close) ?
  7348. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7349. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7350. }
  7351. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7352. close ? "closing" : "opening");
  7353. mmiowb();
  7354. }
  7355. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7356. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7357. {
  7358. /* Do some magic... */
  7359. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7360. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7361. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7362. }
  7363. /**
  7364. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7365. *
  7366. * @bp: driver handle
  7367. * @magic_val: old value of the `magic' bit.
  7368. */
  7369. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7370. {
  7371. /* Restore the `magic' bit value... */
  7372. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7373. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7374. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7375. }
  7376. /**
  7377. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7378. *
  7379. * @bp: driver handle
  7380. * @magic_val: old value of 'magic' bit.
  7381. *
  7382. * Takes care of CLP configurations.
  7383. */
  7384. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7385. {
  7386. u32 shmem;
  7387. u32 validity_offset;
  7388. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7389. /* Set `magic' bit in order to save MF config */
  7390. if (!CHIP_IS_E1(bp))
  7391. bnx2x_clp_reset_prep(bp, magic_val);
  7392. /* Get shmem offset */
  7393. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7394. validity_offset =
  7395. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7396. /* Clear validity map flags */
  7397. if (shmem > 0)
  7398. REG_WR(bp, shmem + validity_offset, 0);
  7399. }
  7400. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7401. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7402. /**
  7403. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7404. *
  7405. * @bp: driver handle
  7406. */
  7407. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7408. {
  7409. /* special handling for emulation and FPGA,
  7410. wait 10 times longer */
  7411. if (CHIP_REV_IS_SLOW(bp))
  7412. msleep(MCP_ONE_TIMEOUT*10);
  7413. else
  7414. msleep(MCP_ONE_TIMEOUT);
  7415. }
  7416. /*
  7417. * initializes bp->common.shmem_base and waits for validity signature to appear
  7418. */
  7419. static int bnx2x_init_shmem(struct bnx2x *bp)
  7420. {
  7421. int cnt = 0;
  7422. u32 val = 0;
  7423. do {
  7424. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7425. if (bp->common.shmem_base) {
  7426. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7427. if (val & SHR_MEM_VALIDITY_MB)
  7428. return 0;
  7429. }
  7430. bnx2x_mcp_wait_one(bp);
  7431. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7432. BNX2X_ERR("BAD MCP validity signature\n");
  7433. return -ENODEV;
  7434. }
  7435. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7436. {
  7437. int rc = bnx2x_init_shmem(bp);
  7438. /* Restore the `magic' bit value */
  7439. if (!CHIP_IS_E1(bp))
  7440. bnx2x_clp_reset_done(bp, magic_val);
  7441. return rc;
  7442. }
  7443. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7444. {
  7445. if (!CHIP_IS_E1(bp)) {
  7446. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7447. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7448. mmiowb();
  7449. }
  7450. }
  7451. /*
  7452. * Reset the whole chip except for:
  7453. * - PCIE core
  7454. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7455. * one reset bit)
  7456. * - IGU
  7457. * - MISC (including AEU)
  7458. * - GRC
  7459. * - RBCN, RBCP
  7460. */
  7461. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7462. {
  7463. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7464. u32 global_bits2, stay_reset2;
  7465. /*
  7466. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7467. * (per chip) blocks.
  7468. */
  7469. global_bits2 =
  7470. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7471. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7472. /* Don't reset the following blocks.
  7473. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7474. * reset, as in 4 port device they might still be owned
  7475. * by the MCP (there is only one leader per path).
  7476. */
  7477. not_reset_mask1 =
  7478. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7479. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7480. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7481. not_reset_mask2 =
  7482. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7483. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7484. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7485. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7486. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7487. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7488. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7489. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7490. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7491. MISC_REGISTERS_RESET_REG_2_PGLC |
  7492. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7493. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7494. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7495. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7496. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7497. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7498. /*
  7499. * Keep the following blocks in reset:
  7500. * - all xxMACs are handled by the bnx2x_link code.
  7501. */
  7502. stay_reset2 =
  7503. MISC_REGISTERS_RESET_REG_2_XMAC |
  7504. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7505. /* Full reset masks according to the chip */
  7506. reset_mask1 = 0xffffffff;
  7507. if (CHIP_IS_E1(bp))
  7508. reset_mask2 = 0xffff;
  7509. else if (CHIP_IS_E1H(bp))
  7510. reset_mask2 = 0x1ffff;
  7511. else if (CHIP_IS_E2(bp))
  7512. reset_mask2 = 0xfffff;
  7513. else /* CHIP_IS_E3 */
  7514. reset_mask2 = 0x3ffffff;
  7515. /* Don't reset global blocks unless we need to */
  7516. if (!global)
  7517. reset_mask2 &= ~global_bits2;
  7518. /*
  7519. * In case of attention in the QM, we need to reset PXP
  7520. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7521. * because otherwise QM reset would release 'close the gates' shortly
  7522. * before resetting the PXP, then the PSWRQ would send a write
  7523. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7524. * read the payload data from PSWWR, but PSWWR would not
  7525. * respond. The write queue in PGLUE would stuck, dmae commands
  7526. * would not return. Therefore it's important to reset the second
  7527. * reset register (containing the
  7528. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7529. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7530. * bit).
  7531. */
  7532. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7533. reset_mask2 & (~not_reset_mask2));
  7534. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7535. reset_mask1 & (~not_reset_mask1));
  7536. barrier();
  7537. mmiowb();
  7538. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7539. reset_mask2 & (~stay_reset2));
  7540. barrier();
  7541. mmiowb();
  7542. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7543. mmiowb();
  7544. }
  7545. /**
  7546. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7547. * It should get cleared in no more than 1s.
  7548. *
  7549. * @bp: driver handle
  7550. *
  7551. * It should get cleared in no more than 1s. Returns 0 if
  7552. * pending writes bit gets cleared.
  7553. */
  7554. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7555. {
  7556. u32 cnt = 1000;
  7557. u32 pend_bits = 0;
  7558. do {
  7559. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7560. if (pend_bits == 0)
  7561. break;
  7562. usleep_range(1000, 1000);
  7563. } while (cnt-- > 0);
  7564. if (cnt <= 0) {
  7565. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7566. pend_bits);
  7567. return -EBUSY;
  7568. }
  7569. return 0;
  7570. }
  7571. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7572. {
  7573. int cnt = 1000;
  7574. u32 val = 0;
  7575. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7576. u32 tags_63_32 = 0;
  7577. /* Empty the Tetris buffer, wait for 1s */
  7578. do {
  7579. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7580. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7581. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7582. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7583. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7584. if (CHIP_IS_E3(bp))
  7585. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7586. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7587. ((port_is_idle_0 & 0x1) == 0x1) &&
  7588. ((port_is_idle_1 & 0x1) == 0x1) &&
  7589. (pgl_exp_rom2 == 0xffffffff) &&
  7590. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7591. break;
  7592. usleep_range(1000, 1000);
  7593. } while (cnt-- > 0);
  7594. if (cnt <= 0) {
  7595. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7596. 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",
  7597. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7598. pgl_exp_rom2);
  7599. return -EAGAIN;
  7600. }
  7601. barrier();
  7602. /* Close gates #2, #3 and #4 */
  7603. bnx2x_set_234_gates(bp, true);
  7604. /* Poll for IGU VQs for 57712 and newer chips */
  7605. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7606. return -EAGAIN;
  7607. /* TBD: Indicate that "process kill" is in progress to MCP */
  7608. /* Clear "unprepared" bit */
  7609. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7610. barrier();
  7611. /* Make sure all is written to the chip before the reset */
  7612. mmiowb();
  7613. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7614. * PSWHST, GRC and PSWRD Tetris buffer.
  7615. */
  7616. usleep_range(1000, 1000);
  7617. /* Prepare to chip reset: */
  7618. /* MCP */
  7619. if (global)
  7620. bnx2x_reset_mcp_prep(bp, &val);
  7621. /* PXP */
  7622. bnx2x_pxp_prep(bp);
  7623. barrier();
  7624. /* reset the chip */
  7625. bnx2x_process_kill_chip_reset(bp, global);
  7626. barrier();
  7627. /* Recover after reset: */
  7628. /* MCP */
  7629. if (global && bnx2x_reset_mcp_comp(bp, val))
  7630. return -EAGAIN;
  7631. /* TBD: Add resetting the NO_MCP mode DB here */
  7632. /* Open the gates #2, #3 and #4 */
  7633. bnx2x_set_234_gates(bp, false);
  7634. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7635. * reset state, re-enable attentions. */
  7636. return 0;
  7637. }
  7638. static int bnx2x_leader_reset(struct bnx2x *bp)
  7639. {
  7640. int rc = 0;
  7641. bool global = bnx2x_reset_is_global(bp);
  7642. u32 load_code;
  7643. /* if not going to reset MCP - load "fake" driver to reset HW while
  7644. * driver is owner of the HW
  7645. */
  7646. if (!global && !BP_NOMCP(bp)) {
  7647. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7648. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7649. if (!load_code) {
  7650. BNX2X_ERR("MCP response failure, aborting\n");
  7651. rc = -EAGAIN;
  7652. goto exit_leader_reset;
  7653. }
  7654. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7655. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7656. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7657. rc = -EAGAIN;
  7658. goto exit_leader_reset2;
  7659. }
  7660. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7661. if (!load_code) {
  7662. BNX2X_ERR("MCP response failure, aborting\n");
  7663. rc = -EAGAIN;
  7664. goto exit_leader_reset2;
  7665. }
  7666. }
  7667. /* Try to recover after the failure */
  7668. if (bnx2x_process_kill(bp, global)) {
  7669. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7670. BP_PATH(bp));
  7671. rc = -EAGAIN;
  7672. goto exit_leader_reset2;
  7673. }
  7674. /*
  7675. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7676. * state.
  7677. */
  7678. bnx2x_set_reset_done(bp);
  7679. if (global)
  7680. bnx2x_clear_reset_global(bp);
  7681. exit_leader_reset2:
  7682. /* unload "fake driver" if it was loaded */
  7683. if (!global && !BP_NOMCP(bp)) {
  7684. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7685. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7686. }
  7687. exit_leader_reset:
  7688. bp->is_leader = 0;
  7689. bnx2x_release_leader_lock(bp);
  7690. smp_mb();
  7691. return rc;
  7692. }
  7693. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7694. {
  7695. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7696. /* Disconnect this device */
  7697. netif_device_detach(bp->dev);
  7698. /*
  7699. * Block ifup for all function on this engine until "process kill"
  7700. * or power cycle.
  7701. */
  7702. bnx2x_set_reset_in_progress(bp);
  7703. /* Shut down the power */
  7704. bnx2x_set_power_state(bp, PCI_D3hot);
  7705. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7706. smp_mb();
  7707. }
  7708. /*
  7709. * Assumption: runs under rtnl lock. This together with the fact
  7710. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7711. * will never be called when netif_running(bp->dev) is false.
  7712. */
  7713. static void bnx2x_parity_recover(struct bnx2x *bp)
  7714. {
  7715. bool global = false;
  7716. u32 error_recovered, error_unrecovered;
  7717. bool is_parity;
  7718. DP(NETIF_MSG_HW, "Handling parity\n");
  7719. while (1) {
  7720. switch (bp->recovery_state) {
  7721. case BNX2X_RECOVERY_INIT:
  7722. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7723. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7724. WARN_ON(!is_parity);
  7725. /* Try to get a LEADER_LOCK HW lock */
  7726. if (bnx2x_trylock_leader_lock(bp)) {
  7727. bnx2x_set_reset_in_progress(bp);
  7728. /*
  7729. * Check if there is a global attention and if
  7730. * there was a global attention, set the global
  7731. * reset bit.
  7732. */
  7733. if (global)
  7734. bnx2x_set_reset_global(bp);
  7735. bp->is_leader = 1;
  7736. }
  7737. /* Stop the driver */
  7738. /* If interface has been removed - break */
  7739. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7740. return;
  7741. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7742. /* Ensure "is_leader", MCP command sequence and
  7743. * "recovery_state" update values are seen on other
  7744. * CPUs.
  7745. */
  7746. smp_mb();
  7747. break;
  7748. case BNX2X_RECOVERY_WAIT:
  7749. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7750. if (bp->is_leader) {
  7751. int other_engine = BP_PATH(bp) ? 0 : 1;
  7752. bool other_load_status =
  7753. bnx2x_get_load_status(bp, other_engine);
  7754. bool load_status =
  7755. bnx2x_get_load_status(bp, BP_PATH(bp));
  7756. global = bnx2x_reset_is_global(bp);
  7757. /*
  7758. * In case of a parity in a global block, let
  7759. * the first leader that performs a
  7760. * leader_reset() reset the global blocks in
  7761. * order to clear global attentions. Otherwise
  7762. * the the gates will remain closed for that
  7763. * engine.
  7764. */
  7765. if (load_status ||
  7766. (global && other_load_status)) {
  7767. /* Wait until all other functions get
  7768. * down.
  7769. */
  7770. schedule_delayed_work(&bp->sp_rtnl_task,
  7771. HZ/10);
  7772. return;
  7773. } else {
  7774. /* If all other functions got down -
  7775. * try to bring the chip back to
  7776. * normal. In any case it's an exit
  7777. * point for a leader.
  7778. */
  7779. if (bnx2x_leader_reset(bp)) {
  7780. bnx2x_recovery_failed(bp);
  7781. return;
  7782. }
  7783. /* If we are here, means that the
  7784. * leader has succeeded and doesn't
  7785. * want to be a leader any more. Try
  7786. * to continue as a none-leader.
  7787. */
  7788. break;
  7789. }
  7790. } else { /* non-leader */
  7791. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7792. /* Try to get a LEADER_LOCK HW lock as
  7793. * long as a former leader may have
  7794. * been unloaded by the user or
  7795. * released a leadership by another
  7796. * reason.
  7797. */
  7798. if (bnx2x_trylock_leader_lock(bp)) {
  7799. /* I'm a leader now! Restart a
  7800. * switch case.
  7801. */
  7802. bp->is_leader = 1;
  7803. break;
  7804. }
  7805. schedule_delayed_work(&bp->sp_rtnl_task,
  7806. HZ/10);
  7807. return;
  7808. } else {
  7809. /*
  7810. * If there was a global attention, wait
  7811. * for it to be cleared.
  7812. */
  7813. if (bnx2x_reset_is_global(bp)) {
  7814. schedule_delayed_work(
  7815. &bp->sp_rtnl_task,
  7816. HZ/10);
  7817. return;
  7818. }
  7819. error_recovered =
  7820. bp->eth_stats.recoverable_error;
  7821. error_unrecovered =
  7822. bp->eth_stats.unrecoverable_error;
  7823. bp->recovery_state =
  7824. BNX2X_RECOVERY_NIC_LOADING;
  7825. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7826. error_unrecovered++;
  7827. netdev_err(bp->dev,
  7828. "Recovery failed. Power cycle needed\n");
  7829. /* Disconnect this device */
  7830. netif_device_detach(bp->dev);
  7831. /* Shut down the power */
  7832. bnx2x_set_power_state(
  7833. bp, PCI_D3hot);
  7834. smp_mb();
  7835. } else {
  7836. bp->recovery_state =
  7837. BNX2X_RECOVERY_DONE;
  7838. error_recovered++;
  7839. smp_mb();
  7840. }
  7841. bp->eth_stats.recoverable_error =
  7842. error_recovered;
  7843. bp->eth_stats.unrecoverable_error =
  7844. error_unrecovered;
  7845. return;
  7846. }
  7847. }
  7848. default:
  7849. return;
  7850. }
  7851. }
  7852. }
  7853. static int bnx2x_close(struct net_device *dev);
  7854. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7855. * scheduled on a general queue in order to prevent a dead lock.
  7856. */
  7857. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7858. {
  7859. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7860. rtnl_lock();
  7861. if (!netif_running(bp->dev))
  7862. goto sp_rtnl_exit;
  7863. /* if stop on error is defined no recovery flows should be executed */
  7864. #ifdef BNX2X_STOP_ON_ERROR
  7865. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7866. "you will need to reboot when done\n");
  7867. goto sp_rtnl_not_reset;
  7868. #endif
  7869. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7870. /*
  7871. * Clear all pending SP commands as we are going to reset the
  7872. * function anyway.
  7873. */
  7874. bp->sp_rtnl_state = 0;
  7875. smp_mb();
  7876. bnx2x_parity_recover(bp);
  7877. goto sp_rtnl_exit;
  7878. }
  7879. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7880. /*
  7881. * Clear all pending SP commands as we are going to reset the
  7882. * function anyway.
  7883. */
  7884. bp->sp_rtnl_state = 0;
  7885. smp_mb();
  7886. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7887. bnx2x_nic_load(bp, LOAD_NORMAL);
  7888. goto sp_rtnl_exit;
  7889. }
  7890. #ifdef BNX2X_STOP_ON_ERROR
  7891. sp_rtnl_not_reset:
  7892. #endif
  7893. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7894. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7895. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7896. bnx2x_after_function_update(bp);
  7897. /*
  7898. * in case of fan failure we need to reset id if the "stop on error"
  7899. * debug flag is set, since we trying to prevent permanent overheating
  7900. * damage
  7901. */
  7902. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7903. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7904. netif_device_detach(bp->dev);
  7905. bnx2x_close(bp->dev);
  7906. }
  7907. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7908. DP(BNX2X_MSG_SP,
  7909. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7910. bnx2x_vfpf_set_mcast(bp->dev);
  7911. }
  7912. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7913. &bp->sp_rtnl_state)) {
  7914. DP(BNX2X_MSG_SP,
  7915. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7916. bnx2x_vfpf_storm_rx_mode(bp);
  7917. }
  7918. sp_rtnl_exit:
  7919. rtnl_unlock();
  7920. }
  7921. /* end of nic load/unload */
  7922. static void bnx2x_period_task(struct work_struct *work)
  7923. {
  7924. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7925. if (!netif_running(bp->dev))
  7926. goto period_task_exit;
  7927. if (CHIP_REV_IS_SLOW(bp)) {
  7928. BNX2X_ERR("period task called on emulation, ignoring\n");
  7929. goto period_task_exit;
  7930. }
  7931. bnx2x_acquire_phy_lock(bp);
  7932. /*
  7933. * The barrier is needed to ensure the ordering between the writing to
  7934. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7935. * the reading here.
  7936. */
  7937. smp_mb();
  7938. if (bp->port.pmf) {
  7939. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7940. /* Re-queue task in 1 sec */
  7941. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7942. }
  7943. bnx2x_release_phy_lock(bp);
  7944. period_task_exit:
  7945. return;
  7946. }
  7947. /*
  7948. * Init service functions
  7949. */
  7950. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7951. {
  7952. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7953. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7954. return base + (BP_ABS_FUNC(bp)) * stride;
  7955. }
  7956. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7957. {
  7958. u32 reg = bnx2x_get_pretend_reg(bp);
  7959. /* Flush all outstanding writes */
  7960. mmiowb();
  7961. /* Pretend to be function 0 */
  7962. REG_WR(bp, reg, 0);
  7963. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7964. /* From now we are in the "like-E1" mode */
  7965. bnx2x_int_disable(bp);
  7966. /* Flush all outstanding writes */
  7967. mmiowb();
  7968. /* Restore the original function */
  7969. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7970. REG_RD(bp, reg);
  7971. }
  7972. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7973. {
  7974. if (CHIP_IS_E1(bp))
  7975. bnx2x_int_disable(bp);
  7976. else
  7977. bnx2x_undi_int_disable_e1h(bp);
  7978. }
  7979. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp)
  7980. {
  7981. u32 val, base_addr, offset, mask, reset_reg;
  7982. bool mac_stopped = false;
  7983. u8 port = BP_PORT(bp);
  7984. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7985. if (!CHIP_IS_E3(bp)) {
  7986. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7987. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7988. if ((mask & reset_reg) && val) {
  7989. u32 wb_data[2];
  7990. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7991. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7992. : NIG_REG_INGRESS_BMAC0_MEM;
  7993. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7994. : BIGMAC_REGISTER_BMAC_CONTROL;
  7995. /*
  7996. * use rd/wr since we cannot use dmae. This is safe
  7997. * since MCP won't access the bus due to the request
  7998. * to unload, and no function on the path can be
  7999. * loaded at this time.
  8000. */
  8001. wb_data[0] = REG_RD(bp, base_addr + offset);
  8002. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8003. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8004. REG_WR(bp, base_addr + offset, wb_data[0]);
  8005. REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
  8006. }
  8007. BNX2X_DEV_INFO("Disable emac Rx\n");
  8008. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
  8009. mac_stopped = true;
  8010. } else {
  8011. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8012. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8013. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8014. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8015. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8016. val & ~(1 << 1));
  8017. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8018. val | (1 << 1));
  8019. REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
  8020. mac_stopped = true;
  8021. }
  8022. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8023. if (mask & reset_reg) {
  8024. BNX2X_DEV_INFO("Disable umac Rx\n");
  8025. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8026. REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
  8027. mac_stopped = true;
  8028. }
  8029. }
  8030. if (mac_stopped)
  8031. msleep(20);
  8032. }
  8033. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8034. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8035. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8036. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8037. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8038. {
  8039. u16 rcq, bd;
  8040. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8041. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8042. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8043. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8044. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8045. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8046. port, bd, rcq);
  8047. }
  8048. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8049. {
  8050. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8051. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8052. if (!rc) {
  8053. BNX2X_ERR("MCP response failure, aborting\n");
  8054. return -EBUSY;
  8055. }
  8056. return 0;
  8057. }
  8058. static struct bnx2x_prev_path_list *
  8059. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8060. {
  8061. struct bnx2x_prev_path_list *tmp_list;
  8062. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8063. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8064. bp->pdev->bus->number == tmp_list->bus &&
  8065. BP_PATH(bp) == tmp_list->path)
  8066. return tmp_list;
  8067. return NULL;
  8068. }
  8069. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8070. {
  8071. struct bnx2x_prev_path_list *tmp_list;
  8072. int rc = false;
  8073. if (down_trylock(&bnx2x_prev_sem))
  8074. return false;
  8075. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  8076. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8077. bp->pdev->bus->number == tmp_list->bus &&
  8078. BP_PATH(bp) == tmp_list->path) {
  8079. rc = true;
  8080. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8081. BP_PATH(bp));
  8082. break;
  8083. }
  8084. }
  8085. up(&bnx2x_prev_sem);
  8086. return rc;
  8087. }
  8088. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8089. {
  8090. struct bnx2x_prev_path_list *tmp_list;
  8091. int rc;
  8092. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8093. if (!tmp_list) {
  8094. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8095. return -ENOMEM;
  8096. }
  8097. tmp_list->bus = bp->pdev->bus->number;
  8098. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8099. tmp_list->path = BP_PATH(bp);
  8100. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8101. rc = down_interruptible(&bnx2x_prev_sem);
  8102. if (rc) {
  8103. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8104. kfree(tmp_list);
  8105. } else {
  8106. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  8107. BP_PATH(bp));
  8108. list_add(&tmp_list->list, &bnx2x_prev_list);
  8109. up(&bnx2x_prev_sem);
  8110. }
  8111. return rc;
  8112. }
  8113. static int bnx2x_do_flr(struct bnx2x *bp)
  8114. {
  8115. int i;
  8116. u16 status;
  8117. struct pci_dev *dev = bp->pdev;
  8118. if (CHIP_IS_E1x(bp)) {
  8119. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8120. return -EINVAL;
  8121. }
  8122. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8123. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8124. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8125. bp->common.bc_ver);
  8126. return -EINVAL;
  8127. }
  8128. /* Wait for Transaction Pending bit clean */
  8129. for (i = 0; i < 4; i++) {
  8130. if (i)
  8131. msleep((1 << (i - 1)) * 100);
  8132. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8133. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8134. goto clear;
  8135. }
  8136. dev_err(&dev->dev,
  8137. "transaction is not cleared; proceeding with reset anyway\n");
  8138. clear:
  8139. BNX2X_DEV_INFO("Initiating FLR\n");
  8140. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8141. return 0;
  8142. }
  8143. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8144. {
  8145. int rc;
  8146. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8147. /* Test if previous unload process was already finished for this path */
  8148. if (bnx2x_prev_is_path_marked(bp))
  8149. return bnx2x_prev_mcp_done(bp);
  8150. /* If function has FLR capabilities, and existing FW version matches
  8151. * the one required, then FLR will be sufficient to clean any residue
  8152. * left by previous driver
  8153. */
  8154. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8155. if (!rc) {
  8156. /* fw version is good */
  8157. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8158. rc = bnx2x_do_flr(bp);
  8159. }
  8160. if (!rc) {
  8161. /* FLR was performed */
  8162. BNX2X_DEV_INFO("FLR successful\n");
  8163. return 0;
  8164. }
  8165. BNX2X_DEV_INFO("Could not FLR\n");
  8166. /* Close the MCP request, return failure*/
  8167. rc = bnx2x_prev_mcp_done(bp);
  8168. if (!rc)
  8169. rc = BNX2X_PREV_WAIT_NEEDED;
  8170. return rc;
  8171. }
  8172. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8173. {
  8174. u32 reset_reg, tmp_reg = 0, rc;
  8175. bool prev_undi = false;
  8176. /* It is possible a previous function received 'common' answer,
  8177. * but hasn't loaded yet, therefore creating a scenario of
  8178. * multiple functions receiving 'common' on the same path.
  8179. */
  8180. BNX2X_DEV_INFO("Common unload Flow\n");
  8181. if (bnx2x_prev_is_path_marked(bp))
  8182. return bnx2x_prev_mcp_done(bp);
  8183. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8184. /* Reset should be performed after BRB is emptied */
  8185. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8186. u32 timer_count = 1000;
  8187. /* Close the MAC Rx to prevent BRB from filling up */
  8188. bnx2x_prev_unload_close_mac(bp);
  8189. /* Check if the UNDI driver was previously loaded
  8190. * UNDI driver initializes CID offset for normal bell to 0x7
  8191. */
  8192. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8193. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8194. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8195. if (tmp_reg == 0x7) {
  8196. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8197. prev_undi = true;
  8198. /* clear the UNDI indication */
  8199. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8200. }
  8201. }
  8202. /* wait until BRB is empty */
  8203. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8204. while (timer_count) {
  8205. u32 prev_brb = tmp_reg;
  8206. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8207. if (!tmp_reg)
  8208. break;
  8209. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8210. /* reset timer as long as BRB actually gets emptied */
  8211. if (prev_brb > tmp_reg)
  8212. timer_count = 1000;
  8213. else
  8214. timer_count--;
  8215. /* If UNDI resides in memory, manually increment it */
  8216. if (prev_undi)
  8217. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8218. udelay(10);
  8219. }
  8220. if (!timer_count)
  8221. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8222. }
  8223. /* No packets are in the pipeline, path is ready for reset */
  8224. bnx2x_reset_common(bp);
  8225. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8226. if (rc) {
  8227. bnx2x_prev_mcp_done(bp);
  8228. return rc;
  8229. }
  8230. return bnx2x_prev_mcp_done(bp);
  8231. }
  8232. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8233. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8234. * the addresses of the transaction, resulting in was-error bit set in the pci
  8235. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8236. * to clear the interrupt which detected this from the pglueb and the was done
  8237. * bit
  8238. */
  8239. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8240. {
  8241. if (!CHIP_IS_E1x(bp)) {
  8242. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8243. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8244. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  8245. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8246. 1 << BP_FUNC(bp));
  8247. }
  8248. }
  8249. }
  8250. static int bnx2x_prev_unload(struct bnx2x *bp)
  8251. {
  8252. int time_counter = 10;
  8253. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8254. struct bnx2x_prev_path_list *prev_list;
  8255. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8256. /* clear hw from errors which may have resulted from an interrupted
  8257. * dmae transaction.
  8258. */
  8259. bnx2x_prev_interrupted_dmae(bp);
  8260. /* Release previously held locks */
  8261. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8262. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8263. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8264. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8265. if (hw_lock_val) {
  8266. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8267. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8268. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8269. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8270. }
  8271. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8272. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8273. } else
  8274. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8275. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8276. BNX2X_DEV_INFO("Release previously held alr\n");
  8277. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8278. }
  8279. do {
  8280. /* Lock MCP using an unload request */
  8281. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8282. if (!fw) {
  8283. BNX2X_ERR("MCP response failure, aborting\n");
  8284. rc = -EBUSY;
  8285. break;
  8286. }
  8287. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8288. rc = bnx2x_prev_unload_common(bp);
  8289. break;
  8290. }
  8291. /* non-common reply from MCP night require looping */
  8292. rc = bnx2x_prev_unload_uncommon(bp);
  8293. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8294. break;
  8295. msleep(20);
  8296. } while (--time_counter);
  8297. if (!time_counter || rc) {
  8298. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8299. rc = -EBUSY;
  8300. }
  8301. /* Mark function if its port was used to boot from SAN */
  8302. prev_list = bnx2x_prev_path_get_entry(bp);
  8303. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8304. bp->link_params.feature_config_flags |=
  8305. FEATURE_CONFIG_BOOT_FROM_SAN;
  8306. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8307. return rc;
  8308. }
  8309. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8310. {
  8311. u32 val, val2, val3, val4, id, boot_mode;
  8312. u16 pmc;
  8313. /* Get the chip revision id and number. */
  8314. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8315. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8316. id = ((val & 0xffff) << 16);
  8317. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8318. id |= ((val & 0xf) << 12);
  8319. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8320. id |= ((val & 0xff) << 4);
  8321. val = REG_RD(bp, MISC_REG_BOND_ID);
  8322. id |= (val & 0xf);
  8323. bp->common.chip_id = id;
  8324. /* force 57811 according to MISC register */
  8325. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8326. if (CHIP_IS_57810(bp))
  8327. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8328. (bp->common.chip_id & 0x0000FFFF);
  8329. else if (CHIP_IS_57810_MF(bp))
  8330. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8331. (bp->common.chip_id & 0x0000FFFF);
  8332. bp->common.chip_id |= 0x1;
  8333. }
  8334. /* Set doorbell size */
  8335. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8336. if (!CHIP_IS_E1x(bp)) {
  8337. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8338. if ((val & 1) == 0)
  8339. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8340. else
  8341. val = (val >> 1) & 1;
  8342. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8343. "2_PORT_MODE");
  8344. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8345. CHIP_2_PORT_MODE;
  8346. if (CHIP_MODE_IS_4_PORT(bp))
  8347. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8348. else
  8349. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8350. } else {
  8351. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8352. bp->pfid = bp->pf_num; /* 0..7 */
  8353. }
  8354. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8355. bp->link_params.chip_id = bp->common.chip_id;
  8356. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8357. val = (REG_RD(bp, 0x2874) & 0x55);
  8358. if ((bp->common.chip_id & 0x1) ||
  8359. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8360. bp->flags |= ONE_PORT_FLAG;
  8361. BNX2X_DEV_INFO("single port device\n");
  8362. }
  8363. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8364. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8365. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8366. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8367. bp->common.flash_size, bp->common.flash_size);
  8368. bnx2x_init_shmem(bp);
  8369. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8370. MISC_REG_GENERIC_CR_1 :
  8371. MISC_REG_GENERIC_CR_0));
  8372. bp->link_params.shmem_base = bp->common.shmem_base;
  8373. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8374. if (SHMEM2_RD(bp, size) >
  8375. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8376. bp->link_params.lfa_base =
  8377. REG_RD(bp, bp->common.shmem2_base +
  8378. (u32)offsetof(struct shmem2_region,
  8379. lfa_host_addr[BP_PORT(bp)]));
  8380. else
  8381. bp->link_params.lfa_base = 0;
  8382. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8383. bp->common.shmem_base, bp->common.shmem2_base);
  8384. if (!bp->common.shmem_base) {
  8385. BNX2X_DEV_INFO("MCP not active\n");
  8386. bp->flags |= NO_MCP_FLAG;
  8387. return;
  8388. }
  8389. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8390. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8391. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8392. SHARED_HW_CFG_LED_MODE_MASK) >>
  8393. SHARED_HW_CFG_LED_MODE_SHIFT);
  8394. bp->link_params.feature_config_flags = 0;
  8395. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8396. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8397. bp->link_params.feature_config_flags |=
  8398. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8399. else
  8400. bp->link_params.feature_config_flags &=
  8401. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8402. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8403. bp->common.bc_ver = val;
  8404. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8405. if (val < BNX2X_BC_VER) {
  8406. /* for now only warn
  8407. * later we might need to enforce this */
  8408. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8409. BNX2X_BC_VER, val);
  8410. }
  8411. bp->link_params.feature_config_flags |=
  8412. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8413. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8414. bp->link_params.feature_config_flags |=
  8415. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8416. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8417. bp->link_params.feature_config_flags |=
  8418. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8419. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8420. bp->link_params.feature_config_flags |=
  8421. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8422. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8423. bp->link_params.feature_config_flags |=
  8424. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8425. FEATURE_CONFIG_MT_SUPPORT : 0;
  8426. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8427. BC_SUPPORTS_PFC_STATS : 0;
  8428. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8429. BC_SUPPORTS_FCOE_FEATURES : 0;
  8430. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8431. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8432. boot_mode = SHMEM_RD(bp,
  8433. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8434. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8435. switch (boot_mode) {
  8436. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8437. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8438. break;
  8439. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8440. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8441. break;
  8442. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8443. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8444. break;
  8445. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8446. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8447. break;
  8448. }
  8449. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8450. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8451. BNX2X_DEV_INFO("%sWoL capable\n",
  8452. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8453. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8454. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8455. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8456. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8457. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8458. val, val2, val3, val4);
  8459. }
  8460. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8461. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8462. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8463. {
  8464. int pfid = BP_FUNC(bp);
  8465. int igu_sb_id;
  8466. u32 val;
  8467. u8 fid, igu_sb_cnt = 0;
  8468. bp->igu_base_sb = 0xff;
  8469. if (CHIP_INT_MODE_IS_BC(bp)) {
  8470. int vn = BP_VN(bp);
  8471. igu_sb_cnt = bp->igu_sb_cnt;
  8472. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8473. FP_SB_MAX_E1x;
  8474. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8475. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8476. return 0;
  8477. }
  8478. /* IGU in normal mode - read CAM */
  8479. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8480. igu_sb_id++) {
  8481. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8482. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8483. continue;
  8484. fid = IGU_FID(val);
  8485. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8486. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8487. continue;
  8488. if (IGU_VEC(val) == 0)
  8489. /* default status block */
  8490. bp->igu_dsb_id = igu_sb_id;
  8491. else {
  8492. if (bp->igu_base_sb == 0xff)
  8493. bp->igu_base_sb = igu_sb_id;
  8494. igu_sb_cnt++;
  8495. }
  8496. }
  8497. }
  8498. #ifdef CONFIG_PCI_MSI
  8499. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8500. * optional that number of CAM entries will not be equal to the value
  8501. * advertised in PCI.
  8502. * Driver should use the minimal value of both as the actual status
  8503. * block count
  8504. */
  8505. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8506. #endif
  8507. if (igu_sb_cnt == 0) {
  8508. BNX2X_ERR("CAM configuration error\n");
  8509. return -EINVAL;
  8510. }
  8511. return 0;
  8512. }
  8513. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8514. {
  8515. int cfg_size = 0, idx, port = BP_PORT(bp);
  8516. /* Aggregation of supported attributes of all external phys */
  8517. bp->port.supported[0] = 0;
  8518. bp->port.supported[1] = 0;
  8519. switch (bp->link_params.num_phys) {
  8520. case 1:
  8521. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8522. cfg_size = 1;
  8523. break;
  8524. case 2:
  8525. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8526. cfg_size = 1;
  8527. break;
  8528. case 3:
  8529. if (bp->link_params.multi_phy_config &
  8530. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8531. bp->port.supported[1] =
  8532. bp->link_params.phy[EXT_PHY1].supported;
  8533. bp->port.supported[0] =
  8534. bp->link_params.phy[EXT_PHY2].supported;
  8535. } else {
  8536. bp->port.supported[0] =
  8537. bp->link_params.phy[EXT_PHY1].supported;
  8538. bp->port.supported[1] =
  8539. bp->link_params.phy[EXT_PHY2].supported;
  8540. }
  8541. cfg_size = 2;
  8542. break;
  8543. }
  8544. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8545. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8546. SHMEM_RD(bp,
  8547. dev_info.port_hw_config[port].external_phy_config),
  8548. SHMEM_RD(bp,
  8549. dev_info.port_hw_config[port].external_phy_config2));
  8550. return;
  8551. }
  8552. if (CHIP_IS_E3(bp))
  8553. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8554. else {
  8555. switch (switch_cfg) {
  8556. case SWITCH_CFG_1G:
  8557. bp->port.phy_addr = REG_RD(
  8558. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8559. break;
  8560. case SWITCH_CFG_10G:
  8561. bp->port.phy_addr = REG_RD(
  8562. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8563. break;
  8564. default:
  8565. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8566. bp->port.link_config[0]);
  8567. return;
  8568. }
  8569. }
  8570. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8571. /* mask what we support according to speed_cap_mask per configuration */
  8572. for (idx = 0; idx < cfg_size; idx++) {
  8573. if (!(bp->link_params.speed_cap_mask[idx] &
  8574. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8575. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8576. if (!(bp->link_params.speed_cap_mask[idx] &
  8577. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8578. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8579. if (!(bp->link_params.speed_cap_mask[idx] &
  8580. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8581. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8582. if (!(bp->link_params.speed_cap_mask[idx] &
  8583. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8584. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8585. if (!(bp->link_params.speed_cap_mask[idx] &
  8586. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8587. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8588. SUPPORTED_1000baseT_Full);
  8589. if (!(bp->link_params.speed_cap_mask[idx] &
  8590. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8591. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8592. if (!(bp->link_params.speed_cap_mask[idx] &
  8593. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8594. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8595. }
  8596. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8597. bp->port.supported[1]);
  8598. }
  8599. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8600. {
  8601. u32 link_config, idx, cfg_size = 0;
  8602. bp->port.advertising[0] = 0;
  8603. bp->port.advertising[1] = 0;
  8604. switch (bp->link_params.num_phys) {
  8605. case 1:
  8606. case 2:
  8607. cfg_size = 1;
  8608. break;
  8609. case 3:
  8610. cfg_size = 2;
  8611. break;
  8612. }
  8613. for (idx = 0; idx < cfg_size; idx++) {
  8614. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8615. link_config = bp->port.link_config[idx];
  8616. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8617. case PORT_FEATURE_LINK_SPEED_AUTO:
  8618. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8619. bp->link_params.req_line_speed[idx] =
  8620. SPEED_AUTO_NEG;
  8621. bp->port.advertising[idx] |=
  8622. bp->port.supported[idx];
  8623. if (bp->link_params.phy[EXT_PHY1].type ==
  8624. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8625. bp->port.advertising[idx] |=
  8626. (SUPPORTED_100baseT_Half |
  8627. SUPPORTED_100baseT_Full);
  8628. } else {
  8629. /* force 10G, no AN */
  8630. bp->link_params.req_line_speed[idx] =
  8631. SPEED_10000;
  8632. bp->port.advertising[idx] |=
  8633. (ADVERTISED_10000baseT_Full |
  8634. ADVERTISED_FIBRE);
  8635. continue;
  8636. }
  8637. break;
  8638. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8639. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8640. bp->link_params.req_line_speed[idx] =
  8641. SPEED_10;
  8642. bp->port.advertising[idx] |=
  8643. (ADVERTISED_10baseT_Full |
  8644. ADVERTISED_TP);
  8645. } else {
  8646. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8647. link_config,
  8648. bp->link_params.speed_cap_mask[idx]);
  8649. return;
  8650. }
  8651. break;
  8652. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8653. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8654. bp->link_params.req_line_speed[idx] =
  8655. SPEED_10;
  8656. bp->link_params.req_duplex[idx] =
  8657. DUPLEX_HALF;
  8658. bp->port.advertising[idx] |=
  8659. (ADVERTISED_10baseT_Half |
  8660. ADVERTISED_TP);
  8661. } else {
  8662. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8663. link_config,
  8664. bp->link_params.speed_cap_mask[idx]);
  8665. return;
  8666. }
  8667. break;
  8668. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8669. if (bp->port.supported[idx] &
  8670. SUPPORTED_100baseT_Full) {
  8671. bp->link_params.req_line_speed[idx] =
  8672. SPEED_100;
  8673. bp->port.advertising[idx] |=
  8674. (ADVERTISED_100baseT_Full |
  8675. ADVERTISED_TP);
  8676. } else {
  8677. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8678. link_config,
  8679. bp->link_params.speed_cap_mask[idx]);
  8680. return;
  8681. }
  8682. break;
  8683. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8684. if (bp->port.supported[idx] &
  8685. SUPPORTED_100baseT_Half) {
  8686. bp->link_params.req_line_speed[idx] =
  8687. SPEED_100;
  8688. bp->link_params.req_duplex[idx] =
  8689. DUPLEX_HALF;
  8690. bp->port.advertising[idx] |=
  8691. (ADVERTISED_100baseT_Half |
  8692. ADVERTISED_TP);
  8693. } else {
  8694. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8695. link_config,
  8696. bp->link_params.speed_cap_mask[idx]);
  8697. return;
  8698. }
  8699. break;
  8700. case PORT_FEATURE_LINK_SPEED_1G:
  8701. if (bp->port.supported[idx] &
  8702. SUPPORTED_1000baseT_Full) {
  8703. bp->link_params.req_line_speed[idx] =
  8704. SPEED_1000;
  8705. bp->port.advertising[idx] |=
  8706. (ADVERTISED_1000baseT_Full |
  8707. ADVERTISED_TP);
  8708. } else {
  8709. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8710. link_config,
  8711. bp->link_params.speed_cap_mask[idx]);
  8712. return;
  8713. }
  8714. break;
  8715. case PORT_FEATURE_LINK_SPEED_2_5G:
  8716. if (bp->port.supported[idx] &
  8717. SUPPORTED_2500baseX_Full) {
  8718. bp->link_params.req_line_speed[idx] =
  8719. SPEED_2500;
  8720. bp->port.advertising[idx] |=
  8721. (ADVERTISED_2500baseX_Full |
  8722. ADVERTISED_TP);
  8723. } else {
  8724. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8725. link_config,
  8726. bp->link_params.speed_cap_mask[idx]);
  8727. return;
  8728. }
  8729. break;
  8730. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8731. if (bp->port.supported[idx] &
  8732. SUPPORTED_10000baseT_Full) {
  8733. bp->link_params.req_line_speed[idx] =
  8734. SPEED_10000;
  8735. bp->port.advertising[idx] |=
  8736. (ADVERTISED_10000baseT_Full |
  8737. ADVERTISED_FIBRE);
  8738. } else {
  8739. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8740. link_config,
  8741. bp->link_params.speed_cap_mask[idx]);
  8742. return;
  8743. }
  8744. break;
  8745. case PORT_FEATURE_LINK_SPEED_20G:
  8746. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8747. break;
  8748. default:
  8749. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8750. link_config);
  8751. bp->link_params.req_line_speed[idx] =
  8752. SPEED_AUTO_NEG;
  8753. bp->port.advertising[idx] =
  8754. bp->port.supported[idx];
  8755. break;
  8756. }
  8757. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8758. PORT_FEATURE_FLOW_CONTROL_MASK);
  8759. if (bp->link_params.req_flow_ctrl[idx] ==
  8760. BNX2X_FLOW_CTRL_AUTO) {
  8761. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8762. bp->link_params.req_flow_ctrl[idx] =
  8763. BNX2X_FLOW_CTRL_NONE;
  8764. else
  8765. bnx2x_set_requested_fc(bp);
  8766. }
  8767. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8768. bp->link_params.req_line_speed[idx],
  8769. bp->link_params.req_duplex[idx],
  8770. bp->link_params.req_flow_ctrl[idx],
  8771. bp->port.advertising[idx]);
  8772. }
  8773. }
  8774. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8775. {
  8776. mac_hi = cpu_to_be16(mac_hi);
  8777. mac_lo = cpu_to_be32(mac_lo);
  8778. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8779. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8780. }
  8781. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8782. {
  8783. int port = BP_PORT(bp);
  8784. u32 config;
  8785. u32 ext_phy_type, ext_phy_config, eee_mode;
  8786. bp->link_params.bp = bp;
  8787. bp->link_params.port = port;
  8788. bp->link_params.lane_config =
  8789. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8790. bp->link_params.speed_cap_mask[0] =
  8791. SHMEM_RD(bp,
  8792. dev_info.port_hw_config[port].speed_capability_mask);
  8793. bp->link_params.speed_cap_mask[1] =
  8794. SHMEM_RD(bp,
  8795. dev_info.port_hw_config[port].speed_capability_mask2);
  8796. bp->port.link_config[0] =
  8797. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8798. bp->port.link_config[1] =
  8799. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8800. bp->link_params.multi_phy_config =
  8801. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8802. /* If the device is capable of WoL, set the default state according
  8803. * to the HW
  8804. */
  8805. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8806. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8807. (config & PORT_FEATURE_WOL_ENABLED));
  8808. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8809. bp->link_params.lane_config,
  8810. bp->link_params.speed_cap_mask[0],
  8811. bp->port.link_config[0]);
  8812. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8813. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8814. bnx2x_phy_probe(&bp->link_params);
  8815. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8816. bnx2x_link_settings_requested(bp);
  8817. /*
  8818. * If connected directly, work with the internal PHY, otherwise, work
  8819. * with the external PHY
  8820. */
  8821. ext_phy_config =
  8822. SHMEM_RD(bp,
  8823. dev_info.port_hw_config[port].external_phy_config);
  8824. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8825. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8826. bp->mdio.prtad = bp->port.phy_addr;
  8827. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8828. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8829. bp->mdio.prtad =
  8830. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8831. /* Configure link feature according to nvram value */
  8832. eee_mode = (((SHMEM_RD(bp, dev_info.
  8833. port_feature_config[port].eee_power_mode)) &
  8834. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8835. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8836. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8837. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8838. EEE_MODE_ENABLE_LPI |
  8839. EEE_MODE_OUTPUT_TIME;
  8840. } else {
  8841. bp->link_params.eee_mode = 0;
  8842. }
  8843. }
  8844. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8845. {
  8846. u32 no_flags = NO_ISCSI_FLAG;
  8847. int port = BP_PORT(bp);
  8848. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8849. drv_lic_key[port].max_iscsi_conn);
  8850. if (!CNIC_SUPPORT(bp)) {
  8851. bp->flags |= no_flags;
  8852. return;
  8853. }
  8854. /* Get the number of maximum allowed iSCSI connections */
  8855. bp->cnic_eth_dev.max_iscsi_conn =
  8856. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8857. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8858. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8859. bp->cnic_eth_dev.max_iscsi_conn);
  8860. /*
  8861. * If maximum allowed number of connections is zero -
  8862. * disable the feature.
  8863. */
  8864. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8865. bp->flags |= no_flags;
  8866. }
  8867. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8868. {
  8869. /* Port info */
  8870. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8871. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8872. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8873. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8874. /* Node info */
  8875. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8876. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8877. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8878. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8879. }
  8880. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8881. {
  8882. int port = BP_PORT(bp);
  8883. int func = BP_ABS_FUNC(bp);
  8884. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8885. drv_lic_key[port].max_fcoe_conn);
  8886. if (!CNIC_SUPPORT(bp)) {
  8887. bp->flags |= NO_FCOE_FLAG;
  8888. return;
  8889. }
  8890. /* Get the number of maximum allowed FCoE connections */
  8891. bp->cnic_eth_dev.max_fcoe_conn =
  8892. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8893. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8894. /* Read the WWN: */
  8895. if (!IS_MF(bp)) {
  8896. /* Port info */
  8897. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8898. SHMEM_RD(bp,
  8899. dev_info.port_hw_config[port].
  8900. fcoe_wwn_port_name_upper);
  8901. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8902. SHMEM_RD(bp,
  8903. dev_info.port_hw_config[port].
  8904. fcoe_wwn_port_name_lower);
  8905. /* Node info */
  8906. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8907. SHMEM_RD(bp,
  8908. dev_info.port_hw_config[port].
  8909. fcoe_wwn_node_name_upper);
  8910. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8911. SHMEM_RD(bp,
  8912. dev_info.port_hw_config[port].
  8913. fcoe_wwn_node_name_lower);
  8914. } else if (!IS_MF_SD(bp)) {
  8915. /*
  8916. * Read the WWN info only if the FCoE feature is enabled for
  8917. * this function.
  8918. */
  8919. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8920. bnx2x_get_ext_wwn_info(bp, func);
  8921. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8922. bnx2x_get_ext_wwn_info(bp, func);
  8923. }
  8924. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8925. /*
  8926. * If maximum allowed number of connections is zero -
  8927. * disable the feature.
  8928. */
  8929. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8930. bp->flags |= NO_FCOE_FLAG;
  8931. }
  8932. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  8933. {
  8934. /*
  8935. * iSCSI may be dynamically disabled but reading
  8936. * info here we will decrease memory usage by driver
  8937. * if the feature is disabled for good
  8938. */
  8939. bnx2x_get_iscsi_info(bp);
  8940. bnx2x_get_fcoe_info(bp);
  8941. }
  8942. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8943. {
  8944. u32 val, val2;
  8945. int func = BP_ABS_FUNC(bp);
  8946. int port = BP_PORT(bp);
  8947. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8948. u8 *fip_mac = bp->fip_mac;
  8949. if (IS_MF(bp)) {
  8950. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8951. * FCoE MAC then the appropriate feature should be disabled.
  8952. * In non SD mode features configuration comes from struct
  8953. * func_ext_config.
  8954. */
  8955. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  8956. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8957. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8958. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8959. iscsi_mac_addr_upper);
  8960. val = MF_CFG_RD(bp, func_ext_config[func].
  8961. iscsi_mac_addr_lower);
  8962. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8963. BNX2X_DEV_INFO
  8964. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8965. } else {
  8966. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8967. }
  8968. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8969. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8970. fcoe_mac_addr_upper);
  8971. val = MF_CFG_RD(bp, func_ext_config[func].
  8972. fcoe_mac_addr_lower);
  8973. bnx2x_set_mac_buf(fip_mac, val, val2);
  8974. BNX2X_DEV_INFO
  8975. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  8976. } else {
  8977. bp->flags |= NO_FCOE_FLAG;
  8978. }
  8979. bp->mf_ext_config = cfg;
  8980. } else { /* SD MODE */
  8981. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8982. /* use primary mac as iscsi mac */
  8983. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  8984. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8985. BNX2X_DEV_INFO
  8986. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8987. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  8988. /* use primary mac as fip mac */
  8989. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  8990. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8991. BNX2X_DEV_INFO
  8992. ("Read FIP MAC: %pM\n", fip_mac);
  8993. }
  8994. }
  8995. if (IS_MF_STORAGE_SD(bp))
  8996. /* Zero primary MAC configuration */
  8997. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8998. if (IS_MF_FCOE_AFEX(bp))
  8999. /* use FIP MAC as primary MAC */
  9000. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9001. } else {
  9002. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9003. iscsi_mac_upper);
  9004. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9005. iscsi_mac_lower);
  9006. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9007. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9008. fcoe_fip_mac_upper);
  9009. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9010. fcoe_fip_mac_lower);
  9011. bnx2x_set_mac_buf(fip_mac, val, val2);
  9012. }
  9013. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9014. if (!is_valid_ether_addr(iscsi_mac)) {
  9015. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9016. memset(iscsi_mac, 0, ETH_ALEN);
  9017. }
  9018. /* Disable FCoE if MAC configuration is invalid. */
  9019. if (!is_valid_ether_addr(fip_mac)) {
  9020. bp->flags |= NO_FCOE_FLAG;
  9021. memset(bp->fip_mac, 0, ETH_ALEN);
  9022. }
  9023. }
  9024. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9025. {
  9026. u32 val, val2;
  9027. int func = BP_ABS_FUNC(bp);
  9028. int port = BP_PORT(bp);
  9029. /* Zero primary MAC configuration */
  9030. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9031. if (BP_NOMCP(bp)) {
  9032. BNX2X_ERROR("warning: random MAC workaround active\n");
  9033. eth_hw_addr_random(bp->dev);
  9034. } else if (IS_MF(bp)) {
  9035. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9036. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9037. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9038. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9039. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9040. if (CNIC_SUPPORT(bp))
  9041. bnx2x_get_cnic_mac_hwinfo(bp);
  9042. } else {
  9043. /* in SF read MACs from port configuration */
  9044. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9045. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9046. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9047. if (CNIC_SUPPORT(bp))
  9048. bnx2x_get_cnic_mac_hwinfo(bp);
  9049. }
  9050. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9051. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  9052. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9053. dev_err(&bp->pdev->dev,
  9054. "bad Ethernet MAC address configuration: %pM\n"
  9055. "change it manually before bringing up the appropriate network interface\n",
  9056. bp->dev->dev_addr);
  9057. }
  9058. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9059. {
  9060. int tmp;
  9061. u32 cfg;
  9062. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9063. /* Take function: tmp = func */
  9064. tmp = BP_ABS_FUNC(bp);
  9065. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9066. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9067. } else {
  9068. /* Take port: tmp = port */
  9069. tmp = BP_PORT(bp);
  9070. cfg = SHMEM_RD(bp,
  9071. dev_info.port_hw_config[tmp].generic_features);
  9072. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9073. }
  9074. return cfg;
  9075. }
  9076. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9077. {
  9078. int /*abs*/func = BP_ABS_FUNC(bp);
  9079. int vn;
  9080. u32 val = 0;
  9081. int rc = 0;
  9082. bnx2x_get_common_hwinfo(bp);
  9083. /*
  9084. * initialize IGU parameters
  9085. */
  9086. if (CHIP_IS_E1x(bp)) {
  9087. bp->common.int_block = INT_BLOCK_HC;
  9088. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9089. bp->igu_base_sb = 0;
  9090. } else {
  9091. bp->common.int_block = INT_BLOCK_IGU;
  9092. /* do not allow device reset during IGU info preocessing */
  9093. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9094. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9095. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9096. int tout = 5000;
  9097. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9098. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9099. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9100. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9101. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9102. tout--;
  9103. usleep_range(1000, 1000);
  9104. }
  9105. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9106. dev_err(&bp->pdev->dev,
  9107. "FORCING Normal Mode failed!!!\n");
  9108. bnx2x_release_hw_lock(bp,
  9109. HW_LOCK_RESOURCE_RESET);
  9110. return -EPERM;
  9111. }
  9112. }
  9113. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9114. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9115. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9116. } else
  9117. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9118. rc = bnx2x_get_igu_cam_info(bp);
  9119. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9120. if (rc)
  9121. return rc;
  9122. }
  9123. /*
  9124. * set base FW non-default (fast path) status block id, this value is
  9125. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9126. * determine the id used by the FW.
  9127. */
  9128. if (CHIP_IS_E1x(bp))
  9129. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9130. else /*
  9131. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9132. * the same queue are indicated on the same IGU SB). So we prefer
  9133. * FW and IGU SBs to be the same value.
  9134. */
  9135. bp->base_fw_ndsb = bp->igu_base_sb;
  9136. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9137. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9138. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9139. /*
  9140. * Initialize MF configuration
  9141. */
  9142. bp->mf_ov = 0;
  9143. bp->mf_mode = 0;
  9144. vn = BP_VN(bp);
  9145. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9146. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9147. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9148. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9149. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9150. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9151. else
  9152. bp->common.mf_cfg_base = bp->common.shmem_base +
  9153. offsetof(struct shmem_region, func_mb) +
  9154. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9155. /*
  9156. * get mf configuration:
  9157. * 1. existence of MF configuration
  9158. * 2. MAC address must be legal (check only upper bytes)
  9159. * for Switch-Independent mode;
  9160. * OVLAN must be legal for Switch-Dependent mode
  9161. * 3. SF_MODE configures specific MF mode
  9162. */
  9163. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9164. /* get mf configuration */
  9165. val = SHMEM_RD(bp,
  9166. dev_info.shared_feature_config.config);
  9167. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9168. switch (val) {
  9169. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9170. val = MF_CFG_RD(bp, func_mf_config[func].
  9171. mac_upper);
  9172. /* check for legal mac (upper bytes)*/
  9173. if (val != 0xffff) {
  9174. bp->mf_mode = MULTI_FUNCTION_SI;
  9175. bp->mf_config[vn] = MF_CFG_RD(bp,
  9176. func_mf_config[func].config);
  9177. } else
  9178. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9179. break;
  9180. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9181. if ((!CHIP_IS_E1x(bp)) &&
  9182. (MF_CFG_RD(bp, func_mf_config[func].
  9183. mac_upper) != 0xffff) &&
  9184. (SHMEM2_HAS(bp,
  9185. afex_driver_support))) {
  9186. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9187. bp->mf_config[vn] = MF_CFG_RD(bp,
  9188. func_mf_config[func].config);
  9189. } else {
  9190. BNX2X_DEV_INFO("can not configure afex mode\n");
  9191. }
  9192. break;
  9193. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9194. /* get OV configuration */
  9195. val = MF_CFG_RD(bp,
  9196. func_mf_config[FUNC_0].e1hov_tag);
  9197. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9198. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9199. bp->mf_mode = MULTI_FUNCTION_SD;
  9200. bp->mf_config[vn] = MF_CFG_RD(bp,
  9201. func_mf_config[func].config);
  9202. } else
  9203. BNX2X_DEV_INFO("illegal OV for SD\n");
  9204. break;
  9205. default:
  9206. /* Unknown configuration: reset mf_config */
  9207. bp->mf_config[vn] = 0;
  9208. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9209. }
  9210. }
  9211. BNX2X_DEV_INFO("%s function mode\n",
  9212. IS_MF(bp) ? "multi" : "single");
  9213. switch (bp->mf_mode) {
  9214. case MULTI_FUNCTION_SD:
  9215. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9216. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9217. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9218. bp->mf_ov = val;
  9219. bp->path_has_ovlan = true;
  9220. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9221. func, bp->mf_ov, bp->mf_ov);
  9222. } else {
  9223. dev_err(&bp->pdev->dev,
  9224. "No valid MF OV for func %d, aborting\n",
  9225. func);
  9226. return -EPERM;
  9227. }
  9228. break;
  9229. case MULTI_FUNCTION_AFEX:
  9230. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9231. break;
  9232. case MULTI_FUNCTION_SI:
  9233. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9234. func);
  9235. break;
  9236. default:
  9237. if (vn) {
  9238. dev_err(&bp->pdev->dev,
  9239. "VN %d is in a single function mode, aborting\n",
  9240. vn);
  9241. return -EPERM;
  9242. }
  9243. break;
  9244. }
  9245. /* check if other port on the path needs ovlan:
  9246. * Since MF configuration is shared between ports
  9247. * Possible mixed modes are only
  9248. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9249. */
  9250. if (CHIP_MODE_IS_4_PORT(bp) &&
  9251. !bp->path_has_ovlan &&
  9252. !IS_MF(bp) &&
  9253. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9254. u8 other_port = !BP_PORT(bp);
  9255. u8 other_func = BP_PATH(bp) + 2*other_port;
  9256. val = MF_CFG_RD(bp,
  9257. func_mf_config[other_func].e1hov_tag);
  9258. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9259. bp->path_has_ovlan = true;
  9260. }
  9261. }
  9262. /* adjust igu_sb_cnt to MF for E1x */
  9263. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9264. bp->igu_sb_cnt /= E1HVN_MAX;
  9265. /* port info */
  9266. bnx2x_get_port_hwinfo(bp);
  9267. /* Get MAC addresses */
  9268. bnx2x_get_mac_hwinfo(bp);
  9269. bnx2x_get_cnic_info(bp);
  9270. return rc;
  9271. }
  9272. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9273. {
  9274. int cnt, i, block_end, rodi;
  9275. char vpd_start[BNX2X_VPD_LEN+1];
  9276. char str_id_reg[VENDOR_ID_LEN+1];
  9277. char str_id_cap[VENDOR_ID_LEN+1];
  9278. char *vpd_data;
  9279. char *vpd_extended_data = NULL;
  9280. u8 len;
  9281. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9282. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9283. if (cnt < BNX2X_VPD_LEN)
  9284. goto out_not_found;
  9285. /* VPD RO tag should be first tag after identifier string, hence
  9286. * we should be able to find it in first BNX2X_VPD_LEN chars
  9287. */
  9288. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9289. PCI_VPD_LRDT_RO_DATA);
  9290. if (i < 0)
  9291. goto out_not_found;
  9292. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9293. pci_vpd_lrdt_size(&vpd_start[i]);
  9294. i += PCI_VPD_LRDT_TAG_SIZE;
  9295. if (block_end > BNX2X_VPD_LEN) {
  9296. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9297. if (vpd_extended_data == NULL)
  9298. goto out_not_found;
  9299. /* read rest of vpd image into vpd_extended_data */
  9300. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9301. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9302. block_end - BNX2X_VPD_LEN,
  9303. vpd_extended_data + BNX2X_VPD_LEN);
  9304. if (cnt < (block_end - BNX2X_VPD_LEN))
  9305. goto out_not_found;
  9306. vpd_data = vpd_extended_data;
  9307. } else
  9308. vpd_data = vpd_start;
  9309. /* now vpd_data holds full vpd content in both cases */
  9310. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9311. PCI_VPD_RO_KEYWORD_MFR_ID);
  9312. if (rodi < 0)
  9313. goto out_not_found;
  9314. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9315. if (len != VENDOR_ID_LEN)
  9316. goto out_not_found;
  9317. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9318. /* vendor specific info */
  9319. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9320. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9321. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9322. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9323. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9324. PCI_VPD_RO_KEYWORD_VENDOR0);
  9325. if (rodi >= 0) {
  9326. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9327. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9328. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9329. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9330. bp->fw_ver[len] = ' ';
  9331. }
  9332. }
  9333. kfree(vpd_extended_data);
  9334. return;
  9335. }
  9336. out_not_found:
  9337. kfree(vpd_extended_data);
  9338. return;
  9339. }
  9340. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9341. {
  9342. u32 flags = 0;
  9343. if (CHIP_REV_IS_FPGA(bp))
  9344. SET_FLAGS(flags, MODE_FPGA);
  9345. else if (CHIP_REV_IS_EMUL(bp))
  9346. SET_FLAGS(flags, MODE_EMUL);
  9347. else
  9348. SET_FLAGS(flags, MODE_ASIC);
  9349. if (CHIP_MODE_IS_4_PORT(bp))
  9350. SET_FLAGS(flags, MODE_PORT4);
  9351. else
  9352. SET_FLAGS(flags, MODE_PORT2);
  9353. if (CHIP_IS_E2(bp))
  9354. SET_FLAGS(flags, MODE_E2);
  9355. else if (CHIP_IS_E3(bp)) {
  9356. SET_FLAGS(flags, MODE_E3);
  9357. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9358. SET_FLAGS(flags, MODE_E3_A0);
  9359. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9360. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9361. }
  9362. if (IS_MF(bp)) {
  9363. SET_FLAGS(flags, MODE_MF);
  9364. switch (bp->mf_mode) {
  9365. case MULTI_FUNCTION_SD:
  9366. SET_FLAGS(flags, MODE_MF_SD);
  9367. break;
  9368. case MULTI_FUNCTION_SI:
  9369. SET_FLAGS(flags, MODE_MF_SI);
  9370. break;
  9371. case MULTI_FUNCTION_AFEX:
  9372. SET_FLAGS(flags, MODE_MF_AFEX);
  9373. break;
  9374. }
  9375. } else
  9376. SET_FLAGS(flags, MODE_SF);
  9377. #if defined(__LITTLE_ENDIAN)
  9378. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9379. #else /*(__BIG_ENDIAN)*/
  9380. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9381. #endif
  9382. INIT_MODE_FLAGS(bp) = flags;
  9383. }
  9384. static int bnx2x_init_bp(struct bnx2x *bp)
  9385. {
  9386. int func;
  9387. int rc;
  9388. mutex_init(&bp->port.phy_mutex);
  9389. mutex_init(&bp->fw_mb_mutex);
  9390. spin_lock_init(&bp->stats_lock);
  9391. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9392. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9393. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9394. if (IS_PF(bp)) {
  9395. rc = bnx2x_get_hwinfo(bp);
  9396. if (rc)
  9397. return rc;
  9398. } else {
  9399. random_ether_addr(bp->dev->dev_addr);
  9400. }
  9401. bnx2x_set_modes_bitmap(bp);
  9402. rc = bnx2x_alloc_mem_bp(bp);
  9403. if (rc)
  9404. return rc;
  9405. bnx2x_read_fwinfo(bp);
  9406. func = BP_FUNC(bp);
  9407. /* need to reset chip if undi was active */
  9408. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9409. /* init fw_seq */
  9410. bp->fw_seq =
  9411. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9412. DRV_MSG_SEQ_NUMBER_MASK;
  9413. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9414. bnx2x_prev_unload(bp);
  9415. }
  9416. if (CHIP_REV_IS_FPGA(bp))
  9417. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9418. if (BP_NOMCP(bp) && (func == 0))
  9419. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9420. bp->disable_tpa = disable_tpa;
  9421. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9422. /* Set TPA flags */
  9423. if (bp->disable_tpa) {
  9424. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9425. bp->dev->features &= ~NETIF_F_LRO;
  9426. } else {
  9427. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9428. bp->dev->features |= NETIF_F_LRO;
  9429. }
  9430. if (CHIP_IS_E1(bp))
  9431. bp->dropless_fc = 0;
  9432. else
  9433. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9434. bp->mrrs = mrrs;
  9435. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9436. if (IS_VF(bp))
  9437. bp->rx_ring_size = MAX_RX_AVAIL;
  9438. /* make sure that the numbers are in the right granularity */
  9439. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9440. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9441. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9442. init_timer(&bp->timer);
  9443. bp->timer.expires = jiffies + bp->current_interval;
  9444. bp->timer.data = (unsigned long) bp;
  9445. bp->timer.function = bnx2x_timer;
  9446. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9447. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9448. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9449. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9450. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9451. bnx2x_dcbx_init_params(bp);
  9452. } else {
  9453. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9454. }
  9455. if (CHIP_IS_E1x(bp))
  9456. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9457. else
  9458. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9459. /* multiple tx priority */
  9460. if (IS_VF(bp))
  9461. bp->max_cos = 1;
  9462. else if (CHIP_IS_E1x(bp))
  9463. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9464. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9465. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9466. else if (CHIP_IS_E3B0(bp))
  9467. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9468. else
  9469. BNX2X_ERR("unknown chip %x revision %x\n",
  9470. CHIP_NUM(bp), CHIP_REV(bp));
  9471. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9472. /* We need at least one default status block for slow-path events,
  9473. * second status block for the L2 queue, and a third status block for
  9474. * CNIC if supproted.
  9475. */
  9476. if (CNIC_SUPPORT(bp))
  9477. bp->min_msix_vec_cnt = 3;
  9478. else
  9479. bp->min_msix_vec_cnt = 2;
  9480. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9481. return rc;
  9482. }
  9483. /****************************************************************************
  9484. * General service functions
  9485. ****************************************************************************/
  9486. /*
  9487. * net_device service functions
  9488. */
  9489. /* called with rtnl_lock */
  9490. static int bnx2x_open(struct net_device *dev)
  9491. {
  9492. struct bnx2x *bp = netdev_priv(dev);
  9493. bool global = false;
  9494. int other_engine = BP_PATH(bp) ? 0 : 1;
  9495. bool other_load_status, load_status;
  9496. bp->stats_init = true;
  9497. netif_carrier_off(dev);
  9498. bnx2x_set_power_state(bp, PCI_D0);
  9499. /* If parity had happen during the unload, then attentions
  9500. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9501. * want the first function loaded on the current engine to
  9502. * complete the recovery.
  9503. * Parity recovery is only relevant for PF driver.
  9504. */
  9505. if (IS_PF(bp)) {
  9506. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9507. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9508. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9509. bnx2x_chk_parity_attn(bp, &global, true)) {
  9510. do {
  9511. /* If there are attentions and they are in a
  9512. * global blocks, set the GLOBAL_RESET bit
  9513. * regardless whether it will be this function
  9514. * that will complete the recovery or not.
  9515. */
  9516. if (global)
  9517. bnx2x_set_reset_global(bp);
  9518. /* Only the first function on the current
  9519. * engine should try to recover in open. In case
  9520. * of attentions in global blocks only the first
  9521. * in the chip should try to recover.
  9522. */
  9523. if ((!load_status &&
  9524. (!global || !other_load_status)) &&
  9525. bnx2x_trylock_leader_lock(bp) &&
  9526. !bnx2x_leader_reset(bp)) {
  9527. netdev_info(bp->dev,
  9528. "Recovered in open\n");
  9529. break;
  9530. }
  9531. /* recovery has failed... */
  9532. bnx2x_set_power_state(bp, PCI_D3hot);
  9533. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9534. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9535. "If you still see this message after a few retries then power cycle is required.\n");
  9536. return -EAGAIN;
  9537. } while (0);
  9538. }
  9539. }
  9540. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9541. return bnx2x_nic_load(bp, LOAD_OPEN);
  9542. }
  9543. /* called with rtnl_lock */
  9544. static int bnx2x_close(struct net_device *dev)
  9545. {
  9546. struct bnx2x *bp = netdev_priv(dev);
  9547. /* Unload the driver, release IRQs */
  9548. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9549. /* Power off */
  9550. bnx2x_set_power_state(bp, PCI_D3hot);
  9551. return 0;
  9552. }
  9553. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9554. struct bnx2x_mcast_ramrod_params *p)
  9555. {
  9556. int mc_count = netdev_mc_count(bp->dev);
  9557. struct bnx2x_mcast_list_elem *mc_mac =
  9558. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9559. struct netdev_hw_addr *ha;
  9560. if (!mc_mac)
  9561. return -ENOMEM;
  9562. INIT_LIST_HEAD(&p->mcast_list);
  9563. netdev_for_each_mc_addr(ha, bp->dev) {
  9564. mc_mac->mac = bnx2x_mc_addr(ha);
  9565. list_add_tail(&mc_mac->link, &p->mcast_list);
  9566. mc_mac++;
  9567. }
  9568. p->mcast_list_len = mc_count;
  9569. return 0;
  9570. }
  9571. static void bnx2x_free_mcast_macs_list(
  9572. struct bnx2x_mcast_ramrod_params *p)
  9573. {
  9574. struct bnx2x_mcast_list_elem *mc_mac =
  9575. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9576. link);
  9577. WARN_ON(!mc_mac);
  9578. kfree(mc_mac);
  9579. }
  9580. /**
  9581. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9582. *
  9583. * @bp: driver handle
  9584. *
  9585. * We will use zero (0) as a MAC type for these MACs.
  9586. */
  9587. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9588. {
  9589. int rc;
  9590. struct net_device *dev = bp->dev;
  9591. struct netdev_hw_addr *ha;
  9592. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9593. unsigned long ramrod_flags = 0;
  9594. /* First schedule a cleanup up of old configuration */
  9595. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9596. if (rc < 0) {
  9597. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9598. return rc;
  9599. }
  9600. netdev_for_each_uc_addr(ha, dev) {
  9601. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9602. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9603. if (rc == -EEXIST) {
  9604. DP(BNX2X_MSG_SP,
  9605. "Failed to schedule ADD operations: %d\n", rc);
  9606. /* do not treat adding same MAC as error */
  9607. rc = 0;
  9608. } else if (rc < 0) {
  9609. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9610. rc);
  9611. return rc;
  9612. }
  9613. }
  9614. /* Execute the pending commands */
  9615. __set_bit(RAMROD_CONT, &ramrod_flags);
  9616. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9617. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9618. }
  9619. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9620. {
  9621. struct net_device *dev = bp->dev;
  9622. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9623. int rc = 0;
  9624. rparam.mcast_obj = &bp->mcast_obj;
  9625. /* first, clear all configured multicast MACs */
  9626. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9627. if (rc < 0) {
  9628. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9629. return rc;
  9630. }
  9631. /* then, configure a new MACs list */
  9632. if (netdev_mc_count(dev)) {
  9633. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9634. if (rc) {
  9635. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9636. rc);
  9637. return rc;
  9638. }
  9639. /* Now add the new MACs */
  9640. rc = bnx2x_config_mcast(bp, &rparam,
  9641. BNX2X_MCAST_CMD_ADD);
  9642. if (rc < 0)
  9643. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9644. rc);
  9645. bnx2x_free_mcast_macs_list(&rparam);
  9646. }
  9647. return rc;
  9648. }
  9649. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9650. void bnx2x_set_rx_mode(struct net_device *dev)
  9651. {
  9652. struct bnx2x *bp = netdev_priv(dev);
  9653. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9654. if (bp->state != BNX2X_STATE_OPEN) {
  9655. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9656. return;
  9657. }
  9658. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9659. if (dev->flags & IFF_PROMISC)
  9660. rx_mode = BNX2X_RX_MODE_PROMISC;
  9661. else if ((dev->flags & IFF_ALLMULTI) ||
  9662. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9663. CHIP_IS_E1(bp)))
  9664. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9665. else {
  9666. if (IS_PF(bp)) {
  9667. /* some multicasts */
  9668. if (bnx2x_set_mc_list(bp) < 0)
  9669. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9670. if (bnx2x_set_uc_list(bp) < 0)
  9671. rx_mode = BNX2X_RX_MODE_PROMISC;
  9672. } else {
  9673. /* configuring mcast to a vf involves sleeping (when we
  9674. * wait for the pf's response). Since this function is
  9675. * called from non sleepable context we must schedule
  9676. * a work item for this purpose
  9677. */
  9678. smp_mb__before_clear_bit();
  9679. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9680. &bp->sp_rtnl_state);
  9681. smp_mb__after_clear_bit();
  9682. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9683. }
  9684. }
  9685. bp->rx_mode = rx_mode;
  9686. /* handle ISCSI SD mode */
  9687. if (IS_MF_ISCSI_SD(bp))
  9688. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9689. /* Schedule the rx_mode command */
  9690. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9691. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9692. return;
  9693. }
  9694. if (IS_PF(bp)) {
  9695. bnx2x_set_storm_rx_mode(bp);
  9696. } else {
  9697. /* configuring rx mode to storms in a vf involves sleeping (when
  9698. * we wait for the pf's response). Since this function is
  9699. * called from non sleepable context we must schedule
  9700. * a work item for this purpose
  9701. */
  9702. smp_mb__before_clear_bit();
  9703. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9704. &bp->sp_rtnl_state);
  9705. smp_mb__after_clear_bit();
  9706. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9707. }
  9708. }
  9709. /* called with rtnl_lock */
  9710. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9711. int devad, u16 addr)
  9712. {
  9713. struct bnx2x *bp = netdev_priv(netdev);
  9714. u16 value;
  9715. int rc;
  9716. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9717. prtad, devad, addr);
  9718. /* The HW expects different devad if CL22 is used */
  9719. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9720. bnx2x_acquire_phy_lock(bp);
  9721. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9722. bnx2x_release_phy_lock(bp);
  9723. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9724. if (!rc)
  9725. rc = value;
  9726. return rc;
  9727. }
  9728. /* called with rtnl_lock */
  9729. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9730. u16 addr, u16 value)
  9731. {
  9732. struct bnx2x *bp = netdev_priv(netdev);
  9733. int rc;
  9734. DP(NETIF_MSG_LINK,
  9735. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9736. prtad, devad, addr, value);
  9737. /* The HW expects different devad if CL22 is used */
  9738. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9739. bnx2x_acquire_phy_lock(bp);
  9740. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9741. bnx2x_release_phy_lock(bp);
  9742. return rc;
  9743. }
  9744. /* called with rtnl_lock */
  9745. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9746. {
  9747. struct bnx2x *bp = netdev_priv(dev);
  9748. struct mii_ioctl_data *mdio = if_mii(ifr);
  9749. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9750. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9751. if (!netif_running(dev))
  9752. return -EAGAIN;
  9753. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9754. }
  9755. #ifdef CONFIG_NET_POLL_CONTROLLER
  9756. static void poll_bnx2x(struct net_device *dev)
  9757. {
  9758. struct bnx2x *bp = netdev_priv(dev);
  9759. int i;
  9760. for_each_eth_queue(bp, i) {
  9761. struct bnx2x_fastpath *fp = &bp->fp[i];
  9762. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9763. }
  9764. }
  9765. #endif
  9766. static int bnx2x_validate_addr(struct net_device *dev)
  9767. {
  9768. struct bnx2x *bp = netdev_priv(dev);
  9769. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9770. BNX2X_ERR("Non-valid Ethernet address\n");
  9771. return -EADDRNOTAVAIL;
  9772. }
  9773. return 0;
  9774. }
  9775. static const struct net_device_ops bnx2x_netdev_ops = {
  9776. .ndo_open = bnx2x_open,
  9777. .ndo_stop = bnx2x_close,
  9778. .ndo_start_xmit = bnx2x_start_xmit,
  9779. .ndo_select_queue = bnx2x_select_queue,
  9780. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9781. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9782. .ndo_validate_addr = bnx2x_validate_addr,
  9783. .ndo_do_ioctl = bnx2x_ioctl,
  9784. .ndo_change_mtu = bnx2x_change_mtu,
  9785. .ndo_fix_features = bnx2x_fix_features,
  9786. .ndo_set_features = bnx2x_set_features,
  9787. .ndo_tx_timeout = bnx2x_tx_timeout,
  9788. #ifdef CONFIG_NET_POLL_CONTROLLER
  9789. .ndo_poll_controller = poll_bnx2x,
  9790. #endif
  9791. .ndo_setup_tc = bnx2x_setup_tc,
  9792. #ifdef NETDEV_FCOE_WWNN
  9793. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9794. #endif
  9795. };
  9796. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9797. {
  9798. struct device *dev = &bp->pdev->dev;
  9799. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9800. bp->flags |= USING_DAC_FLAG;
  9801. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9802. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9803. return -EIO;
  9804. }
  9805. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9806. dev_err(dev, "System does not support DMA, aborting\n");
  9807. return -EIO;
  9808. }
  9809. return 0;
  9810. }
  9811. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9812. struct net_device *dev, unsigned long board_type)
  9813. {
  9814. int rc;
  9815. u32 pci_cfg_dword;
  9816. bool chip_is_e1x = (board_type == BCM57710 ||
  9817. board_type == BCM57711 ||
  9818. board_type == BCM57711E);
  9819. SET_NETDEV_DEV(dev, &pdev->dev);
  9820. bp->dev = dev;
  9821. bp->pdev = pdev;
  9822. rc = pci_enable_device(pdev);
  9823. if (rc) {
  9824. dev_err(&bp->pdev->dev,
  9825. "Cannot enable PCI device, aborting\n");
  9826. goto err_out;
  9827. }
  9828. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9829. dev_err(&bp->pdev->dev,
  9830. "Cannot find PCI device base address, aborting\n");
  9831. rc = -ENODEV;
  9832. goto err_out_disable;
  9833. }
  9834. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9835. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9836. rc = -ENODEV;
  9837. goto err_out_disable;
  9838. }
  9839. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9840. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9841. PCICFG_REVESION_ID_ERROR_VAL) {
  9842. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9843. rc = -ENODEV;
  9844. goto err_out_disable;
  9845. }
  9846. if (atomic_read(&pdev->enable_cnt) == 1) {
  9847. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9848. if (rc) {
  9849. dev_err(&bp->pdev->dev,
  9850. "Cannot obtain PCI resources, aborting\n");
  9851. goto err_out_disable;
  9852. }
  9853. pci_set_master(pdev);
  9854. pci_save_state(pdev);
  9855. }
  9856. if (IS_PF(bp)) {
  9857. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9858. if (bp->pm_cap == 0) {
  9859. dev_err(&bp->pdev->dev,
  9860. "Cannot find power management capability, aborting\n");
  9861. rc = -EIO;
  9862. goto err_out_release;
  9863. }
  9864. }
  9865. if (!pci_is_pcie(pdev)) {
  9866. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9867. rc = -EIO;
  9868. goto err_out_release;
  9869. }
  9870. rc = bnx2x_set_coherency_mask(bp);
  9871. if (rc)
  9872. goto err_out_release;
  9873. dev->mem_start = pci_resource_start(pdev, 0);
  9874. dev->base_addr = dev->mem_start;
  9875. dev->mem_end = pci_resource_end(pdev, 0);
  9876. dev->irq = pdev->irq;
  9877. bp->regview = pci_ioremap_bar(pdev, 0);
  9878. if (!bp->regview) {
  9879. dev_err(&bp->pdev->dev,
  9880. "Cannot map register space, aborting\n");
  9881. rc = -ENOMEM;
  9882. goto err_out_release;
  9883. }
  9884. /* In E1/E1H use pci device function given by kernel.
  9885. * In E2/E3 read physical function from ME register since these chips
  9886. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9887. * (depending on hypervisor).
  9888. */
  9889. if (chip_is_e1x)
  9890. bp->pf_num = PCI_FUNC(pdev->devfn);
  9891. else {/* chip is E2/3*/
  9892. pci_read_config_dword(bp->pdev,
  9893. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9894. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9895. ME_REG_ABS_PF_NUM_SHIFT);
  9896. }
  9897. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9898. bnx2x_set_power_state(bp, PCI_D0);
  9899. /* clean indirect addresses */
  9900. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9901. PCICFG_VENDOR_ID_OFFSET);
  9902. /*
  9903. * Clean the following indirect addresses for all functions since it
  9904. * is not used by the driver.
  9905. */
  9906. if (IS_PF(bp)) {
  9907. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9908. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9909. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9910. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9911. if (chip_is_e1x) {
  9912. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9913. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9914. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9915. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9916. }
  9917. /* Enable internal target-read (in case we are probed after PF
  9918. * FLR). Must be done prior to any BAR read access. Only for
  9919. * 57712 and up
  9920. */
  9921. if (!chip_is_e1x)
  9922. REG_WR(bp,
  9923. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9924. }
  9925. dev->watchdog_timeo = TX_TIMEOUT;
  9926. dev->netdev_ops = &bnx2x_netdev_ops;
  9927. bnx2x_set_ethtool_ops(dev);
  9928. dev->priv_flags |= IFF_UNICAST_FLT;
  9929. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9930. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9931. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9932. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9933. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9934. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9935. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9936. if (bp->flags & USING_DAC_FLAG)
  9937. dev->features |= NETIF_F_HIGHDMA;
  9938. /* Add Loopback capability to the device */
  9939. dev->hw_features |= NETIF_F_LOOPBACK;
  9940. #ifdef BCM_DCBNL
  9941. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9942. #endif
  9943. /* get_port_hwinfo() will set prtad and mmds properly */
  9944. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9945. bp->mdio.mmds = 0;
  9946. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9947. bp->mdio.dev = dev;
  9948. bp->mdio.mdio_read = bnx2x_mdio_read;
  9949. bp->mdio.mdio_write = bnx2x_mdio_write;
  9950. return 0;
  9951. err_out_release:
  9952. if (atomic_read(&pdev->enable_cnt) == 1)
  9953. pci_release_regions(pdev);
  9954. err_out_disable:
  9955. pci_disable_device(pdev);
  9956. pci_set_drvdata(pdev, NULL);
  9957. err_out:
  9958. return rc;
  9959. }
  9960. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  9961. {
  9962. u32 val = 0;
  9963. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  9964. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9965. /* return value of 1=2.5GHz 2=5GHz */
  9966. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9967. }
  9968. static int bnx2x_check_firmware(struct bnx2x *bp)
  9969. {
  9970. const struct firmware *firmware = bp->firmware;
  9971. struct bnx2x_fw_file_hdr *fw_hdr;
  9972. struct bnx2x_fw_file_section *sections;
  9973. u32 offset, len, num_ops;
  9974. u16 *ops_offsets;
  9975. int i;
  9976. const u8 *fw_ver;
  9977. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9978. BNX2X_ERR("Wrong FW size\n");
  9979. return -EINVAL;
  9980. }
  9981. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9982. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9983. /* Make sure none of the offsets and sizes make us read beyond
  9984. * the end of the firmware data */
  9985. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9986. offset = be32_to_cpu(sections[i].offset);
  9987. len = be32_to_cpu(sections[i].len);
  9988. if (offset + len > firmware->size) {
  9989. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9990. return -EINVAL;
  9991. }
  9992. }
  9993. /* Likewise for the init_ops offsets */
  9994. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9995. ops_offsets = (u16 *)(firmware->data + offset);
  9996. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9997. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9998. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9999. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10000. return -EINVAL;
  10001. }
  10002. }
  10003. /* Check FW version */
  10004. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10005. fw_ver = firmware->data + offset;
  10006. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10007. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10008. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10009. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10010. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10011. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10012. BCM_5710_FW_MAJOR_VERSION,
  10013. BCM_5710_FW_MINOR_VERSION,
  10014. BCM_5710_FW_REVISION_VERSION,
  10015. BCM_5710_FW_ENGINEERING_VERSION);
  10016. return -EINVAL;
  10017. }
  10018. return 0;
  10019. }
  10020. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10021. {
  10022. const __be32 *source = (const __be32 *)_source;
  10023. u32 *target = (u32 *)_target;
  10024. u32 i;
  10025. for (i = 0; i < n/4; i++)
  10026. target[i] = be32_to_cpu(source[i]);
  10027. }
  10028. /*
  10029. Ops array is stored in the following format:
  10030. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10031. */
  10032. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10033. {
  10034. const __be32 *source = (const __be32 *)_source;
  10035. struct raw_op *target = (struct raw_op *)_target;
  10036. u32 i, j, tmp;
  10037. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10038. tmp = be32_to_cpu(source[j]);
  10039. target[i].op = (tmp >> 24) & 0xff;
  10040. target[i].offset = tmp & 0xffffff;
  10041. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10042. }
  10043. }
  10044. /* IRO array is stored in the following format:
  10045. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10046. */
  10047. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10048. {
  10049. const __be32 *source = (const __be32 *)_source;
  10050. struct iro *target = (struct iro *)_target;
  10051. u32 i, j, tmp;
  10052. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10053. target[i].base = be32_to_cpu(source[j]);
  10054. j++;
  10055. tmp = be32_to_cpu(source[j]);
  10056. target[i].m1 = (tmp >> 16) & 0xffff;
  10057. target[i].m2 = tmp & 0xffff;
  10058. j++;
  10059. tmp = be32_to_cpu(source[j]);
  10060. target[i].m3 = (tmp >> 16) & 0xffff;
  10061. target[i].size = tmp & 0xffff;
  10062. j++;
  10063. }
  10064. }
  10065. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10066. {
  10067. const __be16 *source = (const __be16 *)_source;
  10068. u16 *target = (u16 *)_target;
  10069. u32 i;
  10070. for (i = 0; i < n/2; i++)
  10071. target[i] = be16_to_cpu(source[i]);
  10072. }
  10073. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10074. do { \
  10075. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10076. bp->arr = kmalloc(len, GFP_KERNEL); \
  10077. if (!bp->arr) \
  10078. goto lbl; \
  10079. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10080. (u8 *)bp->arr, len); \
  10081. } while (0)
  10082. static int bnx2x_init_firmware(struct bnx2x *bp)
  10083. {
  10084. const char *fw_file_name;
  10085. struct bnx2x_fw_file_hdr *fw_hdr;
  10086. int rc;
  10087. if (bp->firmware)
  10088. return 0;
  10089. if (CHIP_IS_E1(bp))
  10090. fw_file_name = FW_FILE_NAME_E1;
  10091. else if (CHIP_IS_E1H(bp))
  10092. fw_file_name = FW_FILE_NAME_E1H;
  10093. else if (!CHIP_IS_E1x(bp))
  10094. fw_file_name = FW_FILE_NAME_E2;
  10095. else {
  10096. BNX2X_ERR("Unsupported chip revision\n");
  10097. return -EINVAL;
  10098. }
  10099. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10100. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10101. if (rc) {
  10102. BNX2X_ERR("Can't load firmware file %s\n",
  10103. fw_file_name);
  10104. goto request_firmware_exit;
  10105. }
  10106. rc = bnx2x_check_firmware(bp);
  10107. if (rc) {
  10108. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10109. goto request_firmware_exit;
  10110. }
  10111. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10112. /* Initialize the pointers to the init arrays */
  10113. /* Blob */
  10114. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10115. /* Opcodes */
  10116. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10117. /* Offsets */
  10118. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10119. be16_to_cpu_n);
  10120. /* STORMs firmware */
  10121. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10122. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10123. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10124. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10125. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10126. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10127. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10128. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10129. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10130. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10131. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10132. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10133. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10134. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10135. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10136. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10137. /* IRO */
  10138. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10139. return 0;
  10140. iro_alloc_err:
  10141. kfree(bp->init_ops_offsets);
  10142. init_offsets_alloc_err:
  10143. kfree(bp->init_ops);
  10144. init_ops_alloc_err:
  10145. kfree(bp->init_data);
  10146. request_firmware_exit:
  10147. release_firmware(bp->firmware);
  10148. bp->firmware = NULL;
  10149. return rc;
  10150. }
  10151. static void bnx2x_release_firmware(struct bnx2x *bp)
  10152. {
  10153. kfree(bp->init_ops_offsets);
  10154. kfree(bp->init_ops);
  10155. kfree(bp->init_data);
  10156. release_firmware(bp->firmware);
  10157. bp->firmware = NULL;
  10158. }
  10159. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10160. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10161. .init_hw_cmn = bnx2x_init_hw_common,
  10162. .init_hw_port = bnx2x_init_hw_port,
  10163. .init_hw_func = bnx2x_init_hw_func,
  10164. .reset_hw_cmn = bnx2x_reset_common,
  10165. .reset_hw_port = bnx2x_reset_port,
  10166. .reset_hw_func = bnx2x_reset_func,
  10167. .gunzip_init = bnx2x_gunzip_init,
  10168. .gunzip_end = bnx2x_gunzip_end,
  10169. .init_fw = bnx2x_init_firmware,
  10170. .release_fw = bnx2x_release_firmware,
  10171. };
  10172. void bnx2x__init_func_obj(struct bnx2x *bp)
  10173. {
  10174. /* Prepare DMAE related driver resources */
  10175. bnx2x_setup_dmae(bp);
  10176. bnx2x_init_func_obj(bp, &bp->func_obj,
  10177. bnx2x_sp(bp, func_rdata),
  10178. bnx2x_sp_mapping(bp, func_rdata),
  10179. bnx2x_sp(bp, func_afex_rdata),
  10180. bnx2x_sp_mapping(bp, func_afex_rdata),
  10181. &bnx2x_func_sp_drv);
  10182. }
  10183. /* must be called after sriov-enable */
  10184. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10185. {
  10186. int cid_count = BNX2X_L2_MAX_CID(bp);
  10187. if (IS_SRIOV(bp))
  10188. cid_count += BNX2X_VF_CIDS;
  10189. if (CNIC_SUPPORT(bp))
  10190. cid_count += CNIC_CID_MAX;
  10191. return roundup(cid_count, QM_CID_ROUND);
  10192. }
  10193. /**
  10194. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10195. *
  10196. * @dev: pci device
  10197. *
  10198. */
  10199. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10200. int cnic_cnt, bool is_vf)
  10201. {
  10202. int pos, index;
  10203. u16 control = 0;
  10204. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10205. /*
  10206. * If MSI-X is not supported - return number of SBs needed to support
  10207. * one fast path queue: one FP queue + SB for CNIC
  10208. */
  10209. if (!pos) {
  10210. dev_info(&pdev->dev, "no msix capability found\n");
  10211. return 1 + cnic_cnt;
  10212. }
  10213. dev_info(&pdev->dev, "msix capability found\n");
  10214. /*
  10215. * The value in the PCI configuration space is the index of the last
  10216. * entry, namely one less than the actual size of the table, which is
  10217. * exactly what we want to return from this function: number of all SBs
  10218. * without the default SB.
  10219. * For VFs there is no default SB, then we return (index+1).
  10220. */
  10221. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10222. index = control & PCI_MSIX_FLAGS_QSIZE;
  10223. return is_vf ? index + 1 : index;
  10224. }
  10225. static int set_max_cos_est(int chip_id)
  10226. {
  10227. switch (chip_id) {
  10228. case BCM57710:
  10229. case BCM57711:
  10230. case BCM57711E:
  10231. return BNX2X_MULTI_TX_COS_E1X;
  10232. case BCM57712:
  10233. case BCM57712_MF:
  10234. case BCM57712_VF:
  10235. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10236. case BCM57800:
  10237. case BCM57800_MF:
  10238. case BCM57800_VF:
  10239. case BCM57810:
  10240. case BCM57810_MF:
  10241. case BCM57840_4_10:
  10242. case BCM57840_2_20:
  10243. case BCM57840_O:
  10244. case BCM57840_MFO:
  10245. case BCM57810_VF:
  10246. case BCM57840_MF:
  10247. case BCM57840_VF:
  10248. case BCM57811:
  10249. case BCM57811_MF:
  10250. case BCM57811_VF:
  10251. return BNX2X_MULTI_TX_COS_E3B0;
  10252. return 1;
  10253. default:
  10254. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10255. return -ENODEV;
  10256. }
  10257. }
  10258. static int set_is_vf(int chip_id)
  10259. {
  10260. switch (chip_id) {
  10261. case BCM57712_VF:
  10262. case BCM57800_VF:
  10263. case BCM57810_VF:
  10264. case BCM57840_VF:
  10265. case BCM57811_VF:
  10266. return true;
  10267. default:
  10268. return false;
  10269. }
  10270. }
  10271. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10272. static int bnx2x_init_one(struct pci_dev *pdev,
  10273. const struct pci_device_id *ent)
  10274. {
  10275. struct net_device *dev = NULL;
  10276. struct bnx2x *bp;
  10277. int pcie_width, pcie_speed;
  10278. int rc, max_non_def_sbs;
  10279. int rx_count, tx_count, rss_count, doorbell_size;
  10280. int max_cos_est;
  10281. bool is_vf;
  10282. int cnic_cnt;
  10283. /* An estimated maximum supported CoS number according to the chip
  10284. * version.
  10285. * We will try to roughly estimate the maximum number of CoSes this chip
  10286. * may support in order to minimize the memory allocated for Tx
  10287. * netdev_queue's. This number will be accurately calculated during the
  10288. * initialization of bp->max_cos based on the chip versions AND chip
  10289. * revision in the bnx2x_init_bp().
  10290. */
  10291. max_cos_est = set_max_cos_est(ent->driver_data);
  10292. if (max_cos_est < 0)
  10293. return max_cos_est;
  10294. is_vf = set_is_vf(ent->driver_data);
  10295. cnic_cnt = is_vf ? 0 : 1;
  10296. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10297. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10298. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10299. if (rss_count < 1)
  10300. return -EINVAL;
  10301. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10302. rx_count = rss_count + cnic_cnt;
  10303. /* Maximum number of netdev Tx queues:
  10304. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10305. */
  10306. tx_count = rss_count * max_cos_est + cnic_cnt;
  10307. /* dev zeroed in init_etherdev */
  10308. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10309. if (!dev)
  10310. return -ENOMEM;
  10311. bp = netdev_priv(dev);
  10312. bp->flags = 0;
  10313. if (is_vf)
  10314. bp->flags |= IS_VF_FLAG;
  10315. bp->igu_sb_cnt = max_non_def_sbs;
  10316. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10317. bp->msg_enable = debug;
  10318. bp->cnic_support = cnic_cnt;
  10319. bp->cnic_probe = bnx2x_cnic_probe;
  10320. pci_set_drvdata(pdev, dev);
  10321. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10322. if (rc < 0) {
  10323. free_netdev(dev);
  10324. return rc;
  10325. }
  10326. BNX2X_DEV_INFO("This is a %s function\n",
  10327. IS_PF(bp) ? "physical" : "virtual");
  10328. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10329. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10330. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10331. tx_count, rx_count);
  10332. rc = bnx2x_init_bp(bp);
  10333. if (rc)
  10334. goto init_one_exit;
  10335. /* Map doorbells here as we need the real value of bp->max_cos which
  10336. * is initialized in bnx2x_init_bp() to determine the number of
  10337. * l2 connections.
  10338. */
  10339. if (IS_VF(bp)) {
  10340. /* vf doorbells are embedded within the regview */
  10341. bp->doorbells = bp->regview + PXP_VF_ADDR_DB_START;
  10342. /* allocate vf2pf mailbox for vf to pf channel */
  10343. BNX2X_PCI_ALLOC(bp->vf2pf_mbox, &bp->vf2pf_mbox_mapping,
  10344. sizeof(struct bnx2x_vf_mbx_msg));
  10345. } else {
  10346. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10347. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10348. dev_err(&bp->pdev->dev,
  10349. "Cannot map doorbells, bar size too small, aborting\n");
  10350. rc = -ENOMEM;
  10351. goto init_one_exit;
  10352. }
  10353. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10354. doorbell_size);
  10355. }
  10356. if (!bp->doorbells) {
  10357. dev_err(&bp->pdev->dev,
  10358. "Cannot map doorbell space, aborting\n");
  10359. rc = -ENOMEM;
  10360. goto init_one_exit;
  10361. }
  10362. if (IS_VF(bp)) {
  10363. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10364. if (rc)
  10365. goto init_one_exit;
  10366. }
  10367. /* Enable SRIOV if capability found in configuration space.
  10368. * Once the generic SR-IOV framework makes it in from the
  10369. * pci tree this will be revised, to allow dynamic control
  10370. * over the number of VFs. Right now, change the num of vfs
  10371. * param below to enable SR-IOV.
  10372. */
  10373. rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/);
  10374. if (rc)
  10375. goto init_one_exit;
  10376. /* calc qm_cid_count */
  10377. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10378. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10379. /* disable FCOE L2 queue for E1x*/
  10380. if (CHIP_IS_E1x(bp))
  10381. bp->flags |= NO_FCOE_FLAG;
  10382. /* disable FCOE for 57840 device, until FW supports it */
  10383. switch (ent->driver_data) {
  10384. case BCM57840_O:
  10385. case BCM57840_4_10:
  10386. case BCM57840_2_20:
  10387. case BCM57840_MFO:
  10388. case BCM57840_MF:
  10389. bp->flags |= NO_FCOE_FLAG;
  10390. }
  10391. /* Set bp->num_queues for MSI-X mode*/
  10392. bnx2x_set_num_queues(bp);
  10393. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10394. * needed.
  10395. */
  10396. rc = bnx2x_set_int_mode(bp);
  10397. if (rc) {
  10398. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10399. goto init_one_exit;
  10400. }
  10401. /* register the net device */
  10402. rc = register_netdev(dev);
  10403. if (rc) {
  10404. dev_err(&pdev->dev, "Cannot register net device\n");
  10405. goto init_one_exit;
  10406. }
  10407. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10408. if (!NO_FCOE(bp)) {
  10409. /* Add storage MAC address */
  10410. rtnl_lock();
  10411. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10412. rtnl_unlock();
  10413. }
  10414. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10415. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10416. pcie_width, pcie_speed);
  10417. BNX2X_DEV_INFO(
  10418. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10419. board_info[ent->driver_data].name,
  10420. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10421. pcie_width,
  10422. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10423. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10424. "5GHz (Gen2)" : "2.5GHz",
  10425. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10426. return 0;
  10427. alloc_mem_err:
  10428. BNX2X_PCI_FREE(bp->vf2pf_mbox, bp->vf2pf_mbox_mapping,
  10429. sizeof(struct bnx2x_vf_mbx_msg));
  10430. rc = -ENOMEM;
  10431. init_one_exit:
  10432. if (bp->regview)
  10433. iounmap(bp->regview);
  10434. if (IS_PF(bp) && bp->doorbells)
  10435. iounmap(bp->doorbells);
  10436. free_netdev(dev);
  10437. if (atomic_read(&pdev->enable_cnt) == 1)
  10438. pci_release_regions(pdev);
  10439. pci_disable_device(pdev);
  10440. pci_set_drvdata(pdev, NULL);
  10441. return rc;
  10442. }
  10443. static void bnx2x_remove_one(struct pci_dev *pdev)
  10444. {
  10445. struct net_device *dev = pci_get_drvdata(pdev);
  10446. struct bnx2x *bp;
  10447. if (!dev) {
  10448. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10449. return;
  10450. }
  10451. bp = netdev_priv(dev);
  10452. /* Delete storage MAC address */
  10453. if (!NO_FCOE(bp)) {
  10454. rtnl_lock();
  10455. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10456. rtnl_unlock();
  10457. }
  10458. #ifdef BCM_DCBNL
  10459. /* Delete app tlvs from dcbnl */
  10460. bnx2x_dcbnl_update_applist(bp, true);
  10461. #endif
  10462. unregister_netdev(dev);
  10463. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10464. if (IS_PF(bp))
  10465. bnx2x_set_power_state(bp, PCI_D0);
  10466. /* Disable MSI/MSI-X */
  10467. bnx2x_disable_msi(bp);
  10468. /* Power off */
  10469. if (IS_PF(bp))
  10470. bnx2x_set_power_state(bp, PCI_D3hot);
  10471. /* Make sure RESET task is not scheduled before continuing */
  10472. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10473. bnx2x_iov_remove_one(bp);
  10474. /* send message via vfpf channel to release the resources of this vf */
  10475. if (IS_VF(bp))
  10476. bnx2x_vfpf_release(bp);
  10477. if (bp->regview)
  10478. iounmap(bp->regview);
  10479. /* for vf doorbells are part of the regview and were unmapped along with
  10480. * it. FW is only loaded by PF.
  10481. */
  10482. if (IS_PF(bp)) {
  10483. if (bp->doorbells)
  10484. iounmap(bp->doorbells);
  10485. bnx2x_release_firmware(bp);
  10486. }
  10487. bnx2x_free_mem_bp(bp);
  10488. free_netdev(dev);
  10489. if (atomic_read(&pdev->enable_cnt) == 1)
  10490. pci_release_regions(pdev);
  10491. pci_disable_device(pdev);
  10492. pci_set_drvdata(pdev, NULL);
  10493. }
  10494. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10495. {
  10496. int i;
  10497. bp->state = BNX2X_STATE_ERROR;
  10498. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10499. if (CNIC_LOADED(bp))
  10500. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10501. /* Stop Tx */
  10502. bnx2x_tx_disable(bp);
  10503. bnx2x_netif_stop(bp, 0);
  10504. /* Delete all NAPI objects */
  10505. bnx2x_del_all_napi(bp);
  10506. if (CNIC_LOADED(bp))
  10507. bnx2x_del_all_napi_cnic(bp);
  10508. del_timer_sync(&bp->timer);
  10509. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10510. /* Release IRQs */
  10511. bnx2x_free_irq(bp);
  10512. /* Free SKBs, SGEs, TPA pool and driver internals */
  10513. bnx2x_free_skbs(bp);
  10514. for_each_rx_queue(bp, i)
  10515. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10516. bnx2x_free_mem(bp);
  10517. bp->state = BNX2X_STATE_CLOSED;
  10518. netif_carrier_off(bp->dev);
  10519. return 0;
  10520. }
  10521. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10522. {
  10523. u32 val;
  10524. mutex_init(&bp->port.phy_mutex);
  10525. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10526. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10527. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10528. BNX2X_ERR("BAD MCP validity signature\n");
  10529. }
  10530. /**
  10531. * bnx2x_io_error_detected - called when PCI error is detected
  10532. * @pdev: Pointer to PCI device
  10533. * @state: The current pci connection state
  10534. *
  10535. * This function is called after a PCI bus error affecting
  10536. * this device has been detected.
  10537. */
  10538. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10539. pci_channel_state_t state)
  10540. {
  10541. struct net_device *dev = pci_get_drvdata(pdev);
  10542. struct bnx2x *bp = netdev_priv(dev);
  10543. rtnl_lock();
  10544. netif_device_detach(dev);
  10545. if (state == pci_channel_io_perm_failure) {
  10546. rtnl_unlock();
  10547. return PCI_ERS_RESULT_DISCONNECT;
  10548. }
  10549. if (netif_running(dev))
  10550. bnx2x_eeh_nic_unload(bp);
  10551. pci_disable_device(pdev);
  10552. rtnl_unlock();
  10553. /* Request a slot reset */
  10554. return PCI_ERS_RESULT_NEED_RESET;
  10555. }
  10556. /**
  10557. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10558. * @pdev: Pointer to PCI device
  10559. *
  10560. * Restart the card from scratch, as if from a cold-boot.
  10561. */
  10562. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10563. {
  10564. struct net_device *dev = pci_get_drvdata(pdev);
  10565. struct bnx2x *bp = netdev_priv(dev);
  10566. rtnl_lock();
  10567. if (pci_enable_device(pdev)) {
  10568. dev_err(&pdev->dev,
  10569. "Cannot re-enable PCI device after reset\n");
  10570. rtnl_unlock();
  10571. return PCI_ERS_RESULT_DISCONNECT;
  10572. }
  10573. pci_set_master(pdev);
  10574. pci_restore_state(pdev);
  10575. if (netif_running(dev))
  10576. bnx2x_set_power_state(bp, PCI_D0);
  10577. rtnl_unlock();
  10578. return PCI_ERS_RESULT_RECOVERED;
  10579. }
  10580. /**
  10581. * bnx2x_io_resume - called when traffic can start flowing again
  10582. * @pdev: Pointer to PCI device
  10583. *
  10584. * This callback is called when the error recovery driver tells us that
  10585. * its OK to resume normal operation.
  10586. */
  10587. static void bnx2x_io_resume(struct pci_dev *pdev)
  10588. {
  10589. struct net_device *dev = pci_get_drvdata(pdev);
  10590. struct bnx2x *bp = netdev_priv(dev);
  10591. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10592. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10593. return;
  10594. }
  10595. rtnl_lock();
  10596. bnx2x_eeh_recover(bp);
  10597. if (netif_running(dev))
  10598. bnx2x_nic_load(bp, LOAD_NORMAL);
  10599. netif_device_attach(dev);
  10600. rtnl_unlock();
  10601. }
  10602. static const struct pci_error_handlers bnx2x_err_handler = {
  10603. .error_detected = bnx2x_io_error_detected,
  10604. .slot_reset = bnx2x_io_slot_reset,
  10605. .resume = bnx2x_io_resume,
  10606. };
  10607. static struct pci_driver bnx2x_pci_driver = {
  10608. .name = DRV_MODULE_NAME,
  10609. .id_table = bnx2x_pci_tbl,
  10610. .probe = bnx2x_init_one,
  10611. .remove = bnx2x_remove_one,
  10612. .suspend = bnx2x_suspend,
  10613. .resume = bnx2x_resume,
  10614. .err_handler = &bnx2x_err_handler,
  10615. };
  10616. static int __init bnx2x_init(void)
  10617. {
  10618. int ret;
  10619. pr_info("%s", version);
  10620. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10621. if (bnx2x_wq == NULL) {
  10622. pr_err("Cannot create workqueue\n");
  10623. return -ENOMEM;
  10624. }
  10625. ret = pci_register_driver(&bnx2x_pci_driver);
  10626. if (ret) {
  10627. pr_err("Cannot register driver\n");
  10628. destroy_workqueue(bnx2x_wq);
  10629. }
  10630. return ret;
  10631. }
  10632. static void __exit bnx2x_cleanup(void)
  10633. {
  10634. struct list_head *pos, *q;
  10635. pci_unregister_driver(&bnx2x_pci_driver);
  10636. destroy_workqueue(bnx2x_wq);
  10637. /* Free globablly allocated resources */
  10638. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10639. struct bnx2x_prev_path_list *tmp =
  10640. list_entry(pos, struct bnx2x_prev_path_list, list);
  10641. list_del(pos);
  10642. kfree(tmp);
  10643. }
  10644. }
  10645. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10646. {
  10647. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10648. }
  10649. module_init(bnx2x_init);
  10650. module_exit(bnx2x_cleanup);
  10651. /**
  10652. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10653. *
  10654. * @bp: driver handle
  10655. * @set: set or clear the CAM entry
  10656. *
  10657. * This function will wait until the ramdord completion returns.
  10658. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10659. */
  10660. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10661. {
  10662. unsigned long ramrod_flags = 0;
  10663. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10664. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10665. &bp->iscsi_l2_mac_obj, true,
  10666. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10667. }
  10668. /* count denotes the number of new completions we have seen */
  10669. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10670. {
  10671. struct eth_spe *spe;
  10672. int cxt_index, cxt_offset;
  10673. #ifdef BNX2X_STOP_ON_ERROR
  10674. if (unlikely(bp->panic))
  10675. return;
  10676. #endif
  10677. spin_lock_bh(&bp->spq_lock);
  10678. BUG_ON(bp->cnic_spq_pending < count);
  10679. bp->cnic_spq_pending -= count;
  10680. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10681. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10682. & SPE_HDR_CONN_TYPE) >>
  10683. SPE_HDR_CONN_TYPE_SHIFT;
  10684. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10685. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10686. /* Set validation for iSCSI L2 client before sending SETUP
  10687. * ramrod
  10688. */
  10689. if (type == ETH_CONNECTION_TYPE) {
  10690. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10691. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10692. ILT_PAGE_CIDS;
  10693. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10694. (cxt_index * ILT_PAGE_CIDS);
  10695. bnx2x_set_ctx_validation(bp,
  10696. &bp->context[cxt_index].
  10697. vcxt[cxt_offset].eth,
  10698. BNX2X_ISCSI_ETH_CID(bp));
  10699. }
  10700. }
  10701. /*
  10702. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10703. * and in the air. We also check that number of outstanding
  10704. * COMMON ramrods is not more than the EQ and SPQ can
  10705. * accommodate.
  10706. */
  10707. if (type == ETH_CONNECTION_TYPE) {
  10708. if (!atomic_read(&bp->cq_spq_left))
  10709. break;
  10710. else
  10711. atomic_dec(&bp->cq_spq_left);
  10712. } else if (type == NONE_CONNECTION_TYPE) {
  10713. if (!atomic_read(&bp->eq_spq_left))
  10714. break;
  10715. else
  10716. atomic_dec(&bp->eq_spq_left);
  10717. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10718. (type == FCOE_CONNECTION_TYPE)) {
  10719. if (bp->cnic_spq_pending >=
  10720. bp->cnic_eth_dev.max_kwqe_pending)
  10721. break;
  10722. else
  10723. bp->cnic_spq_pending++;
  10724. } else {
  10725. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10726. bnx2x_panic();
  10727. break;
  10728. }
  10729. spe = bnx2x_sp_get_next(bp);
  10730. *spe = *bp->cnic_kwq_cons;
  10731. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10732. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10733. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10734. bp->cnic_kwq_cons = bp->cnic_kwq;
  10735. else
  10736. bp->cnic_kwq_cons++;
  10737. }
  10738. bnx2x_sp_prod_update(bp);
  10739. spin_unlock_bh(&bp->spq_lock);
  10740. }
  10741. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10742. struct kwqe_16 *kwqes[], u32 count)
  10743. {
  10744. struct bnx2x *bp = netdev_priv(dev);
  10745. int i;
  10746. #ifdef BNX2X_STOP_ON_ERROR
  10747. if (unlikely(bp->panic)) {
  10748. BNX2X_ERR("Can't post to SP queue while panic\n");
  10749. return -EIO;
  10750. }
  10751. #endif
  10752. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10753. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10754. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10755. return -EAGAIN;
  10756. }
  10757. spin_lock_bh(&bp->spq_lock);
  10758. for (i = 0; i < count; i++) {
  10759. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10760. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10761. break;
  10762. *bp->cnic_kwq_prod = *spe;
  10763. bp->cnic_kwq_pending++;
  10764. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10765. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10766. spe->data.update_data_addr.hi,
  10767. spe->data.update_data_addr.lo,
  10768. bp->cnic_kwq_pending);
  10769. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10770. bp->cnic_kwq_prod = bp->cnic_kwq;
  10771. else
  10772. bp->cnic_kwq_prod++;
  10773. }
  10774. spin_unlock_bh(&bp->spq_lock);
  10775. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10776. bnx2x_cnic_sp_post(bp, 0);
  10777. return i;
  10778. }
  10779. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10780. {
  10781. struct cnic_ops *c_ops;
  10782. int rc = 0;
  10783. mutex_lock(&bp->cnic_mutex);
  10784. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10785. lockdep_is_held(&bp->cnic_mutex));
  10786. if (c_ops)
  10787. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10788. mutex_unlock(&bp->cnic_mutex);
  10789. return rc;
  10790. }
  10791. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10792. {
  10793. struct cnic_ops *c_ops;
  10794. int rc = 0;
  10795. rcu_read_lock();
  10796. c_ops = rcu_dereference(bp->cnic_ops);
  10797. if (c_ops)
  10798. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10799. rcu_read_unlock();
  10800. return rc;
  10801. }
  10802. /*
  10803. * for commands that have no data
  10804. */
  10805. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10806. {
  10807. struct cnic_ctl_info ctl = {0};
  10808. ctl.cmd = cmd;
  10809. return bnx2x_cnic_ctl_send(bp, &ctl);
  10810. }
  10811. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10812. {
  10813. struct cnic_ctl_info ctl = {0};
  10814. /* first we tell CNIC and only then we count this as a completion */
  10815. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10816. ctl.data.comp.cid = cid;
  10817. ctl.data.comp.error = err;
  10818. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10819. bnx2x_cnic_sp_post(bp, 0);
  10820. }
  10821. /* Called with netif_addr_lock_bh() taken.
  10822. * Sets an rx_mode config for an iSCSI ETH client.
  10823. * Doesn't block.
  10824. * Completion should be checked outside.
  10825. */
  10826. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10827. {
  10828. unsigned long accept_flags = 0, ramrod_flags = 0;
  10829. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10830. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10831. if (start) {
  10832. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10833. * because it's the only way for UIO Queue to accept
  10834. * multicasts (in non-promiscuous mode only one Queue per
  10835. * function will receive multicast packets (leading in our
  10836. * case).
  10837. */
  10838. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10839. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10840. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10841. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10842. /* Clear STOP_PENDING bit if START is requested */
  10843. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10844. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10845. } else
  10846. /* Clear START_PENDING bit if STOP is requested */
  10847. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10848. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10849. set_bit(sched_state, &bp->sp_state);
  10850. else {
  10851. __set_bit(RAMROD_RX, &ramrod_flags);
  10852. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10853. ramrod_flags);
  10854. }
  10855. }
  10856. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10857. {
  10858. struct bnx2x *bp = netdev_priv(dev);
  10859. int rc = 0;
  10860. switch (ctl->cmd) {
  10861. case DRV_CTL_CTXTBL_WR_CMD: {
  10862. u32 index = ctl->data.io.offset;
  10863. dma_addr_t addr = ctl->data.io.dma_addr;
  10864. bnx2x_ilt_wr(bp, index, addr);
  10865. break;
  10866. }
  10867. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10868. int count = ctl->data.credit.credit_count;
  10869. bnx2x_cnic_sp_post(bp, count);
  10870. break;
  10871. }
  10872. /* rtnl_lock is held. */
  10873. case DRV_CTL_START_L2_CMD: {
  10874. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10875. unsigned long sp_bits = 0;
  10876. /* Configure the iSCSI classification object */
  10877. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10878. cp->iscsi_l2_client_id,
  10879. cp->iscsi_l2_cid, BP_FUNC(bp),
  10880. bnx2x_sp(bp, mac_rdata),
  10881. bnx2x_sp_mapping(bp, mac_rdata),
  10882. BNX2X_FILTER_MAC_PENDING,
  10883. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10884. &bp->macs_pool);
  10885. /* Set iSCSI MAC address */
  10886. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10887. if (rc)
  10888. break;
  10889. mmiowb();
  10890. barrier();
  10891. /* Start accepting on iSCSI L2 ring */
  10892. netif_addr_lock_bh(dev);
  10893. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10894. netif_addr_unlock_bh(dev);
  10895. /* bits to wait on */
  10896. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10897. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10898. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10899. BNX2X_ERR("rx_mode completion timed out!\n");
  10900. break;
  10901. }
  10902. /* rtnl_lock is held. */
  10903. case DRV_CTL_STOP_L2_CMD: {
  10904. unsigned long sp_bits = 0;
  10905. /* Stop accepting on iSCSI L2 ring */
  10906. netif_addr_lock_bh(dev);
  10907. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10908. netif_addr_unlock_bh(dev);
  10909. /* bits to wait on */
  10910. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10911. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10912. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10913. BNX2X_ERR("rx_mode completion timed out!\n");
  10914. mmiowb();
  10915. barrier();
  10916. /* Unset iSCSI L2 MAC */
  10917. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10918. BNX2X_ISCSI_ETH_MAC, true);
  10919. break;
  10920. }
  10921. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10922. int count = ctl->data.credit.credit_count;
  10923. smp_mb__before_atomic_inc();
  10924. atomic_add(count, &bp->cq_spq_left);
  10925. smp_mb__after_atomic_inc();
  10926. break;
  10927. }
  10928. case DRV_CTL_ULP_REGISTER_CMD: {
  10929. int ulp_type = ctl->data.register_data.ulp_type;
  10930. if (CHIP_IS_E3(bp)) {
  10931. int idx = BP_FW_MB_IDX(bp);
  10932. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10933. int path = BP_PATH(bp);
  10934. int port = BP_PORT(bp);
  10935. int i;
  10936. u32 scratch_offset;
  10937. u32 *host_addr;
  10938. /* first write capability to shmem2 */
  10939. if (ulp_type == CNIC_ULP_ISCSI)
  10940. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10941. else if (ulp_type == CNIC_ULP_FCOE)
  10942. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10943. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10944. if ((ulp_type != CNIC_ULP_FCOE) ||
  10945. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  10946. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  10947. break;
  10948. /* if reached here - should write fcoe capabilities */
  10949. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  10950. if (!scratch_offset)
  10951. break;
  10952. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  10953. fcoe_features[path][port]);
  10954. host_addr = (u32 *) &(ctl->data.register_data.
  10955. fcoe_features);
  10956. for (i = 0; i < sizeof(struct fcoe_capabilities);
  10957. i += 4)
  10958. REG_WR(bp, scratch_offset + i,
  10959. *(host_addr + i/4));
  10960. }
  10961. break;
  10962. }
  10963. case DRV_CTL_ULP_UNREGISTER_CMD: {
  10964. int ulp_type = ctl->data.ulp_type;
  10965. if (CHIP_IS_E3(bp)) {
  10966. int idx = BP_FW_MB_IDX(bp);
  10967. u32 cap;
  10968. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10969. if (ulp_type == CNIC_ULP_ISCSI)
  10970. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10971. else if (ulp_type == CNIC_ULP_FCOE)
  10972. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10973. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10974. }
  10975. break;
  10976. }
  10977. default:
  10978. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10979. rc = -EINVAL;
  10980. }
  10981. return rc;
  10982. }
  10983. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10984. {
  10985. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10986. if (bp->flags & USING_MSIX_FLAG) {
  10987. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10988. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10989. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10990. } else {
  10991. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10992. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10993. }
  10994. if (!CHIP_IS_E1x(bp))
  10995. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  10996. else
  10997. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  10998. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  10999. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11000. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11001. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11002. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11003. cp->num_irq = 2;
  11004. }
  11005. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11006. {
  11007. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11008. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11009. bnx2x_cid_ilt_lines(bp);
  11010. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11011. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11012. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11013. if (NO_ISCSI_OOO(bp))
  11014. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11015. }
  11016. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11017. void *data)
  11018. {
  11019. struct bnx2x *bp = netdev_priv(dev);
  11020. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11021. int rc;
  11022. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11023. if (ops == NULL) {
  11024. BNX2X_ERR("NULL ops received\n");
  11025. return -EINVAL;
  11026. }
  11027. if (!CNIC_SUPPORT(bp)) {
  11028. BNX2X_ERR("Can't register CNIC when not supported\n");
  11029. return -EOPNOTSUPP;
  11030. }
  11031. if (!CNIC_LOADED(bp)) {
  11032. rc = bnx2x_load_cnic(bp);
  11033. if (rc) {
  11034. BNX2X_ERR("CNIC-related load failed\n");
  11035. return rc;
  11036. }
  11037. }
  11038. bp->cnic_enabled = true;
  11039. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11040. if (!bp->cnic_kwq)
  11041. return -ENOMEM;
  11042. bp->cnic_kwq_cons = bp->cnic_kwq;
  11043. bp->cnic_kwq_prod = bp->cnic_kwq;
  11044. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11045. bp->cnic_spq_pending = 0;
  11046. bp->cnic_kwq_pending = 0;
  11047. bp->cnic_data = data;
  11048. cp->num_irq = 0;
  11049. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11050. cp->iro_arr = bp->iro_arr;
  11051. bnx2x_setup_cnic_irq_info(bp);
  11052. rcu_assign_pointer(bp->cnic_ops, ops);
  11053. return 0;
  11054. }
  11055. static int bnx2x_unregister_cnic(struct net_device *dev)
  11056. {
  11057. struct bnx2x *bp = netdev_priv(dev);
  11058. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11059. mutex_lock(&bp->cnic_mutex);
  11060. cp->drv_state = 0;
  11061. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11062. mutex_unlock(&bp->cnic_mutex);
  11063. synchronize_rcu();
  11064. kfree(bp->cnic_kwq);
  11065. bp->cnic_kwq = NULL;
  11066. return 0;
  11067. }
  11068. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11069. {
  11070. struct bnx2x *bp = netdev_priv(dev);
  11071. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11072. /* If both iSCSI and FCoE are disabled - return NULL in
  11073. * order to indicate CNIC that it should not try to work
  11074. * with this device.
  11075. */
  11076. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11077. return NULL;
  11078. cp->drv_owner = THIS_MODULE;
  11079. cp->chip_id = CHIP_ID(bp);
  11080. cp->pdev = bp->pdev;
  11081. cp->io_base = bp->regview;
  11082. cp->io_base2 = bp->doorbells;
  11083. cp->max_kwqe_pending = 8;
  11084. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11085. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11086. bnx2x_cid_ilt_lines(bp);
  11087. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11088. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11089. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11090. cp->drv_ctl = bnx2x_drv_ctl;
  11091. cp->drv_register_cnic = bnx2x_register_cnic;
  11092. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11093. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11094. cp->iscsi_l2_client_id =
  11095. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11096. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11097. if (NO_ISCSI_OOO(bp))
  11098. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11099. if (NO_ISCSI(bp))
  11100. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11101. if (NO_FCOE(bp))
  11102. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11103. BNX2X_DEV_INFO(
  11104. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11105. cp->ctx_blk_size,
  11106. cp->ctx_tbl_offset,
  11107. cp->ctx_tbl_len,
  11108. cp->starting_cid);
  11109. return cp;
  11110. }
  11111. int bnx2x_send_msg2pf(struct bnx2x *bp, u8 *done, dma_addr_t msg_mapping)
  11112. {
  11113. struct cstorm_vf_zone_data __iomem *zone_data =
  11114. REG_ADDR(bp, PXP_VF_ADDR_CSDM_GLOBAL_START);
  11115. int tout = 600, interval = 100; /* wait for 60 seconds */
  11116. if (*done) {
  11117. BNX2X_ERR("done was non zero before message to pf was sent\n");
  11118. WARN_ON(true);
  11119. return -EINVAL;
  11120. }
  11121. /* Write message address */
  11122. writel(U64_LO(msg_mapping),
  11123. &zone_data->non_trigger.vf_pf_channel.msg_addr_lo);
  11124. writel(U64_HI(msg_mapping),
  11125. &zone_data->non_trigger.vf_pf_channel.msg_addr_hi);
  11126. /* make sure the address is written before FW accesses it */
  11127. wmb();
  11128. /* Trigger the PF FW */
  11129. writeb(1, &zone_data->trigger.vf_pf_channel.addr_valid);
  11130. /* Wait for PF to complete */
  11131. while ((tout >= 0) && (!*done)) {
  11132. msleep(interval);
  11133. tout -= 1;
  11134. /* progress indicator - HV can take its own sweet time in
  11135. * answering VFs...
  11136. */
  11137. DP_CONT(BNX2X_MSG_IOV, ".");
  11138. }
  11139. if (!*done) {
  11140. BNX2X_ERR("PF response has timed out\n");
  11141. return -EAGAIN;
  11142. }
  11143. DP(BNX2X_MSG_SP, "Got a response from PF\n");
  11144. return 0;
  11145. }
  11146. int bnx2x_get_vf_id(struct bnx2x *bp, u32 *vf_id)
  11147. {
  11148. u32 me_reg;
  11149. int tout = 10, interval = 100; /* Wait for 1 sec */
  11150. do {
  11151. /* pxp traps vf read of doorbells and returns me reg value */
  11152. me_reg = readl(bp->doorbells);
  11153. if (GOOD_ME_REG(me_reg))
  11154. break;
  11155. msleep(interval);
  11156. BNX2X_ERR("Invalid ME register value: 0x%08x\n. Is pf driver up?",
  11157. me_reg);
  11158. } while (tout-- > 0);
  11159. if (!GOOD_ME_REG(me_reg)) {
  11160. BNX2X_ERR("Invalid ME register value: 0x%08x\n", me_reg);
  11161. return -EINVAL;
  11162. }
  11163. BNX2X_ERR("valid ME register value: 0x%08x\n", me_reg);
  11164. *vf_id = (me_reg & ME_REG_VF_NUM_MASK) >> ME_REG_VF_NUM_SHIFT;
  11165. return 0;
  11166. }
  11167. int bnx2x_vfpf_acquire(struct bnx2x *bp, u8 tx_count, u8 rx_count)
  11168. {
  11169. int rc = 0, attempts = 0;
  11170. struct vfpf_acquire_tlv *req = &bp->vf2pf_mbox->req.acquire;
  11171. struct pfvf_acquire_resp_tlv *resp = &bp->vf2pf_mbox->resp.acquire_resp;
  11172. u32 vf_id;
  11173. bool resources_acquired = false;
  11174. /* clear mailbox and prep first tlv */
  11175. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_ACQUIRE, sizeof(*req));
  11176. if (bnx2x_get_vf_id(bp, &vf_id))
  11177. return -EAGAIN;
  11178. req->vfdev_info.vf_id = vf_id;
  11179. req->vfdev_info.vf_os = 0;
  11180. req->resc_request.num_rxqs = rx_count;
  11181. req->resc_request.num_txqs = tx_count;
  11182. req->resc_request.num_sbs = bp->igu_sb_cnt;
  11183. req->resc_request.num_mac_filters = VF_ACQUIRE_MAC_FILTERS;
  11184. req->resc_request.num_mc_filters = VF_ACQUIRE_MC_FILTERS;
  11185. /* add list termination tlv */
  11186. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11187. sizeof(struct channel_list_end_tlv));
  11188. /* output tlvs list */
  11189. bnx2x_dp_tlv_list(bp, req);
  11190. while (!resources_acquired) {
  11191. DP(BNX2X_MSG_SP, "attempting to acquire resources\n");
  11192. /* send acquire request */
  11193. rc = bnx2x_send_msg2pf(bp,
  11194. &resp->hdr.status,
  11195. bp->vf2pf_mbox_mapping);
  11196. /* PF timeout */
  11197. if (rc)
  11198. return rc;
  11199. /* copy acquire response from buffer to bp */
  11200. memcpy(&bp->acquire_resp, resp, sizeof(bp->acquire_resp));
  11201. attempts++;
  11202. /* test whether the PF accepted our request. If not, humble the
  11203. * the request and try again.
  11204. */
  11205. if (bp->acquire_resp.hdr.status == PFVF_STATUS_SUCCESS) {
  11206. DP(BNX2X_MSG_SP, "resources acquired\n");
  11207. resources_acquired = true;
  11208. } else if (bp->acquire_resp.hdr.status ==
  11209. PFVF_STATUS_NO_RESOURCE &&
  11210. attempts < VF_ACQUIRE_THRESH) {
  11211. DP(BNX2X_MSG_SP,
  11212. "PF unwilling to fulfill resource request. Try PF recommended amount\n");
  11213. /* humble our request */
  11214. req->resc_request.num_txqs =
  11215. bp->acquire_resp.resc.num_txqs;
  11216. req->resc_request.num_rxqs =
  11217. bp->acquire_resp.resc.num_rxqs;
  11218. req->resc_request.num_sbs =
  11219. bp->acquire_resp.resc.num_sbs;
  11220. req->resc_request.num_mac_filters =
  11221. bp->acquire_resp.resc.num_mac_filters;
  11222. req->resc_request.num_vlan_filters =
  11223. bp->acquire_resp.resc.num_vlan_filters;
  11224. req->resc_request.num_mc_filters =
  11225. bp->acquire_resp.resc.num_mc_filters;
  11226. /* Clear response buffer */
  11227. memset(&bp->vf2pf_mbox->resp, 0,
  11228. sizeof(union pfvf_tlvs));
  11229. } else {
  11230. /* PF reports error */
  11231. BNX2X_ERR("Failed to get the requested amount of resources: %d. Breaking...\n",
  11232. bp->acquire_resp.hdr.status);
  11233. return -EAGAIN;
  11234. }
  11235. }
  11236. /* get HW info */
  11237. bp->common.chip_id |= (bp->acquire_resp.pfdev_info.chip_num & 0xffff);
  11238. bp->link_params.chip_id = bp->common.chip_id;
  11239. bp->db_size = bp->acquire_resp.pfdev_info.db_size;
  11240. bp->common.int_block = INT_BLOCK_IGU;
  11241. bp->common.chip_port_mode = CHIP_2_PORT_MODE;
  11242. bp->igu_dsb_id = -1;
  11243. bp->mf_ov = 0;
  11244. bp->mf_mode = 0;
  11245. bp->common.flash_size = 0;
  11246. bp->flags |=
  11247. NO_WOL_FLAG | NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG | NO_FCOE_FLAG;
  11248. bp->igu_sb_cnt = 1;
  11249. bp->igu_base_sb = bp->acquire_resp.resc.hw_sbs[0].hw_sb_id;
  11250. strlcpy(bp->fw_ver, bp->acquire_resp.pfdev_info.fw_ver,
  11251. sizeof(bp->fw_ver));
  11252. if (is_valid_ether_addr(bp->acquire_resp.resc.current_mac_addr))
  11253. memcpy(bp->dev->dev_addr,
  11254. bp->acquire_resp.resc.current_mac_addr,
  11255. ETH_ALEN);
  11256. return 0;
  11257. }
  11258. int bnx2x_vfpf_release(struct bnx2x *bp)
  11259. {
  11260. struct vfpf_release_tlv *req = &bp->vf2pf_mbox->req.release;
  11261. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11262. u32 rc = 0, vf_id;
  11263. /* clear mailbox and prep first tlv */
  11264. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_RELEASE, sizeof(*req));
  11265. if (bnx2x_get_vf_id(bp, &vf_id))
  11266. return -EAGAIN;
  11267. req->vf_id = vf_id;
  11268. /* add list termination tlv */
  11269. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11270. sizeof(struct channel_list_end_tlv));
  11271. /* output tlvs list */
  11272. bnx2x_dp_tlv_list(bp, req);
  11273. /* send release request */
  11274. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11275. if (rc)
  11276. /* PF timeout */
  11277. return rc;
  11278. if (resp->hdr.status == PFVF_STATUS_SUCCESS) {
  11279. /* PF released us */
  11280. DP(BNX2X_MSG_SP, "vf released\n");
  11281. } else {
  11282. /* PF reports error */
  11283. BNX2X_ERR("PF failed our release request - are we out of sync? response status: %d\n",
  11284. resp->hdr.status);
  11285. return -EAGAIN;
  11286. }
  11287. return 0;
  11288. }
  11289. /* Tell PF about SB addresses */
  11290. int bnx2x_vfpf_init(struct bnx2x *bp)
  11291. {
  11292. struct vfpf_init_tlv *req = &bp->vf2pf_mbox->req.init;
  11293. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11294. int rc, i;
  11295. /* clear mailbox and prep first tlv */
  11296. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_INIT, sizeof(*req));
  11297. /* status blocks */
  11298. for_each_eth_queue(bp, i)
  11299. req->sb_addr[i] = (dma_addr_t)bnx2x_fp(bp, i,
  11300. status_blk_mapping);
  11301. /* statistics - requests only supports single queue for now */
  11302. req->stats_addr = bp->fw_stats_data_mapping +
  11303. offsetof(struct bnx2x_fw_stats_data, queue_stats);
  11304. /* add list termination tlv */
  11305. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11306. sizeof(struct channel_list_end_tlv));
  11307. /* output tlvs list */
  11308. bnx2x_dp_tlv_list(bp, req);
  11309. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11310. if (rc)
  11311. return rc;
  11312. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  11313. BNX2X_ERR("INIT VF failed: %d. Breaking...\n",
  11314. resp->hdr.status);
  11315. return -EAGAIN;
  11316. }
  11317. DP(BNX2X_MSG_SP, "INIT VF Succeeded\n");
  11318. return 0;
  11319. }
  11320. /* CLOSE VF - opposite to INIT_VF */
  11321. void bnx2x_vfpf_close_vf(struct bnx2x *bp)
  11322. {
  11323. struct vfpf_close_tlv *req = &bp->vf2pf_mbox->req.close;
  11324. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11325. int i, rc;
  11326. u32 vf_id;
  11327. /* If we haven't got a valid VF id, there is no sense to
  11328. * continue with sending messages
  11329. */
  11330. if (bnx2x_get_vf_id(bp, &vf_id))
  11331. goto free_irq;
  11332. /* Close the queues */
  11333. for_each_queue(bp, i)
  11334. bnx2x_vfpf_teardown_queue(bp, i);
  11335. /* clear mailbox and prep first tlv */
  11336. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_CLOSE, sizeof(*req));
  11337. req->vf_id = vf_id;
  11338. /* add list termination tlv */
  11339. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11340. sizeof(struct channel_list_end_tlv));
  11341. /* output tlvs list */
  11342. bnx2x_dp_tlv_list(bp, req);
  11343. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11344. if (rc)
  11345. BNX2X_ERR("Sending CLOSE failed. rc was: %d\n", rc);
  11346. else if (resp->hdr.status != PFVF_STATUS_SUCCESS)
  11347. BNX2X_ERR("Sending CLOSE failed: pf response was %d\n",
  11348. resp->hdr.status);
  11349. free_irq:
  11350. /* Disable HW interrupts, NAPI */
  11351. bnx2x_netif_stop(bp, 0);
  11352. /* Delete all NAPI objects */
  11353. bnx2x_del_all_napi(bp);
  11354. /* Release IRQs */
  11355. bnx2x_free_irq(bp);
  11356. }
  11357. /* ask the pf to open a queue for the vf */
  11358. int bnx2x_vfpf_setup_q(struct bnx2x *bp, int fp_idx)
  11359. {
  11360. struct vfpf_setup_q_tlv *req = &bp->vf2pf_mbox->req.setup_q;
  11361. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11362. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  11363. u16 tpa_agg_size = 0, flags = 0;
  11364. int rc;
  11365. /* clear mailbox and prep first tlv */
  11366. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SETUP_Q, sizeof(*req));
  11367. /* select tpa mode to request */
  11368. if (!fp->disable_tpa) {
  11369. flags |= VFPF_QUEUE_FLG_TPA;
  11370. flags |= VFPF_QUEUE_FLG_TPA_IPV6;
  11371. if (fp->mode == TPA_MODE_GRO)
  11372. flags |= VFPF_QUEUE_FLG_TPA_GRO;
  11373. tpa_agg_size = TPA_AGG_SIZE;
  11374. }
  11375. /* calculate queue flags */
  11376. flags |= VFPF_QUEUE_FLG_STATS;
  11377. flags |= VFPF_QUEUE_FLG_CACHE_ALIGN;
  11378. flags |= IS_MF_SD(bp) ? VFPF_QUEUE_FLG_OV : 0;
  11379. flags |= VFPF_QUEUE_FLG_VLAN;
  11380. DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
  11381. /* Common */
  11382. req->vf_qid = fp_idx;
  11383. req->param_valid = VFPF_RXQ_VALID | VFPF_TXQ_VALID;
  11384. /* Rx */
  11385. req->rxq.rcq_addr = fp->rx_comp_mapping;
  11386. req->rxq.rcq_np_addr = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  11387. req->rxq.rxq_addr = fp->rx_desc_mapping;
  11388. req->rxq.sge_addr = fp->rx_sge_mapping;
  11389. req->rxq.vf_sb = fp_idx;
  11390. req->rxq.sb_index = HC_INDEX_ETH_RX_CQ_CONS;
  11391. req->rxq.hc_rate = bp->rx_ticks ? 1000000/bp->rx_ticks : 0;
  11392. req->rxq.mtu = bp->dev->mtu;
  11393. req->rxq.buf_sz = fp->rx_buf_size;
  11394. req->rxq.sge_buf_sz = BCM_PAGE_SIZE * PAGES_PER_SGE;
  11395. req->rxq.tpa_agg_sz = tpa_agg_size;
  11396. req->rxq.max_sge_pkt = SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
  11397. req->rxq.max_sge_pkt = ((req->rxq.max_sge_pkt + PAGES_PER_SGE - 1) &
  11398. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  11399. req->rxq.flags = flags;
  11400. req->rxq.drop_flags = 0;
  11401. req->rxq.cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  11402. req->rxq.stat_id = -1; /* No stats at the moment */
  11403. /* Tx */
  11404. req->txq.txq_addr = fp->txdata_ptr[FIRST_TX_COS_INDEX]->tx_desc_mapping;
  11405. req->txq.vf_sb = fp_idx;
  11406. req->txq.sb_index = HC_INDEX_ETH_TX_CQ_CONS_COS0;
  11407. req->txq.hc_rate = bp->tx_ticks ? 1000000/bp->tx_ticks : 0;
  11408. req->txq.flags = flags;
  11409. req->txq.traffic_type = LLFC_TRAFFIC_TYPE_NW;
  11410. /* add list termination tlv */
  11411. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11412. sizeof(struct channel_list_end_tlv));
  11413. /* output tlvs list */
  11414. bnx2x_dp_tlv_list(bp, req);
  11415. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11416. if (rc)
  11417. BNX2X_ERR("Sending SETUP_Q message for queue[%d] failed!\n",
  11418. fp_idx);
  11419. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  11420. BNX2X_ERR("Status of SETUP_Q for queue[%d] is %d\n",
  11421. fp_idx, resp->hdr.status);
  11422. return -EINVAL;
  11423. }
  11424. return rc;
  11425. }
  11426. int bnx2x_vfpf_teardown_queue(struct bnx2x *bp, int qidx)
  11427. {
  11428. struct vfpf_q_op_tlv *req = &bp->vf2pf_mbox->req.q_op;
  11429. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11430. int rc;
  11431. /* clear mailbox and prep first tlv */
  11432. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_TEARDOWN_Q,
  11433. sizeof(*req));
  11434. req->vf_qid = qidx;
  11435. /* add list termination tlv */
  11436. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11437. sizeof(struct channel_list_end_tlv));
  11438. /* output tlvs list */
  11439. bnx2x_dp_tlv_list(bp, req);
  11440. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11441. if (rc) {
  11442. BNX2X_ERR("Sending TEARDOWN for queue %d failed: %d\n", qidx,
  11443. rc);
  11444. return rc;
  11445. }
  11446. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  11447. BNX2X_ERR("TEARDOWN for queue %d failed: %d\n", qidx,
  11448. resp->hdr.status);
  11449. return -EINVAL;
  11450. }
  11451. return 0;
  11452. }
  11453. /* request pf to add a mac for the vf */
  11454. int bnx2x_vfpf_set_mac(struct bnx2x *bp)
  11455. {
  11456. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  11457. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11458. int rc;
  11459. /* clear mailbox and prep first tlv */
  11460. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  11461. sizeof(*req));
  11462. req->flags = VFPF_SET_Q_FILTERS_MAC_VLAN_CHANGED;
  11463. req->vf_qid = 0;
  11464. req->n_mac_vlan_filters = 1;
  11465. req->filters[0].flags =
  11466. VFPF_Q_FILTER_DEST_MAC_VALID | VFPF_Q_FILTER_SET_MAC;
  11467. /* copy mac from device to request */
  11468. memcpy(req->filters[0].mac, bp->dev->dev_addr, ETH_ALEN);
  11469. /* add list termination tlv */
  11470. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11471. sizeof(struct channel_list_end_tlv));
  11472. /* output tlvs list */
  11473. bnx2x_dp_tlv_list(bp, req);
  11474. /* send message to pf */
  11475. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11476. if (rc) {
  11477. BNX2X_ERR("failed to send message to pf. rc was %d\n", rc);
  11478. return rc;
  11479. }
  11480. /* PF failed the transaction */
  11481. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  11482. BNX2X_ERR("vfpf SET MAC failed: %d\n", resp->hdr.status);
  11483. return -EINVAL;
  11484. }
  11485. return 0;
  11486. }
  11487. int bnx2x_vfpf_set_mcast(struct net_device *dev)
  11488. {
  11489. struct bnx2x *bp = netdev_priv(dev);
  11490. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  11491. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11492. int rc, i = 0;
  11493. struct netdev_hw_addr *ha;
  11494. if (bp->state != BNX2X_STATE_OPEN) {
  11495. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  11496. return -EINVAL;
  11497. }
  11498. /* clear mailbox and prep first tlv */
  11499. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  11500. sizeof(*req));
  11501. /* Get Rx mode requested */
  11502. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
  11503. netdev_for_each_mc_addr(ha, dev) {
  11504. DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
  11505. bnx2x_mc_addr(ha));
  11506. memcpy(req->multicast[i], bnx2x_mc_addr(ha), ETH_ALEN);
  11507. i++;
  11508. }
  11509. /* We support four PFVF_MAX_MULTICAST_PER_VF mcast
  11510. * addresses tops
  11511. */
  11512. if (i >= PFVF_MAX_MULTICAST_PER_VF) {
  11513. DP(NETIF_MSG_IFUP,
  11514. "VF supports not more than %d multicast MAC addresses\n",
  11515. PFVF_MAX_MULTICAST_PER_VF);
  11516. return -EINVAL;
  11517. }
  11518. req->n_multicast = i;
  11519. req->flags |= VFPF_SET_Q_FILTERS_MULTICAST_CHANGED;
  11520. req->vf_qid = 0;
  11521. /* add list termination tlv */
  11522. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11523. sizeof(struct channel_list_end_tlv));
  11524. /* output tlvs list */
  11525. bnx2x_dp_tlv_list(bp, req);
  11526. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11527. if (rc) {
  11528. BNX2X_ERR("Sending a message failed: %d\n", rc);
  11529. return rc;
  11530. }
  11531. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  11532. BNX2X_ERR("Set Rx mode/multicast failed: %d\n",
  11533. resp->hdr.status);
  11534. return -EINVAL;
  11535. }
  11536. return 0;
  11537. }
  11538. int bnx2x_vfpf_storm_rx_mode(struct bnx2x *bp)
  11539. {
  11540. int mode = bp->rx_mode;
  11541. struct vfpf_set_q_filters_tlv *req = &bp->vf2pf_mbox->req.set_q_filters;
  11542. struct pfvf_general_resp_tlv *resp = &bp->vf2pf_mbox->resp.general_resp;
  11543. int rc;
  11544. /* clear mailbox and prep first tlv */
  11545. bnx2x_vfpf_prep(bp, &req->first_tlv, CHANNEL_TLV_SET_Q_FILTERS,
  11546. sizeof(*req));
  11547. DP(NETIF_MSG_IFUP, "Rx mode is %d\n", mode);
  11548. switch (mode) {
  11549. case BNX2X_RX_MODE_NONE: /* no Rx */
  11550. req->rx_mask = VFPF_RX_MASK_ACCEPT_NONE;
  11551. break;
  11552. case BNX2X_RX_MODE_NORMAL:
  11553. req->rx_mask = VFPF_RX_MASK_ACCEPT_MATCHED_MULTICAST;
  11554. req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
  11555. req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
  11556. break;
  11557. case BNX2X_RX_MODE_ALLMULTI:
  11558. req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
  11559. req->rx_mask |= VFPF_RX_MASK_ACCEPT_MATCHED_UNICAST;
  11560. req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
  11561. break;
  11562. case BNX2X_RX_MODE_PROMISC:
  11563. req->rx_mask = VFPF_RX_MASK_ACCEPT_ALL_UNICAST;
  11564. req->rx_mask |= VFPF_RX_MASK_ACCEPT_ALL_MULTICAST;
  11565. req->rx_mask |= VFPF_RX_MASK_ACCEPT_BROADCAST;
  11566. break;
  11567. default:
  11568. BNX2X_ERR("BAD rx mode (%d)\n", mode);
  11569. return -EINVAL;
  11570. }
  11571. req->flags |= VFPF_SET_Q_FILTERS_RX_MASK_CHANGED;
  11572. req->vf_qid = 0;
  11573. /* add list termination tlv */
  11574. bnx2x_add_tlv(bp, req, req->first_tlv.tl.length, CHANNEL_TLV_LIST_END,
  11575. sizeof(struct channel_list_end_tlv));
  11576. /* output tlvs list */
  11577. bnx2x_dp_tlv_list(bp, req);
  11578. rc = bnx2x_send_msg2pf(bp, &resp->hdr.status, bp->vf2pf_mbox_mapping);
  11579. if (rc)
  11580. BNX2X_ERR("Sending a message failed: %d\n", rc);
  11581. if (resp->hdr.status != PFVF_STATUS_SUCCESS) {
  11582. BNX2X_ERR("Set Rx mode failed: %d\n", resp->hdr.status);
  11583. return -EINVAL;
  11584. }
  11585. return rc;
  11586. }