bnx2x_main.c 372 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: 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_dcb.h"
  61. #include "bnx2x_sp.h"
  62. #include <linux/firmware.h>
  63. #include "bnx2x_fw_file_hdr.h"
  64. /* FW files */
  65. #define FW_FILE_VERSION \
  66. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  69. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  70. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  73. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] =
  76. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  77. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  78. MODULE_AUTHOR("Eliezer Tamir");
  79. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  80. "BCM57710/57711/57711E/"
  81. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  82. "57840/57840_MF Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_MODULE_VERSION);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues,
  91. " Set number of queues (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. int int_mode;
  96. module_param(int_mode, int, 0);
  97. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  98. "(1 INT#x; 2 MSI)");
  99. static int dropless_fc;
  100. module_param(dropless_fc, int, 0);
  101. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  102. static int mrrs = -1;
  103. module_param(mrrs, int, 0);
  104. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  105. static int debug;
  106. module_param(debug, int, 0);
  107. MODULE_PARM_DESC(debug, " Default debug msglevel");
  108. struct workqueue_struct *bnx2x_wq;
  109. struct bnx2x_mac_vals {
  110. u32 xmac_addr;
  111. u32 xmac_val;
  112. u32 emac_addr;
  113. u32 emac_val;
  114. u32 umac_addr;
  115. u32 umac_val;
  116. u32 bmac_addr;
  117. u32 bmac_val[2];
  118. };
  119. enum bnx2x_board_type {
  120. BCM57710 = 0,
  121. BCM57711,
  122. BCM57711E,
  123. BCM57712,
  124. BCM57712_MF,
  125. BCM57712_VF,
  126. BCM57800,
  127. BCM57800_MF,
  128. BCM57800_VF,
  129. BCM57810,
  130. BCM57810_MF,
  131. BCM57810_VF,
  132. BCM57840_4_10,
  133. BCM57840_2_20,
  134. BCM57840_MF,
  135. BCM57840_VF,
  136. BCM57811,
  137. BCM57811_MF,
  138. BCM57840_O,
  139. BCM57840_MFO,
  140. BCM57811_VF
  141. };
  142. /* indexed by board_type, above */
  143. static struct {
  144. char *name;
  145. } board_info[] = {
  146. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  147. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  148. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  149. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  150. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  151. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  152. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  153. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  154. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  156. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  157. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  159. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  160. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  161. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  162. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  163. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  164. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  165. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  166. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  167. };
  168. #ifndef PCI_DEVICE_ID_NX2_57710
  169. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57711
  172. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711E
  175. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57712
  178. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  181. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  184. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57800
  187. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  190. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  193. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57810
  196. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  199. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57840_O
  202. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  205. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  208. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  211. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  214. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  217. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  220. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57811
  223. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  226. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  229. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  230. #endif
  231. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  232. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  233. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  253. { 0 }
  254. };
  255. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  256. /* Global resources for unloading a previously loaded device */
  257. #define BNX2X_PREV_WAIT_NEEDED 1
  258. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  259. static LIST_HEAD(bnx2x_prev_list);
  260. /****************************************************************************
  261. * General service functions
  262. ****************************************************************************/
  263. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  264. u32 addr, dma_addr_t mapping)
  265. {
  266. REG_WR(bp, addr, U64_LO(mapping));
  267. REG_WR(bp, addr + 4, U64_HI(mapping));
  268. }
  269. static void storm_memset_spq_addr(struct bnx2x *bp,
  270. dma_addr_t mapping, u16 abs_fid)
  271. {
  272. u32 addr = XSEM_REG_FAST_MEMORY +
  273. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  274. __storm_memset_dma_mapping(bp, addr, mapping);
  275. }
  276. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  277. u16 pf_id)
  278. {
  279. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  280. pf_id);
  281. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  282. pf_id);
  283. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  284. pf_id);
  285. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. }
  288. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  289. u8 enable)
  290. {
  291. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  292. enable);
  293. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  294. enable);
  295. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  296. enable);
  297. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. }
  300. static void storm_memset_eq_data(struct bnx2x *bp,
  301. struct event_ring_data *eq_data,
  302. u16 pfid)
  303. {
  304. size_t size = sizeof(struct event_ring_data);
  305. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  306. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  307. }
  308. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  309. u16 pfid)
  310. {
  311. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  312. REG_WR16(bp, addr, eq_prod);
  313. }
  314. /* used only at init
  315. * locking is done by mcp
  316. */
  317. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  318. {
  319. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  320. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  321. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  322. PCICFG_VENDOR_ID_OFFSET);
  323. }
  324. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  325. {
  326. u32 val;
  327. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  328. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  330. PCICFG_VENDOR_ID_OFFSET);
  331. return val;
  332. }
  333. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  334. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  335. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  336. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  337. #define DMAE_DP_DST_NONE "dst_addr [none]"
  338. static void bnx2x_dp_dmae(struct bnx2x *bp,
  339. struct dmae_command *dmae, int msglvl)
  340. {
  341. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  342. int i;
  343. switch (dmae->opcode & DMAE_COMMAND_DST) {
  344. case DMAE_CMD_DST_PCI:
  345. if (src_type == DMAE_CMD_SRC_PCI)
  346. DP(msglvl, "DMAE: opcode 0x%08x\n"
  347. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  348. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  349. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  350. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  351. dmae->comp_addr_hi, dmae->comp_addr_lo,
  352. dmae->comp_val);
  353. else
  354. DP(msglvl, "DMAE: opcode 0x%08x\n"
  355. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  356. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  357. dmae->opcode, dmae->src_addr_lo >> 2,
  358. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  359. dmae->comp_addr_hi, dmae->comp_addr_lo,
  360. dmae->comp_val);
  361. break;
  362. case DMAE_CMD_DST_GRC:
  363. if (src_type == DMAE_CMD_SRC_PCI)
  364. DP(msglvl, "DMAE: opcode 0x%08x\n"
  365. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  366. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  367. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  368. dmae->len, dmae->dst_addr_lo >> 2,
  369. dmae->comp_addr_hi, dmae->comp_addr_lo,
  370. dmae->comp_val);
  371. else
  372. DP(msglvl, "DMAE: opcode 0x%08x\n"
  373. "src [%08x], len [%d*4], dst [%08x]\n"
  374. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  375. dmae->opcode, dmae->src_addr_lo >> 2,
  376. dmae->len, dmae->dst_addr_lo >> 2,
  377. dmae->comp_addr_hi, dmae->comp_addr_lo,
  378. dmae->comp_val);
  379. break;
  380. default:
  381. if (src_type == DMAE_CMD_SRC_PCI)
  382. DP(msglvl, "DMAE: opcode 0x%08x\n"
  383. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  384. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  385. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  386. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  387. dmae->comp_val);
  388. else
  389. DP(msglvl, "DMAE: opcode 0x%08x\n"
  390. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  391. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  392. dmae->opcode, dmae->src_addr_lo >> 2,
  393. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  394. dmae->comp_val);
  395. break;
  396. }
  397. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  398. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  399. i, *(((u32 *)dmae) + i));
  400. }
  401. /* copy command into DMAE command memory and set DMAE command go */
  402. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  403. {
  404. u32 cmd_offset;
  405. int i;
  406. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  407. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  408. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  409. }
  410. REG_WR(bp, dmae_reg_go_c[idx], 1);
  411. }
  412. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  413. {
  414. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  415. DMAE_CMD_C_ENABLE);
  416. }
  417. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  418. {
  419. return opcode & ~DMAE_CMD_SRC_RESET;
  420. }
  421. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  422. bool with_comp, u8 comp_type)
  423. {
  424. u32 opcode = 0;
  425. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  426. (dst_type << DMAE_COMMAND_DST_SHIFT));
  427. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  428. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  429. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  430. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  431. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  432. #ifdef __BIG_ENDIAN
  433. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  434. #else
  435. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  436. #endif
  437. if (with_comp)
  438. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  439. return opcode;
  440. }
  441. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  442. struct dmae_command *dmae,
  443. u8 src_type, u8 dst_type)
  444. {
  445. memset(dmae, 0, sizeof(struct dmae_command));
  446. /* set the opcode */
  447. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  448. true, DMAE_COMP_PCI);
  449. /* fill in the completion parameters */
  450. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  451. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  452. dmae->comp_val = DMAE_COMP_VAL;
  453. }
  454. /* issue a dmae command over the init-channel and wait for completion */
  455. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  456. {
  457. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  458. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  459. int rc = 0;
  460. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  461. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  462. * as long as this code is called both from syscall context and
  463. * from ndo_set_rx_mode() flow that may be called from BH.
  464. */
  465. spin_lock_bh(&bp->dmae_lock);
  466. /* reset completion */
  467. *wb_comp = 0;
  468. /* post the command on the channel used for initializations */
  469. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  470. /* wait for completion */
  471. udelay(5);
  472. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  473. if (!cnt ||
  474. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  475. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  476. BNX2X_ERR("DMAE timeout!\n");
  477. rc = DMAE_TIMEOUT;
  478. goto unlock;
  479. }
  480. cnt--;
  481. udelay(50);
  482. }
  483. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  484. BNX2X_ERR("DMAE PCI error!\n");
  485. rc = DMAE_PCI_ERROR;
  486. }
  487. unlock:
  488. spin_unlock_bh(&bp->dmae_lock);
  489. return rc;
  490. }
  491. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  492. u32 len32)
  493. {
  494. int rc;
  495. struct dmae_command dmae;
  496. if (!bp->dmae_ready) {
  497. u32 *data = bnx2x_sp(bp, wb_data[0]);
  498. if (CHIP_IS_E1(bp))
  499. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  500. else
  501. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  502. return;
  503. }
  504. /* set opcode and fixed command fields */
  505. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  506. /* fill in addresses and len */
  507. dmae.src_addr_lo = U64_LO(dma_addr);
  508. dmae.src_addr_hi = U64_HI(dma_addr);
  509. dmae.dst_addr_lo = dst_addr >> 2;
  510. dmae.dst_addr_hi = 0;
  511. dmae.len = len32;
  512. /* issue the command and wait for completion */
  513. rc = bnx2x_issue_dmae_with_comp(bp, &dmae);
  514. if (rc) {
  515. BNX2X_ERR("DMAE returned failure %d\n", rc);
  516. bnx2x_panic();
  517. }
  518. }
  519. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  520. {
  521. int rc;
  522. struct dmae_command dmae;
  523. if (!bp->dmae_ready) {
  524. u32 *data = bnx2x_sp(bp, wb_data[0]);
  525. int i;
  526. if (CHIP_IS_E1(bp))
  527. for (i = 0; i < len32; i++)
  528. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  529. else
  530. for (i = 0; i < len32; i++)
  531. data[i] = REG_RD(bp, src_addr + i*4);
  532. return;
  533. }
  534. /* set opcode and fixed command fields */
  535. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  536. /* fill in addresses and len */
  537. dmae.src_addr_lo = src_addr >> 2;
  538. dmae.src_addr_hi = 0;
  539. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  540. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  541. dmae.len = len32;
  542. /* issue the command and wait for completion */
  543. rc = bnx2x_issue_dmae_with_comp(bp, &dmae);
  544. if (rc) {
  545. BNX2X_ERR("DMAE returned failure %d\n", rc);
  546. bnx2x_panic();
  547. }
  548. }
  549. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  550. u32 addr, u32 len)
  551. {
  552. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  553. int offset = 0;
  554. while (len > dmae_wr_max) {
  555. bnx2x_write_dmae(bp, phys_addr + offset,
  556. addr + offset, dmae_wr_max);
  557. offset += dmae_wr_max * 4;
  558. len -= dmae_wr_max;
  559. }
  560. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  561. }
  562. static int bnx2x_mc_assert(struct bnx2x *bp)
  563. {
  564. char last_idx;
  565. int i, rc = 0;
  566. u32 row0, row1, row2, row3;
  567. /* XSTORM */
  568. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  569. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  570. if (last_idx)
  571. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  572. /* print the asserts */
  573. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  574. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  575. XSTORM_ASSERT_LIST_OFFSET(i));
  576. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  577. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  578. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  579. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  580. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  581. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  582. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  583. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  584. i, row3, row2, row1, row0);
  585. rc++;
  586. } else {
  587. break;
  588. }
  589. }
  590. /* TSTORM */
  591. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  592. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  593. if (last_idx)
  594. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  595. /* print the asserts */
  596. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  597. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  598. TSTORM_ASSERT_LIST_OFFSET(i));
  599. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  600. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  601. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  602. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  603. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  604. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  605. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  606. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  607. i, row3, row2, row1, row0);
  608. rc++;
  609. } else {
  610. break;
  611. }
  612. }
  613. /* CSTORM */
  614. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  615. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  616. if (last_idx)
  617. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  618. /* print the asserts */
  619. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  620. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  621. CSTORM_ASSERT_LIST_OFFSET(i));
  622. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  623. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  624. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  625. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  626. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  627. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  628. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  629. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  630. i, row3, row2, row1, row0);
  631. rc++;
  632. } else {
  633. break;
  634. }
  635. }
  636. /* USTORM */
  637. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  638. USTORM_ASSERT_LIST_INDEX_OFFSET);
  639. if (last_idx)
  640. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  641. /* print the asserts */
  642. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  643. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  644. USTORM_ASSERT_LIST_OFFSET(i));
  645. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  646. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  647. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  648. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  649. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  650. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  651. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  652. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  653. i, row3, row2, row1, row0);
  654. rc++;
  655. } else {
  656. break;
  657. }
  658. }
  659. return rc;
  660. }
  661. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  662. {
  663. u32 addr, val;
  664. u32 mark, offset;
  665. __be32 data[9];
  666. int word;
  667. u32 trace_shmem_base;
  668. if (BP_NOMCP(bp)) {
  669. BNX2X_ERR("NO MCP - can not dump\n");
  670. return;
  671. }
  672. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  673. (bp->common.bc_ver & 0xff0000) >> 16,
  674. (bp->common.bc_ver & 0xff00) >> 8,
  675. (bp->common.bc_ver & 0xff));
  676. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  677. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  678. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  679. if (BP_PATH(bp) == 0)
  680. trace_shmem_base = bp->common.shmem_base;
  681. else
  682. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  683. addr = trace_shmem_base - 0x800;
  684. /* validate TRCB signature */
  685. mark = REG_RD(bp, addr);
  686. if (mark != MFW_TRACE_SIGNATURE) {
  687. BNX2X_ERR("Trace buffer signature is missing.");
  688. return ;
  689. }
  690. /* read cyclic buffer pointer */
  691. addr += 4;
  692. mark = REG_RD(bp, addr);
  693. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  694. + ((mark + 0x3) & ~0x3) - 0x08000000;
  695. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  696. printk("%s", lvl);
  697. /* dump buffer after the mark */
  698. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  699. for (word = 0; word < 8; word++)
  700. data[word] = htonl(REG_RD(bp, offset + 4*word));
  701. data[8] = 0x0;
  702. pr_cont("%s", (char *)data);
  703. }
  704. /* dump buffer before the mark */
  705. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  706. for (word = 0; word < 8; word++)
  707. data[word] = htonl(REG_RD(bp, offset + 4*word));
  708. data[8] = 0x0;
  709. pr_cont("%s", (char *)data);
  710. }
  711. printk("%s" "end of fw dump\n", lvl);
  712. }
  713. static void bnx2x_fw_dump(struct bnx2x *bp)
  714. {
  715. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  716. }
  717. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  718. {
  719. int port = BP_PORT(bp);
  720. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  721. u32 val = REG_RD(bp, addr);
  722. /* in E1 we must use only PCI configuration space to disable
  723. * MSI/MSIX capability
  724. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  725. */
  726. if (CHIP_IS_E1(bp)) {
  727. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  728. * Use mask register to prevent from HC sending interrupts
  729. * after we exit the function
  730. */
  731. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  732. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  733. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  734. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  735. } else
  736. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  737. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  738. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  739. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  740. DP(NETIF_MSG_IFDOWN,
  741. "write %x to HC %d (addr 0x%x)\n",
  742. val, port, addr);
  743. /* flush all outstanding writes */
  744. mmiowb();
  745. REG_WR(bp, addr, val);
  746. if (REG_RD(bp, addr) != val)
  747. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  748. }
  749. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  750. {
  751. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  752. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  753. IGU_PF_CONF_INT_LINE_EN |
  754. IGU_PF_CONF_ATTN_BIT_EN);
  755. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  756. /* flush all outstanding writes */
  757. mmiowb();
  758. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  759. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  760. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  761. }
  762. static void bnx2x_int_disable(struct bnx2x *bp)
  763. {
  764. if (bp->common.int_block == INT_BLOCK_HC)
  765. bnx2x_hc_int_disable(bp);
  766. else
  767. bnx2x_igu_int_disable(bp);
  768. }
  769. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  770. {
  771. int i;
  772. u16 j;
  773. struct hc_sp_status_block_data sp_sb_data;
  774. int func = BP_FUNC(bp);
  775. #ifdef BNX2X_STOP_ON_ERROR
  776. u16 start = 0, end = 0;
  777. u8 cos;
  778. #endif
  779. if (disable_int)
  780. bnx2x_int_disable(bp);
  781. bp->stats_state = STATS_STATE_DISABLED;
  782. bp->eth_stats.unrecoverable_error++;
  783. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  784. BNX2X_ERR("begin crash dump -----------------\n");
  785. /* Indices */
  786. /* Common */
  787. 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",
  788. bp->def_idx, bp->def_att_idx, bp->attn_state,
  789. bp->spq_prod_idx, bp->stats_counter);
  790. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  791. bp->def_status_blk->atten_status_block.attn_bits,
  792. bp->def_status_blk->atten_status_block.attn_bits_ack,
  793. bp->def_status_blk->atten_status_block.status_block_id,
  794. bp->def_status_blk->atten_status_block.attn_bits_index);
  795. BNX2X_ERR(" def (");
  796. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  797. pr_cont("0x%x%s",
  798. bp->def_status_blk->sp_sb.index_values[i],
  799. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  800. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  801. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  802. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  803. i*sizeof(u32));
  804. 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",
  805. sp_sb_data.igu_sb_id,
  806. sp_sb_data.igu_seg_id,
  807. sp_sb_data.p_func.pf_id,
  808. sp_sb_data.p_func.vnic_id,
  809. sp_sb_data.p_func.vf_id,
  810. sp_sb_data.p_func.vf_valid,
  811. sp_sb_data.state);
  812. for_each_eth_queue(bp, i) {
  813. struct bnx2x_fastpath *fp = &bp->fp[i];
  814. int loop;
  815. struct hc_status_block_data_e2 sb_data_e2;
  816. struct hc_status_block_data_e1x sb_data_e1x;
  817. struct hc_status_block_sm *hc_sm_p =
  818. CHIP_IS_E1x(bp) ?
  819. sb_data_e1x.common.state_machine :
  820. sb_data_e2.common.state_machine;
  821. struct hc_index_data *hc_index_p =
  822. CHIP_IS_E1x(bp) ?
  823. sb_data_e1x.index_data :
  824. sb_data_e2.index_data;
  825. u8 data_size, cos;
  826. u32 *sb_data_p;
  827. struct bnx2x_fp_txdata txdata;
  828. /* Rx */
  829. 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",
  830. i, fp->rx_bd_prod, fp->rx_bd_cons,
  831. fp->rx_comp_prod,
  832. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  833. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  834. fp->rx_sge_prod, fp->last_max_sge,
  835. le16_to_cpu(fp->fp_hc_idx));
  836. /* Tx */
  837. for_each_cos_in_tx_queue(fp, cos)
  838. {
  839. txdata = *fp->txdata_ptr[cos];
  840. 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",
  841. i, txdata.tx_pkt_prod,
  842. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  843. txdata.tx_bd_cons,
  844. le16_to_cpu(*txdata.tx_cons_sb));
  845. }
  846. loop = CHIP_IS_E1x(bp) ?
  847. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  848. /* host sb data */
  849. if (IS_FCOE_FP(fp))
  850. continue;
  851. BNX2X_ERR(" run indexes (");
  852. for (j = 0; j < HC_SB_MAX_SM; j++)
  853. pr_cont("0x%x%s",
  854. fp->sb_running_index[j],
  855. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  856. BNX2X_ERR(" indexes (");
  857. for (j = 0; j < loop; j++)
  858. pr_cont("0x%x%s",
  859. fp->sb_index_values[j],
  860. (j == loop - 1) ? ")" : " ");
  861. /* fw sb data */
  862. data_size = CHIP_IS_E1x(bp) ?
  863. sizeof(struct hc_status_block_data_e1x) :
  864. sizeof(struct hc_status_block_data_e2);
  865. data_size /= sizeof(u32);
  866. sb_data_p = CHIP_IS_E1x(bp) ?
  867. (u32 *)&sb_data_e1x :
  868. (u32 *)&sb_data_e2;
  869. /* copy sb data in here */
  870. for (j = 0; j < data_size; j++)
  871. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  872. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  873. j * sizeof(u32));
  874. if (!CHIP_IS_E1x(bp)) {
  875. 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",
  876. sb_data_e2.common.p_func.pf_id,
  877. sb_data_e2.common.p_func.vf_id,
  878. sb_data_e2.common.p_func.vf_valid,
  879. sb_data_e2.common.p_func.vnic_id,
  880. sb_data_e2.common.same_igu_sb_1b,
  881. sb_data_e2.common.state);
  882. } else {
  883. 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",
  884. sb_data_e1x.common.p_func.pf_id,
  885. sb_data_e1x.common.p_func.vf_id,
  886. sb_data_e1x.common.p_func.vf_valid,
  887. sb_data_e1x.common.p_func.vnic_id,
  888. sb_data_e1x.common.same_igu_sb_1b,
  889. sb_data_e1x.common.state);
  890. }
  891. /* SB_SMs data */
  892. for (j = 0; j < HC_SB_MAX_SM; j++) {
  893. 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",
  894. j, hc_sm_p[j].__flags,
  895. hc_sm_p[j].igu_sb_id,
  896. hc_sm_p[j].igu_seg_id,
  897. hc_sm_p[j].time_to_expire,
  898. hc_sm_p[j].timer_value);
  899. }
  900. /* Indices data */
  901. for (j = 0; j < loop; j++) {
  902. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  903. hc_index_p[j].flags,
  904. hc_index_p[j].timeout);
  905. }
  906. }
  907. #ifdef BNX2X_STOP_ON_ERROR
  908. /* event queue */
  909. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  910. for (i = 0; i < NUM_EQ_DESC; i++) {
  911. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  912. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  913. i, bp->eq_ring[i].message.opcode,
  914. bp->eq_ring[i].message.error);
  915. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  916. }
  917. /* Rings */
  918. /* Rx */
  919. for_each_valid_rx_queue(bp, i) {
  920. struct bnx2x_fastpath *fp = &bp->fp[i];
  921. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  922. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  923. for (j = start; j != end; j = RX_BD(j + 1)) {
  924. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  925. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  926. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  927. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  928. }
  929. start = RX_SGE(fp->rx_sge_prod);
  930. end = RX_SGE(fp->last_max_sge);
  931. for (j = start; j != end; j = RX_SGE(j + 1)) {
  932. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  933. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  934. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  935. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  936. }
  937. start = RCQ_BD(fp->rx_comp_cons - 10);
  938. end = RCQ_BD(fp->rx_comp_cons + 503);
  939. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  940. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  941. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  942. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  943. }
  944. }
  945. /* Tx */
  946. for_each_valid_tx_queue(bp, i) {
  947. struct bnx2x_fastpath *fp = &bp->fp[i];
  948. for_each_cos_in_tx_queue(fp, cos) {
  949. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  950. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  951. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  952. for (j = start; j != end; j = TX_BD(j + 1)) {
  953. struct sw_tx_bd *sw_bd =
  954. &txdata->tx_buf_ring[j];
  955. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  956. i, cos, j, sw_bd->skb,
  957. sw_bd->first_bd);
  958. }
  959. start = TX_BD(txdata->tx_bd_cons - 10);
  960. end = TX_BD(txdata->tx_bd_cons + 254);
  961. for (j = start; j != end; j = TX_BD(j + 1)) {
  962. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  963. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  964. i, cos, j, tx_bd[0], tx_bd[1],
  965. tx_bd[2], tx_bd[3]);
  966. }
  967. }
  968. }
  969. #endif
  970. bnx2x_fw_dump(bp);
  971. bnx2x_mc_assert(bp);
  972. BNX2X_ERR("end crash dump -----------------\n");
  973. }
  974. /*
  975. * FLR Support for E2
  976. *
  977. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  978. * initialization.
  979. */
  980. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  981. #define FLR_WAIT_INTERVAL 50 /* usec */
  982. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  983. struct pbf_pN_buf_regs {
  984. int pN;
  985. u32 init_crd;
  986. u32 crd;
  987. u32 crd_freed;
  988. };
  989. struct pbf_pN_cmd_regs {
  990. int pN;
  991. u32 lines_occup;
  992. u32 lines_freed;
  993. };
  994. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  995. struct pbf_pN_buf_regs *regs,
  996. u32 poll_count)
  997. {
  998. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  999. u32 cur_cnt = poll_count;
  1000. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1001. crd = crd_start = REG_RD(bp, regs->crd);
  1002. init_crd = REG_RD(bp, regs->init_crd);
  1003. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1004. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1005. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1006. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1007. (init_crd - crd_start))) {
  1008. if (cur_cnt--) {
  1009. udelay(FLR_WAIT_INTERVAL);
  1010. crd = REG_RD(bp, regs->crd);
  1011. crd_freed = REG_RD(bp, regs->crd_freed);
  1012. } else {
  1013. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1014. regs->pN);
  1015. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1016. regs->pN, crd);
  1017. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1018. regs->pN, crd_freed);
  1019. break;
  1020. }
  1021. }
  1022. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1023. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1024. }
  1025. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1026. struct pbf_pN_cmd_regs *regs,
  1027. u32 poll_count)
  1028. {
  1029. u32 occup, to_free, freed, freed_start;
  1030. u32 cur_cnt = poll_count;
  1031. occup = to_free = REG_RD(bp, regs->lines_occup);
  1032. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1033. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1034. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1035. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1036. if (cur_cnt--) {
  1037. udelay(FLR_WAIT_INTERVAL);
  1038. occup = REG_RD(bp, regs->lines_occup);
  1039. freed = REG_RD(bp, regs->lines_freed);
  1040. } else {
  1041. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1042. regs->pN);
  1043. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1044. regs->pN, occup);
  1045. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1046. regs->pN, freed);
  1047. break;
  1048. }
  1049. }
  1050. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1051. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1052. }
  1053. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1054. u32 expected, u32 poll_count)
  1055. {
  1056. u32 cur_cnt = poll_count;
  1057. u32 val;
  1058. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1059. udelay(FLR_WAIT_INTERVAL);
  1060. return val;
  1061. }
  1062. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1063. char *msg, u32 poll_cnt)
  1064. {
  1065. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1066. if (val != 0) {
  1067. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. /* Common routines with VF FLR cleanup */
  1073. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1074. {
  1075. /* adjust polling timeout */
  1076. if (CHIP_REV_IS_EMUL(bp))
  1077. return FLR_POLL_CNT * 2000;
  1078. if (CHIP_REV_IS_FPGA(bp))
  1079. return FLR_POLL_CNT * 120;
  1080. return FLR_POLL_CNT;
  1081. }
  1082. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1083. {
  1084. struct pbf_pN_cmd_regs cmd_regs[] = {
  1085. {0, (CHIP_IS_E3B0(bp)) ?
  1086. PBF_REG_TQ_OCCUPANCY_Q0 :
  1087. PBF_REG_P0_TQ_OCCUPANCY,
  1088. (CHIP_IS_E3B0(bp)) ?
  1089. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1090. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1091. {1, (CHIP_IS_E3B0(bp)) ?
  1092. PBF_REG_TQ_OCCUPANCY_Q1 :
  1093. PBF_REG_P1_TQ_OCCUPANCY,
  1094. (CHIP_IS_E3B0(bp)) ?
  1095. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1096. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1097. {4, (CHIP_IS_E3B0(bp)) ?
  1098. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1099. PBF_REG_P4_TQ_OCCUPANCY,
  1100. (CHIP_IS_E3B0(bp)) ?
  1101. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1102. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1103. };
  1104. struct pbf_pN_buf_regs buf_regs[] = {
  1105. {0, (CHIP_IS_E3B0(bp)) ?
  1106. PBF_REG_INIT_CRD_Q0 :
  1107. PBF_REG_P0_INIT_CRD ,
  1108. (CHIP_IS_E3B0(bp)) ?
  1109. PBF_REG_CREDIT_Q0 :
  1110. PBF_REG_P0_CREDIT,
  1111. (CHIP_IS_E3B0(bp)) ?
  1112. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1113. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1114. {1, (CHIP_IS_E3B0(bp)) ?
  1115. PBF_REG_INIT_CRD_Q1 :
  1116. PBF_REG_P1_INIT_CRD,
  1117. (CHIP_IS_E3B0(bp)) ?
  1118. PBF_REG_CREDIT_Q1 :
  1119. PBF_REG_P1_CREDIT,
  1120. (CHIP_IS_E3B0(bp)) ?
  1121. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1122. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1123. {4, (CHIP_IS_E3B0(bp)) ?
  1124. PBF_REG_INIT_CRD_LB_Q :
  1125. PBF_REG_P4_INIT_CRD,
  1126. (CHIP_IS_E3B0(bp)) ?
  1127. PBF_REG_CREDIT_LB_Q :
  1128. PBF_REG_P4_CREDIT,
  1129. (CHIP_IS_E3B0(bp)) ?
  1130. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1131. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1132. };
  1133. int i;
  1134. /* Verify the command queues are flushed P0, P1, P4 */
  1135. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1136. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1137. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1138. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1139. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1140. }
  1141. #define OP_GEN_PARAM(param) \
  1142. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1143. #define OP_GEN_TYPE(type) \
  1144. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1145. #define OP_GEN_AGG_VECT(index) \
  1146. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1147. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1148. {
  1149. u32 op_gen_command = 0;
  1150. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1151. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1152. int ret = 0;
  1153. if (REG_RD(bp, comp_addr)) {
  1154. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1155. return 1;
  1156. }
  1157. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1158. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1159. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1160. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1161. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1162. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1163. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1164. BNX2X_ERR("FW final cleanup did not succeed\n");
  1165. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1166. (REG_RD(bp, comp_addr)));
  1167. bnx2x_panic();
  1168. return 1;
  1169. }
  1170. /* Zero completion for next FLR */
  1171. REG_WR(bp, comp_addr, 0);
  1172. return ret;
  1173. }
  1174. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1175. {
  1176. u16 status;
  1177. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1178. return status & PCI_EXP_DEVSTA_TRPND;
  1179. }
  1180. /* PF FLR specific routines
  1181. */
  1182. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1183. {
  1184. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1185. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1186. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1187. "CFC PF usage counter timed out",
  1188. poll_cnt))
  1189. return 1;
  1190. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1191. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1192. DORQ_REG_PF_USAGE_CNT,
  1193. "DQ PF usage counter timed out",
  1194. poll_cnt))
  1195. return 1;
  1196. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1197. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1198. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1199. "QM PF usage counter timed out",
  1200. poll_cnt))
  1201. return 1;
  1202. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1203. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1204. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1205. "Timers VNIC usage counter timed out",
  1206. poll_cnt))
  1207. return 1;
  1208. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1209. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1210. "Timers NUM_SCANS usage counter timed out",
  1211. poll_cnt))
  1212. return 1;
  1213. /* Wait DMAE PF usage counter to zero */
  1214. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1215. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1216. "DMAE command register timed out",
  1217. poll_cnt))
  1218. return 1;
  1219. return 0;
  1220. }
  1221. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1222. {
  1223. u32 val;
  1224. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1225. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1226. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1227. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1228. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1229. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1230. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1231. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1232. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1233. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1234. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1235. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1236. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1237. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1238. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1239. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1240. val);
  1241. }
  1242. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1243. {
  1244. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1245. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1246. /* Re-enable PF target read access */
  1247. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1248. /* Poll HW usage counters */
  1249. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1250. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1251. return -EBUSY;
  1252. /* Zero the igu 'trailing edge' and 'leading edge' */
  1253. /* Send the FW cleanup command */
  1254. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1255. return -EBUSY;
  1256. /* ATC cleanup */
  1257. /* Verify TX hw is flushed */
  1258. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1259. /* Wait 100ms (not adjusted according to platform) */
  1260. msleep(100);
  1261. /* Verify no pending pci transactions */
  1262. if (bnx2x_is_pcie_pending(bp->pdev))
  1263. BNX2X_ERR("PCIE Transactions still pending\n");
  1264. /* Debug */
  1265. bnx2x_hw_enable_status(bp);
  1266. /*
  1267. * Master enable - Due to WB DMAE writes performed before this
  1268. * register is re-initialized as part of the regular function init
  1269. */
  1270. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1271. return 0;
  1272. }
  1273. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1274. {
  1275. int port = BP_PORT(bp);
  1276. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1277. u32 val = REG_RD(bp, addr);
  1278. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1279. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1280. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1281. if (msix) {
  1282. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1283. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1284. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1285. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1286. if (single_msix)
  1287. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1288. } else if (msi) {
  1289. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1290. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1291. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1292. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1293. } else {
  1294. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1295. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1296. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1297. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1298. if (!CHIP_IS_E1(bp)) {
  1299. DP(NETIF_MSG_IFUP,
  1300. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1301. REG_WR(bp, addr, val);
  1302. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1303. }
  1304. }
  1305. if (CHIP_IS_E1(bp))
  1306. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1307. DP(NETIF_MSG_IFUP,
  1308. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1309. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1310. REG_WR(bp, addr, val);
  1311. /*
  1312. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1313. */
  1314. mmiowb();
  1315. barrier();
  1316. if (!CHIP_IS_E1(bp)) {
  1317. /* init leading/trailing edge */
  1318. if (IS_MF(bp)) {
  1319. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1320. if (bp->port.pmf)
  1321. /* enable nig and gpio3 attention */
  1322. val |= 0x1100;
  1323. } else
  1324. val = 0xffff;
  1325. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1326. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1327. }
  1328. /* Make sure that interrupts are indeed enabled from here on */
  1329. mmiowb();
  1330. }
  1331. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1332. {
  1333. u32 val;
  1334. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1335. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1336. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1337. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1338. if (msix) {
  1339. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1340. IGU_PF_CONF_SINGLE_ISR_EN);
  1341. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1342. IGU_PF_CONF_ATTN_BIT_EN);
  1343. if (single_msix)
  1344. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1345. } else if (msi) {
  1346. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1347. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1348. IGU_PF_CONF_ATTN_BIT_EN |
  1349. IGU_PF_CONF_SINGLE_ISR_EN);
  1350. } else {
  1351. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1352. val |= (IGU_PF_CONF_INT_LINE_EN |
  1353. IGU_PF_CONF_ATTN_BIT_EN |
  1354. IGU_PF_CONF_SINGLE_ISR_EN);
  1355. }
  1356. /* Clean previous status - need to configure igu prior to ack*/
  1357. if ((!msix) || single_msix) {
  1358. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1359. bnx2x_ack_int(bp);
  1360. }
  1361. val |= IGU_PF_CONF_FUNC_EN;
  1362. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1363. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1364. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1365. if (val & IGU_PF_CONF_INT_LINE_EN)
  1366. pci_intx(bp->pdev, true);
  1367. barrier();
  1368. /* init leading/trailing edge */
  1369. if (IS_MF(bp)) {
  1370. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1371. if (bp->port.pmf)
  1372. /* enable nig and gpio3 attention */
  1373. val |= 0x1100;
  1374. } else
  1375. val = 0xffff;
  1376. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1377. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1378. /* Make sure that interrupts are indeed enabled from here on */
  1379. mmiowb();
  1380. }
  1381. void bnx2x_int_enable(struct bnx2x *bp)
  1382. {
  1383. if (bp->common.int_block == INT_BLOCK_HC)
  1384. bnx2x_hc_int_enable(bp);
  1385. else
  1386. bnx2x_igu_int_enable(bp);
  1387. }
  1388. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1389. {
  1390. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1391. int i, offset;
  1392. if (disable_hw)
  1393. /* prevent the HW from sending interrupts */
  1394. bnx2x_int_disable(bp);
  1395. /* make sure all ISRs are done */
  1396. if (msix) {
  1397. synchronize_irq(bp->msix_table[0].vector);
  1398. offset = 1;
  1399. if (CNIC_SUPPORT(bp))
  1400. offset++;
  1401. for_each_eth_queue(bp, i)
  1402. synchronize_irq(bp->msix_table[offset++].vector);
  1403. } else
  1404. synchronize_irq(bp->pdev->irq);
  1405. /* make sure sp_task is not running */
  1406. cancel_delayed_work(&bp->sp_task);
  1407. cancel_delayed_work(&bp->period_task);
  1408. flush_workqueue(bnx2x_wq);
  1409. }
  1410. /* fast path */
  1411. /*
  1412. * General service functions
  1413. */
  1414. /* Return true if succeeded to acquire the lock */
  1415. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1416. {
  1417. u32 lock_status;
  1418. u32 resource_bit = (1 << resource);
  1419. int func = BP_FUNC(bp);
  1420. u32 hw_lock_control_reg;
  1421. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1422. "Trying to take a lock on resource %d\n", resource);
  1423. /* Validating that the resource is within range */
  1424. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1425. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1426. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1427. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1428. return false;
  1429. }
  1430. if (func <= 5)
  1431. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1432. else
  1433. hw_lock_control_reg =
  1434. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1435. /* Try to acquire the lock */
  1436. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1437. lock_status = REG_RD(bp, hw_lock_control_reg);
  1438. if (lock_status & resource_bit)
  1439. return true;
  1440. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1441. "Failed to get a lock on resource %d\n", resource);
  1442. return false;
  1443. }
  1444. /**
  1445. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1446. *
  1447. * @bp: driver handle
  1448. *
  1449. * Returns the recovery leader resource id according to the engine this function
  1450. * belongs to. Currently only only 2 engines is supported.
  1451. */
  1452. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1453. {
  1454. if (BP_PATH(bp))
  1455. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1456. else
  1457. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1458. }
  1459. /**
  1460. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1461. *
  1462. * @bp: driver handle
  1463. *
  1464. * Tries to acquire a leader lock for current engine.
  1465. */
  1466. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1467. {
  1468. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1469. }
  1470. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1471. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1472. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1473. {
  1474. /* Set the interrupt occurred bit for the sp-task to recognize it
  1475. * must ack the interrupt and transition according to the IGU
  1476. * state machine.
  1477. */
  1478. atomic_set(&bp->interrupt_occurred, 1);
  1479. /* The sp_task must execute only after this bit
  1480. * is set, otherwise we will get out of sync and miss all
  1481. * further interrupts. Hence, the barrier.
  1482. */
  1483. smp_wmb();
  1484. /* schedule sp_task to workqueue */
  1485. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1486. }
  1487. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1488. {
  1489. struct bnx2x *bp = fp->bp;
  1490. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1491. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1492. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1493. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1494. DP(BNX2X_MSG_SP,
  1495. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1496. fp->index, cid, command, bp->state,
  1497. rr_cqe->ramrod_cqe.ramrod_type);
  1498. /* If cid is within VF range, replace the slowpath object with the
  1499. * one corresponding to this VF
  1500. */
  1501. if (cid >= BNX2X_FIRST_VF_CID &&
  1502. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1503. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1504. switch (command) {
  1505. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1506. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1507. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1508. break;
  1509. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1510. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1511. drv_cmd = BNX2X_Q_CMD_SETUP;
  1512. break;
  1513. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1514. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1515. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1516. break;
  1517. case (RAMROD_CMD_ID_ETH_HALT):
  1518. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1519. drv_cmd = BNX2X_Q_CMD_HALT;
  1520. break;
  1521. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1522. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1523. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1524. break;
  1525. case (RAMROD_CMD_ID_ETH_EMPTY):
  1526. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1527. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1528. break;
  1529. default:
  1530. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1531. command, fp->index);
  1532. return;
  1533. }
  1534. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1535. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1536. /* q_obj->complete_cmd() failure means that this was
  1537. * an unexpected completion.
  1538. *
  1539. * In this case we don't want to increase the bp->spq_left
  1540. * because apparently we haven't sent this command the first
  1541. * place.
  1542. */
  1543. #ifdef BNX2X_STOP_ON_ERROR
  1544. bnx2x_panic();
  1545. #else
  1546. return;
  1547. #endif
  1548. /* SRIOV: reschedule any 'in_progress' operations */
  1549. bnx2x_iov_sp_event(bp, cid, true);
  1550. smp_mb__before_atomic_inc();
  1551. atomic_inc(&bp->cq_spq_left);
  1552. /* push the change in bp->spq_left and towards the memory */
  1553. smp_mb__after_atomic_inc();
  1554. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1555. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1556. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1557. /* if Q update ramrod is completed for last Q in AFEX vif set
  1558. * flow, then ACK MCP at the end
  1559. *
  1560. * mark pending ACK to MCP bit.
  1561. * prevent case that both bits are cleared.
  1562. * At the end of load/unload driver checks that
  1563. * sp_state is cleared, and this order prevents
  1564. * races
  1565. */
  1566. smp_mb__before_clear_bit();
  1567. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1568. wmb();
  1569. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1570. smp_mb__after_clear_bit();
  1571. /* schedule the sp task as mcp ack is required */
  1572. bnx2x_schedule_sp_task(bp);
  1573. }
  1574. return;
  1575. }
  1576. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1577. {
  1578. struct bnx2x *bp = netdev_priv(dev_instance);
  1579. u16 status = bnx2x_ack_int(bp);
  1580. u16 mask;
  1581. int i;
  1582. u8 cos;
  1583. /* Return here if interrupt is shared and it's not for us */
  1584. if (unlikely(status == 0)) {
  1585. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1586. return IRQ_NONE;
  1587. }
  1588. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1589. #ifdef BNX2X_STOP_ON_ERROR
  1590. if (unlikely(bp->panic))
  1591. return IRQ_HANDLED;
  1592. #endif
  1593. for_each_eth_queue(bp, i) {
  1594. struct bnx2x_fastpath *fp = &bp->fp[i];
  1595. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1596. if (status & mask) {
  1597. /* Handle Rx or Tx according to SB id */
  1598. for_each_cos_in_tx_queue(fp, cos)
  1599. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1600. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1601. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1602. status &= ~mask;
  1603. }
  1604. }
  1605. if (CNIC_SUPPORT(bp)) {
  1606. mask = 0x2;
  1607. if (status & (mask | 0x1)) {
  1608. struct cnic_ops *c_ops = NULL;
  1609. rcu_read_lock();
  1610. c_ops = rcu_dereference(bp->cnic_ops);
  1611. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1612. CNIC_DRV_STATE_HANDLES_IRQ))
  1613. c_ops->cnic_handler(bp->cnic_data, NULL);
  1614. rcu_read_unlock();
  1615. status &= ~mask;
  1616. }
  1617. }
  1618. if (unlikely(status & 0x1)) {
  1619. /* schedule sp task to perform default status block work, ack
  1620. * attentions and enable interrupts.
  1621. */
  1622. bnx2x_schedule_sp_task(bp);
  1623. status &= ~0x1;
  1624. if (!status)
  1625. return IRQ_HANDLED;
  1626. }
  1627. if (unlikely(status))
  1628. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1629. status);
  1630. return IRQ_HANDLED;
  1631. }
  1632. /* Link */
  1633. /*
  1634. * General service functions
  1635. */
  1636. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1637. {
  1638. u32 lock_status;
  1639. u32 resource_bit = (1 << resource);
  1640. int func = BP_FUNC(bp);
  1641. u32 hw_lock_control_reg;
  1642. int cnt;
  1643. /* Validating that the resource is within range */
  1644. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1645. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1646. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1647. return -EINVAL;
  1648. }
  1649. if (func <= 5) {
  1650. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1651. } else {
  1652. hw_lock_control_reg =
  1653. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1654. }
  1655. /* Validating that the resource is not already taken */
  1656. lock_status = REG_RD(bp, hw_lock_control_reg);
  1657. if (lock_status & resource_bit) {
  1658. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1659. lock_status, resource_bit);
  1660. return -EEXIST;
  1661. }
  1662. /* Try for 5 second every 5ms */
  1663. for (cnt = 0; cnt < 1000; cnt++) {
  1664. /* Try to acquire the lock */
  1665. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1666. lock_status = REG_RD(bp, hw_lock_control_reg);
  1667. if (lock_status & resource_bit)
  1668. return 0;
  1669. usleep_range(5000, 10000);
  1670. }
  1671. BNX2X_ERR("Timeout\n");
  1672. return -EAGAIN;
  1673. }
  1674. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1675. {
  1676. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1677. }
  1678. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1679. {
  1680. u32 lock_status;
  1681. u32 resource_bit = (1 << resource);
  1682. int func = BP_FUNC(bp);
  1683. u32 hw_lock_control_reg;
  1684. /* Validating that the resource is within range */
  1685. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1686. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1687. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1688. return -EINVAL;
  1689. }
  1690. if (func <= 5) {
  1691. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1692. } else {
  1693. hw_lock_control_reg =
  1694. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1695. }
  1696. /* Validating that the resource is currently taken */
  1697. lock_status = REG_RD(bp, hw_lock_control_reg);
  1698. if (!(lock_status & resource_bit)) {
  1699. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1700. lock_status, resource_bit);
  1701. return -EFAULT;
  1702. }
  1703. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1704. return 0;
  1705. }
  1706. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1707. {
  1708. /* The GPIO should be swapped if swap register is set and active */
  1709. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1710. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1711. int gpio_shift = gpio_num +
  1712. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1713. u32 gpio_mask = (1 << gpio_shift);
  1714. u32 gpio_reg;
  1715. int value;
  1716. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1717. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1718. return -EINVAL;
  1719. }
  1720. /* read GPIO value */
  1721. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1722. /* get the requested pin value */
  1723. if ((gpio_reg & gpio_mask) == gpio_mask)
  1724. value = 1;
  1725. else
  1726. value = 0;
  1727. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1728. return value;
  1729. }
  1730. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1731. {
  1732. /* The GPIO should be swapped if swap register is set and active */
  1733. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1734. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1735. int gpio_shift = gpio_num +
  1736. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1737. u32 gpio_mask = (1 << gpio_shift);
  1738. u32 gpio_reg;
  1739. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1740. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1741. return -EINVAL;
  1742. }
  1743. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1744. /* read GPIO and mask except the float bits */
  1745. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1746. switch (mode) {
  1747. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1748. DP(NETIF_MSG_LINK,
  1749. "Set GPIO %d (shift %d) -> output low\n",
  1750. gpio_num, gpio_shift);
  1751. /* clear FLOAT and set CLR */
  1752. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1753. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1754. break;
  1755. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1756. DP(NETIF_MSG_LINK,
  1757. "Set GPIO %d (shift %d) -> output high\n",
  1758. gpio_num, gpio_shift);
  1759. /* clear FLOAT and set SET */
  1760. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1761. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1762. break;
  1763. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1764. DP(NETIF_MSG_LINK,
  1765. "Set GPIO %d (shift %d) -> input\n",
  1766. gpio_num, gpio_shift);
  1767. /* set FLOAT */
  1768. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1769. break;
  1770. default:
  1771. break;
  1772. }
  1773. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1774. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1775. return 0;
  1776. }
  1777. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1778. {
  1779. u32 gpio_reg = 0;
  1780. int rc = 0;
  1781. /* Any port swapping should be handled by caller. */
  1782. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1783. /* read GPIO and mask except the float bits */
  1784. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1785. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1786. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1787. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1788. switch (mode) {
  1789. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1790. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1791. /* set CLR */
  1792. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1793. break;
  1794. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1795. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1796. /* set SET */
  1797. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1798. break;
  1799. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1800. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1801. /* set FLOAT */
  1802. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1803. break;
  1804. default:
  1805. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1806. rc = -EINVAL;
  1807. break;
  1808. }
  1809. if (rc == 0)
  1810. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1811. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1812. return rc;
  1813. }
  1814. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1815. {
  1816. /* The GPIO should be swapped if swap register is set and active */
  1817. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1818. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1819. int gpio_shift = gpio_num +
  1820. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1821. u32 gpio_mask = (1 << gpio_shift);
  1822. u32 gpio_reg;
  1823. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1824. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1825. return -EINVAL;
  1826. }
  1827. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1828. /* read GPIO int */
  1829. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1830. switch (mode) {
  1831. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1832. DP(NETIF_MSG_LINK,
  1833. "Clear GPIO INT %d (shift %d) -> output low\n",
  1834. gpio_num, gpio_shift);
  1835. /* clear SET and set CLR */
  1836. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1837. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1838. break;
  1839. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1840. DP(NETIF_MSG_LINK,
  1841. "Set GPIO INT %d (shift %d) -> output high\n",
  1842. gpio_num, gpio_shift);
  1843. /* clear CLR and set SET */
  1844. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1845. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1846. break;
  1847. default:
  1848. break;
  1849. }
  1850. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1851. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1852. return 0;
  1853. }
  1854. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1855. {
  1856. u32 spio_reg;
  1857. /* Only 2 SPIOs are configurable */
  1858. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1859. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1860. return -EINVAL;
  1861. }
  1862. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1863. /* read SPIO and mask except the float bits */
  1864. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1865. switch (mode) {
  1866. case MISC_SPIO_OUTPUT_LOW:
  1867. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1868. /* clear FLOAT and set CLR */
  1869. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1870. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1871. break;
  1872. case MISC_SPIO_OUTPUT_HIGH:
  1873. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1874. /* clear FLOAT and set SET */
  1875. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1876. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1877. break;
  1878. case MISC_SPIO_INPUT_HI_Z:
  1879. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1880. /* set FLOAT */
  1881. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1882. break;
  1883. default:
  1884. break;
  1885. }
  1886. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1887. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1888. return 0;
  1889. }
  1890. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1891. {
  1892. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1893. switch (bp->link_vars.ieee_fc &
  1894. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1895. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1896. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1897. ADVERTISED_Pause);
  1898. break;
  1899. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1900. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1901. ADVERTISED_Pause);
  1902. break;
  1903. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1904. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1905. break;
  1906. default:
  1907. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1908. ADVERTISED_Pause);
  1909. break;
  1910. }
  1911. }
  1912. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1913. {
  1914. /* Initialize link parameters structure variables
  1915. * It is recommended to turn off RX FC for jumbo frames
  1916. * for better performance
  1917. */
  1918. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1919. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1920. else
  1921. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1922. }
  1923. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1924. {
  1925. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1926. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1927. if (!BP_NOMCP(bp)) {
  1928. bnx2x_set_requested_fc(bp);
  1929. bnx2x_acquire_phy_lock(bp);
  1930. if (load_mode == LOAD_DIAG) {
  1931. struct link_params *lp = &bp->link_params;
  1932. lp->loopback_mode = LOOPBACK_XGXS;
  1933. /* do PHY loopback at 10G speed, if possible */
  1934. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1935. if (lp->speed_cap_mask[cfx_idx] &
  1936. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1937. lp->req_line_speed[cfx_idx] =
  1938. SPEED_10000;
  1939. else
  1940. lp->req_line_speed[cfx_idx] =
  1941. SPEED_1000;
  1942. }
  1943. }
  1944. if (load_mode == LOAD_LOOPBACK_EXT) {
  1945. struct link_params *lp = &bp->link_params;
  1946. lp->loopback_mode = LOOPBACK_EXT;
  1947. }
  1948. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1949. bnx2x_release_phy_lock(bp);
  1950. bnx2x_calc_fc_adv(bp);
  1951. if (bp->link_vars.link_up) {
  1952. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1953. bnx2x_link_report(bp);
  1954. }
  1955. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1956. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1957. return rc;
  1958. }
  1959. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1960. return -EINVAL;
  1961. }
  1962. void bnx2x_link_set(struct bnx2x *bp)
  1963. {
  1964. if (!BP_NOMCP(bp)) {
  1965. bnx2x_acquire_phy_lock(bp);
  1966. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1967. bnx2x_release_phy_lock(bp);
  1968. bnx2x_calc_fc_adv(bp);
  1969. } else
  1970. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1971. }
  1972. static void bnx2x__link_reset(struct bnx2x *bp)
  1973. {
  1974. if (!BP_NOMCP(bp)) {
  1975. bnx2x_acquire_phy_lock(bp);
  1976. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1977. bnx2x_release_phy_lock(bp);
  1978. } else
  1979. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1980. }
  1981. void bnx2x_force_link_reset(struct bnx2x *bp)
  1982. {
  1983. bnx2x_acquire_phy_lock(bp);
  1984. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1985. bnx2x_release_phy_lock(bp);
  1986. }
  1987. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1988. {
  1989. u8 rc = 0;
  1990. if (!BP_NOMCP(bp)) {
  1991. bnx2x_acquire_phy_lock(bp);
  1992. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1993. is_serdes);
  1994. bnx2x_release_phy_lock(bp);
  1995. } else
  1996. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1997. return rc;
  1998. }
  1999. /* Calculates the sum of vn_min_rates.
  2000. It's needed for further normalizing of the min_rates.
  2001. Returns:
  2002. sum of vn_min_rates.
  2003. or
  2004. 0 - if all the min_rates are 0.
  2005. In the later case fairness algorithm should be deactivated.
  2006. If not all min_rates are zero then those that are zeroes will be set to 1.
  2007. */
  2008. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2009. struct cmng_init_input *input)
  2010. {
  2011. int all_zero = 1;
  2012. int vn;
  2013. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2014. u32 vn_cfg = bp->mf_config[vn];
  2015. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2016. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2017. /* Skip hidden vns */
  2018. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2019. vn_min_rate = 0;
  2020. /* If min rate is zero - set it to 1 */
  2021. else if (!vn_min_rate)
  2022. vn_min_rate = DEF_MIN_RATE;
  2023. else
  2024. all_zero = 0;
  2025. input->vnic_min_rate[vn] = vn_min_rate;
  2026. }
  2027. /* if ETS or all min rates are zeros - disable fairness */
  2028. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2029. input->flags.cmng_enables &=
  2030. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2031. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2032. } else if (all_zero) {
  2033. input->flags.cmng_enables &=
  2034. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2035. DP(NETIF_MSG_IFUP,
  2036. "All MIN values are zeroes fairness will be disabled\n");
  2037. } else
  2038. input->flags.cmng_enables |=
  2039. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2040. }
  2041. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2042. struct cmng_init_input *input)
  2043. {
  2044. u16 vn_max_rate;
  2045. u32 vn_cfg = bp->mf_config[vn];
  2046. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2047. vn_max_rate = 0;
  2048. else {
  2049. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2050. if (IS_MF_SI(bp)) {
  2051. /* maxCfg in percents of linkspeed */
  2052. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2053. } else /* SD modes */
  2054. /* maxCfg is absolute in 100Mb units */
  2055. vn_max_rate = maxCfg * 100;
  2056. }
  2057. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2058. input->vnic_max_rate[vn] = vn_max_rate;
  2059. }
  2060. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2061. {
  2062. if (CHIP_REV_IS_SLOW(bp))
  2063. return CMNG_FNS_NONE;
  2064. if (IS_MF(bp))
  2065. return CMNG_FNS_MINMAX;
  2066. return CMNG_FNS_NONE;
  2067. }
  2068. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2069. {
  2070. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2071. if (BP_NOMCP(bp))
  2072. return; /* what should be the default value in this case */
  2073. /* For 2 port configuration the absolute function number formula
  2074. * is:
  2075. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2076. *
  2077. * and there are 4 functions per port
  2078. *
  2079. * For 4 port configuration it is
  2080. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2081. *
  2082. * and there are 2 functions per port
  2083. */
  2084. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2085. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2086. if (func >= E1H_FUNC_MAX)
  2087. break;
  2088. bp->mf_config[vn] =
  2089. MF_CFG_RD(bp, func_mf_config[func].config);
  2090. }
  2091. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2092. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2093. bp->flags |= MF_FUNC_DIS;
  2094. } else {
  2095. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2096. bp->flags &= ~MF_FUNC_DIS;
  2097. }
  2098. }
  2099. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2100. {
  2101. struct cmng_init_input input;
  2102. memset(&input, 0, sizeof(struct cmng_init_input));
  2103. input.port_rate = bp->link_vars.line_speed;
  2104. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2105. int vn;
  2106. /* read mf conf from shmem */
  2107. if (read_cfg)
  2108. bnx2x_read_mf_cfg(bp);
  2109. /* vn_weight_sum and enable fairness if not 0 */
  2110. bnx2x_calc_vn_min(bp, &input);
  2111. /* calculate and set min-max rate for each vn */
  2112. if (bp->port.pmf)
  2113. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2114. bnx2x_calc_vn_max(bp, vn, &input);
  2115. /* always enable rate shaping and fairness */
  2116. input.flags.cmng_enables |=
  2117. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2118. bnx2x_init_cmng(&input, &bp->cmng);
  2119. return;
  2120. }
  2121. /* rate shaping and fairness are disabled */
  2122. DP(NETIF_MSG_IFUP,
  2123. "rate shaping and fairness are disabled\n");
  2124. }
  2125. static void storm_memset_cmng(struct bnx2x *bp,
  2126. struct cmng_init *cmng,
  2127. u8 port)
  2128. {
  2129. int vn;
  2130. size_t size = sizeof(struct cmng_struct_per_port);
  2131. u32 addr = BAR_XSTRORM_INTMEM +
  2132. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2133. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2134. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2135. int func = func_by_vn(bp, vn);
  2136. addr = BAR_XSTRORM_INTMEM +
  2137. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2138. size = sizeof(struct rate_shaping_vars_per_vn);
  2139. __storm_memset_struct(bp, addr, size,
  2140. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2141. addr = BAR_XSTRORM_INTMEM +
  2142. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2143. size = sizeof(struct fairness_vars_per_vn);
  2144. __storm_memset_struct(bp, addr, size,
  2145. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2146. }
  2147. }
  2148. /* init cmng mode in HW according to local configuration */
  2149. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2150. {
  2151. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2152. if (cmng_fns != CMNG_FNS_NONE) {
  2153. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2154. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2155. } else {
  2156. /* rate shaping and fairness are disabled */
  2157. DP(NETIF_MSG_IFUP,
  2158. "single function mode without fairness\n");
  2159. }
  2160. }
  2161. /* This function is called upon link interrupt */
  2162. static void bnx2x_link_attn(struct bnx2x *bp)
  2163. {
  2164. /* Make sure that we are synced with the current statistics */
  2165. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2166. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2167. if (bp->link_vars.link_up) {
  2168. /* dropless flow control */
  2169. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2170. int port = BP_PORT(bp);
  2171. u32 pause_enabled = 0;
  2172. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2173. pause_enabled = 1;
  2174. REG_WR(bp, BAR_USTRORM_INTMEM +
  2175. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2176. pause_enabled);
  2177. }
  2178. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2179. struct host_port_stats *pstats;
  2180. pstats = bnx2x_sp(bp, port_stats);
  2181. /* reset old mac stats */
  2182. memset(&(pstats->mac_stx[0]), 0,
  2183. sizeof(struct mac_stx));
  2184. }
  2185. if (bp->state == BNX2X_STATE_OPEN)
  2186. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2187. }
  2188. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2189. bnx2x_set_local_cmng(bp);
  2190. __bnx2x_link_report(bp);
  2191. if (IS_MF(bp))
  2192. bnx2x_link_sync_notify(bp);
  2193. }
  2194. void bnx2x__link_status_update(struct bnx2x *bp)
  2195. {
  2196. if (bp->state != BNX2X_STATE_OPEN)
  2197. return;
  2198. /* read updated dcb configuration */
  2199. if (IS_PF(bp)) {
  2200. bnx2x_dcbx_pmf_update(bp);
  2201. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2202. if (bp->link_vars.link_up)
  2203. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2204. else
  2205. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2206. /* indicate link status */
  2207. bnx2x_link_report(bp);
  2208. } else { /* VF */
  2209. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2210. SUPPORTED_10baseT_Full |
  2211. SUPPORTED_100baseT_Half |
  2212. SUPPORTED_100baseT_Full |
  2213. SUPPORTED_1000baseT_Full |
  2214. SUPPORTED_2500baseX_Full |
  2215. SUPPORTED_10000baseT_Full |
  2216. SUPPORTED_TP |
  2217. SUPPORTED_FIBRE |
  2218. SUPPORTED_Autoneg |
  2219. SUPPORTED_Pause |
  2220. SUPPORTED_Asym_Pause);
  2221. bp->port.advertising[0] = bp->port.supported[0];
  2222. bp->link_params.bp = bp;
  2223. bp->link_params.port = BP_PORT(bp);
  2224. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2225. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2226. bp->link_params.req_line_speed[0] = SPEED_10000;
  2227. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2228. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2229. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2230. bp->link_vars.line_speed = SPEED_10000;
  2231. bp->link_vars.link_status =
  2232. (LINK_STATUS_LINK_UP |
  2233. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2234. bp->link_vars.link_up = 1;
  2235. bp->link_vars.duplex = DUPLEX_FULL;
  2236. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2237. __bnx2x_link_report(bp);
  2238. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2239. }
  2240. }
  2241. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2242. u16 vlan_val, u8 allowed_prio)
  2243. {
  2244. struct bnx2x_func_state_params func_params = {NULL};
  2245. struct bnx2x_func_afex_update_params *f_update_params =
  2246. &func_params.params.afex_update;
  2247. func_params.f_obj = &bp->func_obj;
  2248. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2249. /* no need to wait for RAMROD completion, so don't
  2250. * set RAMROD_COMP_WAIT flag
  2251. */
  2252. f_update_params->vif_id = vifid;
  2253. f_update_params->afex_default_vlan = vlan_val;
  2254. f_update_params->allowed_priorities = allowed_prio;
  2255. /* if ramrod can not be sent, response to MCP immediately */
  2256. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2257. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2258. return 0;
  2259. }
  2260. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2261. u16 vif_index, u8 func_bit_map)
  2262. {
  2263. struct bnx2x_func_state_params func_params = {NULL};
  2264. struct bnx2x_func_afex_viflists_params *update_params =
  2265. &func_params.params.afex_viflists;
  2266. int rc;
  2267. u32 drv_msg_code;
  2268. /* validate only LIST_SET and LIST_GET are received from switch */
  2269. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2270. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2271. cmd_type);
  2272. func_params.f_obj = &bp->func_obj;
  2273. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2274. /* set parameters according to cmd_type */
  2275. update_params->afex_vif_list_command = cmd_type;
  2276. update_params->vif_list_index = vif_index;
  2277. update_params->func_bit_map =
  2278. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2279. update_params->func_to_clear = 0;
  2280. drv_msg_code =
  2281. (cmd_type == VIF_LIST_RULE_GET) ?
  2282. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2283. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2284. /* if ramrod can not be sent, respond to MCP immediately for
  2285. * SET and GET requests (other are not triggered from MCP)
  2286. */
  2287. rc = bnx2x_func_state_change(bp, &func_params);
  2288. if (rc < 0)
  2289. bnx2x_fw_command(bp, drv_msg_code, 0);
  2290. return 0;
  2291. }
  2292. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2293. {
  2294. struct afex_stats afex_stats;
  2295. u32 func = BP_ABS_FUNC(bp);
  2296. u32 mf_config;
  2297. u16 vlan_val;
  2298. u32 vlan_prio;
  2299. u16 vif_id;
  2300. u8 allowed_prio;
  2301. u8 vlan_mode;
  2302. u32 addr_to_write, vifid, addrs, stats_type, i;
  2303. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2304. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2305. DP(BNX2X_MSG_MCP,
  2306. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2307. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2308. }
  2309. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2310. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2311. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2312. DP(BNX2X_MSG_MCP,
  2313. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2314. vifid, addrs);
  2315. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2316. addrs);
  2317. }
  2318. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2319. addr_to_write = SHMEM2_RD(bp,
  2320. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2321. stats_type = SHMEM2_RD(bp,
  2322. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2323. DP(BNX2X_MSG_MCP,
  2324. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2325. addr_to_write);
  2326. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2327. /* write response to scratchpad, for MCP */
  2328. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2329. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2330. *(((u32 *)(&afex_stats))+i));
  2331. /* send ack message to MCP */
  2332. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2333. }
  2334. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2335. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2336. bp->mf_config[BP_VN(bp)] = mf_config;
  2337. DP(BNX2X_MSG_MCP,
  2338. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2339. mf_config);
  2340. /* if VIF_SET is "enabled" */
  2341. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2342. /* set rate limit directly to internal RAM */
  2343. struct cmng_init_input cmng_input;
  2344. struct rate_shaping_vars_per_vn m_rs_vn;
  2345. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2346. u32 addr = BAR_XSTRORM_INTMEM +
  2347. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2348. bp->mf_config[BP_VN(bp)] = mf_config;
  2349. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2350. m_rs_vn.vn_counter.rate =
  2351. cmng_input.vnic_max_rate[BP_VN(bp)];
  2352. m_rs_vn.vn_counter.quota =
  2353. (m_rs_vn.vn_counter.rate *
  2354. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2355. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2356. /* read relevant values from mf_cfg struct in shmem */
  2357. vif_id =
  2358. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2359. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2360. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2361. vlan_val =
  2362. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2363. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2364. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2365. vlan_prio = (mf_config &
  2366. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2367. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2368. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2369. vlan_mode =
  2370. (MF_CFG_RD(bp,
  2371. func_mf_config[func].afex_config) &
  2372. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2373. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2374. allowed_prio =
  2375. (MF_CFG_RD(bp,
  2376. func_mf_config[func].afex_config) &
  2377. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2378. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2379. /* send ramrod to FW, return in case of failure */
  2380. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2381. allowed_prio))
  2382. return;
  2383. bp->afex_def_vlan_tag = vlan_val;
  2384. bp->afex_vlan_mode = vlan_mode;
  2385. } else {
  2386. /* notify link down because BP->flags is disabled */
  2387. bnx2x_link_report(bp);
  2388. /* send INVALID VIF ramrod to FW */
  2389. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2390. /* Reset the default afex VLAN */
  2391. bp->afex_def_vlan_tag = -1;
  2392. }
  2393. }
  2394. }
  2395. static void bnx2x_pmf_update(struct bnx2x *bp)
  2396. {
  2397. int port = BP_PORT(bp);
  2398. u32 val;
  2399. bp->port.pmf = 1;
  2400. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2401. /*
  2402. * We need the mb() to ensure the ordering between the writing to
  2403. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2404. */
  2405. smp_mb();
  2406. /* queue a periodic task */
  2407. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2408. bnx2x_dcbx_pmf_update(bp);
  2409. /* enable nig attention */
  2410. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2411. if (bp->common.int_block == INT_BLOCK_HC) {
  2412. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2413. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2414. } else if (!CHIP_IS_E1x(bp)) {
  2415. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2416. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2417. }
  2418. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2419. }
  2420. /* end of Link */
  2421. /* slow path */
  2422. /*
  2423. * General service functions
  2424. */
  2425. /* send the MCP a request, block until there is a reply */
  2426. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2427. {
  2428. int mb_idx = BP_FW_MB_IDX(bp);
  2429. u32 seq;
  2430. u32 rc = 0;
  2431. u32 cnt = 1;
  2432. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2433. mutex_lock(&bp->fw_mb_mutex);
  2434. seq = ++bp->fw_seq;
  2435. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2436. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2437. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2438. (command | seq), param);
  2439. do {
  2440. /* let the FW do it's magic ... */
  2441. msleep(delay);
  2442. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2443. /* Give the FW up to 5 second (500*10ms) */
  2444. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2445. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2446. cnt*delay, rc, seq);
  2447. /* is this a reply to our command? */
  2448. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2449. rc &= FW_MSG_CODE_MASK;
  2450. else {
  2451. /* FW BUG! */
  2452. BNX2X_ERR("FW failed to respond!\n");
  2453. bnx2x_fw_dump(bp);
  2454. rc = 0;
  2455. }
  2456. mutex_unlock(&bp->fw_mb_mutex);
  2457. return rc;
  2458. }
  2459. static void storm_memset_func_cfg(struct bnx2x *bp,
  2460. struct tstorm_eth_function_common_config *tcfg,
  2461. u16 abs_fid)
  2462. {
  2463. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2464. u32 addr = BAR_TSTRORM_INTMEM +
  2465. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2466. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2467. }
  2468. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2469. {
  2470. if (CHIP_IS_E1x(bp)) {
  2471. struct tstorm_eth_function_common_config tcfg = {0};
  2472. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2473. }
  2474. /* Enable the function in the FW */
  2475. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2476. storm_memset_func_en(bp, p->func_id, 1);
  2477. /* spq */
  2478. if (p->func_flgs & FUNC_FLG_SPQ) {
  2479. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2480. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2481. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2482. }
  2483. }
  2484. /**
  2485. * bnx2x_get_common_flags - Return common flags
  2486. *
  2487. * @bp device handle
  2488. * @fp queue handle
  2489. * @zero_stats TRUE if statistics zeroing is needed
  2490. *
  2491. * Return the flags that are common for the Tx-only and not normal connections.
  2492. */
  2493. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2494. struct bnx2x_fastpath *fp,
  2495. bool zero_stats)
  2496. {
  2497. unsigned long flags = 0;
  2498. /* PF driver will always initialize the Queue to an ACTIVE state */
  2499. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2500. /* tx only connections collect statistics (on the same index as the
  2501. * parent connection). The statistics are zeroed when the parent
  2502. * connection is initialized.
  2503. */
  2504. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2505. if (zero_stats)
  2506. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2507. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2508. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2509. #ifdef BNX2X_STOP_ON_ERROR
  2510. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2511. #endif
  2512. return flags;
  2513. }
  2514. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2515. struct bnx2x_fastpath *fp,
  2516. bool leading)
  2517. {
  2518. unsigned long flags = 0;
  2519. /* calculate other queue flags */
  2520. if (IS_MF_SD(bp))
  2521. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2522. if (IS_FCOE_FP(fp)) {
  2523. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2524. /* For FCoE - force usage of default priority (for afex) */
  2525. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2526. }
  2527. if (!fp->disable_tpa) {
  2528. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2529. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2530. if (fp->mode == TPA_MODE_GRO)
  2531. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2532. }
  2533. if (leading) {
  2534. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2535. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2536. }
  2537. /* Always set HW VLAN stripping */
  2538. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2539. /* configure silent vlan removal */
  2540. if (IS_MF_AFEX(bp))
  2541. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2542. return flags | bnx2x_get_common_flags(bp, fp, true);
  2543. }
  2544. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2545. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2546. u8 cos)
  2547. {
  2548. gen_init->stat_id = bnx2x_stats_id(fp);
  2549. gen_init->spcl_id = fp->cl_id;
  2550. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2551. if (IS_FCOE_FP(fp))
  2552. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2553. else
  2554. gen_init->mtu = bp->dev->mtu;
  2555. gen_init->cos = cos;
  2556. }
  2557. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2558. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2559. struct bnx2x_rxq_setup_params *rxq_init)
  2560. {
  2561. u8 max_sge = 0;
  2562. u16 sge_sz = 0;
  2563. u16 tpa_agg_size = 0;
  2564. if (!fp->disable_tpa) {
  2565. pause->sge_th_lo = SGE_TH_LO(bp);
  2566. pause->sge_th_hi = SGE_TH_HI(bp);
  2567. /* validate SGE ring has enough to cross high threshold */
  2568. WARN_ON(bp->dropless_fc &&
  2569. pause->sge_th_hi + FW_PREFETCH_CNT >
  2570. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2571. tpa_agg_size = TPA_AGG_SIZE;
  2572. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2573. SGE_PAGE_SHIFT;
  2574. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2575. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2576. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2577. }
  2578. /* pause - not for e1 */
  2579. if (!CHIP_IS_E1(bp)) {
  2580. pause->bd_th_lo = BD_TH_LO(bp);
  2581. pause->bd_th_hi = BD_TH_HI(bp);
  2582. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2583. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2584. /*
  2585. * validate that rings have enough entries to cross
  2586. * high thresholds
  2587. */
  2588. WARN_ON(bp->dropless_fc &&
  2589. pause->bd_th_hi + FW_PREFETCH_CNT >
  2590. bp->rx_ring_size);
  2591. WARN_ON(bp->dropless_fc &&
  2592. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2593. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2594. pause->pri_map = 1;
  2595. }
  2596. /* rxq setup */
  2597. rxq_init->dscr_map = fp->rx_desc_mapping;
  2598. rxq_init->sge_map = fp->rx_sge_mapping;
  2599. rxq_init->rcq_map = fp->rx_comp_mapping;
  2600. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2601. /* This should be a maximum number of data bytes that may be
  2602. * placed on the BD (not including paddings).
  2603. */
  2604. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2605. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2606. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2607. rxq_init->tpa_agg_sz = tpa_agg_size;
  2608. rxq_init->sge_buf_sz = sge_sz;
  2609. rxq_init->max_sges_pkt = max_sge;
  2610. rxq_init->rss_engine_id = BP_FUNC(bp);
  2611. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2612. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2613. *
  2614. * For PF Clients it should be the maximum available number.
  2615. * VF driver(s) may want to define it to a smaller value.
  2616. */
  2617. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2618. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2619. rxq_init->fw_sb_id = fp->fw_sb_id;
  2620. if (IS_FCOE_FP(fp))
  2621. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2622. else
  2623. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2624. /* configure silent vlan removal
  2625. * if multi function mode is afex, then mask default vlan
  2626. */
  2627. if (IS_MF_AFEX(bp)) {
  2628. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2629. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2630. }
  2631. }
  2632. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2633. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2634. u8 cos)
  2635. {
  2636. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2637. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2638. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2639. txq_init->fw_sb_id = fp->fw_sb_id;
  2640. /*
  2641. * set the tss leading client id for TX classification ==
  2642. * leading RSS client id
  2643. */
  2644. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2645. if (IS_FCOE_FP(fp)) {
  2646. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2647. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2648. }
  2649. }
  2650. static void bnx2x_pf_init(struct bnx2x *bp)
  2651. {
  2652. struct bnx2x_func_init_params func_init = {0};
  2653. struct event_ring_data eq_data = { {0} };
  2654. u16 flags;
  2655. if (!CHIP_IS_E1x(bp)) {
  2656. /* reset IGU PF statistics: MSIX + ATTN */
  2657. /* PF */
  2658. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2659. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2660. (CHIP_MODE_IS_4_PORT(bp) ?
  2661. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2662. /* ATTN */
  2663. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2664. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2665. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2666. (CHIP_MODE_IS_4_PORT(bp) ?
  2667. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2668. }
  2669. /* function setup flags */
  2670. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2671. /* This flag is relevant for E1x only.
  2672. * E2 doesn't have a TPA configuration in a function level.
  2673. */
  2674. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2675. func_init.func_flgs = flags;
  2676. func_init.pf_id = BP_FUNC(bp);
  2677. func_init.func_id = BP_FUNC(bp);
  2678. func_init.spq_map = bp->spq_mapping;
  2679. func_init.spq_prod = bp->spq_prod_idx;
  2680. bnx2x_func_init(bp, &func_init);
  2681. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2682. /*
  2683. * Congestion management values depend on the link rate
  2684. * There is no active link so initial link rate is set to 10 Gbps.
  2685. * When the link comes up The congestion management values are
  2686. * re-calculated according to the actual link rate.
  2687. */
  2688. bp->link_vars.line_speed = SPEED_10000;
  2689. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2690. /* Only the PMF sets the HW */
  2691. if (bp->port.pmf)
  2692. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2693. /* init Event Queue - PCI bus guarantees correct endianity*/
  2694. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2695. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2696. eq_data.producer = bp->eq_prod;
  2697. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2698. eq_data.sb_id = DEF_SB_ID;
  2699. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2700. }
  2701. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2702. {
  2703. int port = BP_PORT(bp);
  2704. bnx2x_tx_disable(bp);
  2705. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2706. }
  2707. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2708. {
  2709. int port = BP_PORT(bp);
  2710. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2711. /* Tx queue should be only re-enabled */
  2712. netif_tx_wake_all_queues(bp->dev);
  2713. /*
  2714. * Should not call netif_carrier_on since it will be called if the link
  2715. * is up when checking for link state
  2716. */
  2717. }
  2718. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2719. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2720. {
  2721. struct eth_stats_info *ether_stat =
  2722. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2723. struct bnx2x_vlan_mac_obj *mac_obj =
  2724. &bp->sp_objs->mac_obj;
  2725. int i;
  2726. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2727. ETH_STAT_INFO_VERSION_LEN);
  2728. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2729. * mac_local field in ether_stat struct. The base address is offset by 2
  2730. * bytes to account for the field being 8 bytes but a mac address is
  2731. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2732. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2733. * allocated by the ether_stat struct, so the macs will land in their
  2734. * proper positions.
  2735. */
  2736. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2737. memset(ether_stat->mac_local + i, 0,
  2738. sizeof(ether_stat->mac_local[0]));
  2739. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2740. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2741. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2742. ETH_ALEN);
  2743. ether_stat->mtu_size = bp->dev->mtu;
  2744. if (bp->dev->features & NETIF_F_RXCSUM)
  2745. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2746. if (bp->dev->features & NETIF_F_TSO)
  2747. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2748. ether_stat->feature_flags |= bp->common.boot_mode;
  2749. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2750. ether_stat->txq_size = bp->tx_ring_size;
  2751. ether_stat->rxq_size = bp->rx_ring_size;
  2752. }
  2753. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2754. {
  2755. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2756. struct fcoe_stats_info *fcoe_stat =
  2757. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2758. if (!CNIC_LOADED(bp))
  2759. return;
  2760. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2761. fcoe_stat->qos_priority =
  2762. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2763. /* insert FCoE stats from ramrod response */
  2764. if (!NO_FCOE(bp)) {
  2765. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2766. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2767. tstorm_queue_statistics;
  2768. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2769. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2770. xstorm_queue_statistics;
  2771. struct fcoe_statistics_params *fw_fcoe_stat =
  2772. &bp->fw_stats_data->fcoe;
  2773. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2774. fcoe_stat->rx_bytes_lo,
  2775. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2776. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2777. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2778. fcoe_stat->rx_bytes_lo,
  2779. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2780. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2781. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2782. fcoe_stat->rx_bytes_lo,
  2783. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2784. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2785. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2786. fcoe_stat->rx_bytes_lo,
  2787. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2788. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2789. fcoe_stat->rx_frames_lo,
  2790. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2791. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2792. fcoe_stat->rx_frames_lo,
  2793. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2794. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2795. fcoe_stat->rx_frames_lo,
  2796. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2797. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2798. fcoe_stat->rx_frames_lo,
  2799. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2800. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2801. fcoe_stat->tx_bytes_lo,
  2802. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2803. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2804. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2805. fcoe_stat->tx_bytes_lo,
  2806. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2807. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2808. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2809. fcoe_stat->tx_bytes_lo,
  2810. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2811. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2812. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2813. fcoe_stat->tx_bytes_lo,
  2814. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2815. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2816. fcoe_stat->tx_frames_lo,
  2817. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2818. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2819. fcoe_stat->tx_frames_lo,
  2820. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2821. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2822. fcoe_stat->tx_frames_lo,
  2823. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2824. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2825. fcoe_stat->tx_frames_lo,
  2826. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2827. }
  2828. /* ask L5 driver to add data to the struct */
  2829. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2830. }
  2831. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2832. {
  2833. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2834. struct iscsi_stats_info *iscsi_stat =
  2835. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2836. if (!CNIC_LOADED(bp))
  2837. return;
  2838. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2839. ETH_ALEN);
  2840. iscsi_stat->qos_priority =
  2841. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2842. /* ask L5 driver to add data to the struct */
  2843. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2844. }
  2845. /* called due to MCP event (on pmf):
  2846. * reread new bandwidth configuration
  2847. * configure FW
  2848. * notify others function about the change
  2849. */
  2850. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2851. {
  2852. if (bp->link_vars.link_up) {
  2853. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2854. bnx2x_link_sync_notify(bp);
  2855. }
  2856. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2857. }
  2858. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2859. {
  2860. bnx2x_config_mf_bw(bp);
  2861. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2862. }
  2863. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2864. {
  2865. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2866. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2867. }
  2868. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2869. {
  2870. enum drv_info_opcode op_code;
  2871. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2872. /* if drv_info version supported by MFW doesn't match - send NACK */
  2873. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2874. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2875. return;
  2876. }
  2877. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2878. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2879. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2880. sizeof(union drv_info_to_mcp));
  2881. switch (op_code) {
  2882. case ETH_STATS_OPCODE:
  2883. bnx2x_drv_info_ether_stat(bp);
  2884. break;
  2885. case FCOE_STATS_OPCODE:
  2886. bnx2x_drv_info_fcoe_stat(bp);
  2887. break;
  2888. case ISCSI_STATS_OPCODE:
  2889. bnx2x_drv_info_iscsi_stat(bp);
  2890. break;
  2891. default:
  2892. /* if op code isn't supported - send NACK */
  2893. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2894. return;
  2895. }
  2896. /* if we got drv_info attn from MFW then these fields are defined in
  2897. * shmem2 for sure
  2898. */
  2899. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2900. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2901. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2902. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2903. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2904. }
  2905. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2906. {
  2907. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2908. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2909. /*
  2910. * This is the only place besides the function initialization
  2911. * where the bp->flags can change so it is done without any
  2912. * locks
  2913. */
  2914. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2915. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2916. bp->flags |= MF_FUNC_DIS;
  2917. bnx2x_e1h_disable(bp);
  2918. } else {
  2919. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2920. bp->flags &= ~MF_FUNC_DIS;
  2921. bnx2x_e1h_enable(bp);
  2922. }
  2923. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2924. }
  2925. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2926. bnx2x_config_mf_bw(bp);
  2927. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2928. }
  2929. /* Report results to MCP */
  2930. if (dcc_event)
  2931. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2932. else
  2933. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2934. }
  2935. /* must be called under the spq lock */
  2936. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2937. {
  2938. struct eth_spe *next_spe = bp->spq_prod_bd;
  2939. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2940. bp->spq_prod_bd = bp->spq;
  2941. bp->spq_prod_idx = 0;
  2942. DP(BNX2X_MSG_SP, "end of spq\n");
  2943. } else {
  2944. bp->spq_prod_bd++;
  2945. bp->spq_prod_idx++;
  2946. }
  2947. return next_spe;
  2948. }
  2949. /* must be called under the spq lock */
  2950. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2951. {
  2952. int func = BP_FUNC(bp);
  2953. /*
  2954. * Make sure that BD data is updated before writing the producer:
  2955. * BD data is written to the memory, the producer is read from the
  2956. * memory, thus we need a full memory barrier to ensure the ordering.
  2957. */
  2958. mb();
  2959. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2960. bp->spq_prod_idx);
  2961. mmiowb();
  2962. }
  2963. /**
  2964. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2965. *
  2966. * @cmd: command to check
  2967. * @cmd_type: command type
  2968. */
  2969. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2970. {
  2971. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2972. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2973. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2974. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2975. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2976. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2977. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2978. return true;
  2979. else
  2980. return false;
  2981. }
  2982. /**
  2983. * bnx2x_sp_post - place a single command on an SP ring
  2984. *
  2985. * @bp: driver handle
  2986. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2987. * @cid: SW CID the command is related to
  2988. * @data_hi: command private data address (high 32 bits)
  2989. * @data_lo: command private data address (low 32 bits)
  2990. * @cmd_type: command type (e.g. NONE, ETH)
  2991. *
  2992. * SP data is handled as if it's always an address pair, thus data fields are
  2993. * not swapped to little endian in upper functions. Instead this function swaps
  2994. * data as if it's two u32 fields.
  2995. */
  2996. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2997. u32 data_hi, u32 data_lo, int cmd_type)
  2998. {
  2999. struct eth_spe *spe;
  3000. u16 type;
  3001. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3002. #ifdef BNX2X_STOP_ON_ERROR
  3003. if (unlikely(bp->panic)) {
  3004. BNX2X_ERR("Can't post SP when there is panic\n");
  3005. return -EIO;
  3006. }
  3007. #endif
  3008. spin_lock_bh(&bp->spq_lock);
  3009. if (common) {
  3010. if (!atomic_read(&bp->eq_spq_left)) {
  3011. BNX2X_ERR("BUG! EQ ring full!\n");
  3012. spin_unlock_bh(&bp->spq_lock);
  3013. bnx2x_panic();
  3014. return -EBUSY;
  3015. }
  3016. } else if (!atomic_read(&bp->cq_spq_left)) {
  3017. BNX2X_ERR("BUG! SPQ ring full!\n");
  3018. spin_unlock_bh(&bp->spq_lock);
  3019. bnx2x_panic();
  3020. return -EBUSY;
  3021. }
  3022. spe = bnx2x_sp_get_next(bp);
  3023. /* CID needs port number to be encoded int it */
  3024. spe->hdr.conn_and_cmd_data =
  3025. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3026. HW_CID(bp, cid));
  3027. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  3028. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3029. SPE_HDR_FUNCTION_ID);
  3030. spe->hdr.type = cpu_to_le16(type);
  3031. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3032. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3033. /*
  3034. * It's ok if the actual decrement is issued towards the memory
  3035. * somewhere between the spin_lock and spin_unlock. Thus no
  3036. * more explicit memory barrier is needed.
  3037. */
  3038. if (common)
  3039. atomic_dec(&bp->eq_spq_left);
  3040. else
  3041. atomic_dec(&bp->cq_spq_left);
  3042. DP(BNX2X_MSG_SP,
  3043. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3044. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3045. (u32)(U64_LO(bp->spq_mapping) +
  3046. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3047. HW_CID(bp, cid), data_hi, data_lo, type,
  3048. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3049. bnx2x_sp_prod_update(bp);
  3050. spin_unlock_bh(&bp->spq_lock);
  3051. return 0;
  3052. }
  3053. /* acquire split MCP access lock register */
  3054. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3055. {
  3056. u32 j, val;
  3057. int rc = 0;
  3058. might_sleep();
  3059. for (j = 0; j < 1000; j++) {
  3060. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3061. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3062. if (val & MCPR_ACCESS_LOCK_LOCK)
  3063. break;
  3064. usleep_range(5000, 10000);
  3065. }
  3066. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3067. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3068. rc = -EBUSY;
  3069. }
  3070. return rc;
  3071. }
  3072. /* release split MCP access lock register */
  3073. static void bnx2x_release_alr(struct bnx2x *bp)
  3074. {
  3075. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3076. }
  3077. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3078. #define BNX2X_DEF_SB_IDX 0x0002
  3079. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3080. {
  3081. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3082. u16 rc = 0;
  3083. barrier(); /* status block is written to by the chip */
  3084. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3085. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3086. rc |= BNX2X_DEF_SB_ATT_IDX;
  3087. }
  3088. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3089. bp->def_idx = def_sb->sp_sb.running_index;
  3090. rc |= BNX2X_DEF_SB_IDX;
  3091. }
  3092. /* Do not reorder: indices reading should complete before handling */
  3093. barrier();
  3094. return rc;
  3095. }
  3096. /*
  3097. * slow path service functions
  3098. */
  3099. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3100. {
  3101. int port = BP_PORT(bp);
  3102. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3103. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3104. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3105. NIG_REG_MASK_INTERRUPT_PORT0;
  3106. u32 aeu_mask;
  3107. u32 nig_mask = 0;
  3108. u32 reg_addr;
  3109. if (bp->attn_state & asserted)
  3110. BNX2X_ERR("IGU ERROR\n");
  3111. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3112. aeu_mask = REG_RD(bp, aeu_addr);
  3113. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3114. aeu_mask, asserted);
  3115. aeu_mask &= ~(asserted & 0x3ff);
  3116. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3117. REG_WR(bp, aeu_addr, aeu_mask);
  3118. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3119. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3120. bp->attn_state |= asserted;
  3121. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3122. if (asserted & ATTN_HARD_WIRED_MASK) {
  3123. if (asserted & ATTN_NIG_FOR_FUNC) {
  3124. bnx2x_acquire_phy_lock(bp);
  3125. /* save nig interrupt mask */
  3126. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3127. /* If nig_mask is not set, no need to call the update
  3128. * function.
  3129. */
  3130. if (nig_mask) {
  3131. REG_WR(bp, nig_int_mask_addr, 0);
  3132. bnx2x_link_attn(bp);
  3133. }
  3134. /* handle unicore attn? */
  3135. }
  3136. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3137. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3138. if (asserted & GPIO_2_FUNC)
  3139. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3140. if (asserted & GPIO_3_FUNC)
  3141. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3142. if (asserted & GPIO_4_FUNC)
  3143. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3144. if (port == 0) {
  3145. if (asserted & ATTN_GENERAL_ATTN_1) {
  3146. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3147. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3148. }
  3149. if (asserted & ATTN_GENERAL_ATTN_2) {
  3150. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3151. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3152. }
  3153. if (asserted & ATTN_GENERAL_ATTN_3) {
  3154. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3155. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3156. }
  3157. } else {
  3158. if (asserted & ATTN_GENERAL_ATTN_4) {
  3159. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3160. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3161. }
  3162. if (asserted & ATTN_GENERAL_ATTN_5) {
  3163. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3164. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3165. }
  3166. if (asserted & ATTN_GENERAL_ATTN_6) {
  3167. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3168. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3169. }
  3170. }
  3171. } /* if hardwired */
  3172. if (bp->common.int_block == INT_BLOCK_HC)
  3173. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3174. COMMAND_REG_ATTN_BITS_SET);
  3175. else
  3176. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3177. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3178. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3179. REG_WR(bp, reg_addr, asserted);
  3180. /* now set back the mask */
  3181. if (asserted & ATTN_NIG_FOR_FUNC) {
  3182. /* Verify that IGU ack through BAR was written before restoring
  3183. * NIG mask. This loop should exit after 2-3 iterations max.
  3184. */
  3185. if (bp->common.int_block != INT_BLOCK_HC) {
  3186. u32 cnt = 0, igu_acked;
  3187. do {
  3188. igu_acked = REG_RD(bp,
  3189. IGU_REG_ATTENTION_ACK_BITS);
  3190. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3191. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3192. if (!igu_acked)
  3193. DP(NETIF_MSG_HW,
  3194. "Failed to verify IGU ack on time\n");
  3195. barrier();
  3196. }
  3197. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3198. bnx2x_release_phy_lock(bp);
  3199. }
  3200. }
  3201. static void bnx2x_fan_failure(struct bnx2x *bp)
  3202. {
  3203. int port = BP_PORT(bp);
  3204. u32 ext_phy_config;
  3205. /* mark the failure */
  3206. ext_phy_config =
  3207. SHMEM_RD(bp,
  3208. dev_info.port_hw_config[port].external_phy_config);
  3209. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3210. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3211. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3212. ext_phy_config);
  3213. /* log the failure */
  3214. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3215. "Please contact OEM Support for assistance\n");
  3216. /* Schedule device reset (unload)
  3217. * This is due to some boards consuming sufficient power when driver is
  3218. * up to overheat if fan fails.
  3219. */
  3220. smp_mb__before_clear_bit();
  3221. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3222. smp_mb__after_clear_bit();
  3223. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3224. }
  3225. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3226. {
  3227. int port = BP_PORT(bp);
  3228. int reg_offset;
  3229. u32 val;
  3230. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3231. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3232. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3233. val = REG_RD(bp, reg_offset);
  3234. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3235. REG_WR(bp, reg_offset, val);
  3236. BNX2X_ERR("SPIO5 hw attention\n");
  3237. /* Fan failure attention */
  3238. bnx2x_hw_reset_phy(&bp->link_params);
  3239. bnx2x_fan_failure(bp);
  3240. }
  3241. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3242. bnx2x_acquire_phy_lock(bp);
  3243. bnx2x_handle_module_detect_int(&bp->link_params);
  3244. bnx2x_release_phy_lock(bp);
  3245. }
  3246. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3247. val = REG_RD(bp, reg_offset);
  3248. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3249. REG_WR(bp, reg_offset, val);
  3250. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3251. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3252. bnx2x_panic();
  3253. }
  3254. }
  3255. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3256. {
  3257. u32 val;
  3258. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3259. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3260. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3261. /* DORQ discard attention */
  3262. if (val & 0x2)
  3263. BNX2X_ERR("FATAL error from DORQ\n");
  3264. }
  3265. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3266. int port = BP_PORT(bp);
  3267. int reg_offset;
  3268. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3269. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3270. val = REG_RD(bp, reg_offset);
  3271. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3272. REG_WR(bp, reg_offset, val);
  3273. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3274. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3275. bnx2x_panic();
  3276. }
  3277. }
  3278. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3279. {
  3280. u32 val;
  3281. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3282. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3283. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3284. /* CFC error attention */
  3285. if (val & 0x2)
  3286. BNX2X_ERR("FATAL error from CFC\n");
  3287. }
  3288. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3289. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3290. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3291. /* RQ_USDMDP_FIFO_OVERFLOW */
  3292. if (val & 0x18000)
  3293. BNX2X_ERR("FATAL error from PXP\n");
  3294. if (!CHIP_IS_E1x(bp)) {
  3295. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3296. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3297. }
  3298. }
  3299. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3300. int port = BP_PORT(bp);
  3301. int reg_offset;
  3302. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3303. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3304. val = REG_RD(bp, reg_offset);
  3305. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3306. REG_WR(bp, reg_offset, val);
  3307. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3308. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3309. bnx2x_panic();
  3310. }
  3311. }
  3312. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3313. {
  3314. u32 val;
  3315. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3316. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3317. int func = BP_FUNC(bp);
  3318. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3319. bnx2x_read_mf_cfg(bp);
  3320. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3321. func_mf_config[BP_ABS_FUNC(bp)].config);
  3322. val = SHMEM_RD(bp,
  3323. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3324. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3325. bnx2x_dcc_event(bp,
  3326. (val & DRV_STATUS_DCC_EVENT_MASK));
  3327. if (val & DRV_STATUS_SET_MF_BW)
  3328. bnx2x_set_mf_bw(bp);
  3329. if (val & DRV_STATUS_DRV_INFO_REQ)
  3330. bnx2x_handle_drv_info_req(bp);
  3331. if (val & DRV_STATUS_VF_DISABLED)
  3332. bnx2x_vf_handle_flr_event(bp);
  3333. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3334. bnx2x_pmf_update(bp);
  3335. if (bp->port.pmf &&
  3336. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3337. bp->dcbx_enabled > 0)
  3338. /* start dcbx state machine */
  3339. bnx2x_dcbx_set_params(bp,
  3340. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3341. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3342. bnx2x_handle_afex_cmd(bp,
  3343. val & DRV_STATUS_AFEX_EVENT_MASK);
  3344. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3345. bnx2x_handle_eee_event(bp);
  3346. if (bp->link_vars.periodic_flags &
  3347. PERIODIC_FLAGS_LINK_EVENT) {
  3348. /* sync with link */
  3349. bnx2x_acquire_phy_lock(bp);
  3350. bp->link_vars.periodic_flags &=
  3351. ~PERIODIC_FLAGS_LINK_EVENT;
  3352. bnx2x_release_phy_lock(bp);
  3353. if (IS_MF(bp))
  3354. bnx2x_link_sync_notify(bp);
  3355. bnx2x_link_report(bp);
  3356. }
  3357. /* Always call it here: bnx2x_link_report() will
  3358. * prevent the link indication duplication.
  3359. */
  3360. bnx2x__link_status_update(bp);
  3361. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3362. BNX2X_ERR("MC assert!\n");
  3363. bnx2x_mc_assert(bp);
  3364. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3365. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3366. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3367. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3368. bnx2x_panic();
  3369. } else if (attn & BNX2X_MCP_ASSERT) {
  3370. BNX2X_ERR("MCP assert!\n");
  3371. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3372. bnx2x_fw_dump(bp);
  3373. } else
  3374. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3375. }
  3376. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3377. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3378. if (attn & BNX2X_GRC_TIMEOUT) {
  3379. val = CHIP_IS_E1(bp) ? 0 :
  3380. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3381. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3382. }
  3383. if (attn & BNX2X_GRC_RSV) {
  3384. val = CHIP_IS_E1(bp) ? 0 :
  3385. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3386. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3387. }
  3388. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3389. }
  3390. }
  3391. /*
  3392. * Bits map:
  3393. * 0-7 - Engine0 load counter.
  3394. * 8-15 - Engine1 load counter.
  3395. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3396. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3397. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3398. * on the engine
  3399. * 19 - Engine1 ONE_IS_LOADED.
  3400. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3401. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3402. * just the one belonging to its engine).
  3403. *
  3404. */
  3405. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3406. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3407. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3408. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3409. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3410. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3411. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3412. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3413. /*
  3414. * Set the GLOBAL_RESET bit.
  3415. *
  3416. * Should be run under rtnl lock
  3417. */
  3418. void bnx2x_set_reset_global(struct bnx2x *bp)
  3419. {
  3420. u32 val;
  3421. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3422. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3423. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3424. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3425. }
  3426. /*
  3427. * Clear the GLOBAL_RESET bit.
  3428. *
  3429. * Should be run under rtnl lock
  3430. */
  3431. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3432. {
  3433. u32 val;
  3434. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3435. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3436. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3437. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3438. }
  3439. /*
  3440. * Checks the GLOBAL_RESET bit.
  3441. *
  3442. * should be run under rtnl lock
  3443. */
  3444. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3445. {
  3446. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3447. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3448. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3449. }
  3450. /*
  3451. * Clear RESET_IN_PROGRESS bit for the current engine.
  3452. *
  3453. * Should be run under rtnl lock
  3454. */
  3455. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3456. {
  3457. u32 val;
  3458. u32 bit = BP_PATH(bp) ?
  3459. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3460. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3461. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3462. /* Clear the bit */
  3463. val &= ~bit;
  3464. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3465. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3466. }
  3467. /*
  3468. * Set RESET_IN_PROGRESS for the current engine.
  3469. *
  3470. * should be run under rtnl lock
  3471. */
  3472. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3473. {
  3474. u32 val;
  3475. u32 bit = BP_PATH(bp) ?
  3476. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3477. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3478. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3479. /* Set the bit */
  3480. val |= bit;
  3481. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3482. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3483. }
  3484. /*
  3485. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3486. * should be run under rtnl lock
  3487. */
  3488. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3489. {
  3490. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3491. u32 bit = engine ?
  3492. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3493. /* return false if bit is set */
  3494. return (val & bit) ? false : true;
  3495. }
  3496. /*
  3497. * set pf load for the current pf.
  3498. *
  3499. * should be run under rtnl lock
  3500. */
  3501. void bnx2x_set_pf_load(struct bnx2x *bp)
  3502. {
  3503. u32 val1, val;
  3504. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3505. BNX2X_PATH0_LOAD_CNT_MASK;
  3506. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3507. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3508. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3509. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3510. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3511. /* get the current counter value */
  3512. val1 = (val & mask) >> shift;
  3513. /* set bit of that PF */
  3514. val1 |= (1 << bp->pf_num);
  3515. /* clear the old value */
  3516. val &= ~mask;
  3517. /* set the new one */
  3518. val |= ((val1 << shift) & mask);
  3519. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3520. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3521. }
  3522. /**
  3523. * bnx2x_clear_pf_load - clear pf load mark
  3524. *
  3525. * @bp: driver handle
  3526. *
  3527. * Should be run under rtnl lock.
  3528. * Decrements the load counter for the current engine. Returns
  3529. * whether other functions are still loaded
  3530. */
  3531. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3532. {
  3533. u32 val1, val;
  3534. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3535. BNX2X_PATH0_LOAD_CNT_MASK;
  3536. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3537. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3538. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3539. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3540. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3541. /* get the current counter value */
  3542. val1 = (val & mask) >> shift;
  3543. /* clear bit of that PF */
  3544. val1 &= ~(1 << bp->pf_num);
  3545. /* clear the old value */
  3546. val &= ~mask;
  3547. /* set the new one */
  3548. val |= ((val1 << shift) & mask);
  3549. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3550. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3551. return val1 != 0;
  3552. }
  3553. /*
  3554. * Read the load status for the current engine.
  3555. *
  3556. * should be run under rtnl lock
  3557. */
  3558. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3559. {
  3560. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3561. BNX2X_PATH0_LOAD_CNT_MASK);
  3562. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3563. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3564. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3565. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3566. val = (val & mask) >> shift;
  3567. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3568. engine, val);
  3569. return val != 0;
  3570. }
  3571. static void _print_parity(struct bnx2x *bp, u32 reg)
  3572. {
  3573. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3574. }
  3575. static void _print_next_block(int idx, const char *blk)
  3576. {
  3577. pr_cont("%s%s", idx ? ", " : "", blk);
  3578. }
  3579. static int bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3580. int par_num, bool print)
  3581. {
  3582. int i = 0;
  3583. u32 cur_bit = 0;
  3584. for (i = 0; sig; i++) {
  3585. cur_bit = ((u32)0x1 << i);
  3586. if (sig & cur_bit) {
  3587. switch (cur_bit) {
  3588. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3589. if (print) {
  3590. _print_next_block(par_num++, "BRB");
  3591. _print_parity(bp,
  3592. BRB1_REG_BRB1_PRTY_STS);
  3593. }
  3594. break;
  3595. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3596. if (print) {
  3597. _print_next_block(par_num++, "PARSER");
  3598. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3599. }
  3600. break;
  3601. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3602. if (print) {
  3603. _print_next_block(par_num++, "TSDM");
  3604. _print_parity(bp,
  3605. TSDM_REG_TSDM_PRTY_STS);
  3606. }
  3607. break;
  3608. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3609. if (print) {
  3610. _print_next_block(par_num++,
  3611. "SEARCHER");
  3612. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3613. }
  3614. break;
  3615. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3616. if (print) {
  3617. _print_next_block(par_num++, "TCM");
  3618. _print_parity(bp,
  3619. TCM_REG_TCM_PRTY_STS);
  3620. }
  3621. break;
  3622. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3623. if (print) {
  3624. _print_next_block(par_num++, "TSEMI");
  3625. _print_parity(bp,
  3626. TSEM_REG_TSEM_PRTY_STS_0);
  3627. _print_parity(bp,
  3628. TSEM_REG_TSEM_PRTY_STS_1);
  3629. }
  3630. break;
  3631. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3632. if (print) {
  3633. _print_next_block(par_num++, "XPB");
  3634. _print_parity(bp, GRCBASE_XPB +
  3635. PB_REG_PB_PRTY_STS);
  3636. }
  3637. break;
  3638. }
  3639. /* Clear the bit */
  3640. sig &= ~cur_bit;
  3641. }
  3642. }
  3643. return par_num;
  3644. }
  3645. static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3646. int par_num, bool *global,
  3647. bool print)
  3648. {
  3649. int i = 0;
  3650. u32 cur_bit = 0;
  3651. for (i = 0; sig; i++) {
  3652. cur_bit = ((u32)0x1 << i);
  3653. if (sig & cur_bit) {
  3654. switch (cur_bit) {
  3655. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3656. if (print) {
  3657. _print_next_block(par_num++, "PBF");
  3658. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3659. }
  3660. break;
  3661. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3662. if (print) {
  3663. _print_next_block(par_num++, "QM");
  3664. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3665. }
  3666. break;
  3667. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3668. if (print) {
  3669. _print_next_block(par_num++, "TM");
  3670. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3671. }
  3672. break;
  3673. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3674. if (print) {
  3675. _print_next_block(par_num++, "XSDM");
  3676. _print_parity(bp,
  3677. XSDM_REG_XSDM_PRTY_STS);
  3678. }
  3679. break;
  3680. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3681. if (print) {
  3682. _print_next_block(par_num++, "XCM");
  3683. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3684. }
  3685. break;
  3686. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3687. if (print) {
  3688. _print_next_block(par_num++, "XSEMI");
  3689. _print_parity(bp,
  3690. XSEM_REG_XSEM_PRTY_STS_0);
  3691. _print_parity(bp,
  3692. XSEM_REG_XSEM_PRTY_STS_1);
  3693. }
  3694. break;
  3695. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3696. if (print) {
  3697. _print_next_block(par_num++,
  3698. "DOORBELLQ");
  3699. _print_parity(bp,
  3700. DORQ_REG_DORQ_PRTY_STS);
  3701. }
  3702. break;
  3703. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3704. if (print) {
  3705. _print_next_block(par_num++, "NIG");
  3706. if (CHIP_IS_E1x(bp)) {
  3707. _print_parity(bp,
  3708. NIG_REG_NIG_PRTY_STS);
  3709. } else {
  3710. _print_parity(bp,
  3711. NIG_REG_NIG_PRTY_STS_0);
  3712. _print_parity(bp,
  3713. NIG_REG_NIG_PRTY_STS_1);
  3714. }
  3715. }
  3716. break;
  3717. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3718. if (print)
  3719. _print_next_block(par_num++,
  3720. "VAUX PCI CORE");
  3721. *global = true;
  3722. break;
  3723. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3724. if (print) {
  3725. _print_next_block(par_num++, "DEBUG");
  3726. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3727. }
  3728. break;
  3729. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3730. if (print) {
  3731. _print_next_block(par_num++, "USDM");
  3732. _print_parity(bp,
  3733. USDM_REG_USDM_PRTY_STS);
  3734. }
  3735. break;
  3736. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3737. if (print) {
  3738. _print_next_block(par_num++, "UCM");
  3739. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3740. }
  3741. break;
  3742. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3743. if (print) {
  3744. _print_next_block(par_num++, "USEMI");
  3745. _print_parity(bp,
  3746. USEM_REG_USEM_PRTY_STS_0);
  3747. _print_parity(bp,
  3748. USEM_REG_USEM_PRTY_STS_1);
  3749. }
  3750. break;
  3751. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3752. if (print) {
  3753. _print_next_block(par_num++, "UPB");
  3754. _print_parity(bp, GRCBASE_UPB +
  3755. PB_REG_PB_PRTY_STS);
  3756. }
  3757. break;
  3758. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3759. if (print) {
  3760. _print_next_block(par_num++, "CSDM");
  3761. _print_parity(bp,
  3762. CSDM_REG_CSDM_PRTY_STS);
  3763. }
  3764. break;
  3765. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3766. if (print) {
  3767. _print_next_block(par_num++, "CCM");
  3768. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3769. }
  3770. break;
  3771. }
  3772. /* Clear the bit */
  3773. sig &= ~cur_bit;
  3774. }
  3775. }
  3776. return par_num;
  3777. }
  3778. static int bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3779. int par_num, bool print)
  3780. {
  3781. int i = 0;
  3782. u32 cur_bit = 0;
  3783. for (i = 0; sig; i++) {
  3784. cur_bit = ((u32)0x1 << i);
  3785. if (sig & cur_bit) {
  3786. switch (cur_bit) {
  3787. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3788. if (print) {
  3789. _print_next_block(par_num++, "CSEMI");
  3790. _print_parity(bp,
  3791. CSEM_REG_CSEM_PRTY_STS_0);
  3792. _print_parity(bp,
  3793. CSEM_REG_CSEM_PRTY_STS_1);
  3794. }
  3795. break;
  3796. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3797. if (print) {
  3798. _print_next_block(par_num++, "PXP");
  3799. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  3800. _print_parity(bp,
  3801. PXP2_REG_PXP2_PRTY_STS_0);
  3802. _print_parity(bp,
  3803. PXP2_REG_PXP2_PRTY_STS_1);
  3804. }
  3805. break;
  3806. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3807. if (print)
  3808. _print_next_block(par_num++,
  3809. "PXPPCICLOCKCLIENT");
  3810. break;
  3811. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3812. if (print) {
  3813. _print_next_block(par_num++, "CFC");
  3814. _print_parity(bp,
  3815. CFC_REG_CFC_PRTY_STS);
  3816. }
  3817. break;
  3818. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3819. if (print) {
  3820. _print_next_block(par_num++, "CDU");
  3821. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  3822. }
  3823. break;
  3824. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3825. if (print) {
  3826. _print_next_block(par_num++, "DMAE");
  3827. _print_parity(bp,
  3828. DMAE_REG_DMAE_PRTY_STS);
  3829. }
  3830. break;
  3831. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3832. if (print) {
  3833. _print_next_block(par_num++, "IGU");
  3834. if (CHIP_IS_E1x(bp))
  3835. _print_parity(bp,
  3836. HC_REG_HC_PRTY_STS);
  3837. else
  3838. _print_parity(bp,
  3839. IGU_REG_IGU_PRTY_STS);
  3840. }
  3841. break;
  3842. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3843. if (print) {
  3844. _print_next_block(par_num++, "MISC");
  3845. _print_parity(bp,
  3846. MISC_REG_MISC_PRTY_STS);
  3847. }
  3848. break;
  3849. }
  3850. /* Clear the bit */
  3851. sig &= ~cur_bit;
  3852. }
  3853. }
  3854. return par_num;
  3855. }
  3856. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3857. bool *global, bool print)
  3858. {
  3859. int i = 0;
  3860. u32 cur_bit = 0;
  3861. for (i = 0; sig; i++) {
  3862. cur_bit = ((u32)0x1 << i);
  3863. if (sig & cur_bit) {
  3864. switch (cur_bit) {
  3865. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3866. if (print)
  3867. _print_next_block(par_num++, "MCP ROM");
  3868. *global = true;
  3869. break;
  3870. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3871. if (print)
  3872. _print_next_block(par_num++,
  3873. "MCP UMP RX");
  3874. *global = true;
  3875. break;
  3876. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3877. if (print)
  3878. _print_next_block(par_num++,
  3879. "MCP UMP TX");
  3880. *global = true;
  3881. break;
  3882. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3883. if (print)
  3884. _print_next_block(par_num++,
  3885. "MCP SCPAD");
  3886. *global = true;
  3887. break;
  3888. }
  3889. /* Clear the bit */
  3890. sig &= ~cur_bit;
  3891. }
  3892. }
  3893. return par_num;
  3894. }
  3895. static int bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  3896. int par_num, bool print)
  3897. {
  3898. int i = 0;
  3899. u32 cur_bit = 0;
  3900. for (i = 0; sig; i++) {
  3901. cur_bit = ((u32)0x1 << i);
  3902. if (sig & cur_bit) {
  3903. switch (cur_bit) {
  3904. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3905. if (print) {
  3906. _print_next_block(par_num++, "PGLUE_B");
  3907. _print_parity(bp,
  3908. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  3909. }
  3910. break;
  3911. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3912. if (print) {
  3913. _print_next_block(par_num++, "ATC");
  3914. _print_parity(bp,
  3915. ATC_REG_ATC_PRTY_STS);
  3916. }
  3917. break;
  3918. }
  3919. /* Clear the bit */
  3920. sig &= ~cur_bit;
  3921. }
  3922. }
  3923. return par_num;
  3924. }
  3925. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3926. u32 *sig)
  3927. {
  3928. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3929. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3930. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3931. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3932. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3933. int par_num = 0;
  3934. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3935. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3936. sig[0] & HW_PRTY_ASSERT_SET_0,
  3937. sig[1] & HW_PRTY_ASSERT_SET_1,
  3938. sig[2] & HW_PRTY_ASSERT_SET_2,
  3939. sig[3] & HW_PRTY_ASSERT_SET_3,
  3940. sig[4] & HW_PRTY_ASSERT_SET_4);
  3941. if (print)
  3942. netdev_err(bp->dev,
  3943. "Parity errors detected in blocks: ");
  3944. par_num = bnx2x_check_blocks_with_parity0(bp,
  3945. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3946. par_num = bnx2x_check_blocks_with_parity1(bp,
  3947. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3948. par_num = bnx2x_check_blocks_with_parity2(bp,
  3949. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3950. par_num = bnx2x_check_blocks_with_parity3(
  3951. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3952. par_num = bnx2x_check_blocks_with_parity4(bp,
  3953. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3954. if (print)
  3955. pr_cont("\n");
  3956. return true;
  3957. } else
  3958. return false;
  3959. }
  3960. /**
  3961. * bnx2x_chk_parity_attn - checks for parity attentions.
  3962. *
  3963. * @bp: driver handle
  3964. * @global: true if there was a global attention
  3965. * @print: show parity attention in syslog
  3966. */
  3967. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3968. {
  3969. struct attn_route attn = { {0} };
  3970. int port = BP_PORT(bp);
  3971. attn.sig[0] = REG_RD(bp,
  3972. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3973. port*4);
  3974. attn.sig[1] = REG_RD(bp,
  3975. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3976. port*4);
  3977. attn.sig[2] = REG_RD(bp,
  3978. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3979. port*4);
  3980. attn.sig[3] = REG_RD(bp,
  3981. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3982. port*4);
  3983. if (!CHIP_IS_E1x(bp))
  3984. attn.sig[4] = REG_RD(bp,
  3985. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3986. port*4);
  3987. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3988. }
  3989. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3990. {
  3991. u32 val;
  3992. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3993. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3994. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3995. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3996. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3997. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3998. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3999. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4000. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4001. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4002. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4003. if (val &
  4004. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4005. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4006. if (val &
  4007. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4008. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4009. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4010. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4011. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4012. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4013. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4014. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4015. }
  4016. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4017. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4018. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4019. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4020. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4021. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4022. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4023. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4024. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4025. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4026. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4027. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4028. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4029. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4030. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4031. }
  4032. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4033. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4034. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4035. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4036. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4037. }
  4038. }
  4039. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4040. {
  4041. struct attn_route attn, *group_mask;
  4042. int port = BP_PORT(bp);
  4043. int index;
  4044. u32 reg_addr;
  4045. u32 val;
  4046. u32 aeu_mask;
  4047. bool global = false;
  4048. /* need to take HW lock because MCP or other port might also
  4049. try to handle this event */
  4050. bnx2x_acquire_alr(bp);
  4051. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4052. #ifndef BNX2X_STOP_ON_ERROR
  4053. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4054. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4055. /* Disable HW interrupts */
  4056. bnx2x_int_disable(bp);
  4057. /* In case of parity errors don't handle attentions so that
  4058. * other function would "see" parity errors.
  4059. */
  4060. #else
  4061. bnx2x_panic();
  4062. #endif
  4063. bnx2x_release_alr(bp);
  4064. return;
  4065. }
  4066. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4067. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4068. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4069. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4070. if (!CHIP_IS_E1x(bp))
  4071. attn.sig[4] =
  4072. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4073. else
  4074. attn.sig[4] = 0;
  4075. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4076. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4077. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4078. if (deasserted & (1 << index)) {
  4079. group_mask = &bp->attn_group[index];
  4080. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4081. index,
  4082. group_mask->sig[0], group_mask->sig[1],
  4083. group_mask->sig[2], group_mask->sig[3],
  4084. group_mask->sig[4]);
  4085. bnx2x_attn_int_deasserted4(bp,
  4086. attn.sig[4] & group_mask->sig[4]);
  4087. bnx2x_attn_int_deasserted3(bp,
  4088. attn.sig[3] & group_mask->sig[3]);
  4089. bnx2x_attn_int_deasserted1(bp,
  4090. attn.sig[1] & group_mask->sig[1]);
  4091. bnx2x_attn_int_deasserted2(bp,
  4092. attn.sig[2] & group_mask->sig[2]);
  4093. bnx2x_attn_int_deasserted0(bp,
  4094. attn.sig[0] & group_mask->sig[0]);
  4095. }
  4096. }
  4097. bnx2x_release_alr(bp);
  4098. if (bp->common.int_block == INT_BLOCK_HC)
  4099. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4100. COMMAND_REG_ATTN_BITS_CLR);
  4101. else
  4102. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4103. val = ~deasserted;
  4104. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4105. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4106. REG_WR(bp, reg_addr, val);
  4107. if (~bp->attn_state & deasserted)
  4108. BNX2X_ERR("IGU ERROR\n");
  4109. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4110. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4111. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4112. aeu_mask = REG_RD(bp, reg_addr);
  4113. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4114. aeu_mask, deasserted);
  4115. aeu_mask |= (deasserted & 0x3ff);
  4116. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4117. REG_WR(bp, reg_addr, aeu_mask);
  4118. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4119. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4120. bp->attn_state &= ~deasserted;
  4121. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4122. }
  4123. static void bnx2x_attn_int(struct bnx2x *bp)
  4124. {
  4125. /* read local copy of bits */
  4126. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4127. attn_bits);
  4128. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4129. attn_bits_ack);
  4130. u32 attn_state = bp->attn_state;
  4131. /* look for changed bits */
  4132. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4133. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4134. DP(NETIF_MSG_HW,
  4135. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4136. attn_bits, attn_ack, asserted, deasserted);
  4137. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4138. BNX2X_ERR("BAD attention state\n");
  4139. /* handle bits that were raised */
  4140. if (asserted)
  4141. bnx2x_attn_int_asserted(bp, asserted);
  4142. if (deasserted)
  4143. bnx2x_attn_int_deasserted(bp, deasserted);
  4144. }
  4145. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4146. u16 index, u8 op, u8 update)
  4147. {
  4148. u32 igu_addr = bp->igu_base_addr;
  4149. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4150. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4151. igu_addr);
  4152. }
  4153. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4154. {
  4155. /* No memory barriers */
  4156. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4157. mmiowb(); /* keep prod updates ordered */
  4158. }
  4159. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4160. union event_ring_elem *elem)
  4161. {
  4162. u8 err = elem->message.error;
  4163. if (!bp->cnic_eth_dev.starting_cid ||
  4164. (cid < bp->cnic_eth_dev.starting_cid &&
  4165. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4166. return 1;
  4167. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4168. if (unlikely(err)) {
  4169. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4170. cid);
  4171. bnx2x_panic_dump(bp, false);
  4172. }
  4173. bnx2x_cnic_cfc_comp(bp, cid, err);
  4174. return 0;
  4175. }
  4176. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4177. {
  4178. struct bnx2x_mcast_ramrod_params rparam;
  4179. int rc;
  4180. memset(&rparam, 0, sizeof(rparam));
  4181. rparam.mcast_obj = &bp->mcast_obj;
  4182. netif_addr_lock_bh(bp->dev);
  4183. /* Clear pending state for the last command */
  4184. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4185. /* If there are pending mcast commands - send them */
  4186. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4187. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4188. if (rc < 0)
  4189. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4190. rc);
  4191. }
  4192. netif_addr_unlock_bh(bp->dev);
  4193. }
  4194. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4195. union event_ring_elem *elem)
  4196. {
  4197. unsigned long ramrod_flags = 0;
  4198. int rc = 0;
  4199. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4200. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4201. /* Always push next commands out, don't wait here */
  4202. __set_bit(RAMROD_CONT, &ramrod_flags);
  4203. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4204. >> BNX2X_SWCID_SHIFT) {
  4205. case BNX2X_FILTER_MAC_PENDING:
  4206. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4207. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4208. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4209. else
  4210. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4211. break;
  4212. case BNX2X_FILTER_MCAST_PENDING:
  4213. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4214. /* This is only relevant for 57710 where multicast MACs are
  4215. * configured as unicast MACs using the same ramrod.
  4216. */
  4217. bnx2x_handle_mcast_eqe(bp);
  4218. return;
  4219. default:
  4220. BNX2X_ERR("Unsupported classification command: %d\n",
  4221. elem->message.data.eth_event.echo);
  4222. return;
  4223. }
  4224. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4225. if (rc < 0)
  4226. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4227. else if (rc > 0)
  4228. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4229. }
  4230. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4231. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4232. {
  4233. netif_addr_lock_bh(bp->dev);
  4234. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4235. /* Send rx_mode command again if was requested */
  4236. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4237. bnx2x_set_storm_rx_mode(bp);
  4238. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4239. &bp->sp_state))
  4240. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4241. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4242. &bp->sp_state))
  4243. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4244. netif_addr_unlock_bh(bp->dev);
  4245. }
  4246. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4247. union event_ring_elem *elem)
  4248. {
  4249. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4250. DP(BNX2X_MSG_SP,
  4251. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4252. elem->message.data.vif_list_event.func_bit_map);
  4253. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4254. elem->message.data.vif_list_event.func_bit_map);
  4255. } else if (elem->message.data.vif_list_event.echo ==
  4256. VIF_LIST_RULE_SET) {
  4257. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4258. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4259. }
  4260. }
  4261. /* called with rtnl_lock */
  4262. static void bnx2x_after_function_update(struct bnx2x *bp)
  4263. {
  4264. int q, rc;
  4265. struct bnx2x_fastpath *fp;
  4266. struct bnx2x_queue_state_params queue_params = {NULL};
  4267. struct bnx2x_queue_update_params *q_update_params =
  4268. &queue_params.params.update;
  4269. /* Send Q update command with afex vlan removal values for all Qs */
  4270. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4271. /* set silent vlan removal values according to vlan mode */
  4272. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4273. &q_update_params->update_flags);
  4274. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4275. &q_update_params->update_flags);
  4276. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4277. /* in access mode mark mask and value are 0 to strip all vlans */
  4278. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4279. q_update_params->silent_removal_value = 0;
  4280. q_update_params->silent_removal_mask = 0;
  4281. } else {
  4282. q_update_params->silent_removal_value =
  4283. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4284. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4285. }
  4286. for_each_eth_queue(bp, q) {
  4287. /* Set the appropriate Queue object */
  4288. fp = &bp->fp[q];
  4289. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4290. /* send the ramrod */
  4291. rc = bnx2x_queue_state_change(bp, &queue_params);
  4292. if (rc < 0)
  4293. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4294. q);
  4295. }
  4296. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4297. fp = &bp->fp[FCOE_IDX(bp)];
  4298. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4299. /* clear pending completion bit */
  4300. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4301. /* mark latest Q bit */
  4302. smp_mb__before_clear_bit();
  4303. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4304. smp_mb__after_clear_bit();
  4305. /* send Q update ramrod for FCoE Q */
  4306. rc = bnx2x_queue_state_change(bp, &queue_params);
  4307. if (rc < 0)
  4308. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4309. q);
  4310. } else {
  4311. /* If no FCoE ring - ACK MCP now */
  4312. bnx2x_link_report(bp);
  4313. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4314. }
  4315. }
  4316. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4317. struct bnx2x *bp, u32 cid)
  4318. {
  4319. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4320. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4321. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4322. else
  4323. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4324. }
  4325. static void bnx2x_eq_int(struct bnx2x *bp)
  4326. {
  4327. u16 hw_cons, sw_cons, sw_prod;
  4328. union event_ring_elem *elem;
  4329. u8 echo;
  4330. u32 cid;
  4331. u8 opcode;
  4332. int rc, spqe_cnt = 0;
  4333. struct bnx2x_queue_sp_obj *q_obj;
  4334. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4335. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4336. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4337. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4338. * when we get the next-page we need to adjust so the loop
  4339. * condition below will be met. The next element is the size of a
  4340. * regular element and hence incrementing by 1
  4341. */
  4342. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4343. hw_cons++;
  4344. /* This function may never run in parallel with itself for a
  4345. * specific bp, thus there is no need in "paired" read memory
  4346. * barrier here.
  4347. */
  4348. sw_cons = bp->eq_cons;
  4349. sw_prod = bp->eq_prod;
  4350. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4351. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4352. for (; sw_cons != hw_cons;
  4353. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4354. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4355. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4356. if (!rc) {
  4357. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4358. rc);
  4359. goto next_spqe;
  4360. }
  4361. /* elem CID originates from FW; actually LE */
  4362. cid = SW_CID((__force __le32)
  4363. elem->message.data.cfc_del_event.cid);
  4364. opcode = elem->message.opcode;
  4365. /* handle eq element */
  4366. switch (opcode) {
  4367. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4368. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4369. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4370. continue;
  4371. case EVENT_RING_OPCODE_STAT_QUERY:
  4372. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4373. "got statistics comp event %d\n",
  4374. bp->stats_comp++);
  4375. /* nothing to do with stats comp */
  4376. goto next_spqe;
  4377. case EVENT_RING_OPCODE_CFC_DEL:
  4378. /* handle according to cid range */
  4379. /*
  4380. * we may want to verify here that the bp state is
  4381. * HALTING
  4382. */
  4383. DP(BNX2X_MSG_SP,
  4384. "got delete ramrod for MULTI[%d]\n", cid);
  4385. if (CNIC_LOADED(bp) &&
  4386. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4387. goto next_spqe;
  4388. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4389. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4390. break;
  4391. goto next_spqe;
  4392. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4393. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4394. if (f_obj->complete_cmd(bp, f_obj,
  4395. BNX2X_F_CMD_TX_STOP))
  4396. break;
  4397. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4398. goto next_spqe;
  4399. case EVENT_RING_OPCODE_START_TRAFFIC:
  4400. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4401. if (f_obj->complete_cmd(bp, f_obj,
  4402. BNX2X_F_CMD_TX_START))
  4403. break;
  4404. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4405. goto next_spqe;
  4406. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4407. echo = elem->message.data.function_update_event.echo;
  4408. if (echo == SWITCH_UPDATE) {
  4409. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4410. "got FUNC_SWITCH_UPDATE ramrod\n");
  4411. if (f_obj->complete_cmd(
  4412. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4413. break;
  4414. } else {
  4415. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4416. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4417. f_obj->complete_cmd(bp, f_obj,
  4418. BNX2X_F_CMD_AFEX_UPDATE);
  4419. /* We will perform the Queues update from
  4420. * sp_rtnl task as all Queue SP operations
  4421. * should run under rtnl_lock.
  4422. */
  4423. smp_mb__before_clear_bit();
  4424. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4425. &bp->sp_rtnl_state);
  4426. smp_mb__after_clear_bit();
  4427. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4428. }
  4429. goto next_spqe;
  4430. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4431. f_obj->complete_cmd(bp, f_obj,
  4432. BNX2X_F_CMD_AFEX_VIFLISTS);
  4433. bnx2x_after_afex_vif_lists(bp, elem);
  4434. goto next_spqe;
  4435. case EVENT_RING_OPCODE_FUNCTION_START:
  4436. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4437. "got FUNC_START ramrod\n");
  4438. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4439. break;
  4440. goto next_spqe;
  4441. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4442. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4443. "got FUNC_STOP ramrod\n");
  4444. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4445. break;
  4446. goto next_spqe;
  4447. }
  4448. switch (opcode | bp->state) {
  4449. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4450. BNX2X_STATE_OPEN):
  4451. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4452. BNX2X_STATE_OPENING_WAIT4_PORT):
  4453. cid = elem->message.data.eth_event.echo &
  4454. BNX2X_SWCID_MASK;
  4455. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4456. cid);
  4457. rss_raw->clear_pending(rss_raw);
  4458. break;
  4459. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4460. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4461. case (EVENT_RING_OPCODE_SET_MAC |
  4462. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4463. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4464. BNX2X_STATE_OPEN):
  4465. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4466. BNX2X_STATE_DIAG):
  4467. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4468. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4469. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4470. bnx2x_handle_classification_eqe(bp, elem);
  4471. break;
  4472. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4473. BNX2X_STATE_OPEN):
  4474. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4475. BNX2X_STATE_DIAG):
  4476. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4477. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4478. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4479. bnx2x_handle_mcast_eqe(bp);
  4480. break;
  4481. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4482. BNX2X_STATE_OPEN):
  4483. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4484. BNX2X_STATE_DIAG):
  4485. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4486. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4487. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4488. bnx2x_handle_rx_mode_eqe(bp);
  4489. break;
  4490. default:
  4491. /* unknown event log error and continue */
  4492. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4493. elem->message.opcode, bp->state);
  4494. }
  4495. next_spqe:
  4496. spqe_cnt++;
  4497. } /* for */
  4498. smp_mb__before_atomic_inc();
  4499. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4500. bp->eq_cons = sw_cons;
  4501. bp->eq_prod = sw_prod;
  4502. /* Make sure that above mem writes were issued towards the memory */
  4503. smp_wmb();
  4504. /* update producer */
  4505. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4506. }
  4507. static void bnx2x_sp_task(struct work_struct *work)
  4508. {
  4509. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4510. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4511. /* make sure the atomic interrupt_occurred has been written */
  4512. smp_rmb();
  4513. if (atomic_read(&bp->interrupt_occurred)) {
  4514. /* what work needs to be performed? */
  4515. u16 status = bnx2x_update_dsb_idx(bp);
  4516. DP(BNX2X_MSG_SP, "status %x\n", status);
  4517. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4518. atomic_set(&bp->interrupt_occurred, 0);
  4519. /* HW attentions */
  4520. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4521. bnx2x_attn_int(bp);
  4522. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4523. }
  4524. /* SP events: STAT_QUERY and others */
  4525. if (status & BNX2X_DEF_SB_IDX) {
  4526. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4527. if (FCOE_INIT(bp) &&
  4528. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4529. /* Prevent local bottom-halves from running as
  4530. * we are going to change the local NAPI list.
  4531. */
  4532. local_bh_disable();
  4533. napi_schedule(&bnx2x_fcoe(bp, napi));
  4534. local_bh_enable();
  4535. }
  4536. /* Handle EQ completions */
  4537. bnx2x_eq_int(bp);
  4538. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4539. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4540. status &= ~BNX2X_DEF_SB_IDX;
  4541. }
  4542. /* if status is non zero then perhaps something went wrong */
  4543. if (unlikely(status))
  4544. DP(BNX2X_MSG_SP,
  4545. "got an unknown interrupt! (status 0x%x)\n", status);
  4546. /* ack status block only if something was actually handled */
  4547. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4548. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4549. }
  4550. /* must be called after the EQ processing (since eq leads to sriov
  4551. * ramrod completion flows).
  4552. * This flow may have been scheduled by the arrival of a ramrod
  4553. * completion, or by the sriov code rescheduling itself.
  4554. */
  4555. bnx2x_iov_sp_task(bp);
  4556. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4557. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4558. &bp->sp_state)) {
  4559. bnx2x_link_report(bp);
  4560. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4561. }
  4562. }
  4563. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4564. {
  4565. struct net_device *dev = dev_instance;
  4566. struct bnx2x *bp = netdev_priv(dev);
  4567. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4568. IGU_INT_DISABLE, 0);
  4569. #ifdef BNX2X_STOP_ON_ERROR
  4570. if (unlikely(bp->panic))
  4571. return IRQ_HANDLED;
  4572. #endif
  4573. if (CNIC_LOADED(bp)) {
  4574. struct cnic_ops *c_ops;
  4575. rcu_read_lock();
  4576. c_ops = rcu_dereference(bp->cnic_ops);
  4577. if (c_ops)
  4578. c_ops->cnic_handler(bp->cnic_data, NULL);
  4579. rcu_read_unlock();
  4580. }
  4581. /* schedule sp task to perform default status block work, ack
  4582. * attentions and enable interrupts.
  4583. */
  4584. bnx2x_schedule_sp_task(bp);
  4585. return IRQ_HANDLED;
  4586. }
  4587. /* end of slow path */
  4588. void bnx2x_drv_pulse(struct bnx2x *bp)
  4589. {
  4590. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4591. bp->fw_drv_pulse_wr_seq);
  4592. }
  4593. static void bnx2x_timer(unsigned long data)
  4594. {
  4595. struct bnx2x *bp = (struct bnx2x *) data;
  4596. if (!netif_running(bp->dev))
  4597. return;
  4598. if (IS_PF(bp) &&
  4599. !BP_NOMCP(bp)) {
  4600. int mb_idx = BP_FW_MB_IDX(bp);
  4601. u32 drv_pulse;
  4602. u32 mcp_pulse;
  4603. ++bp->fw_drv_pulse_wr_seq;
  4604. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4605. /* TBD - add SYSTEM_TIME */
  4606. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4607. bnx2x_drv_pulse(bp);
  4608. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4609. MCP_PULSE_SEQ_MASK);
  4610. /* The delta between driver pulse and mcp response
  4611. * should be 1 (before mcp response) or 0 (after mcp response)
  4612. */
  4613. if ((drv_pulse != mcp_pulse) &&
  4614. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4615. /* someone lost a heartbeat... */
  4616. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4617. drv_pulse, mcp_pulse);
  4618. }
  4619. }
  4620. if (bp->state == BNX2X_STATE_OPEN)
  4621. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4622. /* sample pf vf bulletin board for new posts from pf */
  4623. if (IS_VF(bp))
  4624. bnx2x_timer_sriov(bp);
  4625. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4626. }
  4627. /* end of Statistics */
  4628. /* nic init */
  4629. /*
  4630. * nic init service functions
  4631. */
  4632. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4633. {
  4634. u32 i;
  4635. if (!(len%4) && !(addr%4))
  4636. for (i = 0; i < len; i += 4)
  4637. REG_WR(bp, addr + i, fill);
  4638. else
  4639. for (i = 0; i < len; i++)
  4640. REG_WR8(bp, addr + i, fill);
  4641. }
  4642. /* helper: writes FP SP data to FW - data_size in dwords */
  4643. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4644. int fw_sb_id,
  4645. u32 *sb_data_p,
  4646. u32 data_size)
  4647. {
  4648. int index;
  4649. for (index = 0; index < data_size; index++)
  4650. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4651. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4652. sizeof(u32)*index,
  4653. *(sb_data_p + index));
  4654. }
  4655. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4656. {
  4657. u32 *sb_data_p;
  4658. u32 data_size = 0;
  4659. struct hc_status_block_data_e2 sb_data_e2;
  4660. struct hc_status_block_data_e1x sb_data_e1x;
  4661. /* disable the function first */
  4662. if (!CHIP_IS_E1x(bp)) {
  4663. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4664. sb_data_e2.common.state = SB_DISABLED;
  4665. sb_data_e2.common.p_func.vf_valid = false;
  4666. sb_data_p = (u32 *)&sb_data_e2;
  4667. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4668. } else {
  4669. memset(&sb_data_e1x, 0,
  4670. sizeof(struct hc_status_block_data_e1x));
  4671. sb_data_e1x.common.state = SB_DISABLED;
  4672. sb_data_e1x.common.p_func.vf_valid = false;
  4673. sb_data_p = (u32 *)&sb_data_e1x;
  4674. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4675. }
  4676. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4677. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4678. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4679. CSTORM_STATUS_BLOCK_SIZE);
  4680. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4681. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4682. CSTORM_SYNC_BLOCK_SIZE);
  4683. }
  4684. /* helper: writes SP SB data to FW */
  4685. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4686. struct hc_sp_status_block_data *sp_sb_data)
  4687. {
  4688. int func = BP_FUNC(bp);
  4689. int i;
  4690. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4691. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4692. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4693. i*sizeof(u32),
  4694. *((u32 *)sp_sb_data + i));
  4695. }
  4696. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4697. {
  4698. int func = BP_FUNC(bp);
  4699. struct hc_sp_status_block_data sp_sb_data;
  4700. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4701. sp_sb_data.state = SB_DISABLED;
  4702. sp_sb_data.p_func.vf_valid = false;
  4703. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4704. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4705. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4706. CSTORM_SP_STATUS_BLOCK_SIZE);
  4707. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4708. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4709. CSTORM_SP_SYNC_BLOCK_SIZE);
  4710. }
  4711. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4712. int igu_sb_id, int igu_seg_id)
  4713. {
  4714. hc_sm->igu_sb_id = igu_sb_id;
  4715. hc_sm->igu_seg_id = igu_seg_id;
  4716. hc_sm->timer_value = 0xFF;
  4717. hc_sm->time_to_expire = 0xFFFFFFFF;
  4718. }
  4719. /* allocates state machine ids. */
  4720. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4721. {
  4722. /* zero out state machine indices */
  4723. /* rx indices */
  4724. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4725. /* tx indices */
  4726. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4727. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4728. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4729. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4730. /* map indices */
  4731. /* rx indices */
  4732. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4733. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4734. /* tx indices */
  4735. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4736. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4737. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4738. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4739. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4740. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4741. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4742. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4743. }
  4744. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4745. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4746. {
  4747. int igu_seg_id;
  4748. struct hc_status_block_data_e2 sb_data_e2;
  4749. struct hc_status_block_data_e1x sb_data_e1x;
  4750. struct hc_status_block_sm *hc_sm_p;
  4751. int data_size;
  4752. u32 *sb_data_p;
  4753. if (CHIP_INT_MODE_IS_BC(bp))
  4754. igu_seg_id = HC_SEG_ACCESS_NORM;
  4755. else
  4756. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4757. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4758. if (!CHIP_IS_E1x(bp)) {
  4759. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4760. sb_data_e2.common.state = SB_ENABLED;
  4761. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4762. sb_data_e2.common.p_func.vf_id = vfid;
  4763. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4764. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4765. sb_data_e2.common.same_igu_sb_1b = true;
  4766. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4767. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4768. hc_sm_p = sb_data_e2.common.state_machine;
  4769. sb_data_p = (u32 *)&sb_data_e2;
  4770. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4771. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4772. } else {
  4773. memset(&sb_data_e1x, 0,
  4774. sizeof(struct hc_status_block_data_e1x));
  4775. sb_data_e1x.common.state = SB_ENABLED;
  4776. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4777. sb_data_e1x.common.p_func.vf_id = 0xff;
  4778. sb_data_e1x.common.p_func.vf_valid = false;
  4779. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4780. sb_data_e1x.common.same_igu_sb_1b = true;
  4781. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4782. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4783. hc_sm_p = sb_data_e1x.common.state_machine;
  4784. sb_data_p = (u32 *)&sb_data_e1x;
  4785. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4786. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4787. }
  4788. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4789. igu_sb_id, igu_seg_id);
  4790. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4791. igu_sb_id, igu_seg_id);
  4792. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4793. /* write indices to HW - PCI guarantees endianity of regpairs */
  4794. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4795. }
  4796. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4797. u16 tx_usec, u16 rx_usec)
  4798. {
  4799. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4800. false, rx_usec);
  4801. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4802. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4803. tx_usec);
  4804. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4805. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4806. tx_usec);
  4807. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4808. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4809. tx_usec);
  4810. }
  4811. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4812. {
  4813. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4814. dma_addr_t mapping = bp->def_status_blk_mapping;
  4815. int igu_sp_sb_index;
  4816. int igu_seg_id;
  4817. int port = BP_PORT(bp);
  4818. int func = BP_FUNC(bp);
  4819. int reg_offset, reg_offset_en5;
  4820. u64 section;
  4821. int index;
  4822. struct hc_sp_status_block_data sp_sb_data;
  4823. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4824. if (CHIP_INT_MODE_IS_BC(bp)) {
  4825. igu_sp_sb_index = DEF_SB_IGU_ID;
  4826. igu_seg_id = HC_SEG_ACCESS_DEF;
  4827. } else {
  4828. igu_sp_sb_index = bp->igu_dsb_id;
  4829. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4830. }
  4831. /* ATTN */
  4832. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4833. atten_status_block);
  4834. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4835. bp->attn_state = 0;
  4836. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4837. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4838. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4839. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4840. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4841. int sindex;
  4842. /* take care of sig[0]..sig[4] */
  4843. for (sindex = 0; sindex < 4; sindex++)
  4844. bp->attn_group[index].sig[sindex] =
  4845. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4846. if (!CHIP_IS_E1x(bp))
  4847. /*
  4848. * enable5 is separate from the rest of the registers,
  4849. * and therefore the address skip is 4
  4850. * and not 16 between the different groups
  4851. */
  4852. bp->attn_group[index].sig[4] = REG_RD(bp,
  4853. reg_offset_en5 + 0x4*index);
  4854. else
  4855. bp->attn_group[index].sig[4] = 0;
  4856. }
  4857. if (bp->common.int_block == INT_BLOCK_HC) {
  4858. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4859. HC_REG_ATTN_MSG0_ADDR_L);
  4860. REG_WR(bp, reg_offset, U64_LO(section));
  4861. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4862. } else if (!CHIP_IS_E1x(bp)) {
  4863. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4864. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4865. }
  4866. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4867. sp_sb);
  4868. bnx2x_zero_sp_sb(bp);
  4869. /* PCI guarantees endianity of regpairs */
  4870. sp_sb_data.state = SB_ENABLED;
  4871. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4872. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4873. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4874. sp_sb_data.igu_seg_id = igu_seg_id;
  4875. sp_sb_data.p_func.pf_id = func;
  4876. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4877. sp_sb_data.p_func.vf_id = 0xff;
  4878. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4879. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4880. }
  4881. void bnx2x_update_coalesce(struct bnx2x *bp)
  4882. {
  4883. int i;
  4884. for_each_eth_queue(bp, i)
  4885. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4886. bp->tx_ticks, bp->rx_ticks);
  4887. }
  4888. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4889. {
  4890. spin_lock_init(&bp->spq_lock);
  4891. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4892. bp->spq_prod_idx = 0;
  4893. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4894. bp->spq_prod_bd = bp->spq;
  4895. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4896. }
  4897. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4898. {
  4899. int i;
  4900. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4901. union event_ring_elem *elem =
  4902. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4903. elem->next_page.addr.hi =
  4904. cpu_to_le32(U64_HI(bp->eq_mapping +
  4905. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4906. elem->next_page.addr.lo =
  4907. cpu_to_le32(U64_LO(bp->eq_mapping +
  4908. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4909. }
  4910. bp->eq_cons = 0;
  4911. bp->eq_prod = NUM_EQ_DESC;
  4912. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4913. /* we want a warning message before it gets wrought... */
  4914. atomic_set(&bp->eq_spq_left,
  4915. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4916. }
  4917. /* called with netif_addr_lock_bh() */
  4918. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4919. unsigned long rx_mode_flags,
  4920. unsigned long rx_accept_flags,
  4921. unsigned long tx_accept_flags,
  4922. unsigned long ramrod_flags)
  4923. {
  4924. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4925. int rc;
  4926. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4927. /* Prepare ramrod parameters */
  4928. ramrod_param.cid = 0;
  4929. ramrod_param.cl_id = cl_id;
  4930. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4931. ramrod_param.func_id = BP_FUNC(bp);
  4932. ramrod_param.pstate = &bp->sp_state;
  4933. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4934. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4935. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4936. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4937. ramrod_param.ramrod_flags = ramrod_flags;
  4938. ramrod_param.rx_mode_flags = rx_mode_flags;
  4939. ramrod_param.rx_accept_flags = rx_accept_flags;
  4940. ramrod_param.tx_accept_flags = tx_accept_flags;
  4941. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4942. if (rc < 0) {
  4943. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4944. return rc;
  4945. }
  4946. return 0;
  4947. }
  4948. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4949. unsigned long *rx_accept_flags,
  4950. unsigned long *tx_accept_flags)
  4951. {
  4952. /* Clear the flags first */
  4953. *rx_accept_flags = 0;
  4954. *tx_accept_flags = 0;
  4955. switch (rx_mode) {
  4956. case BNX2X_RX_MODE_NONE:
  4957. /*
  4958. * 'drop all' supersedes any accept flags that may have been
  4959. * passed to the function.
  4960. */
  4961. break;
  4962. case BNX2X_RX_MODE_NORMAL:
  4963. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4964. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4965. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4966. /* internal switching mode */
  4967. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4968. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4969. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4970. break;
  4971. case BNX2X_RX_MODE_ALLMULTI:
  4972. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4973. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4974. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4975. /* internal switching mode */
  4976. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4977. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4978. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4979. break;
  4980. case BNX2X_RX_MODE_PROMISC:
  4981. /* According to definition of SI mode, iface in promisc mode
  4982. * should receive matched and unmatched (in resolution of port)
  4983. * unicast packets.
  4984. */
  4985. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  4986. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4987. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4988. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4989. /* internal switching mode */
  4990. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4991. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4992. if (IS_MF_SI(bp))
  4993. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  4994. else
  4995. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4996. break;
  4997. default:
  4998. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  4999. return -EINVAL;
  5000. }
  5001. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5002. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  5003. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5004. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5005. }
  5006. return 0;
  5007. }
  5008. /* called with netif_addr_lock_bh() */
  5009. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5010. {
  5011. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5012. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5013. int rc;
  5014. if (!NO_FCOE(bp))
  5015. /* Configure rx_mode of FCoE Queue */
  5016. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5017. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5018. &tx_accept_flags);
  5019. if (rc)
  5020. return rc;
  5021. __set_bit(RAMROD_RX, &ramrod_flags);
  5022. __set_bit(RAMROD_TX, &ramrod_flags);
  5023. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5024. rx_accept_flags, tx_accept_flags,
  5025. ramrod_flags);
  5026. }
  5027. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5028. {
  5029. int i;
  5030. if (IS_MF_SI(bp))
  5031. /*
  5032. * In switch independent mode, the TSTORM needs to accept
  5033. * packets that failed classification, since approximate match
  5034. * mac addresses aren't written to NIG LLH
  5035. */
  5036. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5037. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  5038. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  5039. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5040. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  5041. /* Zero this manually as its initialization is
  5042. currently missing in the initTool */
  5043. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5044. REG_WR(bp, BAR_USTRORM_INTMEM +
  5045. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5046. if (!CHIP_IS_E1x(bp)) {
  5047. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5048. CHIP_INT_MODE_IS_BC(bp) ?
  5049. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5050. }
  5051. }
  5052. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5053. {
  5054. switch (load_code) {
  5055. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5056. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5057. bnx2x_init_internal_common(bp);
  5058. /* no break */
  5059. case FW_MSG_CODE_DRV_LOAD_PORT:
  5060. /* nothing to do */
  5061. /* no break */
  5062. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5063. /* internal memory per function is
  5064. initialized inside bnx2x_pf_init */
  5065. break;
  5066. default:
  5067. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5068. break;
  5069. }
  5070. }
  5071. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5072. {
  5073. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5074. }
  5075. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5076. {
  5077. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5078. }
  5079. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5080. {
  5081. if (CHIP_IS_E1x(fp->bp))
  5082. return BP_L_ID(fp->bp) + fp->index;
  5083. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5084. return bnx2x_fp_igu_sb_id(fp);
  5085. }
  5086. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5087. {
  5088. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5089. u8 cos;
  5090. unsigned long q_type = 0;
  5091. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5092. fp->rx_queue = fp_idx;
  5093. fp->cid = fp_idx;
  5094. fp->cl_id = bnx2x_fp_cl_id(fp);
  5095. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5096. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5097. /* qZone id equals to FW (per path) client id */
  5098. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5099. /* init shortcut */
  5100. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5101. /* Setup SB indices */
  5102. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5103. /* Configure Queue State object */
  5104. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5105. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5106. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5107. /* init tx data */
  5108. for_each_cos_in_tx_queue(fp, cos) {
  5109. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5110. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5111. FP_COS_TO_TXQ(fp, cos, bp),
  5112. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5113. cids[cos] = fp->txdata_ptr[cos]->cid;
  5114. }
  5115. /* nothing more for vf to do here */
  5116. if (IS_VF(bp))
  5117. return;
  5118. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5119. fp->fw_sb_id, fp->igu_sb_id);
  5120. bnx2x_update_fpsb_idx(fp);
  5121. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5122. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5123. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5124. /**
  5125. * Configure classification DBs: Always enable Tx switching
  5126. */
  5127. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5128. DP(NETIF_MSG_IFUP,
  5129. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5130. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5131. fp->igu_sb_id);
  5132. }
  5133. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5134. {
  5135. int i;
  5136. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5137. struct eth_tx_next_bd *tx_next_bd =
  5138. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5139. tx_next_bd->addr_hi =
  5140. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5141. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5142. tx_next_bd->addr_lo =
  5143. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5144. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5145. }
  5146. *txdata->tx_cons_sb = cpu_to_le16(0);
  5147. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5148. txdata->tx_db.data.zero_fill1 = 0;
  5149. txdata->tx_db.data.prod = 0;
  5150. txdata->tx_pkt_prod = 0;
  5151. txdata->tx_pkt_cons = 0;
  5152. txdata->tx_bd_prod = 0;
  5153. txdata->tx_bd_cons = 0;
  5154. txdata->tx_pkt = 0;
  5155. }
  5156. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5157. {
  5158. int i;
  5159. for_each_tx_queue_cnic(bp, i)
  5160. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5161. }
  5162. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5163. {
  5164. int i;
  5165. u8 cos;
  5166. for_each_eth_queue(bp, i)
  5167. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5168. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5169. }
  5170. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5171. {
  5172. if (!NO_FCOE(bp))
  5173. bnx2x_init_fcoe_fp(bp);
  5174. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5175. BNX2X_VF_ID_INVALID, false,
  5176. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5177. /* ensure status block indices were read */
  5178. rmb();
  5179. bnx2x_init_rx_rings_cnic(bp);
  5180. bnx2x_init_tx_rings_cnic(bp);
  5181. /* flush all */
  5182. mb();
  5183. mmiowb();
  5184. }
  5185. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5186. {
  5187. int i;
  5188. /* Setup NIC internals and enable interrupts */
  5189. for_each_eth_queue(bp, i)
  5190. bnx2x_init_eth_fp(bp, i);
  5191. /* ensure status block indices were read */
  5192. rmb();
  5193. bnx2x_init_rx_rings(bp);
  5194. bnx2x_init_tx_rings(bp);
  5195. if (IS_PF(bp)) {
  5196. /* Initialize MOD_ABS interrupts */
  5197. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5198. bp->common.shmem_base,
  5199. bp->common.shmem2_base, BP_PORT(bp));
  5200. /* initialize the default status block and sp ring */
  5201. bnx2x_init_def_sb(bp);
  5202. bnx2x_update_dsb_idx(bp);
  5203. bnx2x_init_sp_ring(bp);
  5204. } else {
  5205. bnx2x_memset_stats(bp);
  5206. }
  5207. }
  5208. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5209. {
  5210. bnx2x_init_eq_ring(bp);
  5211. bnx2x_init_internal(bp, load_code);
  5212. bnx2x_pf_init(bp);
  5213. bnx2x_stats_init(bp);
  5214. /* flush all before enabling interrupts */
  5215. mb();
  5216. mmiowb();
  5217. bnx2x_int_enable(bp);
  5218. /* Check for SPIO5 */
  5219. bnx2x_attn_int_deasserted0(bp,
  5220. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5221. AEU_INPUTS_ATTN_BITS_SPIO5);
  5222. }
  5223. /* gzip service functions */
  5224. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5225. {
  5226. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5227. &bp->gunzip_mapping, GFP_KERNEL);
  5228. if (bp->gunzip_buf == NULL)
  5229. goto gunzip_nomem1;
  5230. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5231. if (bp->strm == NULL)
  5232. goto gunzip_nomem2;
  5233. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5234. if (bp->strm->workspace == NULL)
  5235. goto gunzip_nomem3;
  5236. return 0;
  5237. gunzip_nomem3:
  5238. kfree(bp->strm);
  5239. bp->strm = NULL;
  5240. gunzip_nomem2:
  5241. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5242. bp->gunzip_mapping);
  5243. bp->gunzip_buf = NULL;
  5244. gunzip_nomem1:
  5245. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5246. return -ENOMEM;
  5247. }
  5248. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5249. {
  5250. if (bp->strm) {
  5251. vfree(bp->strm->workspace);
  5252. kfree(bp->strm);
  5253. bp->strm = NULL;
  5254. }
  5255. if (bp->gunzip_buf) {
  5256. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5257. bp->gunzip_mapping);
  5258. bp->gunzip_buf = NULL;
  5259. }
  5260. }
  5261. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5262. {
  5263. int n, rc;
  5264. /* check gzip header */
  5265. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5266. BNX2X_ERR("Bad gzip header\n");
  5267. return -EINVAL;
  5268. }
  5269. n = 10;
  5270. #define FNAME 0x8
  5271. if (zbuf[3] & FNAME)
  5272. while ((zbuf[n++] != 0) && (n < len));
  5273. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5274. bp->strm->avail_in = len - n;
  5275. bp->strm->next_out = bp->gunzip_buf;
  5276. bp->strm->avail_out = FW_BUF_SIZE;
  5277. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5278. if (rc != Z_OK)
  5279. return rc;
  5280. rc = zlib_inflate(bp->strm, Z_FINISH);
  5281. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5282. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5283. bp->strm->msg);
  5284. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5285. if (bp->gunzip_outlen & 0x3)
  5286. netdev_err(bp->dev,
  5287. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5288. bp->gunzip_outlen);
  5289. bp->gunzip_outlen >>= 2;
  5290. zlib_inflateEnd(bp->strm);
  5291. if (rc == Z_STREAM_END)
  5292. return 0;
  5293. return rc;
  5294. }
  5295. /* nic load/unload */
  5296. /*
  5297. * General service functions
  5298. */
  5299. /* send a NIG loopback debug packet */
  5300. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5301. {
  5302. u32 wb_write[3];
  5303. /* Ethernet source and destination addresses */
  5304. wb_write[0] = 0x55555555;
  5305. wb_write[1] = 0x55555555;
  5306. wb_write[2] = 0x20; /* SOP */
  5307. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5308. /* NON-IP protocol */
  5309. wb_write[0] = 0x09000000;
  5310. wb_write[1] = 0x55555555;
  5311. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5312. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5313. }
  5314. /* some of the internal memories
  5315. * are not directly readable from the driver
  5316. * to test them we send debug packets
  5317. */
  5318. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5319. {
  5320. int factor;
  5321. int count, i;
  5322. u32 val = 0;
  5323. if (CHIP_REV_IS_FPGA(bp))
  5324. factor = 120;
  5325. else if (CHIP_REV_IS_EMUL(bp))
  5326. factor = 200;
  5327. else
  5328. factor = 1;
  5329. /* Disable inputs of parser neighbor blocks */
  5330. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5331. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5332. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5333. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5334. /* Write 0 to parser credits for CFC search request */
  5335. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5336. /* send Ethernet packet */
  5337. bnx2x_lb_pckt(bp);
  5338. /* TODO do i reset NIG statistic? */
  5339. /* Wait until NIG register shows 1 packet of size 0x10 */
  5340. count = 1000 * factor;
  5341. while (count) {
  5342. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5343. val = *bnx2x_sp(bp, wb_data[0]);
  5344. if (val == 0x10)
  5345. break;
  5346. usleep_range(10000, 20000);
  5347. count--;
  5348. }
  5349. if (val != 0x10) {
  5350. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5351. return -1;
  5352. }
  5353. /* Wait until PRS register shows 1 packet */
  5354. count = 1000 * factor;
  5355. while (count) {
  5356. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5357. if (val == 1)
  5358. break;
  5359. usleep_range(10000, 20000);
  5360. count--;
  5361. }
  5362. if (val != 0x1) {
  5363. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5364. return -2;
  5365. }
  5366. /* Reset and init BRB, PRS */
  5367. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5368. msleep(50);
  5369. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5370. msleep(50);
  5371. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5372. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5373. DP(NETIF_MSG_HW, "part2\n");
  5374. /* Disable inputs of parser neighbor blocks */
  5375. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5376. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5377. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5378. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5379. /* Write 0 to parser credits for CFC search request */
  5380. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5381. /* send 10 Ethernet packets */
  5382. for (i = 0; i < 10; i++)
  5383. bnx2x_lb_pckt(bp);
  5384. /* Wait until NIG register shows 10 + 1
  5385. packets of size 11*0x10 = 0xb0 */
  5386. count = 1000 * factor;
  5387. while (count) {
  5388. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5389. val = *bnx2x_sp(bp, wb_data[0]);
  5390. if (val == 0xb0)
  5391. break;
  5392. usleep_range(10000, 20000);
  5393. count--;
  5394. }
  5395. if (val != 0xb0) {
  5396. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5397. return -3;
  5398. }
  5399. /* Wait until PRS register shows 2 packets */
  5400. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5401. if (val != 2)
  5402. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5403. /* Write 1 to parser credits for CFC search request */
  5404. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5405. /* Wait until PRS register shows 3 packets */
  5406. msleep(10 * factor);
  5407. /* Wait until NIG register shows 1 packet of size 0x10 */
  5408. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5409. if (val != 3)
  5410. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5411. /* clear NIG EOP FIFO */
  5412. for (i = 0; i < 11; i++)
  5413. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5414. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5415. if (val != 1) {
  5416. BNX2X_ERR("clear of NIG failed\n");
  5417. return -4;
  5418. }
  5419. /* Reset and init BRB, PRS, NIG */
  5420. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5421. msleep(50);
  5422. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5423. msleep(50);
  5424. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5425. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5426. if (!CNIC_SUPPORT(bp))
  5427. /* set NIC mode */
  5428. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5429. /* Enable inputs of parser neighbor blocks */
  5430. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5431. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5432. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5433. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5434. DP(NETIF_MSG_HW, "done\n");
  5435. return 0; /* OK */
  5436. }
  5437. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5438. {
  5439. u32 val;
  5440. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5441. if (!CHIP_IS_E1x(bp))
  5442. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5443. else
  5444. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5445. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5446. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5447. /*
  5448. * mask read length error interrupts in brb for parser
  5449. * (parsing unit and 'checksum and crc' unit)
  5450. * these errors are legal (PU reads fixed length and CAC can cause
  5451. * read length error on truncated packets)
  5452. */
  5453. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5454. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5455. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5456. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5457. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5458. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5459. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5460. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5461. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5462. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5463. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5464. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5465. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5466. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5467. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5468. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5469. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5470. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5471. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5472. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5473. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5474. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5475. if (!CHIP_IS_E1x(bp))
  5476. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5477. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5478. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5479. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5480. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5481. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5482. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5483. if (!CHIP_IS_E1x(bp))
  5484. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5485. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5486. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5487. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5488. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5489. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5490. }
  5491. static void bnx2x_reset_common(struct bnx2x *bp)
  5492. {
  5493. u32 val = 0x1400;
  5494. /* reset_common */
  5495. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5496. 0xd3ffff7f);
  5497. if (CHIP_IS_E3(bp)) {
  5498. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5499. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5500. }
  5501. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5502. }
  5503. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5504. {
  5505. bp->dmae_ready = 0;
  5506. spin_lock_init(&bp->dmae_lock);
  5507. }
  5508. static void bnx2x_init_pxp(struct bnx2x *bp)
  5509. {
  5510. u16 devctl;
  5511. int r_order, w_order;
  5512. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5513. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5514. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5515. if (bp->mrrs == -1)
  5516. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5517. else {
  5518. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5519. r_order = bp->mrrs;
  5520. }
  5521. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5522. }
  5523. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5524. {
  5525. int is_required;
  5526. u32 val;
  5527. int port;
  5528. if (BP_NOMCP(bp))
  5529. return;
  5530. is_required = 0;
  5531. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5532. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5533. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5534. is_required = 1;
  5535. /*
  5536. * The fan failure mechanism is usually related to the PHY type since
  5537. * the power consumption of the board is affected by the PHY. Currently,
  5538. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5539. */
  5540. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5541. for (port = PORT_0; port < PORT_MAX; port++) {
  5542. is_required |=
  5543. bnx2x_fan_failure_det_req(
  5544. bp,
  5545. bp->common.shmem_base,
  5546. bp->common.shmem2_base,
  5547. port);
  5548. }
  5549. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5550. if (is_required == 0)
  5551. return;
  5552. /* Fan failure is indicated by SPIO 5 */
  5553. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5554. /* set to active low mode */
  5555. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5556. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5557. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5558. /* enable interrupt to signal the IGU */
  5559. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5560. val |= MISC_SPIO_SPIO5;
  5561. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5562. }
  5563. void bnx2x_pf_disable(struct bnx2x *bp)
  5564. {
  5565. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5566. val &= ~IGU_PF_CONF_FUNC_EN;
  5567. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5568. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5569. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5570. }
  5571. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5572. {
  5573. u32 shmem_base[2], shmem2_base[2];
  5574. /* Avoid common init in case MFW supports LFA */
  5575. if (SHMEM2_RD(bp, size) >
  5576. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5577. return;
  5578. shmem_base[0] = bp->common.shmem_base;
  5579. shmem2_base[0] = bp->common.shmem2_base;
  5580. if (!CHIP_IS_E1x(bp)) {
  5581. shmem_base[1] =
  5582. SHMEM2_RD(bp, other_shmem_base_addr);
  5583. shmem2_base[1] =
  5584. SHMEM2_RD(bp, other_shmem2_base_addr);
  5585. }
  5586. bnx2x_acquire_phy_lock(bp);
  5587. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5588. bp->common.chip_id);
  5589. bnx2x_release_phy_lock(bp);
  5590. }
  5591. /**
  5592. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5593. *
  5594. * @bp: driver handle
  5595. */
  5596. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5597. {
  5598. u32 val;
  5599. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5600. /*
  5601. * take the RESET lock to protect undi_unload flow from accessing
  5602. * registers while we're resetting the chip
  5603. */
  5604. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5605. bnx2x_reset_common(bp);
  5606. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5607. val = 0xfffc;
  5608. if (CHIP_IS_E3(bp)) {
  5609. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5610. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5611. }
  5612. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5613. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5614. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5615. if (!CHIP_IS_E1x(bp)) {
  5616. u8 abs_func_id;
  5617. /**
  5618. * 4-port mode or 2-port mode we need to turn of master-enable
  5619. * for everyone, after that, turn it back on for self.
  5620. * so, we disregard multi-function or not, and always disable
  5621. * for all functions on the given path, this means 0,2,4,6 for
  5622. * path 0 and 1,3,5,7 for path 1
  5623. */
  5624. for (abs_func_id = BP_PATH(bp);
  5625. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5626. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5627. REG_WR(bp,
  5628. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5629. 1);
  5630. continue;
  5631. }
  5632. bnx2x_pretend_func(bp, abs_func_id);
  5633. /* clear pf enable */
  5634. bnx2x_pf_disable(bp);
  5635. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5636. }
  5637. }
  5638. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5639. if (CHIP_IS_E1(bp)) {
  5640. /* enable HW interrupt from PXP on USDM overflow
  5641. bit 16 on INT_MASK_0 */
  5642. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5643. }
  5644. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5645. bnx2x_init_pxp(bp);
  5646. #ifdef __BIG_ENDIAN
  5647. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5648. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5649. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5650. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5651. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5652. /* make sure this value is 0 */
  5653. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5654. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5655. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5656. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5657. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5658. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5659. #endif
  5660. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5661. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5662. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5663. /* let the HW do it's magic ... */
  5664. msleep(100);
  5665. /* finish PXP init */
  5666. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5667. if (val != 1) {
  5668. BNX2X_ERR("PXP2 CFG failed\n");
  5669. return -EBUSY;
  5670. }
  5671. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5672. if (val != 1) {
  5673. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5674. return -EBUSY;
  5675. }
  5676. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5677. * have entries with value "0" and valid bit on.
  5678. * This needs to be done by the first PF that is loaded in a path
  5679. * (i.e. common phase)
  5680. */
  5681. if (!CHIP_IS_E1x(bp)) {
  5682. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5683. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5684. * This occurs when a different function (func2,3) is being marked
  5685. * as "scan-off". Real-life scenario for example: if a driver is being
  5686. * load-unloaded while func6,7 are down. This will cause the timer to access
  5687. * the ilt, translate to a logical address and send a request to read/write.
  5688. * Since the ilt for the function that is down is not valid, this will cause
  5689. * a translation error which is unrecoverable.
  5690. * The Workaround is intended to make sure that when this happens nothing fatal
  5691. * will occur. The workaround:
  5692. * 1. First PF driver which loads on a path will:
  5693. * a. After taking the chip out of reset, by using pretend,
  5694. * it will write "0" to the following registers of
  5695. * the other vnics.
  5696. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5697. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5698. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5699. * And for itself it will write '1' to
  5700. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5701. * dmae-operations (writing to pram for example.)
  5702. * note: can be done for only function 6,7 but cleaner this
  5703. * way.
  5704. * b. Write zero+valid to the entire ILT.
  5705. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5706. * VNIC3 (of that port). The range allocated will be the
  5707. * entire ILT. This is needed to prevent ILT range error.
  5708. * 2. Any PF driver load flow:
  5709. * a. ILT update with the physical addresses of the allocated
  5710. * logical pages.
  5711. * b. Wait 20msec. - note that this timeout is needed to make
  5712. * sure there are no requests in one of the PXP internal
  5713. * queues with "old" ILT addresses.
  5714. * c. PF enable in the PGLC.
  5715. * d. Clear the was_error of the PF in the PGLC. (could have
  5716. * occurred while driver was down)
  5717. * e. PF enable in the CFC (WEAK + STRONG)
  5718. * f. Timers scan enable
  5719. * 3. PF driver unload flow:
  5720. * a. Clear the Timers scan_en.
  5721. * b. Polling for scan_on=0 for that PF.
  5722. * c. Clear the PF enable bit in the PXP.
  5723. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5724. * e. Write zero+valid to all ILT entries (The valid bit must
  5725. * stay set)
  5726. * f. If this is VNIC 3 of a port then also init
  5727. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5728. * to the last entry in the ILT.
  5729. *
  5730. * Notes:
  5731. * Currently the PF error in the PGLC is non recoverable.
  5732. * In the future the there will be a recovery routine for this error.
  5733. * Currently attention is masked.
  5734. * Having an MCP lock on the load/unload process does not guarantee that
  5735. * there is no Timer disable during Func6/7 enable. This is because the
  5736. * Timers scan is currently being cleared by the MCP on FLR.
  5737. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5738. * there is error before clearing it. But the flow above is simpler and
  5739. * more general.
  5740. * All ILT entries are written by zero+valid and not just PF6/7
  5741. * ILT entries since in the future the ILT entries allocation for
  5742. * PF-s might be dynamic.
  5743. */
  5744. struct ilt_client_info ilt_cli;
  5745. struct bnx2x_ilt ilt;
  5746. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5747. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5748. /* initialize dummy TM client */
  5749. ilt_cli.start = 0;
  5750. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5751. ilt_cli.client_num = ILT_CLIENT_TM;
  5752. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5753. * Step 2: set the timers first/last ilt entry to point
  5754. * to the entire range to prevent ILT range error for 3rd/4th
  5755. * vnic (this code assumes existence of the vnic)
  5756. *
  5757. * both steps performed by call to bnx2x_ilt_client_init_op()
  5758. * with dummy TM client
  5759. *
  5760. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5761. * and his brother are split registers
  5762. */
  5763. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5764. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5765. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5766. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5767. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5768. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5769. }
  5770. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5771. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5772. if (!CHIP_IS_E1x(bp)) {
  5773. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5774. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5775. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5776. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5777. /* let the HW do it's magic ... */
  5778. do {
  5779. msleep(200);
  5780. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5781. } while (factor-- && (val != 1));
  5782. if (val != 1) {
  5783. BNX2X_ERR("ATC_INIT failed\n");
  5784. return -EBUSY;
  5785. }
  5786. }
  5787. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5788. bnx2x_iov_init_dmae(bp);
  5789. /* clean the DMAE memory */
  5790. bp->dmae_ready = 1;
  5791. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5792. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5793. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5794. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5795. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5796. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5797. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5798. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5799. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5800. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5801. /* QM queues pointers table */
  5802. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5803. /* soft reset pulse */
  5804. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5805. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5806. if (CNIC_SUPPORT(bp))
  5807. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5808. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5809. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5810. if (!CHIP_REV_IS_SLOW(bp))
  5811. /* enable hw interrupt from doorbell Q */
  5812. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5813. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5814. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5815. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5816. if (!CHIP_IS_E1(bp))
  5817. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5818. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5819. if (IS_MF_AFEX(bp)) {
  5820. /* configure that VNTag and VLAN headers must be
  5821. * received in afex mode
  5822. */
  5823. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5824. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5825. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5826. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5827. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5828. } else {
  5829. /* Bit-map indicating which L2 hdrs may appear
  5830. * after the basic Ethernet header
  5831. */
  5832. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5833. bp->path_has_ovlan ? 7 : 6);
  5834. }
  5835. }
  5836. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5837. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5838. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5839. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5840. if (!CHIP_IS_E1x(bp)) {
  5841. /* reset VFC memories */
  5842. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5843. VFC_MEMORIES_RST_REG_CAM_RST |
  5844. VFC_MEMORIES_RST_REG_RAM_RST);
  5845. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5846. VFC_MEMORIES_RST_REG_CAM_RST |
  5847. VFC_MEMORIES_RST_REG_RAM_RST);
  5848. msleep(20);
  5849. }
  5850. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5851. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5852. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5853. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5854. /* sync semi rtc */
  5855. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5856. 0x80000000);
  5857. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5858. 0x80000000);
  5859. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5860. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5861. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5862. if (!CHIP_IS_E1x(bp)) {
  5863. if (IS_MF_AFEX(bp)) {
  5864. /* configure that VNTag and VLAN headers must be
  5865. * sent in afex mode
  5866. */
  5867. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5868. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5869. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5870. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5871. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5872. } else {
  5873. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5874. bp->path_has_ovlan ? 7 : 6);
  5875. }
  5876. }
  5877. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5878. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5879. if (CNIC_SUPPORT(bp)) {
  5880. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5881. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5882. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5883. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5884. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5885. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5886. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5887. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5888. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5889. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5890. }
  5891. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5892. if (sizeof(union cdu_context) != 1024)
  5893. /* we currently assume that a context is 1024 bytes */
  5894. dev_alert(&bp->pdev->dev,
  5895. "please adjust the size of cdu_context(%ld)\n",
  5896. (long)sizeof(union cdu_context));
  5897. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5898. val = (4 << 24) + (0 << 12) + 1024;
  5899. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5900. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5901. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5902. /* enable context validation interrupt from CFC */
  5903. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5904. /* set the thresholds to prevent CFC/CDU race */
  5905. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5906. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5907. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5908. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5909. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5910. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5911. /* Reset PCIE errors for debug */
  5912. REG_WR(bp, 0x2814, 0xffffffff);
  5913. REG_WR(bp, 0x3820, 0xffffffff);
  5914. if (!CHIP_IS_E1x(bp)) {
  5915. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5916. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5917. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5918. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5919. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5920. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5921. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5922. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5923. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5924. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5925. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5926. }
  5927. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5928. if (!CHIP_IS_E1(bp)) {
  5929. /* in E3 this done in per-port section */
  5930. if (!CHIP_IS_E3(bp))
  5931. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5932. }
  5933. if (CHIP_IS_E1H(bp))
  5934. /* not applicable for E2 (and above ...) */
  5935. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5936. if (CHIP_REV_IS_SLOW(bp))
  5937. msleep(200);
  5938. /* finish CFC init */
  5939. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5940. if (val != 1) {
  5941. BNX2X_ERR("CFC LL_INIT failed\n");
  5942. return -EBUSY;
  5943. }
  5944. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5945. if (val != 1) {
  5946. BNX2X_ERR("CFC AC_INIT failed\n");
  5947. return -EBUSY;
  5948. }
  5949. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5950. if (val != 1) {
  5951. BNX2X_ERR("CFC CAM_INIT failed\n");
  5952. return -EBUSY;
  5953. }
  5954. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5955. if (CHIP_IS_E1(bp)) {
  5956. /* read NIG statistic
  5957. to see if this is our first up since powerup */
  5958. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5959. val = *bnx2x_sp(bp, wb_data[0]);
  5960. /* do internal memory self test */
  5961. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5962. BNX2X_ERR("internal mem self test failed\n");
  5963. return -EBUSY;
  5964. }
  5965. }
  5966. bnx2x_setup_fan_failure_detection(bp);
  5967. /* clear PXP2 attentions */
  5968. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5969. bnx2x_enable_blocks_attention(bp);
  5970. bnx2x_enable_blocks_parity(bp);
  5971. if (!BP_NOMCP(bp)) {
  5972. if (CHIP_IS_E1x(bp))
  5973. bnx2x__common_init_phy(bp);
  5974. } else
  5975. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5976. return 0;
  5977. }
  5978. /**
  5979. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5980. *
  5981. * @bp: driver handle
  5982. */
  5983. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5984. {
  5985. int rc = bnx2x_init_hw_common(bp);
  5986. if (rc)
  5987. return rc;
  5988. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5989. if (!BP_NOMCP(bp))
  5990. bnx2x__common_init_phy(bp);
  5991. return 0;
  5992. }
  5993. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5994. {
  5995. int port = BP_PORT(bp);
  5996. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5997. u32 low, high;
  5998. u32 val;
  5999. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6000. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6001. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6002. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6003. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6004. /* Timers bug workaround: disables the pf_master bit in pglue at
  6005. * common phase, we need to enable it here before any dmae access are
  6006. * attempted. Therefore we manually added the enable-master to the
  6007. * port phase (it also happens in the function phase)
  6008. */
  6009. if (!CHIP_IS_E1x(bp))
  6010. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6011. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6012. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6013. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6014. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6015. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6016. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6017. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6018. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6019. /* QM cid (connection) count */
  6020. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6021. if (CNIC_SUPPORT(bp)) {
  6022. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6023. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6024. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6025. }
  6026. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6027. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6028. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6029. if (IS_MF(bp))
  6030. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6031. else if (bp->dev->mtu > 4096) {
  6032. if (bp->flags & ONE_PORT_FLAG)
  6033. low = 160;
  6034. else {
  6035. val = bp->dev->mtu;
  6036. /* (24*1024 + val*4)/256 */
  6037. low = 96 + (val/64) +
  6038. ((val % 64) ? 1 : 0);
  6039. }
  6040. } else
  6041. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6042. high = low + 56; /* 14*1024/256 */
  6043. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6044. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6045. }
  6046. if (CHIP_MODE_IS_4_PORT(bp))
  6047. REG_WR(bp, (BP_PORT(bp) ?
  6048. BRB1_REG_MAC_GUARANTIED_1 :
  6049. BRB1_REG_MAC_GUARANTIED_0), 40);
  6050. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6051. if (CHIP_IS_E3B0(bp)) {
  6052. if (IS_MF_AFEX(bp)) {
  6053. /* configure headers for AFEX mode */
  6054. REG_WR(bp, BP_PORT(bp) ?
  6055. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6056. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6057. REG_WR(bp, BP_PORT(bp) ?
  6058. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6059. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6060. REG_WR(bp, BP_PORT(bp) ?
  6061. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6062. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6063. } else {
  6064. /* Ovlan exists only if we are in multi-function +
  6065. * switch-dependent mode, in switch-independent there
  6066. * is no ovlan headers
  6067. */
  6068. REG_WR(bp, BP_PORT(bp) ?
  6069. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6070. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6071. (bp->path_has_ovlan ? 7 : 6));
  6072. }
  6073. }
  6074. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6075. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6076. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6077. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6078. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6079. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6080. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6081. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6082. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6083. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6084. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6085. if (CHIP_IS_E1x(bp)) {
  6086. /* configure PBF to work without PAUSE mtu 9000 */
  6087. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6088. /* update threshold */
  6089. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6090. /* update init credit */
  6091. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6092. /* probe changes */
  6093. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6094. udelay(50);
  6095. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6096. }
  6097. if (CNIC_SUPPORT(bp))
  6098. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6099. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6100. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6101. if (CHIP_IS_E1(bp)) {
  6102. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6103. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6104. }
  6105. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6106. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6107. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6108. /* init aeu_mask_attn_func_0/1:
  6109. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6110. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6111. * bits 4-7 are used for "per vn group attention" */
  6112. val = IS_MF(bp) ? 0xF7 : 0x7;
  6113. /* Enable DCBX attention for all but E1 */
  6114. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6115. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6116. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6117. if (!CHIP_IS_E1x(bp)) {
  6118. /* Bit-map indicating which L2 hdrs may appear after the
  6119. * basic Ethernet header
  6120. */
  6121. if (IS_MF_AFEX(bp))
  6122. REG_WR(bp, BP_PORT(bp) ?
  6123. NIG_REG_P1_HDRS_AFTER_BASIC :
  6124. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6125. else
  6126. REG_WR(bp, BP_PORT(bp) ?
  6127. NIG_REG_P1_HDRS_AFTER_BASIC :
  6128. NIG_REG_P0_HDRS_AFTER_BASIC,
  6129. IS_MF_SD(bp) ? 7 : 6);
  6130. if (CHIP_IS_E3(bp))
  6131. REG_WR(bp, BP_PORT(bp) ?
  6132. NIG_REG_LLH1_MF_MODE :
  6133. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6134. }
  6135. if (!CHIP_IS_E3(bp))
  6136. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6137. if (!CHIP_IS_E1(bp)) {
  6138. /* 0x2 disable mf_ov, 0x1 enable */
  6139. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6140. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6141. if (!CHIP_IS_E1x(bp)) {
  6142. val = 0;
  6143. switch (bp->mf_mode) {
  6144. case MULTI_FUNCTION_SD:
  6145. val = 1;
  6146. break;
  6147. case MULTI_FUNCTION_SI:
  6148. case MULTI_FUNCTION_AFEX:
  6149. val = 2;
  6150. break;
  6151. }
  6152. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6153. NIG_REG_LLH0_CLS_TYPE), val);
  6154. }
  6155. {
  6156. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6157. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6158. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6159. }
  6160. }
  6161. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6162. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6163. if (val & MISC_SPIO_SPIO5) {
  6164. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6165. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6166. val = REG_RD(bp, reg_addr);
  6167. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6168. REG_WR(bp, reg_addr, val);
  6169. }
  6170. return 0;
  6171. }
  6172. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6173. {
  6174. int reg;
  6175. u32 wb_write[2];
  6176. if (CHIP_IS_E1(bp))
  6177. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6178. else
  6179. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6180. wb_write[0] = ONCHIP_ADDR1(addr);
  6181. wb_write[1] = ONCHIP_ADDR2(addr);
  6182. REG_WR_DMAE(bp, reg, wb_write, 2);
  6183. }
  6184. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6185. {
  6186. u32 data, ctl, cnt = 100;
  6187. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6188. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6189. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6190. u32 sb_bit = 1 << (idu_sb_id%32);
  6191. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6192. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6193. /* Not supported in BC mode */
  6194. if (CHIP_INT_MODE_IS_BC(bp))
  6195. return;
  6196. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6197. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6198. IGU_REGULAR_CLEANUP_SET |
  6199. IGU_REGULAR_BCLEANUP;
  6200. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6201. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6202. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6203. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6204. data, igu_addr_data);
  6205. REG_WR(bp, igu_addr_data, data);
  6206. mmiowb();
  6207. barrier();
  6208. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6209. ctl, igu_addr_ctl);
  6210. REG_WR(bp, igu_addr_ctl, ctl);
  6211. mmiowb();
  6212. barrier();
  6213. /* wait for clean up to finish */
  6214. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6215. msleep(20);
  6216. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6217. DP(NETIF_MSG_HW,
  6218. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6219. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6220. }
  6221. }
  6222. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6223. {
  6224. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6225. }
  6226. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6227. {
  6228. u32 i, base = FUNC_ILT_BASE(func);
  6229. for (i = base; i < base + ILT_PER_FUNC; i++)
  6230. bnx2x_ilt_wr(bp, i, 0);
  6231. }
  6232. static void bnx2x_init_searcher(struct bnx2x *bp)
  6233. {
  6234. int port = BP_PORT(bp);
  6235. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6236. /* T1 hash bits value determines the T1 number of entries */
  6237. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6238. }
  6239. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6240. {
  6241. int rc;
  6242. struct bnx2x_func_state_params func_params = {NULL};
  6243. struct bnx2x_func_switch_update_params *switch_update_params =
  6244. &func_params.params.switch_update;
  6245. /* Prepare parameters for function state transitions */
  6246. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6247. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6248. func_params.f_obj = &bp->func_obj;
  6249. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6250. /* Function parameters */
  6251. switch_update_params->suspend = suspend;
  6252. rc = bnx2x_func_state_change(bp, &func_params);
  6253. return rc;
  6254. }
  6255. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6256. {
  6257. int rc, i, port = BP_PORT(bp);
  6258. int vlan_en = 0, mac_en[NUM_MACS];
  6259. /* Close input from network */
  6260. if (bp->mf_mode == SINGLE_FUNCTION) {
  6261. bnx2x_set_rx_filter(&bp->link_params, 0);
  6262. } else {
  6263. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6264. NIG_REG_LLH0_FUNC_EN);
  6265. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6266. NIG_REG_LLH0_FUNC_EN, 0);
  6267. for (i = 0; i < NUM_MACS; i++) {
  6268. mac_en[i] = REG_RD(bp, port ?
  6269. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6270. 4 * i) :
  6271. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6272. 4 * i));
  6273. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6274. 4 * i) :
  6275. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6276. }
  6277. }
  6278. /* Close BMC to host */
  6279. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6280. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6281. /* Suspend Tx switching to the PF. Completion of this ramrod
  6282. * further guarantees that all the packets of that PF / child
  6283. * VFs in BRB were processed by the Parser, so it is safe to
  6284. * change the NIC_MODE register.
  6285. */
  6286. rc = bnx2x_func_switch_update(bp, 1);
  6287. if (rc) {
  6288. BNX2X_ERR("Can't suspend tx-switching!\n");
  6289. return rc;
  6290. }
  6291. /* Change NIC_MODE register */
  6292. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6293. /* Open input from network */
  6294. if (bp->mf_mode == SINGLE_FUNCTION) {
  6295. bnx2x_set_rx_filter(&bp->link_params, 1);
  6296. } else {
  6297. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6298. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6299. for (i = 0; i < NUM_MACS; i++) {
  6300. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6301. 4 * i) :
  6302. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6303. mac_en[i]);
  6304. }
  6305. }
  6306. /* Enable BMC to host */
  6307. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6308. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6309. /* Resume Tx switching to the PF */
  6310. rc = bnx2x_func_switch_update(bp, 0);
  6311. if (rc) {
  6312. BNX2X_ERR("Can't resume tx-switching!\n");
  6313. return rc;
  6314. }
  6315. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6316. return 0;
  6317. }
  6318. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6319. {
  6320. int rc;
  6321. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6322. if (CONFIGURE_NIC_MODE(bp)) {
  6323. /* Configure searcher as part of function hw init */
  6324. bnx2x_init_searcher(bp);
  6325. /* Reset NIC mode */
  6326. rc = bnx2x_reset_nic_mode(bp);
  6327. if (rc)
  6328. BNX2X_ERR("Can't change NIC mode!\n");
  6329. return rc;
  6330. }
  6331. return 0;
  6332. }
  6333. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6334. {
  6335. int port = BP_PORT(bp);
  6336. int func = BP_FUNC(bp);
  6337. int init_phase = PHASE_PF0 + func;
  6338. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6339. u16 cdu_ilt_start;
  6340. u32 addr, val;
  6341. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6342. int i, main_mem_width, rc;
  6343. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6344. /* FLR cleanup - hmmm */
  6345. if (!CHIP_IS_E1x(bp)) {
  6346. rc = bnx2x_pf_flr_clnup(bp);
  6347. if (rc) {
  6348. bnx2x_fw_dump(bp);
  6349. return rc;
  6350. }
  6351. }
  6352. /* set MSI reconfigure capability */
  6353. if (bp->common.int_block == INT_BLOCK_HC) {
  6354. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6355. val = REG_RD(bp, addr);
  6356. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6357. REG_WR(bp, addr, val);
  6358. }
  6359. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6360. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6361. ilt = BP_ILT(bp);
  6362. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6363. if (IS_SRIOV(bp))
  6364. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6365. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6366. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6367. * those of the VFs, so start line should be reset
  6368. */
  6369. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6370. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6371. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6372. ilt->lines[cdu_ilt_start + i].page_mapping =
  6373. bp->context[i].cxt_mapping;
  6374. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6375. }
  6376. bnx2x_ilt_init_op(bp, INITOP_SET);
  6377. if (!CONFIGURE_NIC_MODE(bp)) {
  6378. bnx2x_init_searcher(bp);
  6379. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6380. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6381. } else {
  6382. /* Set NIC mode */
  6383. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6384. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6385. }
  6386. if (!CHIP_IS_E1x(bp)) {
  6387. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6388. /* Turn on a single ISR mode in IGU if driver is going to use
  6389. * INT#x or MSI
  6390. */
  6391. if (!(bp->flags & USING_MSIX_FLAG))
  6392. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6393. /*
  6394. * Timers workaround bug: function init part.
  6395. * Need to wait 20msec after initializing ILT,
  6396. * needed to make sure there are no requests in
  6397. * one of the PXP internal queues with "old" ILT addresses
  6398. */
  6399. msleep(20);
  6400. /*
  6401. * Master enable - Due to WB DMAE writes performed before this
  6402. * register is re-initialized as part of the regular function
  6403. * init
  6404. */
  6405. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6406. /* Enable the function in IGU */
  6407. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6408. }
  6409. bp->dmae_ready = 1;
  6410. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6411. if (!CHIP_IS_E1x(bp))
  6412. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6413. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6414. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6415. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6416. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6417. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6418. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6419. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6420. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6421. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6422. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6423. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6424. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6425. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6426. if (!CHIP_IS_E1x(bp))
  6427. REG_WR(bp, QM_REG_PF_EN, 1);
  6428. if (!CHIP_IS_E1x(bp)) {
  6429. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6430. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6431. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6432. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6433. }
  6434. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6435. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6436. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6437. bnx2x_iov_init_dq(bp);
  6438. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6439. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6440. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6441. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6442. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6443. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6444. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6445. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6446. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6447. if (!CHIP_IS_E1x(bp))
  6448. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6449. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6450. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6451. if (!CHIP_IS_E1x(bp))
  6452. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6453. if (IS_MF(bp)) {
  6454. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6455. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6456. }
  6457. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6458. /* HC init per function */
  6459. if (bp->common.int_block == INT_BLOCK_HC) {
  6460. if (CHIP_IS_E1H(bp)) {
  6461. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6462. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6463. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6464. }
  6465. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6466. } else {
  6467. int num_segs, sb_idx, prod_offset;
  6468. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6469. if (!CHIP_IS_E1x(bp)) {
  6470. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6471. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6472. }
  6473. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6474. if (!CHIP_IS_E1x(bp)) {
  6475. int dsb_idx = 0;
  6476. /**
  6477. * Producer memory:
  6478. * E2 mode: address 0-135 match to the mapping memory;
  6479. * 136 - PF0 default prod; 137 - PF1 default prod;
  6480. * 138 - PF2 default prod; 139 - PF3 default prod;
  6481. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6482. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6483. * 144-147 reserved.
  6484. *
  6485. * E1.5 mode - In backward compatible mode;
  6486. * for non default SB; each even line in the memory
  6487. * holds the U producer and each odd line hold
  6488. * the C producer. The first 128 producers are for
  6489. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6490. * producers are for the DSB for each PF.
  6491. * Each PF has five segments: (the order inside each
  6492. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6493. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6494. * 144-147 attn prods;
  6495. */
  6496. /* non-default-status-blocks */
  6497. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6498. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6499. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6500. prod_offset = (bp->igu_base_sb + sb_idx) *
  6501. num_segs;
  6502. for (i = 0; i < num_segs; i++) {
  6503. addr = IGU_REG_PROD_CONS_MEMORY +
  6504. (prod_offset + i) * 4;
  6505. REG_WR(bp, addr, 0);
  6506. }
  6507. /* send consumer update with value 0 */
  6508. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6509. USTORM_ID, 0, IGU_INT_NOP, 1);
  6510. bnx2x_igu_clear_sb(bp,
  6511. bp->igu_base_sb + sb_idx);
  6512. }
  6513. /* default-status-blocks */
  6514. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6515. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6516. if (CHIP_MODE_IS_4_PORT(bp))
  6517. dsb_idx = BP_FUNC(bp);
  6518. else
  6519. dsb_idx = BP_VN(bp);
  6520. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6521. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6522. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6523. /*
  6524. * igu prods come in chunks of E1HVN_MAX (4) -
  6525. * does not matters what is the current chip mode
  6526. */
  6527. for (i = 0; i < (num_segs * E1HVN_MAX);
  6528. i += E1HVN_MAX) {
  6529. addr = IGU_REG_PROD_CONS_MEMORY +
  6530. (prod_offset + i)*4;
  6531. REG_WR(bp, addr, 0);
  6532. }
  6533. /* send consumer update with 0 */
  6534. if (CHIP_INT_MODE_IS_BC(bp)) {
  6535. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6536. USTORM_ID, 0, IGU_INT_NOP, 1);
  6537. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6538. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6539. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6540. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6541. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6542. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6543. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6544. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6545. } else {
  6546. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6547. USTORM_ID, 0, IGU_INT_NOP, 1);
  6548. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6549. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6550. }
  6551. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6552. /* !!! These should become driver const once
  6553. rf-tool supports split-68 const */
  6554. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6555. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6556. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6557. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6558. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6559. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6560. }
  6561. }
  6562. /* Reset PCIE errors for debug */
  6563. REG_WR(bp, 0x2114, 0xffffffff);
  6564. REG_WR(bp, 0x2120, 0xffffffff);
  6565. if (CHIP_IS_E1x(bp)) {
  6566. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6567. main_mem_base = HC_REG_MAIN_MEMORY +
  6568. BP_PORT(bp) * (main_mem_size * 4);
  6569. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6570. main_mem_width = 8;
  6571. val = REG_RD(bp, main_mem_prty_clr);
  6572. if (val)
  6573. DP(NETIF_MSG_HW,
  6574. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6575. val);
  6576. /* Clear "false" parity errors in MSI-X table */
  6577. for (i = main_mem_base;
  6578. i < main_mem_base + main_mem_size * 4;
  6579. i += main_mem_width) {
  6580. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6581. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6582. i, main_mem_width / 4);
  6583. }
  6584. /* Clear HC parity attention */
  6585. REG_RD(bp, main_mem_prty_clr);
  6586. }
  6587. #ifdef BNX2X_STOP_ON_ERROR
  6588. /* Enable STORMs SP logging */
  6589. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6590. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6591. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6592. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6593. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6594. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6595. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6596. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6597. #endif
  6598. bnx2x_phy_probe(&bp->link_params);
  6599. return 0;
  6600. }
  6601. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6602. {
  6603. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6604. if (!CHIP_IS_E1x(bp))
  6605. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6606. sizeof(struct host_hc_status_block_e2));
  6607. else
  6608. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6609. sizeof(struct host_hc_status_block_e1x));
  6610. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6611. }
  6612. void bnx2x_free_mem(struct bnx2x *bp)
  6613. {
  6614. int i;
  6615. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6616. sizeof(struct host_sp_status_block));
  6617. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6618. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6619. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6620. sizeof(struct bnx2x_slowpath));
  6621. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6622. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6623. bp->context[i].size);
  6624. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6625. BNX2X_FREE(bp->ilt->lines);
  6626. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6627. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6628. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6629. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6630. bnx2x_iov_free_mem(bp);
  6631. }
  6632. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6633. {
  6634. if (!CHIP_IS_E1x(bp))
  6635. /* size = the status block + ramrod buffers */
  6636. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6637. sizeof(struct host_hc_status_block_e2));
  6638. else
  6639. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6640. &bp->cnic_sb_mapping,
  6641. sizeof(struct
  6642. host_hc_status_block_e1x));
  6643. if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6644. /* allocate searcher T2 table, as it wasn't allocated before */
  6645. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6646. /* write address to which L5 should insert its values */
  6647. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6648. &bp->slowpath->drv_info_to_mcp;
  6649. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6650. goto alloc_mem_err;
  6651. return 0;
  6652. alloc_mem_err:
  6653. bnx2x_free_mem_cnic(bp);
  6654. BNX2X_ERR("Can't allocate memory\n");
  6655. return -ENOMEM;
  6656. }
  6657. int bnx2x_alloc_mem(struct bnx2x *bp)
  6658. {
  6659. int i, allocated, context_size;
  6660. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6661. /* allocate searcher T2 table */
  6662. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6663. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6664. sizeof(struct host_sp_status_block));
  6665. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6666. sizeof(struct bnx2x_slowpath));
  6667. /* Allocate memory for CDU context:
  6668. * This memory is allocated separately and not in the generic ILT
  6669. * functions because CDU differs in few aspects:
  6670. * 1. There are multiple entities allocating memory for context -
  6671. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6672. * its own ILT lines.
  6673. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6674. * for the other ILT clients), to be efficient we want to support
  6675. * allocation of sub-page-size in the last entry.
  6676. * 3. Context pointers are used by the driver to pass to FW / update
  6677. * the context (for the other ILT clients the pointers are used just to
  6678. * free the memory during unload).
  6679. */
  6680. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6681. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6682. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6683. (context_size - allocated));
  6684. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6685. &bp->context[i].cxt_mapping,
  6686. bp->context[i].size);
  6687. allocated += bp->context[i].size;
  6688. }
  6689. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6690. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6691. goto alloc_mem_err;
  6692. if (bnx2x_iov_alloc_mem(bp))
  6693. goto alloc_mem_err;
  6694. /* Slow path ring */
  6695. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6696. /* EQ */
  6697. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6698. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6699. return 0;
  6700. alloc_mem_err:
  6701. bnx2x_free_mem(bp);
  6702. BNX2X_ERR("Can't allocate memory\n");
  6703. return -ENOMEM;
  6704. }
  6705. /*
  6706. * Init service functions
  6707. */
  6708. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6709. struct bnx2x_vlan_mac_obj *obj, bool set,
  6710. int mac_type, unsigned long *ramrod_flags)
  6711. {
  6712. int rc;
  6713. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6714. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6715. /* Fill general parameters */
  6716. ramrod_param.vlan_mac_obj = obj;
  6717. ramrod_param.ramrod_flags = *ramrod_flags;
  6718. /* Fill a user request section if needed */
  6719. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6720. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6721. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6722. /* Set the command: ADD or DEL */
  6723. if (set)
  6724. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6725. else
  6726. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6727. }
  6728. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6729. if (rc == -EEXIST) {
  6730. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6731. /* do not treat adding same MAC as error */
  6732. rc = 0;
  6733. } else if (rc < 0)
  6734. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6735. return rc;
  6736. }
  6737. int bnx2x_del_all_macs(struct bnx2x *bp,
  6738. struct bnx2x_vlan_mac_obj *mac_obj,
  6739. int mac_type, bool wait_for_comp)
  6740. {
  6741. int rc;
  6742. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6743. /* Wait for completion of requested */
  6744. if (wait_for_comp)
  6745. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6746. /* Set the mac type of addresses we want to clear */
  6747. __set_bit(mac_type, &vlan_mac_flags);
  6748. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6749. if (rc < 0)
  6750. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6751. return rc;
  6752. }
  6753. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6754. {
  6755. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6756. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6757. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6758. "Ignoring Zero MAC for STORAGE SD mode\n");
  6759. return 0;
  6760. }
  6761. if (IS_PF(bp)) {
  6762. unsigned long ramrod_flags = 0;
  6763. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6764. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6765. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6766. &bp->sp_objs->mac_obj, set,
  6767. BNX2X_ETH_MAC, &ramrod_flags);
  6768. } else { /* vf */
  6769. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6770. bp->fp->index, true);
  6771. }
  6772. }
  6773. int bnx2x_setup_leading(struct bnx2x *bp)
  6774. {
  6775. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6776. }
  6777. /**
  6778. * bnx2x_set_int_mode - configure interrupt mode
  6779. *
  6780. * @bp: driver handle
  6781. *
  6782. * In case of MSI-X it will also try to enable MSI-X.
  6783. */
  6784. int bnx2x_set_int_mode(struct bnx2x *bp)
  6785. {
  6786. int rc = 0;
  6787. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6788. return -EINVAL;
  6789. switch (int_mode) {
  6790. case BNX2X_INT_MODE_MSIX:
  6791. /* attempt to enable msix */
  6792. rc = bnx2x_enable_msix(bp);
  6793. /* msix attained */
  6794. if (!rc)
  6795. return 0;
  6796. /* vfs use only msix */
  6797. if (rc && IS_VF(bp))
  6798. return rc;
  6799. /* failed to enable multiple MSI-X */
  6800. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6801. bp->num_queues,
  6802. 1 + bp->num_cnic_queues);
  6803. /* falling through... */
  6804. case BNX2X_INT_MODE_MSI:
  6805. bnx2x_enable_msi(bp);
  6806. /* falling through... */
  6807. case BNX2X_INT_MODE_INTX:
  6808. bp->num_ethernet_queues = 1;
  6809. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6810. BNX2X_DEV_INFO("set number of queues to 1\n");
  6811. break;
  6812. default:
  6813. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6814. return -EINVAL;
  6815. }
  6816. return 0;
  6817. }
  6818. /* must be called prior to any HW initializations */
  6819. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6820. {
  6821. if (IS_SRIOV(bp))
  6822. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6823. return L2_ILT_LINES(bp);
  6824. }
  6825. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6826. {
  6827. struct ilt_client_info *ilt_client;
  6828. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6829. u16 line = 0;
  6830. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6831. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6832. /* CDU */
  6833. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6834. ilt_client->client_num = ILT_CLIENT_CDU;
  6835. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6836. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6837. ilt_client->start = line;
  6838. line += bnx2x_cid_ilt_lines(bp);
  6839. if (CNIC_SUPPORT(bp))
  6840. line += CNIC_ILT_LINES;
  6841. ilt_client->end = line - 1;
  6842. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6843. ilt_client->start,
  6844. ilt_client->end,
  6845. ilt_client->page_size,
  6846. ilt_client->flags,
  6847. ilog2(ilt_client->page_size >> 12));
  6848. /* QM */
  6849. if (QM_INIT(bp->qm_cid_count)) {
  6850. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6851. ilt_client->client_num = ILT_CLIENT_QM;
  6852. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6853. ilt_client->flags = 0;
  6854. ilt_client->start = line;
  6855. /* 4 bytes for each cid */
  6856. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6857. QM_ILT_PAGE_SZ);
  6858. ilt_client->end = line - 1;
  6859. DP(NETIF_MSG_IFUP,
  6860. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6861. ilt_client->start,
  6862. ilt_client->end,
  6863. ilt_client->page_size,
  6864. ilt_client->flags,
  6865. ilog2(ilt_client->page_size >> 12));
  6866. }
  6867. if (CNIC_SUPPORT(bp)) {
  6868. /* SRC */
  6869. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6870. ilt_client->client_num = ILT_CLIENT_SRC;
  6871. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6872. ilt_client->flags = 0;
  6873. ilt_client->start = line;
  6874. line += SRC_ILT_LINES;
  6875. ilt_client->end = line - 1;
  6876. DP(NETIF_MSG_IFUP,
  6877. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6878. ilt_client->start,
  6879. ilt_client->end,
  6880. ilt_client->page_size,
  6881. ilt_client->flags,
  6882. ilog2(ilt_client->page_size >> 12));
  6883. /* TM */
  6884. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6885. ilt_client->client_num = ILT_CLIENT_TM;
  6886. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6887. ilt_client->flags = 0;
  6888. ilt_client->start = line;
  6889. line += TM_ILT_LINES;
  6890. ilt_client->end = line - 1;
  6891. DP(NETIF_MSG_IFUP,
  6892. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6893. ilt_client->start,
  6894. ilt_client->end,
  6895. ilt_client->page_size,
  6896. ilt_client->flags,
  6897. ilog2(ilt_client->page_size >> 12));
  6898. }
  6899. BUG_ON(line > ILT_MAX_LINES);
  6900. }
  6901. /**
  6902. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6903. *
  6904. * @bp: driver handle
  6905. * @fp: pointer to fastpath
  6906. * @init_params: pointer to parameters structure
  6907. *
  6908. * parameters configured:
  6909. * - HC configuration
  6910. * - Queue's CDU context
  6911. */
  6912. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6913. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6914. {
  6915. u8 cos;
  6916. int cxt_index, cxt_offset;
  6917. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6918. if (!IS_FCOE_FP(fp)) {
  6919. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6920. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6921. /* If HC is supported, enable host coalescing in the transition
  6922. * to INIT state.
  6923. */
  6924. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6925. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6926. /* HC rate */
  6927. init_params->rx.hc_rate = bp->rx_ticks ?
  6928. (1000000 / bp->rx_ticks) : 0;
  6929. init_params->tx.hc_rate = bp->tx_ticks ?
  6930. (1000000 / bp->tx_ticks) : 0;
  6931. /* FW SB ID */
  6932. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6933. fp->fw_sb_id;
  6934. /*
  6935. * CQ index among the SB indices: FCoE clients uses the default
  6936. * SB, therefore it's different.
  6937. */
  6938. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6939. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6940. }
  6941. /* set maximum number of COSs supported by this queue */
  6942. init_params->max_cos = fp->max_cos;
  6943. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6944. fp->index, init_params->max_cos);
  6945. /* set the context pointers queue object */
  6946. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6947. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6948. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6949. ILT_PAGE_CIDS);
  6950. init_params->cxts[cos] =
  6951. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6952. }
  6953. }
  6954. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6955. struct bnx2x_queue_state_params *q_params,
  6956. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6957. int tx_index, bool leading)
  6958. {
  6959. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6960. /* Set the command */
  6961. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6962. /* Set tx-only QUEUE flags: don't zero statistics */
  6963. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6964. /* choose the index of the cid to send the slow path on */
  6965. tx_only_params->cid_index = tx_index;
  6966. /* Set general TX_ONLY_SETUP parameters */
  6967. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6968. /* Set Tx TX_ONLY_SETUP parameters */
  6969. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6970. DP(NETIF_MSG_IFUP,
  6971. "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",
  6972. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6973. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6974. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6975. /* send the ramrod */
  6976. return bnx2x_queue_state_change(bp, q_params);
  6977. }
  6978. /**
  6979. * bnx2x_setup_queue - setup queue
  6980. *
  6981. * @bp: driver handle
  6982. * @fp: pointer to fastpath
  6983. * @leading: is leading
  6984. *
  6985. * This function performs 2 steps in a Queue state machine
  6986. * actually: 1) RESET->INIT 2) INIT->SETUP
  6987. */
  6988. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6989. bool leading)
  6990. {
  6991. struct bnx2x_queue_state_params q_params = {NULL};
  6992. struct bnx2x_queue_setup_params *setup_params =
  6993. &q_params.params.setup;
  6994. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6995. &q_params.params.tx_only;
  6996. int rc;
  6997. u8 tx_index;
  6998. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6999. /* reset IGU state skip FCoE L2 queue */
  7000. if (!IS_FCOE_FP(fp))
  7001. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7002. IGU_INT_ENABLE, 0);
  7003. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7004. /* We want to wait for completion in this context */
  7005. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7006. /* Prepare the INIT parameters */
  7007. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7008. /* Set the command */
  7009. q_params.cmd = BNX2X_Q_CMD_INIT;
  7010. /* Change the state to INIT */
  7011. rc = bnx2x_queue_state_change(bp, &q_params);
  7012. if (rc) {
  7013. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7014. return rc;
  7015. }
  7016. DP(NETIF_MSG_IFUP, "init complete\n");
  7017. /* Now move the Queue to the SETUP state... */
  7018. memset(setup_params, 0, sizeof(*setup_params));
  7019. /* Set QUEUE flags */
  7020. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7021. /* Set general SETUP parameters */
  7022. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7023. FIRST_TX_COS_INDEX);
  7024. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7025. &setup_params->rxq_params);
  7026. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7027. FIRST_TX_COS_INDEX);
  7028. /* Set the command */
  7029. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7030. if (IS_FCOE_FP(fp))
  7031. bp->fcoe_init = true;
  7032. /* Change the state to SETUP */
  7033. rc = bnx2x_queue_state_change(bp, &q_params);
  7034. if (rc) {
  7035. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7036. return rc;
  7037. }
  7038. /* loop through the relevant tx-only indices */
  7039. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7040. tx_index < fp->max_cos;
  7041. tx_index++) {
  7042. /* prepare and send tx-only ramrod*/
  7043. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7044. tx_only_params, tx_index, leading);
  7045. if (rc) {
  7046. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7047. fp->index, tx_index);
  7048. return rc;
  7049. }
  7050. }
  7051. return rc;
  7052. }
  7053. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7054. {
  7055. struct bnx2x_fastpath *fp = &bp->fp[index];
  7056. struct bnx2x_fp_txdata *txdata;
  7057. struct bnx2x_queue_state_params q_params = {NULL};
  7058. int rc, tx_index;
  7059. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7060. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7061. /* We want to wait for completion in this context */
  7062. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7063. /* close tx-only connections */
  7064. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7065. tx_index < fp->max_cos;
  7066. tx_index++){
  7067. /* ascertain this is a normal queue*/
  7068. txdata = fp->txdata_ptr[tx_index];
  7069. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7070. txdata->txq_index);
  7071. /* send halt terminate on tx-only connection */
  7072. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7073. memset(&q_params.params.terminate, 0,
  7074. sizeof(q_params.params.terminate));
  7075. q_params.params.terminate.cid_index = tx_index;
  7076. rc = bnx2x_queue_state_change(bp, &q_params);
  7077. if (rc)
  7078. return rc;
  7079. /* send halt terminate on tx-only connection */
  7080. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7081. memset(&q_params.params.cfc_del, 0,
  7082. sizeof(q_params.params.cfc_del));
  7083. q_params.params.cfc_del.cid_index = tx_index;
  7084. rc = bnx2x_queue_state_change(bp, &q_params);
  7085. if (rc)
  7086. return rc;
  7087. }
  7088. /* Stop the primary connection: */
  7089. /* ...halt the connection */
  7090. q_params.cmd = BNX2X_Q_CMD_HALT;
  7091. rc = bnx2x_queue_state_change(bp, &q_params);
  7092. if (rc)
  7093. return rc;
  7094. /* ...terminate the connection */
  7095. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7096. memset(&q_params.params.terminate, 0,
  7097. sizeof(q_params.params.terminate));
  7098. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7099. rc = bnx2x_queue_state_change(bp, &q_params);
  7100. if (rc)
  7101. return rc;
  7102. /* ...delete cfc entry */
  7103. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7104. memset(&q_params.params.cfc_del, 0,
  7105. sizeof(q_params.params.cfc_del));
  7106. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7107. return bnx2x_queue_state_change(bp, &q_params);
  7108. }
  7109. static void bnx2x_reset_func(struct bnx2x *bp)
  7110. {
  7111. int port = BP_PORT(bp);
  7112. int func = BP_FUNC(bp);
  7113. int i;
  7114. /* Disable the function in the FW */
  7115. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7116. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7117. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7118. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7119. /* FP SBs */
  7120. for_each_eth_queue(bp, i) {
  7121. struct bnx2x_fastpath *fp = &bp->fp[i];
  7122. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7123. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7124. SB_DISABLED);
  7125. }
  7126. if (CNIC_LOADED(bp))
  7127. /* CNIC SB */
  7128. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7129. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7130. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7131. /* SP SB */
  7132. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7133. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7134. SB_DISABLED);
  7135. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7136. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7137. 0);
  7138. /* Configure IGU */
  7139. if (bp->common.int_block == INT_BLOCK_HC) {
  7140. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7141. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7142. } else {
  7143. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7144. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7145. }
  7146. if (CNIC_LOADED(bp)) {
  7147. /* Disable Timer scan */
  7148. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7149. /*
  7150. * Wait for at least 10ms and up to 2 second for the timers
  7151. * scan to complete
  7152. */
  7153. for (i = 0; i < 200; i++) {
  7154. usleep_range(10000, 20000);
  7155. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7156. break;
  7157. }
  7158. }
  7159. /* Clear ILT */
  7160. bnx2x_clear_func_ilt(bp, func);
  7161. /* Timers workaround bug for E2: if this is vnic-3,
  7162. * we need to set the entire ilt range for this timers.
  7163. */
  7164. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7165. struct ilt_client_info ilt_cli;
  7166. /* use dummy TM client */
  7167. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7168. ilt_cli.start = 0;
  7169. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7170. ilt_cli.client_num = ILT_CLIENT_TM;
  7171. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7172. }
  7173. /* this assumes that reset_port() called before reset_func()*/
  7174. if (!CHIP_IS_E1x(bp))
  7175. bnx2x_pf_disable(bp);
  7176. bp->dmae_ready = 0;
  7177. }
  7178. static void bnx2x_reset_port(struct bnx2x *bp)
  7179. {
  7180. int port = BP_PORT(bp);
  7181. u32 val;
  7182. /* Reset physical Link */
  7183. bnx2x__link_reset(bp);
  7184. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7185. /* Do not rcv packets to BRB */
  7186. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7187. /* Do not direct rcv packets that are not for MCP to the BRB */
  7188. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7189. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7190. /* Configure AEU */
  7191. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7192. msleep(100);
  7193. /* Check for BRB port occupancy */
  7194. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7195. if (val)
  7196. DP(NETIF_MSG_IFDOWN,
  7197. "BRB1 is not empty %d blocks are occupied\n", val);
  7198. /* TODO: Close Doorbell port? */
  7199. }
  7200. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7201. {
  7202. struct bnx2x_func_state_params func_params = {NULL};
  7203. /* Prepare parameters for function state transitions */
  7204. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7205. func_params.f_obj = &bp->func_obj;
  7206. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7207. func_params.params.hw_init.load_phase = load_code;
  7208. return bnx2x_func_state_change(bp, &func_params);
  7209. }
  7210. static int bnx2x_func_stop(struct bnx2x *bp)
  7211. {
  7212. struct bnx2x_func_state_params func_params = {NULL};
  7213. int rc;
  7214. /* Prepare parameters for function state transitions */
  7215. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7216. func_params.f_obj = &bp->func_obj;
  7217. func_params.cmd = BNX2X_F_CMD_STOP;
  7218. /*
  7219. * Try to stop the function the 'good way'. If fails (in case
  7220. * of a parity error during bnx2x_chip_cleanup()) and we are
  7221. * not in a debug mode, perform a state transaction in order to
  7222. * enable further HW_RESET transaction.
  7223. */
  7224. rc = bnx2x_func_state_change(bp, &func_params);
  7225. if (rc) {
  7226. #ifdef BNX2X_STOP_ON_ERROR
  7227. return rc;
  7228. #else
  7229. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7230. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7231. return bnx2x_func_state_change(bp, &func_params);
  7232. #endif
  7233. }
  7234. return 0;
  7235. }
  7236. /**
  7237. * bnx2x_send_unload_req - request unload mode from the MCP.
  7238. *
  7239. * @bp: driver handle
  7240. * @unload_mode: requested function's unload mode
  7241. *
  7242. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7243. */
  7244. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7245. {
  7246. u32 reset_code = 0;
  7247. int port = BP_PORT(bp);
  7248. /* Select the UNLOAD request mode */
  7249. if (unload_mode == UNLOAD_NORMAL)
  7250. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7251. else if (bp->flags & NO_WOL_FLAG)
  7252. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7253. else if (bp->wol) {
  7254. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7255. u8 *mac_addr = bp->dev->dev_addr;
  7256. u32 val;
  7257. u16 pmc;
  7258. /* The mac address is written to entries 1-4 to
  7259. * preserve entry 0 which is used by the PMF
  7260. */
  7261. u8 entry = (BP_VN(bp) + 1)*8;
  7262. val = (mac_addr[0] << 8) | mac_addr[1];
  7263. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7264. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7265. (mac_addr[4] << 8) | mac_addr[5];
  7266. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7267. /* Enable the PME and clear the status */
  7268. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7269. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7270. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7271. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7272. } else
  7273. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7274. /* Send the request to the MCP */
  7275. if (!BP_NOMCP(bp))
  7276. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7277. else {
  7278. int path = BP_PATH(bp);
  7279. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7280. path, load_count[path][0], load_count[path][1],
  7281. load_count[path][2]);
  7282. load_count[path][0]--;
  7283. load_count[path][1 + port]--;
  7284. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7285. path, load_count[path][0], load_count[path][1],
  7286. load_count[path][2]);
  7287. if (load_count[path][0] == 0)
  7288. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7289. else if (load_count[path][1 + port] == 0)
  7290. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7291. else
  7292. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7293. }
  7294. return reset_code;
  7295. }
  7296. /**
  7297. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7298. *
  7299. * @bp: driver handle
  7300. * @keep_link: true iff link should be kept up
  7301. */
  7302. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7303. {
  7304. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7305. /* Report UNLOAD_DONE to MCP */
  7306. if (!BP_NOMCP(bp))
  7307. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7308. }
  7309. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7310. {
  7311. int tout = 50;
  7312. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7313. if (!bp->port.pmf)
  7314. return 0;
  7315. /*
  7316. * (assumption: No Attention from MCP at this stage)
  7317. * PMF probably in the middle of TX disable/enable transaction
  7318. * 1. Sync IRS for default SB
  7319. * 2. Sync SP queue - this guarantees us that attention handling started
  7320. * 3. Wait, that TX disable/enable transaction completes
  7321. *
  7322. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7323. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7324. * received completion for the transaction the state is TX_STOPPED.
  7325. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7326. * transaction.
  7327. */
  7328. /* make sure default SB ISR is done */
  7329. if (msix)
  7330. synchronize_irq(bp->msix_table[0].vector);
  7331. else
  7332. synchronize_irq(bp->pdev->irq);
  7333. flush_workqueue(bnx2x_wq);
  7334. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7335. BNX2X_F_STATE_STARTED && tout--)
  7336. msleep(20);
  7337. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7338. BNX2X_F_STATE_STARTED) {
  7339. #ifdef BNX2X_STOP_ON_ERROR
  7340. BNX2X_ERR("Wrong function state\n");
  7341. return -EBUSY;
  7342. #else
  7343. /*
  7344. * Failed to complete the transaction in a "good way"
  7345. * Force both transactions with CLR bit
  7346. */
  7347. struct bnx2x_func_state_params func_params = {NULL};
  7348. DP(NETIF_MSG_IFDOWN,
  7349. "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7350. func_params.f_obj = &bp->func_obj;
  7351. __set_bit(RAMROD_DRV_CLR_ONLY,
  7352. &func_params.ramrod_flags);
  7353. /* STARTED-->TX_ST0PPED */
  7354. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7355. bnx2x_func_state_change(bp, &func_params);
  7356. /* TX_ST0PPED-->STARTED */
  7357. func_params.cmd = BNX2X_F_CMD_TX_START;
  7358. return bnx2x_func_state_change(bp, &func_params);
  7359. #endif
  7360. }
  7361. return 0;
  7362. }
  7363. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7364. {
  7365. int port = BP_PORT(bp);
  7366. int i, rc = 0;
  7367. u8 cos;
  7368. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7369. u32 reset_code;
  7370. /* Wait until tx fastpath tasks complete */
  7371. for_each_tx_queue(bp, i) {
  7372. struct bnx2x_fastpath *fp = &bp->fp[i];
  7373. for_each_cos_in_tx_queue(fp, cos)
  7374. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7375. #ifdef BNX2X_STOP_ON_ERROR
  7376. if (rc)
  7377. return;
  7378. #endif
  7379. }
  7380. /* Give HW time to discard old tx messages */
  7381. usleep_range(1000, 2000);
  7382. /* Clean all ETH MACs */
  7383. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7384. false);
  7385. if (rc < 0)
  7386. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7387. /* Clean up UC list */
  7388. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7389. true);
  7390. if (rc < 0)
  7391. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7392. rc);
  7393. /* Disable LLH */
  7394. if (!CHIP_IS_E1(bp))
  7395. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7396. /* Set "drop all" (stop Rx).
  7397. * We need to take a netif_addr_lock() here in order to prevent
  7398. * a race between the completion code and this code.
  7399. */
  7400. netif_addr_lock_bh(bp->dev);
  7401. /* Schedule the rx_mode command */
  7402. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7403. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7404. else
  7405. bnx2x_set_storm_rx_mode(bp);
  7406. /* Cleanup multicast configuration */
  7407. rparam.mcast_obj = &bp->mcast_obj;
  7408. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7409. if (rc < 0)
  7410. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7411. netif_addr_unlock_bh(bp->dev);
  7412. bnx2x_iov_chip_cleanup(bp);
  7413. /*
  7414. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7415. * this function should perform FUNC, PORT or COMMON HW
  7416. * reset.
  7417. */
  7418. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7419. /*
  7420. * (assumption: No Attention from MCP at this stage)
  7421. * PMF probably in the middle of TX disable/enable transaction
  7422. */
  7423. rc = bnx2x_func_wait_started(bp);
  7424. if (rc) {
  7425. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7426. #ifdef BNX2X_STOP_ON_ERROR
  7427. return;
  7428. #endif
  7429. }
  7430. /* Close multi and leading connections
  7431. * Completions for ramrods are collected in a synchronous way
  7432. */
  7433. for_each_eth_queue(bp, i)
  7434. if (bnx2x_stop_queue(bp, i))
  7435. #ifdef BNX2X_STOP_ON_ERROR
  7436. return;
  7437. #else
  7438. goto unload_error;
  7439. #endif
  7440. if (CNIC_LOADED(bp)) {
  7441. for_each_cnic_queue(bp, i)
  7442. if (bnx2x_stop_queue(bp, i))
  7443. #ifdef BNX2X_STOP_ON_ERROR
  7444. return;
  7445. #else
  7446. goto unload_error;
  7447. #endif
  7448. }
  7449. /* If SP settings didn't get completed so far - something
  7450. * very wrong has happen.
  7451. */
  7452. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7453. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7454. #ifndef BNX2X_STOP_ON_ERROR
  7455. unload_error:
  7456. #endif
  7457. rc = bnx2x_func_stop(bp);
  7458. if (rc) {
  7459. BNX2X_ERR("Function stop failed!\n");
  7460. #ifdef BNX2X_STOP_ON_ERROR
  7461. return;
  7462. #endif
  7463. }
  7464. /* Disable HW interrupts, NAPI */
  7465. bnx2x_netif_stop(bp, 1);
  7466. /* Delete all NAPI objects */
  7467. bnx2x_del_all_napi(bp);
  7468. if (CNIC_LOADED(bp))
  7469. bnx2x_del_all_napi_cnic(bp);
  7470. /* Release IRQs */
  7471. bnx2x_free_irq(bp);
  7472. /* Reset the chip */
  7473. rc = bnx2x_reset_hw(bp, reset_code);
  7474. if (rc)
  7475. BNX2X_ERR("HW_RESET failed\n");
  7476. /* Report UNLOAD_DONE to MCP */
  7477. bnx2x_send_unload_done(bp, keep_link);
  7478. }
  7479. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7480. {
  7481. u32 val;
  7482. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7483. if (CHIP_IS_E1(bp)) {
  7484. int port = BP_PORT(bp);
  7485. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7486. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7487. val = REG_RD(bp, addr);
  7488. val &= ~(0x300);
  7489. REG_WR(bp, addr, val);
  7490. } else {
  7491. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7492. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7493. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7494. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7495. }
  7496. }
  7497. /* Close gates #2, #3 and #4: */
  7498. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7499. {
  7500. u32 val;
  7501. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7502. if (!CHIP_IS_E1(bp)) {
  7503. /* #4 */
  7504. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7505. /* #2 */
  7506. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7507. }
  7508. /* #3 */
  7509. if (CHIP_IS_E1x(bp)) {
  7510. /* Prevent interrupts from HC on both ports */
  7511. val = REG_RD(bp, HC_REG_CONFIG_1);
  7512. REG_WR(bp, HC_REG_CONFIG_1,
  7513. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7514. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7515. val = REG_RD(bp, HC_REG_CONFIG_0);
  7516. REG_WR(bp, HC_REG_CONFIG_0,
  7517. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7518. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7519. } else {
  7520. /* Prevent incoming interrupts in IGU */
  7521. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7522. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7523. (!close) ?
  7524. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7525. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7526. }
  7527. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7528. close ? "closing" : "opening");
  7529. mmiowb();
  7530. }
  7531. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7532. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7533. {
  7534. /* Do some magic... */
  7535. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7536. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7537. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7538. }
  7539. /**
  7540. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7541. *
  7542. * @bp: driver handle
  7543. * @magic_val: old value of the `magic' bit.
  7544. */
  7545. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7546. {
  7547. /* Restore the `magic' bit value... */
  7548. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7549. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7550. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7551. }
  7552. /**
  7553. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7554. *
  7555. * @bp: driver handle
  7556. * @magic_val: old value of 'magic' bit.
  7557. *
  7558. * Takes care of CLP configurations.
  7559. */
  7560. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7561. {
  7562. u32 shmem;
  7563. u32 validity_offset;
  7564. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7565. /* Set `magic' bit in order to save MF config */
  7566. if (!CHIP_IS_E1(bp))
  7567. bnx2x_clp_reset_prep(bp, magic_val);
  7568. /* Get shmem offset */
  7569. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7570. validity_offset =
  7571. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7572. /* Clear validity map flags */
  7573. if (shmem > 0)
  7574. REG_WR(bp, shmem + validity_offset, 0);
  7575. }
  7576. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7577. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7578. /**
  7579. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7580. *
  7581. * @bp: driver handle
  7582. */
  7583. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7584. {
  7585. /* special handling for emulation and FPGA,
  7586. wait 10 times longer */
  7587. if (CHIP_REV_IS_SLOW(bp))
  7588. msleep(MCP_ONE_TIMEOUT*10);
  7589. else
  7590. msleep(MCP_ONE_TIMEOUT);
  7591. }
  7592. /*
  7593. * initializes bp->common.shmem_base and waits for validity signature to appear
  7594. */
  7595. static int bnx2x_init_shmem(struct bnx2x *bp)
  7596. {
  7597. int cnt = 0;
  7598. u32 val = 0;
  7599. do {
  7600. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7601. if (bp->common.shmem_base) {
  7602. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7603. if (val & SHR_MEM_VALIDITY_MB)
  7604. return 0;
  7605. }
  7606. bnx2x_mcp_wait_one(bp);
  7607. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7608. BNX2X_ERR("BAD MCP validity signature\n");
  7609. return -ENODEV;
  7610. }
  7611. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7612. {
  7613. int rc = bnx2x_init_shmem(bp);
  7614. /* Restore the `magic' bit value */
  7615. if (!CHIP_IS_E1(bp))
  7616. bnx2x_clp_reset_done(bp, magic_val);
  7617. return rc;
  7618. }
  7619. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7620. {
  7621. if (!CHIP_IS_E1(bp)) {
  7622. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7623. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7624. mmiowb();
  7625. }
  7626. }
  7627. /*
  7628. * Reset the whole chip except for:
  7629. * - PCIE core
  7630. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7631. * one reset bit)
  7632. * - IGU
  7633. * - MISC (including AEU)
  7634. * - GRC
  7635. * - RBCN, RBCP
  7636. */
  7637. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7638. {
  7639. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7640. u32 global_bits2, stay_reset2;
  7641. /*
  7642. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7643. * (per chip) blocks.
  7644. */
  7645. global_bits2 =
  7646. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7647. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7648. /* Don't reset the following blocks.
  7649. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7650. * reset, as in 4 port device they might still be owned
  7651. * by the MCP (there is only one leader per path).
  7652. */
  7653. not_reset_mask1 =
  7654. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7655. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7656. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7657. not_reset_mask2 =
  7658. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7659. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7660. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7661. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7662. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7663. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7664. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7665. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7666. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7667. MISC_REGISTERS_RESET_REG_2_PGLC |
  7668. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7669. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7670. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7671. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7672. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7673. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7674. /*
  7675. * Keep the following blocks in reset:
  7676. * - all xxMACs are handled by the bnx2x_link code.
  7677. */
  7678. stay_reset2 =
  7679. MISC_REGISTERS_RESET_REG_2_XMAC |
  7680. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7681. /* Full reset masks according to the chip */
  7682. reset_mask1 = 0xffffffff;
  7683. if (CHIP_IS_E1(bp))
  7684. reset_mask2 = 0xffff;
  7685. else if (CHIP_IS_E1H(bp))
  7686. reset_mask2 = 0x1ffff;
  7687. else if (CHIP_IS_E2(bp))
  7688. reset_mask2 = 0xfffff;
  7689. else /* CHIP_IS_E3 */
  7690. reset_mask2 = 0x3ffffff;
  7691. /* Don't reset global blocks unless we need to */
  7692. if (!global)
  7693. reset_mask2 &= ~global_bits2;
  7694. /*
  7695. * In case of attention in the QM, we need to reset PXP
  7696. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7697. * because otherwise QM reset would release 'close the gates' shortly
  7698. * before resetting the PXP, then the PSWRQ would send a write
  7699. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7700. * read the payload data from PSWWR, but PSWWR would not
  7701. * respond. The write queue in PGLUE would stuck, dmae commands
  7702. * would not return. Therefore it's important to reset the second
  7703. * reset register (containing the
  7704. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7705. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7706. * bit).
  7707. */
  7708. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7709. reset_mask2 & (~not_reset_mask2));
  7710. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7711. reset_mask1 & (~not_reset_mask1));
  7712. barrier();
  7713. mmiowb();
  7714. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7715. reset_mask2 & (~stay_reset2));
  7716. barrier();
  7717. mmiowb();
  7718. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7719. mmiowb();
  7720. }
  7721. /**
  7722. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7723. * It should get cleared in no more than 1s.
  7724. *
  7725. * @bp: driver handle
  7726. *
  7727. * It should get cleared in no more than 1s. Returns 0 if
  7728. * pending writes bit gets cleared.
  7729. */
  7730. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7731. {
  7732. u32 cnt = 1000;
  7733. u32 pend_bits = 0;
  7734. do {
  7735. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7736. if (pend_bits == 0)
  7737. break;
  7738. usleep_range(1000, 2000);
  7739. } while (cnt-- > 0);
  7740. if (cnt <= 0) {
  7741. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7742. pend_bits);
  7743. return -EBUSY;
  7744. }
  7745. return 0;
  7746. }
  7747. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7748. {
  7749. int cnt = 1000;
  7750. u32 val = 0;
  7751. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7752. u32 tags_63_32 = 0;
  7753. /* Empty the Tetris buffer, wait for 1s */
  7754. do {
  7755. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7756. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7757. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7758. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7759. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7760. if (CHIP_IS_E3(bp))
  7761. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7762. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7763. ((port_is_idle_0 & 0x1) == 0x1) &&
  7764. ((port_is_idle_1 & 0x1) == 0x1) &&
  7765. (pgl_exp_rom2 == 0xffffffff) &&
  7766. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7767. break;
  7768. usleep_range(1000, 2000);
  7769. } while (cnt-- > 0);
  7770. if (cnt <= 0) {
  7771. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7772. 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",
  7773. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7774. pgl_exp_rom2);
  7775. return -EAGAIN;
  7776. }
  7777. barrier();
  7778. /* Close gates #2, #3 and #4 */
  7779. bnx2x_set_234_gates(bp, true);
  7780. /* Poll for IGU VQs for 57712 and newer chips */
  7781. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7782. return -EAGAIN;
  7783. /* TBD: Indicate that "process kill" is in progress to MCP */
  7784. /* Clear "unprepared" bit */
  7785. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7786. barrier();
  7787. /* Make sure all is written to the chip before the reset */
  7788. mmiowb();
  7789. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7790. * PSWHST, GRC and PSWRD Tetris buffer.
  7791. */
  7792. usleep_range(1000, 2000);
  7793. /* Prepare to chip reset: */
  7794. /* MCP */
  7795. if (global)
  7796. bnx2x_reset_mcp_prep(bp, &val);
  7797. /* PXP */
  7798. bnx2x_pxp_prep(bp);
  7799. barrier();
  7800. /* reset the chip */
  7801. bnx2x_process_kill_chip_reset(bp, global);
  7802. barrier();
  7803. /* Recover after reset: */
  7804. /* MCP */
  7805. if (global && bnx2x_reset_mcp_comp(bp, val))
  7806. return -EAGAIN;
  7807. /* TBD: Add resetting the NO_MCP mode DB here */
  7808. /* Open the gates #2, #3 and #4 */
  7809. bnx2x_set_234_gates(bp, false);
  7810. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7811. * reset state, re-enable attentions. */
  7812. return 0;
  7813. }
  7814. static int bnx2x_leader_reset(struct bnx2x *bp)
  7815. {
  7816. int rc = 0;
  7817. bool global = bnx2x_reset_is_global(bp);
  7818. u32 load_code;
  7819. /* if not going to reset MCP - load "fake" driver to reset HW while
  7820. * driver is owner of the HW
  7821. */
  7822. if (!global && !BP_NOMCP(bp)) {
  7823. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7824. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7825. if (!load_code) {
  7826. BNX2X_ERR("MCP response failure, aborting\n");
  7827. rc = -EAGAIN;
  7828. goto exit_leader_reset;
  7829. }
  7830. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7831. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7832. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7833. rc = -EAGAIN;
  7834. goto exit_leader_reset2;
  7835. }
  7836. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7837. if (!load_code) {
  7838. BNX2X_ERR("MCP response failure, aborting\n");
  7839. rc = -EAGAIN;
  7840. goto exit_leader_reset2;
  7841. }
  7842. }
  7843. /* Try to recover after the failure */
  7844. if (bnx2x_process_kill(bp, global)) {
  7845. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7846. BP_PATH(bp));
  7847. rc = -EAGAIN;
  7848. goto exit_leader_reset2;
  7849. }
  7850. /*
  7851. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7852. * state.
  7853. */
  7854. bnx2x_set_reset_done(bp);
  7855. if (global)
  7856. bnx2x_clear_reset_global(bp);
  7857. exit_leader_reset2:
  7858. /* unload "fake driver" if it was loaded */
  7859. if (!global && !BP_NOMCP(bp)) {
  7860. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7861. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7862. }
  7863. exit_leader_reset:
  7864. bp->is_leader = 0;
  7865. bnx2x_release_leader_lock(bp);
  7866. smp_mb();
  7867. return rc;
  7868. }
  7869. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7870. {
  7871. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7872. /* Disconnect this device */
  7873. netif_device_detach(bp->dev);
  7874. /*
  7875. * Block ifup for all function on this engine until "process kill"
  7876. * or power cycle.
  7877. */
  7878. bnx2x_set_reset_in_progress(bp);
  7879. /* Shut down the power */
  7880. bnx2x_set_power_state(bp, PCI_D3hot);
  7881. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7882. smp_mb();
  7883. }
  7884. /*
  7885. * Assumption: runs under rtnl lock. This together with the fact
  7886. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7887. * will never be called when netif_running(bp->dev) is false.
  7888. */
  7889. static void bnx2x_parity_recover(struct bnx2x *bp)
  7890. {
  7891. bool global = false;
  7892. u32 error_recovered, error_unrecovered;
  7893. bool is_parity;
  7894. DP(NETIF_MSG_HW, "Handling parity\n");
  7895. while (1) {
  7896. switch (bp->recovery_state) {
  7897. case BNX2X_RECOVERY_INIT:
  7898. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7899. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7900. WARN_ON(!is_parity);
  7901. /* Try to get a LEADER_LOCK HW lock */
  7902. if (bnx2x_trylock_leader_lock(bp)) {
  7903. bnx2x_set_reset_in_progress(bp);
  7904. /*
  7905. * Check if there is a global attention and if
  7906. * there was a global attention, set the global
  7907. * reset bit.
  7908. */
  7909. if (global)
  7910. bnx2x_set_reset_global(bp);
  7911. bp->is_leader = 1;
  7912. }
  7913. /* Stop the driver */
  7914. /* If interface has been removed - break */
  7915. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7916. return;
  7917. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7918. /* Ensure "is_leader", MCP command sequence and
  7919. * "recovery_state" update values are seen on other
  7920. * CPUs.
  7921. */
  7922. smp_mb();
  7923. break;
  7924. case BNX2X_RECOVERY_WAIT:
  7925. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7926. if (bp->is_leader) {
  7927. int other_engine = BP_PATH(bp) ? 0 : 1;
  7928. bool other_load_status =
  7929. bnx2x_get_load_status(bp, other_engine);
  7930. bool load_status =
  7931. bnx2x_get_load_status(bp, BP_PATH(bp));
  7932. global = bnx2x_reset_is_global(bp);
  7933. /*
  7934. * In case of a parity in a global block, let
  7935. * the first leader that performs a
  7936. * leader_reset() reset the global blocks in
  7937. * order to clear global attentions. Otherwise
  7938. * the gates will remain closed for that
  7939. * engine.
  7940. */
  7941. if (load_status ||
  7942. (global && other_load_status)) {
  7943. /* Wait until all other functions get
  7944. * down.
  7945. */
  7946. schedule_delayed_work(&bp->sp_rtnl_task,
  7947. HZ/10);
  7948. return;
  7949. } else {
  7950. /* If all other functions got down -
  7951. * try to bring the chip back to
  7952. * normal. In any case it's an exit
  7953. * point for a leader.
  7954. */
  7955. if (bnx2x_leader_reset(bp)) {
  7956. bnx2x_recovery_failed(bp);
  7957. return;
  7958. }
  7959. /* If we are here, means that the
  7960. * leader has succeeded and doesn't
  7961. * want to be a leader any more. Try
  7962. * to continue as a none-leader.
  7963. */
  7964. break;
  7965. }
  7966. } else { /* non-leader */
  7967. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7968. /* Try to get a LEADER_LOCK HW lock as
  7969. * long as a former leader may have
  7970. * been unloaded by the user or
  7971. * released a leadership by another
  7972. * reason.
  7973. */
  7974. if (bnx2x_trylock_leader_lock(bp)) {
  7975. /* I'm a leader now! Restart a
  7976. * switch case.
  7977. */
  7978. bp->is_leader = 1;
  7979. break;
  7980. }
  7981. schedule_delayed_work(&bp->sp_rtnl_task,
  7982. HZ/10);
  7983. return;
  7984. } else {
  7985. /*
  7986. * If there was a global attention, wait
  7987. * for it to be cleared.
  7988. */
  7989. if (bnx2x_reset_is_global(bp)) {
  7990. schedule_delayed_work(
  7991. &bp->sp_rtnl_task,
  7992. HZ/10);
  7993. return;
  7994. }
  7995. error_recovered =
  7996. bp->eth_stats.recoverable_error;
  7997. error_unrecovered =
  7998. bp->eth_stats.unrecoverable_error;
  7999. bp->recovery_state =
  8000. BNX2X_RECOVERY_NIC_LOADING;
  8001. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8002. error_unrecovered++;
  8003. netdev_err(bp->dev,
  8004. "Recovery failed. Power cycle needed\n");
  8005. /* Disconnect this device */
  8006. netif_device_detach(bp->dev);
  8007. /* Shut down the power */
  8008. bnx2x_set_power_state(
  8009. bp, PCI_D3hot);
  8010. smp_mb();
  8011. } else {
  8012. bp->recovery_state =
  8013. BNX2X_RECOVERY_DONE;
  8014. error_recovered++;
  8015. smp_mb();
  8016. }
  8017. bp->eth_stats.recoverable_error =
  8018. error_recovered;
  8019. bp->eth_stats.unrecoverable_error =
  8020. error_unrecovered;
  8021. return;
  8022. }
  8023. }
  8024. default:
  8025. return;
  8026. }
  8027. }
  8028. }
  8029. static int bnx2x_close(struct net_device *dev);
  8030. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8031. * scheduled on a general queue in order to prevent a dead lock.
  8032. */
  8033. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8034. {
  8035. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8036. rtnl_lock();
  8037. if (!netif_running(bp->dev)) {
  8038. rtnl_unlock();
  8039. return;
  8040. }
  8041. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8042. #ifdef BNX2X_STOP_ON_ERROR
  8043. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8044. "you will need to reboot when done\n");
  8045. goto sp_rtnl_not_reset;
  8046. #endif
  8047. /*
  8048. * Clear all pending SP commands as we are going to reset the
  8049. * function anyway.
  8050. */
  8051. bp->sp_rtnl_state = 0;
  8052. smp_mb();
  8053. bnx2x_parity_recover(bp);
  8054. rtnl_unlock();
  8055. return;
  8056. }
  8057. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8058. #ifdef BNX2X_STOP_ON_ERROR
  8059. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8060. "you will need to reboot when done\n");
  8061. goto sp_rtnl_not_reset;
  8062. #endif
  8063. /*
  8064. * Clear all pending SP commands as we are going to reset the
  8065. * function anyway.
  8066. */
  8067. bp->sp_rtnl_state = 0;
  8068. smp_mb();
  8069. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8070. bnx2x_nic_load(bp, LOAD_NORMAL);
  8071. rtnl_unlock();
  8072. return;
  8073. }
  8074. #ifdef BNX2X_STOP_ON_ERROR
  8075. sp_rtnl_not_reset:
  8076. #endif
  8077. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8078. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8079. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8080. bnx2x_after_function_update(bp);
  8081. /*
  8082. * in case of fan failure we need to reset id if the "stop on error"
  8083. * debug flag is set, since we trying to prevent permanent overheating
  8084. * damage
  8085. */
  8086. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8087. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8088. netif_device_detach(bp->dev);
  8089. bnx2x_close(bp->dev);
  8090. rtnl_unlock();
  8091. return;
  8092. }
  8093. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8094. DP(BNX2X_MSG_SP,
  8095. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8096. bnx2x_vfpf_set_mcast(bp->dev);
  8097. }
  8098. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8099. &bp->sp_rtnl_state)){
  8100. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8101. bnx2x_tx_disable(bp);
  8102. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8103. }
  8104. }
  8105. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  8106. &bp->sp_rtnl_state)) {
  8107. DP(BNX2X_MSG_SP,
  8108. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  8109. bnx2x_vfpf_storm_rx_mode(bp);
  8110. }
  8111. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8112. &bp->sp_rtnl_state))
  8113. bnx2x_pf_set_vfs_vlan(bp);
  8114. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8115. * can be called from other contexts as well)
  8116. */
  8117. rtnl_unlock();
  8118. /* enable SR-IOV if applicable */
  8119. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8120. &bp->sp_rtnl_state)) {
  8121. bnx2x_disable_sriov(bp);
  8122. bnx2x_enable_sriov(bp);
  8123. }
  8124. }
  8125. static void bnx2x_period_task(struct work_struct *work)
  8126. {
  8127. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8128. if (!netif_running(bp->dev))
  8129. goto period_task_exit;
  8130. if (CHIP_REV_IS_SLOW(bp)) {
  8131. BNX2X_ERR("period task called on emulation, ignoring\n");
  8132. goto period_task_exit;
  8133. }
  8134. bnx2x_acquire_phy_lock(bp);
  8135. /*
  8136. * The barrier is needed to ensure the ordering between the writing to
  8137. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8138. * the reading here.
  8139. */
  8140. smp_mb();
  8141. if (bp->port.pmf) {
  8142. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8143. /* Re-queue task in 1 sec */
  8144. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8145. }
  8146. bnx2x_release_phy_lock(bp);
  8147. period_task_exit:
  8148. return;
  8149. }
  8150. /*
  8151. * Init service functions
  8152. */
  8153. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8154. {
  8155. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8156. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8157. return base + (BP_ABS_FUNC(bp)) * stride;
  8158. }
  8159. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8160. struct bnx2x_mac_vals *vals)
  8161. {
  8162. u32 val, base_addr, offset, mask, reset_reg;
  8163. bool mac_stopped = false;
  8164. u8 port = BP_PORT(bp);
  8165. /* reset addresses as they also mark which values were changed */
  8166. vals->bmac_addr = 0;
  8167. vals->umac_addr = 0;
  8168. vals->xmac_addr = 0;
  8169. vals->emac_addr = 0;
  8170. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8171. if (!CHIP_IS_E3(bp)) {
  8172. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8173. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8174. if ((mask & reset_reg) && val) {
  8175. u32 wb_data[2];
  8176. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8177. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8178. : NIG_REG_INGRESS_BMAC0_MEM;
  8179. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8180. : BIGMAC_REGISTER_BMAC_CONTROL;
  8181. /*
  8182. * use rd/wr since we cannot use dmae. This is safe
  8183. * since MCP won't access the bus due to the request
  8184. * to unload, and no function on the path can be
  8185. * loaded at this time.
  8186. */
  8187. wb_data[0] = REG_RD(bp, base_addr + offset);
  8188. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8189. vals->bmac_addr = base_addr + offset;
  8190. vals->bmac_val[0] = wb_data[0];
  8191. vals->bmac_val[1] = wb_data[1];
  8192. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8193. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8194. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8195. }
  8196. BNX2X_DEV_INFO("Disable emac Rx\n");
  8197. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8198. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8199. REG_WR(bp, vals->emac_addr, 0);
  8200. mac_stopped = true;
  8201. } else {
  8202. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8203. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8204. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8205. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8206. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8207. val & ~(1 << 1));
  8208. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8209. val | (1 << 1));
  8210. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8211. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8212. REG_WR(bp, vals->xmac_addr, 0);
  8213. mac_stopped = true;
  8214. }
  8215. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8216. if (mask & reset_reg) {
  8217. BNX2X_DEV_INFO("Disable umac Rx\n");
  8218. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8219. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8220. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8221. REG_WR(bp, vals->umac_addr, 0);
  8222. mac_stopped = true;
  8223. }
  8224. }
  8225. if (mac_stopped)
  8226. msleep(20);
  8227. }
  8228. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8229. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8230. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8231. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8232. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8233. {
  8234. u16 rcq, bd;
  8235. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8236. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8237. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8238. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8239. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8240. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8241. port, bd, rcq);
  8242. }
  8243. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8244. {
  8245. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8246. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8247. if (!rc) {
  8248. BNX2X_ERR("MCP response failure, aborting\n");
  8249. return -EBUSY;
  8250. }
  8251. return 0;
  8252. }
  8253. static struct bnx2x_prev_path_list *
  8254. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8255. {
  8256. struct bnx2x_prev_path_list *tmp_list;
  8257. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8258. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8259. bp->pdev->bus->number == tmp_list->bus &&
  8260. BP_PATH(bp) == tmp_list->path)
  8261. return tmp_list;
  8262. return NULL;
  8263. }
  8264. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8265. {
  8266. struct bnx2x_prev_path_list *tmp_list;
  8267. int rc;
  8268. rc = down_interruptible(&bnx2x_prev_sem);
  8269. if (rc) {
  8270. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8271. return rc;
  8272. }
  8273. tmp_list = bnx2x_prev_path_get_entry(bp);
  8274. if (tmp_list) {
  8275. tmp_list->aer = 1;
  8276. rc = 0;
  8277. } else {
  8278. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8279. BP_PATH(bp));
  8280. }
  8281. up(&bnx2x_prev_sem);
  8282. return rc;
  8283. }
  8284. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8285. {
  8286. struct bnx2x_prev_path_list *tmp_list;
  8287. int rc = false;
  8288. if (down_trylock(&bnx2x_prev_sem))
  8289. return false;
  8290. tmp_list = bnx2x_prev_path_get_entry(bp);
  8291. if (tmp_list) {
  8292. if (tmp_list->aer) {
  8293. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8294. BP_PATH(bp));
  8295. } else {
  8296. rc = true;
  8297. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8298. BP_PATH(bp));
  8299. }
  8300. }
  8301. up(&bnx2x_prev_sem);
  8302. return rc;
  8303. }
  8304. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8305. {
  8306. struct bnx2x_prev_path_list *entry;
  8307. bool val;
  8308. down(&bnx2x_prev_sem);
  8309. entry = bnx2x_prev_path_get_entry(bp);
  8310. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8311. up(&bnx2x_prev_sem);
  8312. return val;
  8313. }
  8314. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8315. {
  8316. struct bnx2x_prev_path_list *tmp_list;
  8317. int rc;
  8318. rc = down_interruptible(&bnx2x_prev_sem);
  8319. if (rc) {
  8320. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8321. return rc;
  8322. }
  8323. /* Check whether the entry for this path already exists */
  8324. tmp_list = bnx2x_prev_path_get_entry(bp);
  8325. if (tmp_list) {
  8326. if (!tmp_list->aer) {
  8327. BNX2X_ERR("Re-Marking the path.\n");
  8328. } else {
  8329. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8330. BP_PATH(bp));
  8331. tmp_list->aer = 0;
  8332. }
  8333. up(&bnx2x_prev_sem);
  8334. return 0;
  8335. }
  8336. up(&bnx2x_prev_sem);
  8337. /* Create an entry for this path and add it */
  8338. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8339. if (!tmp_list) {
  8340. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8341. return -ENOMEM;
  8342. }
  8343. tmp_list->bus = bp->pdev->bus->number;
  8344. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8345. tmp_list->path = BP_PATH(bp);
  8346. tmp_list->aer = 0;
  8347. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8348. rc = down_interruptible(&bnx2x_prev_sem);
  8349. if (rc) {
  8350. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8351. kfree(tmp_list);
  8352. } else {
  8353. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8354. BP_PATH(bp));
  8355. list_add(&tmp_list->list, &bnx2x_prev_list);
  8356. up(&bnx2x_prev_sem);
  8357. }
  8358. return rc;
  8359. }
  8360. static int bnx2x_do_flr(struct bnx2x *bp)
  8361. {
  8362. int i;
  8363. u16 status;
  8364. struct pci_dev *dev = bp->pdev;
  8365. if (CHIP_IS_E1x(bp)) {
  8366. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8367. return -EINVAL;
  8368. }
  8369. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8370. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8371. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8372. bp->common.bc_ver);
  8373. return -EINVAL;
  8374. }
  8375. /* Wait for Transaction Pending bit clean */
  8376. for (i = 0; i < 4; i++) {
  8377. if (i)
  8378. msleep((1 << (i - 1)) * 100);
  8379. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8380. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8381. goto clear;
  8382. }
  8383. dev_err(&dev->dev,
  8384. "transaction is not cleared; proceeding with reset anyway\n");
  8385. clear:
  8386. BNX2X_DEV_INFO("Initiating FLR\n");
  8387. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8388. return 0;
  8389. }
  8390. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8391. {
  8392. int rc;
  8393. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8394. /* Test if previous unload process was already finished for this path */
  8395. if (bnx2x_prev_is_path_marked(bp))
  8396. return bnx2x_prev_mcp_done(bp);
  8397. BNX2X_DEV_INFO("Path is unmarked\n");
  8398. /* If function has FLR capabilities, and existing FW version matches
  8399. * the one required, then FLR will be sufficient to clean any residue
  8400. * left by previous driver
  8401. */
  8402. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8403. if (!rc) {
  8404. /* fw version is good */
  8405. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8406. rc = bnx2x_do_flr(bp);
  8407. }
  8408. if (!rc) {
  8409. /* FLR was performed */
  8410. BNX2X_DEV_INFO("FLR successful\n");
  8411. return 0;
  8412. }
  8413. BNX2X_DEV_INFO("Could not FLR\n");
  8414. /* Close the MCP request, return failure*/
  8415. rc = bnx2x_prev_mcp_done(bp);
  8416. if (!rc)
  8417. rc = BNX2X_PREV_WAIT_NEEDED;
  8418. return rc;
  8419. }
  8420. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8421. {
  8422. u32 reset_reg, tmp_reg = 0, rc;
  8423. bool prev_undi = false;
  8424. struct bnx2x_mac_vals mac_vals;
  8425. /* It is possible a previous function received 'common' answer,
  8426. * but hasn't loaded yet, therefore creating a scenario of
  8427. * multiple functions receiving 'common' on the same path.
  8428. */
  8429. BNX2X_DEV_INFO("Common unload Flow\n");
  8430. memset(&mac_vals, 0, sizeof(mac_vals));
  8431. if (bnx2x_prev_is_path_marked(bp))
  8432. return bnx2x_prev_mcp_done(bp);
  8433. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8434. /* Reset should be performed after BRB is emptied */
  8435. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8436. u32 timer_count = 1000;
  8437. /* Close the MAC Rx to prevent BRB from filling up */
  8438. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8439. /* close LLH filters towards the BRB */
  8440. bnx2x_set_rx_filter(&bp->link_params, 0);
  8441. /* Check if the UNDI driver was previously loaded
  8442. * UNDI driver initializes CID offset for normal bell to 0x7
  8443. */
  8444. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8445. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8446. if (tmp_reg == 0x7) {
  8447. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8448. prev_undi = true;
  8449. /* clear the UNDI indication */
  8450. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8451. /* clear possible idle check errors */
  8452. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8453. }
  8454. }
  8455. if (!CHIP_IS_E1x(bp))
  8456. /* block FW from writing to host */
  8457. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8458. /* wait until BRB is empty */
  8459. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8460. while (timer_count) {
  8461. u32 prev_brb = tmp_reg;
  8462. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8463. if (!tmp_reg)
  8464. break;
  8465. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8466. /* reset timer as long as BRB actually gets emptied */
  8467. if (prev_brb > tmp_reg)
  8468. timer_count = 1000;
  8469. else
  8470. timer_count--;
  8471. /* If UNDI resides in memory, manually increment it */
  8472. if (prev_undi)
  8473. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8474. udelay(10);
  8475. }
  8476. if (!timer_count)
  8477. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8478. }
  8479. /* No packets are in the pipeline, path is ready for reset */
  8480. bnx2x_reset_common(bp);
  8481. if (mac_vals.xmac_addr)
  8482. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8483. if (mac_vals.umac_addr)
  8484. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8485. if (mac_vals.emac_addr)
  8486. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8487. if (mac_vals.bmac_addr) {
  8488. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8489. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8490. }
  8491. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8492. if (rc) {
  8493. bnx2x_prev_mcp_done(bp);
  8494. return rc;
  8495. }
  8496. return bnx2x_prev_mcp_done(bp);
  8497. }
  8498. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8499. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8500. * the addresses of the transaction, resulting in was-error bit set in the pci
  8501. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8502. * to clear the interrupt which detected this from the pglueb and the was done
  8503. * bit
  8504. */
  8505. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8506. {
  8507. if (!CHIP_IS_E1x(bp)) {
  8508. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8509. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8510. DP(BNX2X_MSG_SP,
  8511. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8512. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8513. 1 << BP_FUNC(bp));
  8514. }
  8515. }
  8516. }
  8517. static int bnx2x_prev_unload(struct bnx2x *bp)
  8518. {
  8519. int time_counter = 10;
  8520. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8521. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8522. /* clear hw from errors which may have resulted from an interrupted
  8523. * dmae transaction.
  8524. */
  8525. bnx2x_prev_interrupted_dmae(bp);
  8526. /* Release previously held locks */
  8527. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8528. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8529. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8530. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8531. if (hw_lock_val) {
  8532. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8533. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8534. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8535. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8536. }
  8537. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8538. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8539. } else
  8540. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8541. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8542. BNX2X_DEV_INFO("Release previously held alr\n");
  8543. bnx2x_release_alr(bp);
  8544. }
  8545. do {
  8546. int aer = 0;
  8547. /* Lock MCP using an unload request */
  8548. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8549. if (!fw) {
  8550. BNX2X_ERR("MCP response failure, aborting\n");
  8551. rc = -EBUSY;
  8552. break;
  8553. }
  8554. rc = down_interruptible(&bnx2x_prev_sem);
  8555. if (rc) {
  8556. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8557. rc);
  8558. } else {
  8559. /* If Path is marked by EEH, ignore unload status */
  8560. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8561. bnx2x_prev_path_get_entry(bp)->aer);
  8562. up(&bnx2x_prev_sem);
  8563. }
  8564. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8565. rc = bnx2x_prev_unload_common(bp);
  8566. break;
  8567. }
  8568. /* non-common reply from MCP might require looping */
  8569. rc = bnx2x_prev_unload_uncommon(bp);
  8570. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8571. break;
  8572. msleep(20);
  8573. } while (--time_counter);
  8574. if (!time_counter || rc) {
  8575. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8576. rc = -EBUSY;
  8577. }
  8578. /* Mark function if its port was used to boot from SAN */
  8579. if (bnx2x_port_after_undi(bp))
  8580. bp->link_params.feature_config_flags |=
  8581. FEATURE_CONFIG_BOOT_FROM_SAN;
  8582. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8583. return rc;
  8584. }
  8585. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8586. {
  8587. u32 val, val2, val3, val4, id, boot_mode;
  8588. u16 pmc;
  8589. /* Get the chip revision id and number. */
  8590. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8591. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8592. id = ((val & 0xffff) << 16);
  8593. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8594. id |= ((val & 0xf) << 12);
  8595. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8596. * the configuration space (so we need to reg_rd)
  8597. */
  8598. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8599. id |= (((val >> 24) & 0xf) << 4);
  8600. val = REG_RD(bp, MISC_REG_BOND_ID);
  8601. id |= (val & 0xf);
  8602. bp->common.chip_id = id;
  8603. /* force 57811 according to MISC register */
  8604. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8605. if (CHIP_IS_57810(bp))
  8606. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8607. (bp->common.chip_id & 0x0000FFFF);
  8608. else if (CHIP_IS_57810_MF(bp))
  8609. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8610. (bp->common.chip_id & 0x0000FFFF);
  8611. bp->common.chip_id |= 0x1;
  8612. }
  8613. /* Set doorbell size */
  8614. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8615. if (!CHIP_IS_E1x(bp)) {
  8616. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8617. if ((val & 1) == 0)
  8618. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8619. else
  8620. val = (val >> 1) & 1;
  8621. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8622. "2_PORT_MODE");
  8623. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8624. CHIP_2_PORT_MODE;
  8625. if (CHIP_MODE_IS_4_PORT(bp))
  8626. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8627. else
  8628. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8629. } else {
  8630. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8631. bp->pfid = bp->pf_num; /* 0..7 */
  8632. }
  8633. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8634. bp->link_params.chip_id = bp->common.chip_id;
  8635. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8636. val = (REG_RD(bp, 0x2874) & 0x55);
  8637. if ((bp->common.chip_id & 0x1) ||
  8638. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8639. bp->flags |= ONE_PORT_FLAG;
  8640. BNX2X_DEV_INFO("single port device\n");
  8641. }
  8642. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8643. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8644. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8645. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8646. bp->common.flash_size, bp->common.flash_size);
  8647. bnx2x_init_shmem(bp);
  8648. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8649. MISC_REG_GENERIC_CR_1 :
  8650. MISC_REG_GENERIC_CR_0));
  8651. bp->link_params.shmem_base = bp->common.shmem_base;
  8652. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8653. if (SHMEM2_RD(bp, size) >
  8654. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8655. bp->link_params.lfa_base =
  8656. REG_RD(bp, bp->common.shmem2_base +
  8657. (u32)offsetof(struct shmem2_region,
  8658. lfa_host_addr[BP_PORT(bp)]));
  8659. else
  8660. bp->link_params.lfa_base = 0;
  8661. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8662. bp->common.shmem_base, bp->common.shmem2_base);
  8663. if (!bp->common.shmem_base) {
  8664. BNX2X_DEV_INFO("MCP not active\n");
  8665. bp->flags |= NO_MCP_FLAG;
  8666. return;
  8667. }
  8668. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8669. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8670. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8671. SHARED_HW_CFG_LED_MODE_MASK) >>
  8672. SHARED_HW_CFG_LED_MODE_SHIFT);
  8673. bp->link_params.feature_config_flags = 0;
  8674. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8675. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8676. bp->link_params.feature_config_flags |=
  8677. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8678. else
  8679. bp->link_params.feature_config_flags &=
  8680. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8681. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8682. bp->common.bc_ver = val;
  8683. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8684. if (val < BNX2X_BC_VER) {
  8685. /* for now only warn
  8686. * later we might need to enforce this */
  8687. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8688. BNX2X_BC_VER, val);
  8689. }
  8690. bp->link_params.feature_config_flags |=
  8691. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8692. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8693. bp->link_params.feature_config_flags |=
  8694. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8695. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8696. bp->link_params.feature_config_flags |=
  8697. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8698. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8699. bp->link_params.feature_config_flags |=
  8700. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8701. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8702. bp->link_params.feature_config_flags |=
  8703. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8704. FEATURE_CONFIG_MT_SUPPORT : 0;
  8705. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8706. BC_SUPPORTS_PFC_STATS : 0;
  8707. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8708. BC_SUPPORTS_FCOE_FEATURES : 0;
  8709. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8710. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8711. boot_mode = SHMEM_RD(bp,
  8712. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8713. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8714. switch (boot_mode) {
  8715. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8716. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8717. break;
  8718. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8719. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8720. break;
  8721. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8722. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8723. break;
  8724. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8725. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8726. break;
  8727. }
  8728. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8729. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8730. BNX2X_DEV_INFO("%sWoL capable\n",
  8731. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8732. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8733. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8734. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8735. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8736. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8737. val, val2, val3, val4);
  8738. }
  8739. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8740. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8741. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8742. {
  8743. int pfid = BP_FUNC(bp);
  8744. int igu_sb_id;
  8745. u32 val;
  8746. u8 fid, igu_sb_cnt = 0;
  8747. bp->igu_base_sb = 0xff;
  8748. if (CHIP_INT_MODE_IS_BC(bp)) {
  8749. int vn = BP_VN(bp);
  8750. igu_sb_cnt = bp->igu_sb_cnt;
  8751. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8752. FP_SB_MAX_E1x;
  8753. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8754. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8755. return 0;
  8756. }
  8757. /* IGU in normal mode - read CAM */
  8758. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8759. igu_sb_id++) {
  8760. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8761. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8762. continue;
  8763. fid = IGU_FID(val);
  8764. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8765. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8766. continue;
  8767. if (IGU_VEC(val) == 0)
  8768. /* default status block */
  8769. bp->igu_dsb_id = igu_sb_id;
  8770. else {
  8771. if (bp->igu_base_sb == 0xff)
  8772. bp->igu_base_sb = igu_sb_id;
  8773. igu_sb_cnt++;
  8774. }
  8775. }
  8776. }
  8777. #ifdef CONFIG_PCI_MSI
  8778. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8779. * optional that number of CAM entries will not be equal to the value
  8780. * advertised in PCI.
  8781. * Driver should use the minimal value of both as the actual status
  8782. * block count
  8783. */
  8784. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8785. #endif
  8786. if (igu_sb_cnt == 0) {
  8787. BNX2X_ERR("CAM configuration error\n");
  8788. return -EINVAL;
  8789. }
  8790. return 0;
  8791. }
  8792. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8793. {
  8794. int cfg_size = 0, idx, port = BP_PORT(bp);
  8795. /* Aggregation of supported attributes of all external phys */
  8796. bp->port.supported[0] = 0;
  8797. bp->port.supported[1] = 0;
  8798. switch (bp->link_params.num_phys) {
  8799. case 1:
  8800. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8801. cfg_size = 1;
  8802. break;
  8803. case 2:
  8804. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8805. cfg_size = 1;
  8806. break;
  8807. case 3:
  8808. if (bp->link_params.multi_phy_config &
  8809. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8810. bp->port.supported[1] =
  8811. bp->link_params.phy[EXT_PHY1].supported;
  8812. bp->port.supported[0] =
  8813. bp->link_params.phy[EXT_PHY2].supported;
  8814. } else {
  8815. bp->port.supported[0] =
  8816. bp->link_params.phy[EXT_PHY1].supported;
  8817. bp->port.supported[1] =
  8818. bp->link_params.phy[EXT_PHY2].supported;
  8819. }
  8820. cfg_size = 2;
  8821. break;
  8822. }
  8823. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8824. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8825. SHMEM_RD(bp,
  8826. dev_info.port_hw_config[port].external_phy_config),
  8827. SHMEM_RD(bp,
  8828. dev_info.port_hw_config[port].external_phy_config2));
  8829. return;
  8830. }
  8831. if (CHIP_IS_E3(bp))
  8832. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8833. else {
  8834. switch (switch_cfg) {
  8835. case SWITCH_CFG_1G:
  8836. bp->port.phy_addr = REG_RD(
  8837. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8838. break;
  8839. case SWITCH_CFG_10G:
  8840. bp->port.phy_addr = REG_RD(
  8841. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8842. break;
  8843. default:
  8844. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8845. bp->port.link_config[0]);
  8846. return;
  8847. }
  8848. }
  8849. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8850. /* mask what we support according to speed_cap_mask per configuration */
  8851. for (idx = 0; idx < cfg_size; idx++) {
  8852. if (!(bp->link_params.speed_cap_mask[idx] &
  8853. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8854. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8855. if (!(bp->link_params.speed_cap_mask[idx] &
  8856. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8857. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8858. if (!(bp->link_params.speed_cap_mask[idx] &
  8859. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8860. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8861. if (!(bp->link_params.speed_cap_mask[idx] &
  8862. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8863. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8864. if (!(bp->link_params.speed_cap_mask[idx] &
  8865. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8866. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8867. SUPPORTED_1000baseT_Full);
  8868. if (!(bp->link_params.speed_cap_mask[idx] &
  8869. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8870. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8871. if (!(bp->link_params.speed_cap_mask[idx] &
  8872. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8873. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8874. if (!(bp->link_params.speed_cap_mask[idx] &
  8875. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  8876. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  8877. }
  8878. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8879. bp->port.supported[1]);
  8880. }
  8881. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8882. {
  8883. u32 link_config, idx, cfg_size = 0;
  8884. bp->port.advertising[0] = 0;
  8885. bp->port.advertising[1] = 0;
  8886. switch (bp->link_params.num_phys) {
  8887. case 1:
  8888. case 2:
  8889. cfg_size = 1;
  8890. break;
  8891. case 3:
  8892. cfg_size = 2;
  8893. break;
  8894. }
  8895. for (idx = 0; idx < cfg_size; idx++) {
  8896. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8897. link_config = bp->port.link_config[idx];
  8898. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8899. case PORT_FEATURE_LINK_SPEED_AUTO:
  8900. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8901. bp->link_params.req_line_speed[idx] =
  8902. SPEED_AUTO_NEG;
  8903. bp->port.advertising[idx] |=
  8904. bp->port.supported[idx];
  8905. if (bp->link_params.phy[EXT_PHY1].type ==
  8906. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8907. bp->port.advertising[idx] |=
  8908. (SUPPORTED_100baseT_Half |
  8909. SUPPORTED_100baseT_Full);
  8910. } else {
  8911. /* force 10G, no AN */
  8912. bp->link_params.req_line_speed[idx] =
  8913. SPEED_10000;
  8914. bp->port.advertising[idx] |=
  8915. (ADVERTISED_10000baseT_Full |
  8916. ADVERTISED_FIBRE);
  8917. continue;
  8918. }
  8919. break;
  8920. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8921. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8922. bp->link_params.req_line_speed[idx] =
  8923. SPEED_10;
  8924. bp->port.advertising[idx] |=
  8925. (ADVERTISED_10baseT_Full |
  8926. ADVERTISED_TP);
  8927. } else {
  8928. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8929. link_config,
  8930. bp->link_params.speed_cap_mask[idx]);
  8931. return;
  8932. }
  8933. break;
  8934. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8935. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8936. bp->link_params.req_line_speed[idx] =
  8937. SPEED_10;
  8938. bp->link_params.req_duplex[idx] =
  8939. DUPLEX_HALF;
  8940. bp->port.advertising[idx] |=
  8941. (ADVERTISED_10baseT_Half |
  8942. ADVERTISED_TP);
  8943. } else {
  8944. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8945. link_config,
  8946. bp->link_params.speed_cap_mask[idx]);
  8947. return;
  8948. }
  8949. break;
  8950. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8951. if (bp->port.supported[idx] &
  8952. SUPPORTED_100baseT_Full) {
  8953. bp->link_params.req_line_speed[idx] =
  8954. SPEED_100;
  8955. bp->port.advertising[idx] |=
  8956. (ADVERTISED_100baseT_Full |
  8957. ADVERTISED_TP);
  8958. } else {
  8959. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8960. link_config,
  8961. bp->link_params.speed_cap_mask[idx]);
  8962. return;
  8963. }
  8964. break;
  8965. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8966. if (bp->port.supported[idx] &
  8967. SUPPORTED_100baseT_Half) {
  8968. bp->link_params.req_line_speed[idx] =
  8969. SPEED_100;
  8970. bp->link_params.req_duplex[idx] =
  8971. DUPLEX_HALF;
  8972. bp->port.advertising[idx] |=
  8973. (ADVERTISED_100baseT_Half |
  8974. ADVERTISED_TP);
  8975. } else {
  8976. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8977. link_config,
  8978. bp->link_params.speed_cap_mask[idx]);
  8979. return;
  8980. }
  8981. break;
  8982. case PORT_FEATURE_LINK_SPEED_1G:
  8983. if (bp->port.supported[idx] &
  8984. SUPPORTED_1000baseT_Full) {
  8985. bp->link_params.req_line_speed[idx] =
  8986. SPEED_1000;
  8987. bp->port.advertising[idx] |=
  8988. (ADVERTISED_1000baseT_Full |
  8989. ADVERTISED_TP);
  8990. } else {
  8991. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8992. link_config,
  8993. bp->link_params.speed_cap_mask[idx]);
  8994. return;
  8995. }
  8996. break;
  8997. case PORT_FEATURE_LINK_SPEED_2_5G:
  8998. if (bp->port.supported[idx] &
  8999. SUPPORTED_2500baseX_Full) {
  9000. bp->link_params.req_line_speed[idx] =
  9001. SPEED_2500;
  9002. bp->port.advertising[idx] |=
  9003. (ADVERTISED_2500baseX_Full |
  9004. ADVERTISED_TP);
  9005. } else {
  9006. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9007. link_config,
  9008. bp->link_params.speed_cap_mask[idx]);
  9009. return;
  9010. }
  9011. break;
  9012. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9013. if (bp->port.supported[idx] &
  9014. SUPPORTED_10000baseT_Full) {
  9015. bp->link_params.req_line_speed[idx] =
  9016. SPEED_10000;
  9017. bp->port.advertising[idx] |=
  9018. (ADVERTISED_10000baseT_Full |
  9019. ADVERTISED_FIBRE);
  9020. } else {
  9021. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9022. link_config,
  9023. bp->link_params.speed_cap_mask[idx]);
  9024. return;
  9025. }
  9026. break;
  9027. case PORT_FEATURE_LINK_SPEED_20G:
  9028. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9029. break;
  9030. default:
  9031. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9032. link_config);
  9033. bp->link_params.req_line_speed[idx] =
  9034. SPEED_AUTO_NEG;
  9035. bp->port.advertising[idx] =
  9036. bp->port.supported[idx];
  9037. break;
  9038. }
  9039. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9040. PORT_FEATURE_FLOW_CONTROL_MASK);
  9041. if (bp->link_params.req_flow_ctrl[idx] ==
  9042. BNX2X_FLOW_CTRL_AUTO) {
  9043. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9044. bp->link_params.req_flow_ctrl[idx] =
  9045. BNX2X_FLOW_CTRL_NONE;
  9046. else
  9047. bnx2x_set_requested_fc(bp);
  9048. }
  9049. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9050. bp->link_params.req_line_speed[idx],
  9051. bp->link_params.req_duplex[idx],
  9052. bp->link_params.req_flow_ctrl[idx],
  9053. bp->port.advertising[idx]);
  9054. }
  9055. }
  9056. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9057. {
  9058. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9059. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9060. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9061. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9062. }
  9063. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9064. {
  9065. int port = BP_PORT(bp);
  9066. u32 config;
  9067. u32 ext_phy_type, ext_phy_config, eee_mode;
  9068. bp->link_params.bp = bp;
  9069. bp->link_params.port = port;
  9070. bp->link_params.lane_config =
  9071. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9072. bp->link_params.speed_cap_mask[0] =
  9073. SHMEM_RD(bp,
  9074. dev_info.port_hw_config[port].speed_capability_mask) &
  9075. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9076. bp->link_params.speed_cap_mask[1] =
  9077. SHMEM_RD(bp,
  9078. dev_info.port_hw_config[port].speed_capability_mask2) &
  9079. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9080. bp->port.link_config[0] =
  9081. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9082. bp->port.link_config[1] =
  9083. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9084. bp->link_params.multi_phy_config =
  9085. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9086. /* If the device is capable of WoL, set the default state according
  9087. * to the HW
  9088. */
  9089. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9090. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9091. (config & PORT_FEATURE_WOL_ENABLED));
  9092. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9093. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9094. bp->flags |= NO_ISCSI_FLAG;
  9095. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9096. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9097. bp->flags |= NO_FCOE_FLAG;
  9098. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9099. bp->link_params.lane_config,
  9100. bp->link_params.speed_cap_mask[0],
  9101. bp->port.link_config[0]);
  9102. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9103. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9104. bnx2x_phy_probe(&bp->link_params);
  9105. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9106. bnx2x_link_settings_requested(bp);
  9107. /*
  9108. * If connected directly, work with the internal PHY, otherwise, work
  9109. * with the external PHY
  9110. */
  9111. ext_phy_config =
  9112. SHMEM_RD(bp,
  9113. dev_info.port_hw_config[port].external_phy_config);
  9114. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9115. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9116. bp->mdio.prtad = bp->port.phy_addr;
  9117. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9118. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9119. bp->mdio.prtad =
  9120. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9121. /* Configure link feature according to nvram value */
  9122. eee_mode = (((SHMEM_RD(bp, dev_info.
  9123. port_feature_config[port].eee_power_mode)) &
  9124. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9125. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9126. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9127. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9128. EEE_MODE_ENABLE_LPI |
  9129. EEE_MODE_OUTPUT_TIME;
  9130. } else {
  9131. bp->link_params.eee_mode = 0;
  9132. }
  9133. }
  9134. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9135. {
  9136. u32 no_flags = NO_ISCSI_FLAG;
  9137. int port = BP_PORT(bp);
  9138. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9139. drv_lic_key[port].max_iscsi_conn);
  9140. if (!CNIC_SUPPORT(bp)) {
  9141. bp->flags |= no_flags;
  9142. return;
  9143. }
  9144. /* Get the number of maximum allowed iSCSI connections */
  9145. bp->cnic_eth_dev.max_iscsi_conn =
  9146. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9147. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9148. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9149. bp->cnic_eth_dev.max_iscsi_conn);
  9150. /*
  9151. * If maximum allowed number of connections is zero -
  9152. * disable the feature.
  9153. */
  9154. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9155. bp->flags |= no_flags;
  9156. }
  9157. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9158. {
  9159. /* Port info */
  9160. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9161. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9162. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9163. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9164. /* Node info */
  9165. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9166. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9167. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9168. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9169. }
  9170. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9171. {
  9172. u8 count = 0;
  9173. if (IS_MF(bp)) {
  9174. u8 fid;
  9175. /* iterate over absolute function ids for this path: */
  9176. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9177. if (IS_MF_SD(bp)) {
  9178. u32 cfg = MF_CFG_RD(bp,
  9179. func_mf_config[fid].config);
  9180. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9181. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9182. FUNC_MF_CFG_PROTOCOL_FCOE))
  9183. count++;
  9184. } else {
  9185. u32 cfg = MF_CFG_RD(bp,
  9186. func_ext_config[fid].
  9187. func_cfg);
  9188. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9189. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9190. count++;
  9191. }
  9192. }
  9193. } else { /* SF */
  9194. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9195. for (port = 0; port < port_cnt; port++) {
  9196. u32 lic = SHMEM_RD(bp,
  9197. drv_lic_key[port].max_fcoe_conn) ^
  9198. FW_ENCODE_32BIT_PATTERN;
  9199. if (lic)
  9200. count++;
  9201. }
  9202. }
  9203. return count;
  9204. }
  9205. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9206. {
  9207. int port = BP_PORT(bp);
  9208. int func = BP_ABS_FUNC(bp);
  9209. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9210. drv_lic_key[port].max_fcoe_conn);
  9211. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9212. if (!CNIC_SUPPORT(bp)) {
  9213. bp->flags |= NO_FCOE_FLAG;
  9214. return;
  9215. }
  9216. /* Get the number of maximum allowed FCoE connections */
  9217. bp->cnic_eth_dev.max_fcoe_conn =
  9218. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9219. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9220. /* Calculate the number of maximum allowed FCoE tasks */
  9221. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9222. /* check if FCoE resources must be shared between different functions */
  9223. if (num_fcoe_func)
  9224. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9225. /* Read the WWN: */
  9226. if (!IS_MF(bp)) {
  9227. /* Port info */
  9228. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9229. SHMEM_RD(bp,
  9230. dev_info.port_hw_config[port].
  9231. fcoe_wwn_port_name_upper);
  9232. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9233. SHMEM_RD(bp,
  9234. dev_info.port_hw_config[port].
  9235. fcoe_wwn_port_name_lower);
  9236. /* Node info */
  9237. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9238. SHMEM_RD(bp,
  9239. dev_info.port_hw_config[port].
  9240. fcoe_wwn_node_name_upper);
  9241. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9242. SHMEM_RD(bp,
  9243. dev_info.port_hw_config[port].
  9244. fcoe_wwn_node_name_lower);
  9245. } else if (!IS_MF_SD(bp)) {
  9246. /*
  9247. * Read the WWN info only if the FCoE feature is enabled for
  9248. * this function.
  9249. */
  9250. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9251. bnx2x_get_ext_wwn_info(bp, func);
  9252. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9253. bnx2x_get_ext_wwn_info(bp, func);
  9254. }
  9255. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9256. /*
  9257. * If maximum allowed number of connections is zero -
  9258. * disable the feature.
  9259. */
  9260. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9261. bp->flags |= NO_FCOE_FLAG;
  9262. }
  9263. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9264. {
  9265. /*
  9266. * iSCSI may be dynamically disabled but reading
  9267. * info here we will decrease memory usage by driver
  9268. * if the feature is disabled for good
  9269. */
  9270. bnx2x_get_iscsi_info(bp);
  9271. bnx2x_get_fcoe_info(bp);
  9272. }
  9273. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9274. {
  9275. u32 val, val2;
  9276. int func = BP_ABS_FUNC(bp);
  9277. int port = BP_PORT(bp);
  9278. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9279. u8 *fip_mac = bp->fip_mac;
  9280. if (IS_MF(bp)) {
  9281. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9282. * FCoE MAC then the appropriate feature should be disabled.
  9283. * In non SD mode features configuration comes from struct
  9284. * func_ext_config.
  9285. */
  9286. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9287. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9288. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9289. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9290. iscsi_mac_addr_upper);
  9291. val = MF_CFG_RD(bp, func_ext_config[func].
  9292. iscsi_mac_addr_lower);
  9293. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9294. BNX2X_DEV_INFO
  9295. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9296. } else {
  9297. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9298. }
  9299. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9300. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9301. fcoe_mac_addr_upper);
  9302. val = MF_CFG_RD(bp, func_ext_config[func].
  9303. fcoe_mac_addr_lower);
  9304. bnx2x_set_mac_buf(fip_mac, val, val2);
  9305. BNX2X_DEV_INFO
  9306. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9307. } else {
  9308. bp->flags |= NO_FCOE_FLAG;
  9309. }
  9310. bp->mf_ext_config = cfg;
  9311. } else { /* SD MODE */
  9312. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9313. /* use primary mac as iscsi mac */
  9314. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9315. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9316. BNX2X_DEV_INFO
  9317. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9318. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9319. /* use primary mac as fip mac */
  9320. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9321. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9322. BNX2X_DEV_INFO
  9323. ("Read FIP MAC: %pM\n", fip_mac);
  9324. }
  9325. }
  9326. /* If this is a storage-only interface, use SAN mac as
  9327. * primary MAC. Notice that for SD this is already the case,
  9328. * as the SAN mac was copied from the primary MAC.
  9329. */
  9330. if (IS_MF_FCOE_AFEX(bp))
  9331. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9332. } else {
  9333. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9334. iscsi_mac_upper);
  9335. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9336. iscsi_mac_lower);
  9337. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9338. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9339. fcoe_fip_mac_upper);
  9340. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9341. fcoe_fip_mac_lower);
  9342. bnx2x_set_mac_buf(fip_mac, val, val2);
  9343. }
  9344. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9345. if (!is_valid_ether_addr(iscsi_mac)) {
  9346. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9347. memset(iscsi_mac, 0, ETH_ALEN);
  9348. }
  9349. /* Disable FCoE if MAC configuration is invalid. */
  9350. if (!is_valid_ether_addr(fip_mac)) {
  9351. bp->flags |= NO_FCOE_FLAG;
  9352. memset(bp->fip_mac, 0, ETH_ALEN);
  9353. }
  9354. }
  9355. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9356. {
  9357. u32 val, val2;
  9358. int func = BP_ABS_FUNC(bp);
  9359. int port = BP_PORT(bp);
  9360. /* Zero primary MAC configuration */
  9361. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9362. if (BP_NOMCP(bp)) {
  9363. BNX2X_ERROR("warning: random MAC workaround active\n");
  9364. eth_hw_addr_random(bp->dev);
  9365. } else if (IS_MF(bp)) {
  9366. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9367. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9368. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9369. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9370. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9371. if (CNIC_SUPPORT(bp))
  9372. bnx2x_get_cnic_mac_hwinfo(bp);
  9373. } else {
  9374. /* in SF read MACs from port configuration */
  9375. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9376. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9377. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9378. if (CNIC_SUPPORT(bp))
  9379. bnx2x_get_cnic_mac_hwinfo(bp);
  9380. }
  9381. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9382. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9383. dev_err(&bp->pdev->dev,
  9384. "bad Ethernet MAC address configuration: %pM\n"
  9385. "change it manually before bringing up the appropriate network interface\n",
  9386. bp->dev->dev_addr);
  9387. }
  9388. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9389. {
  9390. int tmp;
  9391. u32 cfg;
  9392. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9393. /* Take function: tmp = func */
  9394. tmp = BP_ABS_FUNC(bp);
  9395. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9396. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9397. } else {
  9398. /* Take port: tmp = port */
  9399. tmp = BP_PORT(bp);
  9400. cfg = SHMEM_RD(bp,
  9401. dev_info.port_hw_config[tmp].generic_features);
  9402. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9403. }
  9404. return cfg;
  9405. }
  9406. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9407. {
  9408. int /*abs*/func = BP_ABS_FUNC(bp);
  9409. int vn;
  9410. u32 val = 0;
  9411. int rc = 0;
  9412. bnx2x_get_common_hwinfo(bp);
  9413. /*
  9414. * initialize IGU parameters
  9415. */
  9416. if (CHIP_IS_E1x(bp)) {
  9417. bp->common.int_block = INT_BLOCK_HC;
  9418. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9419. bp->igu_base_sb = 0;
  9420. } else {
  9421. bp->common.int_block = INT_BLOCK_IGU;
  9422. /* do not allow device reset during IGU info processing */
  9423. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9424. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9425. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9426. int tout = 5000;
  9427. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9428. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9429. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9430. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9431. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9432. tout--;
  9433. usleep_range(1000, 2000);
  9434. }
  9435. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9436. dev_err(&bp->pdev->dev,
  9437. "FORCING Normal Mode failed!!!\n");
  9438. bnx2x_release_hw_lock(bp,
  9439. HW_LOCK_RESOURCE_RESET);
  9440. return -EPERM;
  9441. }
  9442. }
  9443. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9444. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9445. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9446. } else
  9447. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9448. rc = bnx2x_get_igu_cam_info(bp);
  9449. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9450. if (rc)
  9451. return rc;
  9452. }
  9453. /*
  9454. * set base FW non-default (fast path) status block id, this value is
  9455. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9456. * determine the id used by the FW.
  9457. */
  9458. if (CHIP_IS_E1x(bp))
  9459. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9460. else /*
  9461. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9462. * the same queue are indicated on the same IGU SB). So we prefer
  9463. * FW and IGU SBs to be the same value.
  9464. */
  9465. bp->base_fw_ndsb = bp->igu_base_sb;
  9466. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9467. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9468. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9469. /*
  9470. * Initialize MF configuration
  9471. */
  9472. bp->mf_ov = 0;
  9473. bp->mf_mode = 0;
  9474. vn = BP_VN(bp);
  9475. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9476. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9477. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9478. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9479. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9480. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9481. else
  9482. bp->common.mf_cfg_base = bp->common.shmem_base +
  9483. offsetof(struct shmem_region, func_mb) +
  9484. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9485. /*
  9486. * get mf configuration:
  9487. * 1. Existence of MF configuration
  9488. * 2. MAC address must be legal (check only upper bytes)
  9489. * for Switch-Independent mode;
  9490. * OVLAN must be legal for Switch-Dependent mode
  9491. * 3. SF_MODE configures specific MF mode
  9492. */
  9493. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9494. /* get mf configuration */
  9495. val = SHMEM_RD(bp,
  9496. dev_info.shared_feature_config.config);
  9497. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9498. switch (val) {
  9499. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9500. val = MF_CFG_RD(bp, func_mf_config[func].
  9501. mac_upper);
  9502. /* check for legal mac (upper bytes)*/
  9503. if (val != 0xffff) {
  9504. bp->mf_mode = MULTI_FUNCTION_SI;
  9505. bp->mf_config[vn] = MF_CFG_RD(bp,
  9506. func_mf_config[func].config);
  9507. } else
  9508. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9509. break;
  9510. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9511. if ((!CHIP_IS_E1x(bp)) &&
  9512. (MF_CFG_RD(bp, func_mf_config[func].
  9513. mac_upper) != 0xffff) &&
  9514. (SHMEM2_HAS(bp,
  9515. afex_driver_support))) {
  9516. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9517. bp->mf_config[vn] = MF_CFG_RD(bp,
  9518. func_mf_config[func].config);
  9519. } else {
  9520. BNX2X_DEV_INFO("can not configure afex mode\n");
  9521. }
  9522. break;
  9523. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9524. /* get OV configuration */
  9525. val = MF_CFG_RD(bp,
  9526. func_mf_config[FUNC_0].e1hov_tag);
  9527. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9528. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9529. bp->mf_mode = MULTI_FUNCTION_SD;
  9530. bp->mf_config[vn] = MF_CFG_RD(bp,
  9531. func_mf_config[func].config);
  9532. } else
  9533. BNX2X_DEV_INFO("illegal OV for SD\n");
  9534. break;
  9535. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9536. bp->mf_config[vn] = 0;
  9537. break;
  9538. default:
  9539. /* Unknown configuration: reset mf_config */
  9540. bp->mf_config[vn] = 0;
  9541. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9542. }
  9543. }
  9544. BNX2X_DEV_INFO("%s function mode\n",
  9545. IS_MF(bp) ? "multi" : "single");
  9546. switch (bp->mf_mode) {
  9547. case MULTI_FUNCTION_SD:
  9548. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9549. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9550. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9551. bp->mf_ov = val;
  9552. bp->path_has_ovlan = true;
  9553. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9554. func, bp->mf_ov, bp->mf_ov);
  9555. } else {
  9556. dev_err(&bp->pdev->dev,
  9557. "No valid MF OV for func %d, aborting\n",
  9558. func);
  9559. return -EPERM;
  9560. }
  9561. break;
  9562. case MULTI_FUNCTION_AFEX:
  9563. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9564. break;
  9565. case MULTI_FUNCTION_SI:
  9566. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9567. func);
  9568. break;
  9569. default:
  9570. if (vn) {
  9571. dev_err(&bp->pdev->dev,
  9572. "VN %d is in a single function mode, aborting\n",
  9573. vn);
  9574. return -EPERM;
  9575. }
  9576. break;
  9577. }
  9578. /* check if other port on the path needs ovlan:
  9579. * Since MF configuration is shared between ports
  9580. * Possible mixed modes are only
  9581. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9582. */
  9583. if (CHIP_MODE_IS_4_PORT(bp) &&
  9584. !bp->path_has_ovlan &&
  9585. !IS_MF(bp) &&
  9586. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9587. u8 other_port = !BP_PORT(bp);
  9588. u8 other_func = BP_PATH(bp) + 2*other_port;
  9589. val = MF_CFG_RD(bp,
  9590. func_mf_config[other_func].e1hov_tag);
  9591. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9592. bp->path_has_ovlan = true;
  9593. }
  9594. }
  9595. /* adjust igu_sb_cnt to MF for E1x */
  9596. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9597. bp->igu_sb_cnt /= E1HVN_MAX;
  9598. /* port info */
  9599. bnx2x_get_port_hwinfo(bp);
  9600. /* Get MAC addresses */
  9601. bnx2x_get_mac_hwinfo(bp);
  9602. bnx2x_get_cnic_info(bp);
  9603. return rc;
  9604. }
  9605. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9606. {
  9607. int cnt, i, block_end, rodi;
  9608. char vpd_start[BNX2X_VPD_LEN+1];
  9609. char str_id_reg[VENDOR_ID_LEN+1];
  9610. char str_id_cap[VENDOR_ID_LEN+1];
  9611. char *vpd_data;
  9612. char *vpd_extended_data = NULL;
  9613. u8 len;
  9614. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9615. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9616. if (cnt < BNX2X_VPD_LEN)
  9617. goto out_not_found;
  9618. /* VPD RO tag should be first tag after identifier string, hence
  9619. * we should be able to find it in first BNX2X_VPD_LEN chars
  9620. */
  9621. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9622. PCI_VPD_LRDT_RO_DATA);
  9623. if (i < 0)
  9624. goto out_not_found;
  9625. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9626. pci_vpd_lrdt_size(&vpd_start[i]);
  9627. i += PCI_VPD_LRDT_TAG_SIZE;
  9628. if (block_end > BNX2X_VPD_LEN) {
  9629. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9630. if (vpd_extended_data == NULL)
  9631. goto out_not_found;
  9632. /* read rest of vpd image into vpd_extended_data */
  9633. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9634. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9635. block_end - BNX2X_VPD_LEN,
  9636. vpd_extended_data + BNX2X_VPD_LEN);
  9637. if (cnt < (block_end - BNX2X_VPD_LEN))
  9638. goto out_not_found;
  9639. vpd_data = vpd_extended_data;
  9640. } else
  9641. vpd_data = vpd_start;
  9642. /* now vpd_data holds full vpd content in both cases */
  9643. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9644. PCI_VPD_RO_KEYWORD_MFR_ID);
  9645. if (rodi < 0)
  9646. goto out_not_found;
  9647. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9648. if (len != VENDOR_ID_LEN)
  9649. goto out_not_found;
  9650. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9651. /* vendor specific info */
  9652. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9653. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9654. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9655. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9656. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9657. PCI_VPD_RO_KEYWORD_VENDOR0);
  9658. if (rodi >= 0) {
  9659. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9660. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9661. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9662. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9663. bp->fw_ver[len] = ' ';
  9664. }
  9665. }
  9666. kfree(vpd_extended_data);
  9667. return;
  9668. }
  9669. out_not_found:
  9670. kfree(vpd_extended_data);
  9671. return;
  9672. }
  9673. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9674. {
  9675. u32 flags = 0;
  9676. if (CHIP_REV_IS_FPGA(bp))
  9677. SET_FLAGS(flags, MODE_FPGA);
  9678. else if (CHIP_REV_IS_EMUL(bp))
  9679. SET_FLAGS(flags, MODE_EMUL);
  9680. else
  9681. SET_FLAGS(flags, MODE_ASIC);
  9682. if (CHIP_MODE_IS_4_PORT(bp))
  9683. SET_FLAGS(flags, MODE_PORT4);
  9684. else
  9685. SET_FLAGS(flags, MODE_PORT2);
  9686. if (CHIP_IS_E2(bp))
  9687. SET_FLAGS(flags, MODE_E2);
  9688. else if (CHIP_IS_E3(bp)) {
  9689. SET_FLAGS(flags, MODE_E3);
  9690. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9691. SET_FLAGS(flags, MODE_E3_A0);
  9692. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9693. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9694. }
  9695. if (IS_MF(bp)) {
  9696. SET_FLAGS(flags, MODE_MF);
  9697. switch (bp->mf_mode) {
  9698. case MULTI_FUNCTION_SD:
  9699. SET_FLAGS(flags, MODE_MF_SD);
  9700. break;
  9701. case MULTI_FUNCTION_SI:
  9702. SET_FLAGS(flags, MODE_MF_SI);
  9703. break;
  9704. case MULTI_FUNCTION_AFEX:
  9705. SET_FLAGS(flags, MODE_MF_AFEX);
  9706. break;
  9707. }
  9708. } else
  9709. SET_FLAGS(flags, MODE_SF);
  9710. #if defined(__LITTLE_ENDIAN)
  9711. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9712. #else /*(__BIG_ENDIAN)*/
  9713. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9714. #endif
  9715. INIT_MODE_FLAGS(bp) = flags;
  9716. }
  9717. static int bnx2x_init_bp(struct bnx2x *bp)
  9718. {
  9719. int func;
  9720. int rc;
  9721. mutex_init(&bp->port.phy_mutex);
  9722. mutex_init(&bp->fw_mb_mutex);
  9723. spin_lock_init(&bp->stats_lock);
  9724. sema_init(&bp->stats_sema, 1);
  9725. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9726. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9727. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9728. if (IS_PF(bp)) {
  9729. rc = bnx2x_get_hwinfo(bp);
  9730. if (rc)
  9731. return rc;
  9732. } else {
  9733. eth_zero_addr(bp->dev->dev_addr);
  9734. }
  9735. bnx2x_set_modes_bitmap(bp);
  9736. rc = bnx2x_alloc_mem_bp(bp);
  9737. if (rc)
  9738. return rc;
  9739. bnx2x_read_fwinfo(bp);
  9740. func = BP_FUNC(bp);
  9741. /* need to reset chip if undi was active */
  9742. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9743. /* init fw_seq */
  9744. bp->fw_seq =
  9745. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9746. DRV_MSG_SEQ_NUMBER_MASK;
  9747. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9748. bnx2x_prev_unload(bp);
  9749. }
  9750. if (CHIP_REV_IS_FPGA(bp))
  9751. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9752. if (BP_NOMCP(bp) && (func == 0))
  9753. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9754. bp->disable_tpa = disable_tpa;
  9755. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9756. /* Set TPA flags */
  9757. if (bp->disable_tpa) {
  9758. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9759. bp->dev->features &= ~NETIF_F_LRO;
  9760. } else {
  9761. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9762. bp->dev->features |= NETIF_F_LRO;
  9763. }
  9764. if (CHIP_IS_E1(bp))
  9765. bp->dropless_fc = 0;
  9766. else
  9767. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9768. bp->mrrs = mrrs;
  9769. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9770. if (IS_VF(bp))
  9771. bp->rx_ring_size = MAX_RX_AVAIL;
  9772. /* make sure that the numbers are in the right granularity */
  9773. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9774. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9775. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9776. init_timer(&bp->timer);
  9777. bp->timer.expires = jiffies + bp->current_interval;
  9778. bp->timer.data = (unsigned long) bp;
  9779. bp->timer.function = bnx2x_timer;
  9780. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9781. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9782. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9783. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9784. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9785. bnx2x_dcbx_init_params(bp);
  9786. } else {
  9787. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9788. }
  9789. if (CHIP_IS_E1x(bp))
  9790. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9791. else
  9792. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9793. /* multiple tx priority */
  9794. if (IS_VF(bp))
  9795. bp->max_cos = 1;
  9796. else if (CHIP_IS_E1x(bp))
  9797. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9798. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9799. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9800. else if (CHIP_IS_E3B0(bp))
  9801. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9802. else
  9803. BNX2X_ERR("unknown chip %x revision %x\n",
  9804. CHIP_NUM(bp), CHIP_REV(bp));
  9805. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9806. /* We need at least one default status block for slow-path events,
  9807. * second status block for the L2 queue, and a third status block for
  9808. * CNIC if supported.
  9809. */
  9810. if (CNIC_SUPPORT(bp))
  9811. bp->min_msix_vec_cnt = 3;
  9812. else
  9813. bp->min_msix_vec_cnt = 2;
  9814. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9815. bp->dump_preset_idx = 1;
  9816. return rc;
  9817. }
  9818. /****************************************************************************
  9819. * General service functions
  9820. ****************************************************************************/
  9821. /*
  9822. * net_device service functions
  9823. */
  9824. /* called with rtnl_lock */
  9825. static int bnx2x_open(struct net_device *dev)
  9826. {
  9827. struct bnx2x *bp = netdev_priv(dev);
  9828. bool global = false;
  9829. int other_engine = BP_PATH(bp) ? 0 : 1;
  9830. bool other_load_status, load_status;
  9831. int rc;
  9832. bp->stats_init = true;
  9833. netif_carrier_off(dev);
  9834. bnx2x_set_power_state(bp, PCI_D0);
  9835. /* If parity had happen during the unload, then attentions
  9836. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9837. * want the first function loaded on the current engine to
  9838. * complete the recovery.
  9839. * Parity recovery is only relevant for PF driver.
  9840. */
  9841. if (IS_PF(bp)) {
  9842. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9843. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9844. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9845. bnx2x_chk_parity_attn(bp, &global, true)) {
  9846. do {
  9847. /* If there are attentions and they are in a
  9848. * global blocks, set the GLOBAL_RESET bit
  9849. * regardless whether it will be this function
  9850. * that will complete the recovery or not.
  9851. */
  9852. if (global)
  9853. bnx2x_set_reset_global(bp);
  9854. /* Only the first function on the current
  9855. * engine should try to recover in open. In case
  9856. * of attentions in global blocks only the first
  9857. * in the chip should try to recover.
  9858. */
  9859. if ((!load_status &&
  9860. (!global || !other_load_status)) &&
  9861. bnx2x_trylock_leader_lock(bp) &&
  9862. !bnx2x_leader_reset(bp)) {
  9863. netdev_info(bp->dev,
  9864. "Recovered in open\n");
  9865. break;
  9866. }
  9867. /* recovery has failed... */
  9868. bnx2x_set_power_state(bp, PCI_D3hot);
  9869. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9870. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9871. "If you still see this message after a few retries then power cycle is required.\n");
  9872. return -EAGAIN;
  9873. } while (0);
  9874. }
  9875. }
  9876. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9877. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9878. if (rc)
  9879. return rc;
  9880. return bnx2x_open_epilog(bp);
  9881. }
  9882. /* called with rtnl_lock */
  9883. static int bnx2x_close(struct net_device *dev)
  9884. {
  9885. struct bnx2x *bp = netdev_priv(dev);
  9886. /* Unload the driver, release IRQs */
  9887. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9888. return 0;
  9889. }
  9890. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9891. struct bnx2x_mcast_ramrod_params *p)
  9892. {
  9893. int mc_count = netdev_mc_count(bp->dev);
  9894. struct bnx2x_mcast_list_elem *mc_mac =
  9895. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9896. struct netdev_hw_addr *ha;
  9897. if (!mc_mac)
  9898. return -ENOMEM;
  9899. INIT_LIST_HEAD(&p->mcast_list);
  9900. netdev_for_each_mc_addr(ha, bp->dev) {
  9901. mc_mac->mac = bnx2x_mc_addr(ha);
  9902. list_add_tail(&mc_mac->link, &p->mcast_list);
  9903. mc_mac++;
  9904. }
  9905. p->mcast_list_len = mc_count;
  9906. return 0;
  9907. }
  9908. static void bnx2x_free_mcast_macs_list(
  9909. struct bnx2x_mcast_ramrod_params *p)
  9910. {
  9911. struct bnx2x_mcast_list_elem *mc_mac =
  9912. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9913. link);
  9914. WARN_ON(!mc_mac);
  9915. kfree(mc_mac);
  9916. }
  9917. /**
  9918. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9919. *
  9920. * @bp: driver handle
  9921. *
  9922. * We will use zero (0) as a MAC type for these MACs.
  9923. */
  9924. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9925. {
  9926. int rc;
  9927. struct net_device *dev = bp->dev;
  9928. struct netdev_hw_addr *ha;
  9929. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9930. unsigned long ramrod_flags = 0;
  9931. /* First schedule a cleanup up of old configuration */
  9932. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9933. if (rc < 0) {
  9934. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9935. return rc;
  9936. }
  9937. netdev_for_each_uc_addr(ha, dev) {
  9938. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9939. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9940. if (rc == -EEXIST) {
  9941. DP(BNX2X_MSG_SP,
  9942. "Failed to schedule ADD operations: %d\n", rc);
  9943. /* do not treat adding same MAC as error */
  9944. rc = 0;
  9945. } else if (rc < 0) {
  9946. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9947. rc);
  9948. return rc;
  9949. }
  9950. }
  9951. /* Execute the pending commands */
  9952. __set_bit(RAMROD_CONT, &ramrod_flags);
  9953. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9954. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9955. }
  9956. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9957. {
  9958. struct net_device *dev = bp->dev;
  9959. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9960. int rc = 0;
  9961. rparam.mcast_obj = &bp->mcast_obj;
  9962. /* first, clear all configured multicast MACs */
  9963. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9964. if (rc < 0) {
  9965. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9966. return rc;
  9967. }
  9968. /* then, configure a new MACs list */
  9969. if (netdev_mc_count(dev)) {
  9970. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9971. if (rc) {
  9972. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9973. rc);
  9974. return rc;
  9975. }
  9976. /* Now add the new MACs */
  9977. rc = bnx2x_config_mcast(bp, &rparam,
  9978. BNX2X_MCAST_CMD_ADD);
  9979. if (rc < 0)
  9980. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9981. rc);
  9982. bnx2x_free_mcast_macs_list(&rparam);
  9983. }
  9984. return rc;
  9985. }
  9986. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9987. void bnx2x_set_rx_mode(struct net_device *dev)
  9988. {
  9989. struct bnx2x *bp = netdev_priv(dev);
  9990. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9991. if (bp->state != BNX2X_STATE_OPEN) {
  9992. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9993. return;
  9994. }
  9995. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9996. if (dev->flags & IFF_PROMISC)
  9997. rx_mode = BNX2X_RX_MODE_PROMISC;
  9998. else if ((dev->flags & IFF_ALLMULTI) ||
  9999. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  10000. CHIP_IS_E1(bp)))
  10001. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10002. else {
  10003. if (IS_PF(bp)) {
  10004. /* some multicasts */
  10005. if (bnx2x_set_mc_list(bp) < 0)
  10006. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10007. if (bnx2x_set_uc_list(bp) < 0)
  10008. rx_mode = BNX2X_RX_MODE_PROMISC;
  10009. } else {
  10010. /* configuring mcast to a vf involves sleeping (when we
  10011. * wait for the pf's response). Since this function is
  10012. * called from non sleepable context we must schedule
  10013. * a work item for this purpose
  10014. */
  10015. smp_mb__before_clear_bit();
  10016. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  10017. &bp->sp_rtnl_state);
  10018. smp_mb__after_clear_bit();
  10019. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10020. }
  10021. }
  10022. bp->rx_mode = rx_mode;
  10023. /* handle ISCSI SD mode */
  10024. if (IS_MF_ISCSI_SD(bp))
  10025. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10026. /* Schedule the rx_mode command */
  10027. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10028. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10029. return;
  10030. }
  10031. if (IS_PF(bp)) {
  10032. bnx2x_set_storm_rx_mode(bp);
  10033. } else {
  10034. /* configuring rx mode to storms in a vf involves sleeping (when
  10035. * we wait for the pf's response). Since this function is
  10036. * called from non sleepable context we must schedule
  10037. * a work item for this purpose
  10038. */
  10039. smp_mb__before_clear_bit();
  10040. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  10041. &bp->sp_rtnl_state);
  10042. smp_mb__after_clear_bit();
  10043. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10044. }
  10045. }
  10046. /* called with rtnl_lock */
  10047. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10048. int devad, u16 addr)
  10049. {
  10050. struct bnx2x *bp = netdev_priv(netdev);
  10051. u16 value;
  10052. int rc;
  10053. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10054. prtad, devad, addr);
  10055. /* The HW expects different devad if CL22 is used */
  10056. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10057. bnx2x_acquire_phy_lock(bp);
  10058. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10059. bnx2x_release_phy_lock(bp);
  10060. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10061. if (!rc)
  10062. rc = value;
  10063. return rc;
  10064. }
  10065. /* called with rtnl_lock */
  10066. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10067. u16 addr, u16 value)
  10068. {
  10069. struct bnx2x *bp = netdev_priv(netdev);
  10070. int rc;
  10071. DP(NETIF_MSG_LINK,
  10072. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10073. prtad, devad, addr, value);
  10074. /* The HW expects different devad if CL22 is used */
  10075. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10076. bnx2x_acquire_phy_lock(bp);
  10077. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10078. bnx2x_release_phy_lock(bp);
  10079. return rc;
  10080. }
  10081. /* called with rtnl_lock */
  10082. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10083. {
  10084. struct bnx2x *bp = netdev_priv(dev);
  10085. struct mii_ioctl_data *mdio = if_mii(ifr);
  10086. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10087. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10088. if (!netif_running(dev))
  10089. return -EAGAIN;
  10090. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10091. }
  10092. #ifdef CONFIG_NET_POLL_CONTROLLER
  10093. static void poll_bnx2x(struct net_device *dev)
  10094. {
  10095. struct bnx2x *bp = netdev_priv(dev);
  10096. int i;
  10097. for_each_eth_queue(bp, i) {
  10098. struct bnx2x_fastpath *fp = &bp->fp[i];
  10099. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10100. }
  10101. }
  10102. #endif
  10103. static int bnx2x_validate_addr(struct net_device *dev)
  10104. {
  10105. struct bnx2x *bp = netdev_priv(dev);
  10106. /* query the bulletin board for mac address configured by the PF */
  10107. if (IS_VF(bp))
  10108. bnx2x_sample_bulletin(bp);
  10109. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  10110. BNX2X_ERR("Non-valid Ethernet address\n");
  10111. return -EADDRNOTAVAIL;
  10112. }
  10113. return 0;
  10114. }
  10115. static const struct net_device_ops bnx2x_netdev_ops = {
  10116. .ndo_open = bnx2x_open,
  10117. .ndo_stop = bnx2x_close,
  10118. .ndo_start_xmit = bnx2x_start_xmit,
  10119. .ndo_select_queue = bnx2x_select_queue,
  10120. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10121. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10122. .ndo_validate_addr = bnx2x_validate_addr,
  10123. .ndo_do_ioctl = bnx2x_ioctl,
  10124. .ndo_change_mtu = bnx2x_change_mtu,
  10125. .ndo_fix_features = bnx2x_fix_features,
  10126. .ndo_set_features = bnx2x_set_features,
  10127. .ndo_tx_timeout = bnx2x_tx_timeout,
  10128. #ifdef CONFIG_NET_POLL_CONTROLLER
  10129. .ndo_poll_controller = poll_bnx2x,
  10130. #endif
  10131. .ndo_setup_tc = bnx2x_setup_tc,
  10132. #ifdef CONFIG_BNX2X_SRIOV
  10133. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10134. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10135. .ndo_get_vf_config = bnx2x_get_vf_config,
  10136. #endif
  10137. #ifdef NETDEV_FCOE_WWNN
  10138. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10139. #endif
  10140. #ifdef CONFIG_NET_RX_BUSY_POLL
  10141. .ndo_busy_poll = bnx2x_low_latency_recv,
  10142. #endif
  10143. };
  10144. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10145. {
  10146. struct device *dev = &bp->pdev->dev;
  10147. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  10148. bp->flags |= USING_DAC_FLAG;
  10149. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  10150. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  10151. return -EIO;
  10152. }
  10153. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  10154. dev_err(dev, "System does not support DMA, aborting\n");
  10155. return -EIO;
  10156. }
  10157. return 0;
  10158. }
  10159. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10160. struct net_device *dev, unsigned long board_type)
  10161. {
  10162. int rc;
  10163. u32 pci_cfg_dword;
  10164. bool chip_is_e1x = (board_type == BCM57710 ||
  10165. board_type == BCM57711 ||
  10166. board_type == BCM57711E);
  10167. SET_NETDEV_DEV(dev, &pdev->dev);
  10168. bp->dev = dev;
  10169. bp->pdev = pdev;
  10170. rc = pci_enable_device(pdev);
  10171. if (rc) {
  10172. dev_err(&bp->pdev->dev,
  10173. "Cannot enable PCI device, aborting\n");
  10174. goto err_out;
  10175. }
  10176. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10177. dev_err(&bp->pdev->dev,
  10178. "Cannot find PCI device base address, aborting\n");
  10179. rc = -ENODEV;
  10180. goto err_out_disable;
  10181. }
  10182. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10183. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10184. rc = -ENODEV;
  10185. goto err_out_disable;
  10186. }
  10187. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10188. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10189. PCICFG_REVESION_ID_ERROR_VAL) {
  10190. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10191. rc = -ENODEV;
  10192. goto err_out_disable;
  10193. }
  10194. if (atomic_read(&pdev->enable_cnt) == 1) {
  10195. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10196. if (rc) {
  10197. dev_err(&bp->pdev->dev,
  10198. "Cannot obtain PCI resources, aborting\n");
  10199. goto err_out_disable;
  10200. }
  10201. pci_set_master(pdev);
  10202. pci_save_state(pdev);
  10203. }
  10204. if (IS_PF(bp)) {
  10205. bp->pm_cap = pdev->pm_cap;
  10206. if (bp->pm_cap == 0) {
  10207. dev_err(&bp->pdev->dev,
  10208. "Cannot find power management capability, aborting\n");
  10209. rc = -EIO;
  10210. goto err_out_release;
  10211. }
  10212. }
  10213. if (!pci_is_pcie(pdev)) {
  10214. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10215. rc = -EIO;
  10216. goto err_out_release;
  10217. }
  10218. rc = bnx2x_set_coherency_mask(bp);
  10219. if (rc)
  10220. goto err_out_release;
  10221. dev->mem_start = pci_resource_start(pdev, 0);
  10222. dev->base_addr = dev->mem_start;
  10223. dev->mem_end = pci_resource_end(pdev, 0);
  10224. dev->irq = pdev->irq;
  10225. bp->regview = pci_ioremap_bar(pdev, 0);
  10226. if (!bp->regview) {
  10227. dev_err(&bp->pdev->dev,
  10228. "Cannot map register space, aborting\n");
  10229. rc = -ENOMEM;
  10230. goto err_out_release;
  10231. }
  10232. /* In E1/E1H use pci device function given by kernel.
  10233. * In E2/E3 read physical function from ME register since these chips
  10234. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10235. * (depending on hypervisor).
  10236. */
  10237. if (chip_is_e1x) {
  10238. bp->pf_num = PCI_FUNC(pdev->devfn);
  10239. } else {
  10240. /* chip is E2/3*/
  10241. pci_read_config_dword(bp->pdev,
  10242. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10243. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10244. ME_REG_ABS_PF_NUM_SHIFT);
  10245. }
  10246. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10247. /* clean indirect addresses */
  10248. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10249. PCICFG_VENDOR_ID_OFFSET);
  10250. /*
  10251. * Clean the following indirect addresses for all functions since it
  10252. * is not used by the driver.
  10253. */
  10254. if (IS_PF(bp)) {
  10255. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10256. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10257. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10258. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10259. if (chip_is_e1x) {
  10260. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10261. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10262. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10263. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10264. }
  10265. /* Enable internal target-read (in case we are probed after PF
  10266. * FLR). Must be done prior to any BAR read access. Only for
  10267. * 57712 and up
  10268. */
  10269. if (!chip_is_e1x)
  10270. REG_WR(bp,
  10271. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10272. }
  10273. dev->watchdog_timeo = TX_TIMEOUT;
  10274. dev->netdev_ops = &bnx2x_netdev_ops;
  10275. bnx2x_set_ethtool_ops(bp, dev);
  10276. dev->priv_flags |= IFF_UNICAST_FLT;
  10277. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10278. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10279. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10280. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10281. if (!CHIP_IS_E1x(bp)) {
  10282. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10283. dev->hw_enc_features =
  10284. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10285. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10286. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10287. }
  10288. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10289. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10290. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10291. if (bp->flags & USING_DAC_FLAG)
  10292. dev->features |= NETIF_F_HIGHDMA;
  10293. /* Add Loopback capability to the device */
  10294. dev->hw_features |= NETIF_F_LOOPBACK;
  10295. #ifdef BCM_DCBNL
  10296. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10297. #endif
  10298. /* get_port_hwinfo() will set prtad and mmds properly */
  10299. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10300. bp->mdio.mmds = 0;
  10301. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10302. bp->mdio.dev = dev;
  10303. bp->mdio.mdio_read = bnx2x_mdio_read;
  10304. bp->mdio.mdio_write = bnx2x_mdio_write;
  10305. return 0;
  10306. err_out_release:
  10307. if (atomic_read(&pdev->enable_cnt) == 1)
  10308. pci_release_regions(pdev);
  10309. err_out_disable:
  10310. pci_disable_device(pdev);
  10311. pci_set_drvdata(pdev, NULL);
  10312. err_out:
  10313. return rc;
  10314. }
  10315. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width,
  10316. enum bnx2x_pci_bus_speed *speed)
  10317. {
  10318. u32 link_speed, val = 0;
  10319. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10320. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10321. link_speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10322. switch (link_speed) {
  10323. case 3:
  10324. *speed = BNX2X_PCI_LINK_SPEED_8000;
  10325. break;
  10326. case 2:
  10327. *speed = BNX2X_PCI_LINK_SPEED_5000;
  10328. break;
  10329. default:
  10330. *speed = BNX2X_PCI_LINK_SPEED_2500;
  10331. }
  10332. }
  10333. static int bnx2x_check_firmware(struct bnx2x *bp)
  10334. {
  10335. const struct firmware *firmware = bp->firmware;
  10336. struct bnx2x_fw_file_hdr *fw_hdr;
  10337. struct bnx2x_fw_file_section *sections;
  10338. u32 offset, len, num_ops;
  10339. __be16 *ops_offsets;
  10340. int i;
  10341. const u8 *fw_ver;
  10342. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10343. BNX2X_ERR("Wrong FW size\n");
  10344. return -EINVAL;
  10345. }
  10346. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10347. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10348. /* Make sure none of the offsets and sizes make us read beyond
  10349. * the end of the firmware data */
  10350. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10351. offset = be32_to_cpu(sections[i].offset);
  10352. len = be32_to_cpu(sections[i].len);
  10353. if (offset + len > firmware->size) {
  10354. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10355. return -EINVAL;
  10356. }
  10357. }
  10358. /* Likewise for the init_ops offsets */
  10359. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10360. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10361. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10362. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10363. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10364. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10365. return -EINVAL;
  10366. }
  10367. }
  10368. /* Check FW version */
  10369. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10370. fw_ver = firmware->data + offset;
  10371. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10372. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10373. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10374. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10375. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10376. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10377. BCM_5710_FW_MAJOR_VERSION,
  10378. BCM_5710_FW_MINOR_VERSION,
  10379. BCM_5710_FW_REVISION_VERSION,
  10380. BCM_5710_FW_ENGINEERING_VERSION);
  10381. return -EINVAL;
  10382. }
  10383. return 0;
  10384. }
  10385. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10386. {
  10387. const __be32 *source = (const __be32 *)_source;
  10388. u32 *target = (u32 *)_target;
  10389. u32 i;
  10390. for (i = 0; i < n/4; i++)
  10391. target[i] = be32_to_cpu(source[i]);
  10392. }
  10393. /*
  10394. Ops array is stored in the following format:
  10395. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10396. */
  10397. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10398. {
  10399. const __be32 *source = (const __be32 *)_source;
  10400. struct raw_op *target = (struct raw_op *)_target;
  10401. u32 i, j, tmp;
  10402. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10403. tmp = be32_to_cpu(source[j]);
  10404. target[i].op = (tmp >> 24) & 0xff;
  10405. target[i].offset = tmp & 0xffffff;
  10406. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10407. }
  10408. }
  10409. /* IRO array is stored in the following format:
  10410. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10411. */
  10412. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10413. {
  10414. const __be32 *source = (const __be32 *)_source;
  10415. struct iro *target = (struct iro *)_target;
  10416. u32 i, j, tmp;
  10417. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10418. target[i].base = be32_to_cpu(source[j]);
  10419. j++;
  10420. tmp = be32_to_cpu(source[j]);
  10421. target[i].m1 = (tmp >> 16) & 0xffff;
  10422. target[i].m2 = tmp & 0xffff;
  10423. j++;
  10424. tmp = be32_to_cpu(source[j]);
  10425. target[i].m3 = (tmp >> 16) & 0xffff;
  10426. target[i].size = tmp & 0xffff;
  10427. j++;
  10428. }
  10429. }
  10430. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10431. {
  10432. const __be16 *source = (const __be16 *)_source;
  10433. u16 *target = (u16 *)_target;
  10434. u32 i;
  10435. for (i = 0; i < n/2; i++)
  10436. target[i] = be16_to_cpu(source[i]);
  10437. }
  10438. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10439. do { \
  10440. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10441. bp->arr = kmalloc(len, GFP_KERNEL); \
  10442. if (!bp->arr) \
  10443. goto lbl; \
  10444. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10445. (u8 *)bp->arr, len); \
  10446. } while (0)
  10447. static int bnx2x_init_firmware(struct bnx2x *bp)
  10448. {
  10449. const char *fw_file_name;
  10450. struct bnx2x_fw_file_hdr *fw_hdr;
  10451. int rc;
  10452. if (bp->firmware)
  10453. return 0;
  10454. if (CHIP_IS_E1(bp))
  10455. fw_file_name = FW_FILE_NAME_E1;
  10456. else if (CHIP_IS_E1H(bp))
  10457. fw_file_name = FW_FILE_NAME_E1H;
  10458. else if (!CHIP_IS_E1x(bp))
  10459. fw_file_name = FW_FILE_NAME_E2;
  10460. else {
  10461. BNX2X_ERR("Unsupported chip revision\n");
  10462. return -EINVAL;
  10463. }
  10464. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10465. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10466. if (rc) {
  10467. BNX2X_ERR("Can't load firmware file %s\n",
  10468. fw_file_name);
  10469. goto request_firmware_exit;
  10470. }
  10471. rc = bnx2x_check_firmware(bp);
  10472. if (rc) {
  10473. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10474. goto request_firmware_exit;
  10475. }
  10476. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10477. /* Initialize the pointers to the init arrays */
  10478. /* Blob */
  10479. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10480. /* Opcodes */
  10481. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10482. /* Offsets */
  10483. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10484. be16_to_cpu_n);
  10485. /* STORMs firmware */
  10486. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10487. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10488. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10489. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10490. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10491. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10492. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10493. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10494. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10495. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10496. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10497. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10498. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10499. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10500. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10501. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10502. /* IRO */
  10503. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10504. return 0;
  10505. iro_alloc_err:
  10506. kfree(bp->init_ops_offsets);
  10507. init_offsets_alloc_err:
  10508. kfree(bp->init_ops);
  10509. init_ops_alloc_err:
  10510. kfree(bp->init_data);
  10511. request_firmware_exit:
  10512. release_firmware(bp->firmware);
  10513. bp->firmware = NULL;
  10514. return rc;
  10515. }
  10516. static void bnx2x_release_firmware(struct bnx2x *bp)
  10517. {
  10518. kfree(bp->init_ops_offsets);
  10519. kfree(bp->init_ops);
  10520. kfree(bp->init_data);
  10521. release_firmware(bp->firmware);
  10522. bp->firmware = NULL;
  10523. }
  10524. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10525. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10526. .init_hw_cmn = bnx2x_init_hw_common,
  10527. .init_hw_port = bnx2x_init_hw_port,
  10528. .init_hw_func = bnx2x_init_hw_func,
  10529. .reset_hw_cmn = bnx2x_reset_common,
  10530. .reset_hw_port = bnx2x_reset_port,
  10531. .reset_hw_func = bnx2x_reset_func,
  10532. .gunzip_init = bnx2x_gunzip_init,
  10533. .gunzip_end = bnx2x_gunzip_end,
  10534. .init_fw = bnx2x_init_firmware,
  10535. .release_fw = bnx2x_release_firmware,
  10536. };
  10537. void bnx2x__init_func_obj(struct bnx2x *bp)
  10538. {
  10539. /* Prepare DMAE related driver resources */
  10540. bnx2x_setup_dmae(bp);
  10541. bnx2x_init_func_obj(bp, &bp->func_obj,
  10542. bnx2x_sp(bp, func_rdata),
  10543. bnx2x_sp_mapping(bp, func_rdata),
  10544. bnx2x_sp(bp, func_afex_rdata),
  10545. bnx2x_sp_mapping(bp, func_afex_rdata),
  10546. &bnx2x_func_sp_drv);
  10547. }
  10548. /* must be called after sriov-enable */
  10549. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10550. {
  10551. int cid_count = BNX2X_L2_MAX_CID(bp);
  10552. if (IS_SRIOV(bp))
  10553. cid_count += BNX2X_VF_CIDS;
  10554. if (CNIC_SUPPORT(bp))
  10555. cid_count += CNIC_CID_MAX;
  10556. return roundup(cid_count, QM_CID_ROUND);
  10557. }
  10558. /**
  10559. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10560. *
  10561. * @dev: pci device
  10562. *
  10563. */
  10564. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10565. int cnic_cnt, bool is_vf)
  10566. {
  10567. int pos, index;
  10568. u16 control = 0;
  10569. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10570. /*
  10571. * If MSI-X is not supported - return number of SBs needed to support
  10572. * one fast path queue: one FP queue + SB for CNIC
  10573. */
  10574. if (!pos) {
  10575. dev_info(&pdev->dev, "no msix capability found\n");
  10576. return 1 + cnic_cnt;
  10577. }
  10578. dev_info(&pdev->dev, "msix capability found\n");
  10579. /*
  10580. * The value in the PCI configuration space is the index of the last
  10581. * entry, namely one less than the actual size of the table, which is
  10582. * exactly what we want to return from this function: number of all SBs
  10583. * without the default SB.
  10584. * For VFs there is no default SB, then we return (index+1).
  10585. */
  10586. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10587. index = control & PCI_MSIX_FLAGS_QSIZE;
  10588. return is_vf ? index + 1 : index;
  10589. }
  10590. static int set_max_cos_est(int chip_id)
  10591. {
  10592. switch (chip_id) {
  10593. case BCM57710:
  10594. case BCM57711:
  10595. case BCM57711E:
  10596. return BNX2X_MULTI_TX_COS_E1X;
  10597. case BCM57712:
  10598. case BCM57712_MF:
  10599. case BCM57712_VF:
  10600. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10601. case BCM57800:
  10602. case BCM57800_MF:
  10603. case BCM57800_VF:
  10604. case BCM57810:
  10605. case BCM57810_MF:
  10606. case BCM57840_4_10:
  10607. case BCM57840_2_20:
  10608. case BCM57840_O:
  10609. case BCM57840_MFO:
  10610. case BCM57810_VF:
  10611. case BCM57840_MF:
  10612. case BCM57840_VF:
  10613. case BCM57811:
  10614. case BCM57811_MF:
  10615. case BCM57811_VF:
  10616. return BNX2X_MULTI_TX_COS_E3B0;
  10617. return 1;
  10618. default:
  10619. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10620. return -ENODEV;
  10621. }
  10622. }
  10623. static int set_is_vf(int chip_id)
  10624. {
  10625. switch (chip_id) {
  10626. case BCM57712_VF:
  10627. case BCM57800_VF:
  10628. case BCM57810_VF:
  10629. case BCM57840_VF:
  10630. case BCM57811_VF:
  10631. return true;
  10632. default:
  10633. return false;
  10634. }
  10635. }
  10636. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10637. static int bnx2x_init_one(struct pci_dev *pdev,
  10638. const struct pci_device_id *ent)
  10639. {
  10640. struct net_device *dev = NULL;
  10641. struct bnx2x *bp;
  10642. int pcie_width;
  10643. enum bnx2x_pci_bus_speed pcie_speed;
  10644. int rc, max_non_def_sbs;
  10645. int rx_count, tx_count, rss_count, doorbell_size;
  10646. int max_cos_est;
  10647. bool is_vf;
  10648. int cnic_cnt;
  10649. /* An estimated maximum supported CoS number according to the chip
  10650. * version.
  10651. * We will try to roughly estimate the maximum number of CoSes this chip
  10652. * may support in order to minimize the memory allocated for Tx
  10653. * netdev_queue's. This number will be accurately calculated during the
  10654. * initialization of bp->max_cos based on the chip versions AND chip
  10655. * revision in the bnx2x_init_bp().
  10656. */
  10657. max_cos_est = set_max_cos_est(ent->driver_data);
  10658. if (max_cos_est < 0)
  10659. return max_cos_est;
  10660. is_vf = set_is_vf(ent->driver_data);
  10661. cnic_cnt = is_vf ? 0 : 1;
  10662. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10663. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10664. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10665. if (rss_count < 1)
  10666. return -EINVAL;
  10667. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10668. rx_count = rss_count + cnic_cnt;
  10669. /* Maximum number of netdev Tx queues:
  10670. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10671. */
  10672. tx_count = rss_count * max_cos_est + cnic_cnt;
  10673. /* dev zeroed in init_etherdev */
  10674. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10675. if (!dev)
  10676. return -ENOMEM;
  10677. bp = netdev_priv(dev);
  10678. bp->flags = 0;
  10679. if (is_vf)
  10680. bp->flags |= IS_VF_FLAG;
  10681. bp->igu_sb_cnt = max_non_def_sbs;
  10682. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10683. bp->msg_enable = debug;
  10684. bp->cnic_support = cnic_cnt;
  10685. bp->cnic_probe = bnx2x_cnic_probe;
  10686. pci_set_drvdata(pdev, dev);
  10687. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10688. if (rc < 0) {
  10689. free_netdev(dev);
  10690. return rc;
  10691. }
  10692. BNX2X_DEV_INFO("This is a %s function\n",
  10693. IS_PF(bp) ? "physical" : "virtual");
  10694. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10695. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10696. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10697. tx_count, rx_count);
  10698. rc = bnx2x_init_bp(bp);
  10699. if (rc)
  10700. goto init_one_exit;
  10701. /* Map doorbells here as we need the real value of bp->max_cos which
  10702. * is initialized in bnx2x_init_bp() to determine the number of
  10703. * l2 connections.
  10704. */
  10705. if (IS_VF(bp)) {
  10706. bp->doorbells = bnx2x_vf_doorbells(bp);
  10707. rc = bnx2x_vf_pci_alloc(bp);
  10708. if (rc)
  10709. goto init_one_exit;
  10710. } else {
  10711. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10712. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10713. dev_err(&bp->pdev->dev,
  10714. "Cannot map doorbells, bar size too small, aborting\n");
  10715. rc = -ENOMEM;
  10716. goto init_one_exit;
  10717. }
  10718. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10719. doorbell_size);
  10720. }
  10721. if (!bp->doorbells) {
  10722. dev_err(&bp->pdev->dev,
  10723. "Cannot map doorbell space, aborting\n");
  10724. rc = -ENOMEM;
  10725. goto init_one_exit;
  10726. }
  10727. if (IS_VF(bp)) {
  10728. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10729. if (rc)
  10730. goto init_one_exit;
  10731. }
  10732. /* Enable SRIOV if capability found in configuration space */
  10733. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10734. if (rc)
  10735. goto init_one_exit;
  10736. /* calc qm_cid_count */
  10737. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10738. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10739. /* disable FCOE L2 queue for E1x*/
  10740. if (CHIP_IS_E1x(bp))
  10741. bp->flags |= NO_FCOE_FLAG;
  10742. /* Set bp->num_queues for MSI-X mode*/
  10743. bnx2x_set_num_queues(bp);
  10744. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10745. * needed.
  10746. */
  10747. rc = bnx2x_set_int_mode(bp);
  10748. if (rc) {
  10749. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10750. goto init_one_exit;
  10751. }
  10752. BNX2X_DEV_INFO("set interrupts successfully\n");
  10753. /* register the net device */
  10754. rc = register_netdev(dev);
  10755. if (rc) {
  10756. dev_err(&pdev->dev, "Cannot register net device\n");
  10757. goto init_one_exit;
  10758. }
  10759. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10760. if (!NO_FCOE(bp)) {
  10761. /* Add storage MAC address */
  10762. rtnl_lock();
  10763. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10764. rtnl_unlock();
  10765. }
  10766. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10767. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10768. pcie_width, pcie_speed);
  10769. BNX2X_DEV_INFO("%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10770. board_info[ent->driver_data].name,
  10771. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10772. pcie_width,
  10773. pcie_speed == BNX2X_PCI_LINK_SPEED_2500 ? "2.5GHz" :
  10774. pcie_speed == BNX2X_PCI_LINK_SPEED_5000 ? "5.0GHz" :
  10775. pcie_speed == BNX2X_PCI_LINK_SPEED_8000 ? "8.0GHz" :
  10776. "Unknown",
  10777. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10778. return 0;
  10779. init_one_exit:
  10780. if (bp->regview)
  10781. iounmap(bp->regview);
  10782. if (IS_PF(bp) && bp->doorbells)
  10783. iounmap(bp->doorbells);
  10784. free_netdev(dev);
  10785. if (atomic_read(&pdev->enable_cnt) == 1)
  10786. pci_release_regions(pdev);
  10787. pci_disable_device(pdev);
  10788. pci_set_drvdata(pdev, NULL);
  10789. return rc;
  10790. }
  10791. static void __bnx2x_remove(struct pci_dev *pdev,
  10792. struct net_device *dev,
  10793. struct bnx2x *bp,
  10794. bool remove_netdev)
  10795. {
  10796. /* Delete storage MAC address */
  10797. if (!NO_FCOE(bp)) {
  10798. rtnl_lock();
  10799. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10800. rtnl_unlock();
  10801. }
  10802. #ifdef BCM_DCBNL
  10803. /* Delete app tlvs from dcbnl */
  10804. bnx2x_dcbnl_update_applist(bp, true);
  10805. #endif
  10806. /* Close the interface - either directly or implicitly */
  10807. if (remove_netdev) {
  10808. unregister_netdev(dev);
  10809. } else {
  10810. rtnl_lock();
  10811. if (netif_running(dev))
  10812. bnx2x_close(dev);
  10813. rtnl_unlock();
  10814. }
  10815. bnx2x_iov_remove_one(bp);
  10816. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10817. if (IS_PF(bp))
  10818. bnx2x_set_power_state(bp, PCI_D0);
  10819. /* Disable MSI/MSI-X */
  10820. bnx2x_disable_msi(bp);
  10821. /* Power off */
  10822. if (IS_PF(bp))
  10823. bnx2x_set_power_state(bp, PCI_D3hot);
  10824. /* Make sure RESET task is not scheduled before continuing */
  10825. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10826. /* send message via vfpf channel to release the resources of this vf */
  10827. if (IS_VF(bp))
  10828. bnx2x_vfpf_release(bp);
  10829. /* Assumes no further PCIe PM changes will occur */
  10830. if (system_state == SYSTEM_POWER_OFF) {
  10831. pci_wake_from_d3(pdev, bp->wol);
  10832. pci_set_power_state(pdev, PCI_D3hot);
  10833. }
  10834. if (bp->regview)
  10835. iounmap(bp->regview);
  10836. /* for vf doorbells are part of the regview and were unmapped along with
  10837. * it. FW is only loaded by PF.
  10838. */
  10839. if (IS_PF(bp)) {
  10840. if (bp->doorbells)
  10841. iounmap(bp->doorbells);
  10842. bnx2x_release_firmware(bp);
  10843. }
  10844. bnx2x_free_mem_bp(bp);
  10845. if (remove_netdev)
  10846. free_netdev(dev);
  10847. if (atomic_read(&pdev->enable_cnt) == 1)
  10848. pci_release_regions(pdev);
  10849. pci_disable_device(pdev);
  10850. pci_set_drvdata(pdev, NULL);
  10851. }
  10852. static void bnx2x_remove_one(struct pci_dev *pdev)
  10853. {
  10854. struct net_device *dev = pci_get_drvdata(pdev);
  10855. struct bnx2x *bp;
  10856. if (!dev) {
  10857. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10858. return;
  10859. }
  10860. bp = netdev_priv(dev);
  10861. __bnx2x_remove(pdev, dev, bp, true);
  10862. }
  10863. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10864. {
  10865. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  10866. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10867. if (CNIC_LOADED(bp))
  10868. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10869. /* Stop Tx */
  10870. bnx2x_tx_disable(bp);
  10871. /* Delete all NAPI objects */
  10872. bnx2x_del_all_napi(bp);
  10873. if (CNIC_LOADED(bp))
  10874. bnx2x_del_all_napi_cnic(bp);
  10875. netdev_reset_tc(bp->dev);
  10876. del_timer_sync(&bp->timer);
  10877. cancel_delayed_work(&bp->sp_task);
  10878. cancel_delayed_work(&bp->period_task);
  10879. spin_lock_bh(&bp->stats_lock);
  10880. bp->stats_state = STATS_STATE_DISABLED;
  10881. spin_unlock_bh(&bp->stats_lock);
  10882. bnx2x_save_statistics(bp);
  10883. netif_carrier_off(bp->dev);
  10884. return 0;
  10885. }
  10886. /**
  10887. * bnx2x_io_error_detected - called when PCI error is detected
  10888. * @pdev: Pointer to PCI device
  10889. * @state: The current pci connection state
  10890. *
  10891. * This function is called after a PCI bus error affecting
  10892. * this device has been detected.
  10893. */
  10894. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10895. pci_channel_state_t state)
  10896. {
  10897. struct net_device *dev = pci_get_drvdata(pdev);
  10898. struct bnx2x *bp = netdev_priv(dev);
  10899. rtnl_lock();
  10900. BNX2X_ERR("IO error detected\n");
  10901. netif_device_detach(dev);
  10902. if (state == pci_channel_io_perm_failure) {
  10903. rtnl_unlock();
  10904. return PCI_ERS_RESULT_DISCONNECT;
  10905. }
  10906. if (netif_running(dev))
  10907. bnx2x_eeh_nic_unload(bp);
  10908. bnx2x_prev_path_mark_eeh(bp);
  10909. pci_disable_device(pdev);
  10910. rtnl_unlock();
  10911. /* Request a slot reset */
  10912. return PCI_ERS_RESULT_NEED_RESET;
  10913. }
  10914. /**
  10915. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10916. * @pdev: Pointer to PCI device
  10917. *
  10918. * Restart the card from scratch, as if from a cold-boot.
  10919. */
  10920. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10921. {
  10922. struct net_device *dev = pci_get_drvdata(pdev);
  10923. struct bnx2x *bp = netdev_priv(dev);
  10924. int i;
  10925. rtnl_lock();
  10926. BNX2X_ERR("IO slot reset initializing...\n");
  10927. if (pci_enable_device(pdev)) {
  10928. dev_err(&pdev->dev,
  10929. "Cannot re-enable PCI device after reset\n");
  10930. rtnl_unlock();
  10931. return PCI_ERS_RESULT_DISCONNECT;
  10932. }
  10933. pci_set_master(pdev);
  10934. pci_restore_state(pdev);
  10935. pci_save_state(pdev);
  10936. if (netif_running(dev))
  10937. bnx2x_set_power_state(bp, PCI_D0);
  10938. if (netif_running(dev)) {
  10939. BNX2X_ERR("IO slot reset --> driver unload\n");
  10940. /* MCP should have been reset; Need to wait for validity */
  10941. bnx2x_init_shmem(bp);
  10942. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  10943. u32 v;
  10944. v = SHMEM2_RD(bp,
  10945. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  10946. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  10947. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  10948. }
  10949. bnx2x_drain_tx_queues(bp);
  10950. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  10951. bnx2x_netif_stop(bp, 1);
  10952. bnx2x_free_irq(bp);
  10953. /* Report UNLOAD_DONE to MCP */
  10954. bnx2x_send_unload_done(bp, true);
  10955. bp->sp_state = 0;
  10956. bp->port.pmf = 0;
  10957. bnx2x_prev_unload(bp);
  10958. /* We should have reseted the engine, so It's fair to
  10959. * assume the FW will no longer write to the bnx2x driver.
  10960. */
  10961. bnx2x_squeeze_objects(bp);
  10962. bnx2x_free_skbs(bp);
  10963. for_each_rx_queue(bp, i)
  10964. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10965. bnx2x_free_fp_mem(bp);
  10966. bnx2x_free_mem(bp);
  10967. bp->state = BNX2X_STATE_CLOSED;
  10968. }
  10969. rtnl_unlock();
  10970. return PCI_ERS_RESULT_RECOVERED;
  10971. }
  10972. /**
  10973. * bnx2x_io_resume - called when traffic can start flowing again
  10974. * @pdev: Pointer to PCI device
  10975. *
  10976. * This callback is called when the error recovery driver tells us that
  10977. * its OK to resume normal operation.
  10978. */
  10979. static void bnx2x_io_resume(struct pci_dev *pdev)
  10980. {
  10981. struct net_device *dev = pci_get_drvdata(pdev);
  10982. struct bnx2x *bp = netdev_priv(dev);
  10983. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10984. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10985. return;
  10986. }
  10987. rtnl_lock();
  10988. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10989. DRV_MSG_SEQ_NUMBER_MASK;
  10990. if (netif_running(dev))
  10991. bnx2x_nic_load(bp, LOAD_NORMAL);
  10992. netif_device_attach(dev);
  10993. rtnl_unlock();
  10994. }
  10995. static const struct pci_error_handlers bnx2x_err_handler = {
  10996. .error_detected = bnx2x_io_error_detected,
  10997. .slot_reset = bnx2x_io_slot_reset,
  10998. .resume = bnx2x_io_resume,
  10999. };
  11000. static void bnx2x_shutdown(struct pci_dev *pdev)
  11001. {
  11002. struct net_device *dev = pci_get_drvdata(pdev);
  11003. struct bnx2x *bp;
  11004. if (!dev)
  11005. return;
  11006. bp = netdev_priv(dev);
  11007. if (!bp)
  11008. return;
  11009. rtnl_lock();
  11010. netif_device_detach(dev);
  11011. rtnl_unlock();
  11012. /* Don't remove the netdevice, as there are scenarios which will cause
  11013. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11014. * rootfs is mounted from SAN.
  11015. */
  11016. __bnx2x_remove(pdev, dev, bp, false);
  11017. }
  11018. static struct pci_driver bnx2x_pci_driver = {
  11019. .name = DRV_MODULE_NAME,
  11020. .id_table = bnx2x_pci_tbl,
  11021. .probe = bnx2x_init_one,
  11022. .remove = bnx2x_remove_one,
  11023. .suspend = bnx2x_suspend,
  11024. .resume = bnx2x_resume,
  11025. .err_handler = &bnx2x_err_handler,
  11026. #ifdef CONFIG_BNX2X_SRIOV
  11027. .sriov_configure = bnx2x_sriov_configure,
  11028. #endif
  11029. .shutdown = bnx2x_shutdown,
  11030. };
  11031. static int __init bnx2x_init(void)
  11032. {
  11033. int ret;
  11034. pr_info("%s", version);
  11035. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11036. if (bnx2x_wq == NULL) {
  11037. pr_err("Cannot create workqueue\n");
  11038. return -ENOMEM;
  11039. }
  11040. ret = pci_register_driver(&bnx2x_pci_driver);
  11041. if (ret) {
  11042. pr_err("Cannot register driver\n");
  11043. destroy_workqueue(bnx2x_wq);
  11044. }
  11045. return ret;
  11046. }
  11047. static void __exit bnx2x_cleanup(void)
  11048. {
  11049. struct list_head *pos, *q;
  11050. pci_unregister_driver(&bnx2x_pci_driver);
  11051. destroy_workqueue(bnx2x_wq);
  11052. /* Free globally allocated resources */
  11053. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11054. struct bnx2x_prev_path_list *tmp =
  11055. list_entry(pos, struct bnx2x_prev_path_list, list);
  11056. list_del(pos);
  11057. kfree(tmp);
  11058. }
  11059. }
  11060. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11061. {
  11062. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11063. }
  11064. module_init(bnx2x_init);
  11065. module_exit(bnx2x_cleanup);
  11066. /**
  11067. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11068. *
  11069. * @bp: driver handle
  11070. * @set: set or clear the CAM entry
  11071. *
  11072. * This function will wait until the ramrod completion returns.
  11073. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11074. */
  11075. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11076. {
  11077. unsigned long ramrod_flags = 0;
  11078. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11079. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11080. &bp->iscsi_l2_mac_obj, true,
  11081. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11082. }
  11083. /* count denotes the number of new completions we have seen */
  11084. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11085. {
  11086. struct eth_spe *spe;
  11087. int cxt_index, cxt_offset;
  11088. #ifdef BNX2X_STOP_ON_ERROR
  11089. if (unlikely(bp->panic))
  11090. return;
  11091. #endif
  11092. spin_lock_bh(&bp->spq_lock);
  11093. BUG_ON(bp->cnic_spq_pending < count);
  11094. bp->cnic_spq_pending -= count;
  11095. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11096. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11097. & SPE_HDR_CONN_TYPE) >>
  11098. SPE_HDR_CONN_TYPE_SHIFT;
  11099. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11100. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11101. /* Set validation for iSCSI L2 client before sending SETUP
  11102. * ramrod
  11103. */
  11104. if (type == ETH_CONNECTION_TYPE) {
  11105. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11106. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11107. ILT_PAGE_CIDS;
  11108. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11109. (cxt_index * ILT_PAGE_CIDS);
  11110. bnx2x_set_ctx_validation(bp,
  11111. &bp->context[cxt_index].
  11112. vcxt[cxt_offset].eth,
  11113. BNX2X_ISCSI_ETH_CID(bp));
  11114. }
  11115. }
  11116. /*
  11117. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11118. * and in the air. We also check that number of outstanding
  11119. * COMMON ramrods is not more than the EQ and SPQ can
  11120. * accommodate.
  11121. */
  11122. if (type == ETH_CONNECTION_TYPE) {
  11123. if (!atomic_read(&bp->cq_spq_left))
  11124. break;
  11125. else
  11126. atomic_dec(&bp->cq_spq_left);
  11127. } else if (type == NONE_CONNECTION_TYPE) {
  11128. if (!atomic_read(&bp->eq_spq_left))
  11129. break;
  11130. else
  11131. atomic_dec(&bp->eq_spq_left);
  11132. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11133. (type == FCOE_CONNECTION_TYPE)) {
  11134. if (bp->cnic_spq_pending >=
  11135. bp->cnic_eth_dev.max_kwqe_pending)
  11136. break;
  11137. else
  11138. bp->cnic_spq_pending++;
  11139. } else {
  11140. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11141. bnx2x_panic();
  11142. break;
  11143. }
  11144. spe = bnx2x_sp_get_next(bp);
  11145. *spe = *bp->cnic_kwq_cons;
  11146. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11147. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11148. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11149. bp->cnic_kwq_cons = bp->cnic_kwq;
  11150. else
  11151. bp->cnic_kwq_cons++;
  11152. }
  11153. bnx2x_sp_prod_update(bp);
  11154. spin_unlock_bh(&bp->spq_lock);
  11155. }
  11156. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11157. struct kwqe_16 *kwqes[], u32 count)
  11158. {
  11159. struct bnx2x *bp = netdev_priv(dev);
  11160. int i;
  11161. #ifdef BNX2X_STOP_ON_ERROR
  11162. if (unlikely(bp->panic)) {
  11163. BNX2X_ERR("Can't post to SP queue while panic\n");
  11164. return -EIO;
  11165. }
  11166. #endif
  11167. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11168. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11169. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11170. return -EAGAIN;
  11171. }
  11172. spin_lock_bh(&bp->spq_lock);
  11173. for (i = 0; i < count; i++) {
  11174. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11175. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11176. break;
  11177. *bp->cnic_kwq_prod = *spe;
  11178. bp->cnic_kwq_pending++;
  11179. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11180. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11181. spe->data.update_data_addr.hi,
  11182. spe->data.update_data_addr.lo,
  11183. bp->cnic_kwq_pending);
  11184. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11185. bp->cnic_kwq_prod = bp->cnic_kwq;
  11186. else
  11187. bp->cnic_kwq_prod++;
  11188. }
  11189. spin_unlock_bh(&bp->spq_lock);
  11190. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11191. bnx2x_cnic_sp_post(bp, 0);
  11192. return i;
  11193. }
  11194. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11195. {
  11196. struct cnic_ops *c_ops;
  11197. int rc = 0;
  11198. mutex_lock(&bp->cnic_mutex);
  11199. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11200. lockdep_is_held(&bp->cnic_mutex));
  11201. if (c_ops)
  11202. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11203. mutex_unlock(&bp->cnic_mutex);
  11204. return rc;
  11205. }
  11206. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11207. {
  11208. struct cnic_ops *c_ops;
  11209. int rc = 0;
  11210. rcu_read_lock();
  11211. c_ops = rcu_dereference(bp->cnic_ops);
  11212. if (c_ops)
  11213. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11214. rcu_read_unlock();
  11215. return rc;
  11216. }
  11217. /*
  11218. * for commands that have no data
  11219. */
  11220. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11221. {
  11222. struct cnic_ctl_info ctl = {0};
  11223. ctl.cmd = cmd;
  11224. return bnx2x_cnic_ctl_send(bp, &ctl);
  11225. }
  11226. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11227. {
  11228. struct cnic_ctl_info ctl = {0};
  11229. /* first we tell CNIC and only then we count this as a completion */
  11230. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11231. ctl.data.comp.cid = cid;
  11232. ctl.data.comp.error = err;
  11233. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11234. bnx2x_cnic_sp_post(bp, 0);
  11235. }
  11236. /* Called with netif_addr_lock_bh() taken.
  11237. * Sets an rx_mode config for an iSCSI ETH client.
  11238. * Doesn't block.
  11239. * Completion should be checked outside.
  11240. */
  11241. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11242. {
  11243. unsigned long accept_flags = 0, ramrod_flags = 0;
  11244. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11245. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11246. if (start) {
  11247. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11248. * because it's the only way for UIO Queue to accept
  11249. * multicasts (in non-promiscuous mode only one Queue per
  11250. * function will receive multicast packets (leading in our
  11251. * case).
  11252. */
  11253. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11254. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11255. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11256. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11257. /* Clear STOP_PENDING bit if START is requested */
  11258. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11259. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11260. } else
  11261. /* Clear START_PENDING bit if STOP is requested */
  11262. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11263. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11264. set_bit(sched_state, &bp->sp_state);
  11265. else {
  11266. __set_bit(RAMROD_RX, &ramrod_flags);
  11267. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11268. ramrod_flags);
  11269. }
  11270. }
  11271. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11272. {
  11273. struct bnx2x *bp = netdev_priv(dev);
  11274. int rc = 0;
  11275. switch (ctl->cmd) {
  11276. case DRV_CTL_CTXTBL_WR_CMD: {
  11277. u32 index = ctl->data.io.offset;
  11278. dma_addr_t addr = ctl->data.io.dma_addr;
  11279. bnx2x_ilt_wr(bp, index, addr);
  11280. break;
  11281. }
  11282. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11283. int count = ctl->data.credit.credit_count;
  11284. bnx2x_cnic_sp_post(bp, count);
  11285. break;
  11286. }
  11287. /* rtnl_lock is held. */
  11288. case DRV_CTL_START_L2_CMD: {
  11289. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11290. unsigned long sp_bits = 0;
  11291. /* Configure the iSCSI classification object */
  11292. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11293. cp->iscsi_l2_client_id,
  11294. cp->iscsi_l2_cid, BP_FUNC(bp),
  11295. bnx2x_sp(bp, mac_rdata),
  11296. bnx2x_sp_mapping(bp, mac_rdata),
  11297. BNX2X_FILTER_MAC_PENDING,
  11298. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11299. &bp->macs_pool);
  11300. /* Set iSCSI MAC address */
  11301. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11302. if (rc)
  11303. break;
  11304. mmiowb();
  11305. barrier();
  11306. /* Start accepting on iSCSI L2 ring */
  11307. netif_addr_lock_bh(dev);
  11308. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11309. netif_addr_unlock_bh(dev);
  11310. /* bits to wait on */
  11311. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11312. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11313. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11314. BNX2X_ERR("rx_mode completion timed out!\n");
  11315. break;
  11316. }
  11317. /* rtnl_lock is held. */
  11318. case DRV_CTL_STOP_L2_CMD: {
  11319. unsigned long sp_bits = 0;
  11320. /* Stop accepting on iSCSI L2 ring */
  11321. netif_addr_lock_bh(dev);
  11322. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11323. netif_addr_unlock_bh(dev);
  11324. /* bits to wait on */
  11325. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11326. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11327. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11328. BNX2X_ERR("rx_mode completion timed out!\n");
  11329. mmiowb();
  11330. barrier();
  11331. /* Unset iSCSI L2 MAC */
  11332. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11333. BNX2X_ISCSI_ETH_MAC, true);
  11334. break;
  11335. }
  11336. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11337. int count = ctl->data.credit.credit_count;
  11338. smp_mb__before_atomic_inc();
  11339. atomic_add(count, &bp->cq_spq_left);
  11340. smp_mb__after_atomic_inc();
  11341. break;
  11342. }
  11343. case DRV_CTL_ULP_REGISTER_CMD: {
  11344. int ulp_type = ctl->data.register_data.ulp_type;
  11345. if (CHIP_IS_E3(bp)) {
  11346. int idx = BP_FW_MB_IDX(bp);
  11347. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11348. int path = BP_PATH(bp);
  11349. int port = BP_PORT(bp);
  11350. int i;
  11351. u32 scratch_offset;
  11352. u32 *host_addr;
  11353. /* first write capability to shmem2 */
  11354. if (ulp_type == CNIC_ULP_ISCSI)
  11355. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11356. else if (ulp_type == CNIC_ULP_FCOE)
  11357. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11358. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11359. if ((ulp_type != CNIC_ULP_FCOE) ||
  11360. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11361. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11362. break;
  11363. /* if reached here - should write fcoe capabilities */
  11364. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11365. if (!scratch_offset)
  11366. break;
  11367. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11368. fcoe_features[path][port]);
  11369. host_addr = (u32 *) &(ctl->data.register_data.
  11370. fcoe_features);
  11371. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11372. i += 4)
  11373. REG_WR(bp, scratch_offset + i,
  11374. *(host_addr + i/4));
  11375. }
  11376. break;
  11377. }
  11378. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11379. int ulp_type = ctl->data.ulp_type;
  11380. if (CHIP_IS_E3(bp)) {
  11381. int idx = BP_FW_MB_IDX(bp);
  11382. u32 cap;
  11383. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11384. if (ulp_type == CNIC_ULP_ISCSI)
  11385. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11386. else if (ulp_type == CNIC_ULP_FCOE)
  11387. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11388. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11389. }
  11390. break;
  11391. }
  11392. default:
  11393. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11394. rc = -EINVAL;
  11395. }
  11396. return rc;
  11397. }
  11398. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11399. {
  11400. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11401. if (bp->flags & USING_MSIX_FLAG) {
  11402. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11403. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11404. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11405. } else {
  11406. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11407. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11408. }
  11409. if (!CHIP_IS_E1x(bp))
  11410. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11411. else
  11412. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11413. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11414. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11415. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11416. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11417. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11418. cp->num_irq = 2;
  11419. }
  11420. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11421. {
  11422. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11423. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11424. bnx2x_cid_ilt_lines(bp);
  11425. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11426. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11427. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11428. if (NO_ISCSI_OOO(bp))
  11429. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11430. }
  11431. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11432. void *data)
  11433. {
  11434. struct bnx2x *bp = netdev_priv(dev);
  11435. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11436. int rc;
  11437. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11438. if (ops == NULL) {
  11439. BNX2X_ERR("NULL ops received\n");
  11440. return -EINVAL;
  11441. }
  11442. if (!CNIC_SUPPORT(bp)) {
  11443. BNX2X_ERR("Can't register CNIC when not supported\n");
  11444. return -EOPNOTSUPP;
  11445. }
  11446. if (!CNIC_LOADED(bp)) {
  11447. rc = bnx2x_load_cnic(bp);
  11448. if (rc) {
  11449. BNX2X_ERR("CNIC-related load failed\n");
  11450. return rc;
  11451. }
  11452. }
  11453. bp->cnic_enabled = true;
  11454. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11455. if (!bp->cnic_kwq)
  11456. return -ENOMEM;
  11457. bp->cnic_kwq_cons = bp->cnic_kwq;
  11458. bp->cnic_kwq_prod = bp->cnic_kwq;
  11459. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11460. bp->cnic_spq_pending = 0;
  11461. bp->cnic_kwq_pending = 0;
  11462. bp->cnic_data = data;
  11463. cp->num_irq = 0;
  11464. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11465. cp->iro_arr = bp->iro_arr;
  11466. bnx2x_setup_cnic_irq_info(bp);
  11467. rcu_assign_pointer(bp->cnic_ops, ops);
  11468. return 0;
  11469. }
  11470. static int bnx2x_unregister_cnic(struct net_device *dev)
  11471. {
  11472. struct bnx2x *bp = netdev_priv(dev);
  11473. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11474. mutex_lock(&bp->cnic_mutex);
  11475. cp->drv_state = 0;
  11476. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11477. mutex_unlock(&bp->cnic_mutex);
  11478. synchronize_rcu();
  11479. bp->cnic_enabled = false;
  11480. kfree(bp->cnic_kwq);
  11481. bp->cnic_kwq = NULL;
  11482. return 0;
  11483. }
  11484. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11485. {
  11486. struct bnx2x *bp = netdev_priv(dev);
  11487. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11488. /* If both iSCSI and FCoE are disabled - return NULL in
  11489. * order to indicate CNIC that it should not try to work
  11490. * with this device.
  11491. */
  11492. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11493. return NULL;
  11494. cp->drv_owner = THIS_MODULE;
  11495. cp->chip_id = CHIP_ID(bp);
  11496. cp->pdev = bp->pdev;
  11497. cp->io_base = bp->regview;
  11498. cp->io_base2 = bp->doorbells;
  11499. cp->max_kwqe_pending = 8;
  11500. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11501. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11502. bnx2x_cid_ilt_lines(bp);
  11503. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11504. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11505. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11506. cp->drv_ctl = bnx2x_drv_ctl;
  11507. cp->drv_register_cnic = bnx2x_register_cnic;
  11508. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11509. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11510. cp->iscsi_l2_client_id =
  11511. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11512. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11513. if (NO_ISCSI_OOO(bp))
  11514. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11515. if (NO_ISCSI(bp))
  11516. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11517. if (NO_FCOE(bp))
  11518. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11519. BNX2X_DEV_INFO(
  11520. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11521. cp->ctx_blk_size,
  11522. cp->ctx_tbl_offset,
  11523. cp->ctx_tbl_len,
  11524. cp->starting_cid);
  11525. return cp;
  11526. }
  11527. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11528. {
  11529. struct bnx2x *bp = fp->bp;
  11530. u32 offset = BAR_USTRORM_INTMEM;
  11531. if (IS_VF(bp))
  11532. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11533. else if (!CHIP_IS_E1x(bp))
  11534. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11535. else
  11536. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11537. return offset;
  11538. }
  11539. /* called only on E1H or E2.
  11540. * When pretending to be PF, the pretend value is the function number 0...7
  11541. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11542. * combination
  11543. */
  11544. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11545. {
  11546. u32 pretend_reg;
  11547. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11548. return -1;
  11549. /* get my own pretend register */
  11550. pretend_reg = bnx2x_get_pretend_reg(bp);
  11551. REG_WR(bp, pretend_reg, pretend_func_val);
  11552. REG_RD(bp, pretend_reg);
  11553. return 0;
  11554. }