bnx2x_main.c 372 KB

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