bnx2x_main.c 305 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2011 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. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/device.h> /* for dev_info() */
  21. #include <linux/timer.h>
  22. #include <linux/errno.h>
  23. #include <linux/ioport.h>
  24. #include <linux/slab.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/pci.h>
  27. #include <linux/init.h>
  28. #include <linux/netdevice.h>
  29. #include <linux/etherdevice.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/bitops.h>
  33. #include <linux/irq.h>
  34. #include <linux/delay.h>
  35. #include <asm/byteorder.h>
  36. #include <linux/time.h>
  37. #include <linux/ethtool.h>
  38. #include <linux/mii.h>
  39. #include <linux/if_vlan.h>
  40. #include <net/ip.h>
  41. #include <net/ipv6.h>
  42. #include <net/tcp.h>
  43. #include <net/checksum.h>
  44. #include <net/ip6_checksum.h>
  45. #include <linux/workqueue.h>
  46. #include <linux/crc32.h>
  47. #include <linux/crc32c.h>
  48. #include <linux/prefetch.h>
  49. #include <linux/zlib.h>
  50. #include <linux/io.h>
  51. #include <linux/stringify.h>
  52. #include <linux/vmalloc.h>
  53. #include "bnx2x.h"
  54. #include "bnx2x_init.h"
  55. #include "bnx2x_init_ops.h"
  56. #include "bnx2x_cmn.h"
  57. #include "bnx2x_dcb.h"
  58. #include "bnx2x_sp.h"
  59. #include <linux/firmware.h>
  60. #include "bnx2x_fw_file_hdr.h"
  61. /* FW files */
  62. #define FW_FILE_VERSION \
  63. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  64. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  65. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  66. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  67. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  68. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  69. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  70. /* Time in jiffies before concluding the transmitter is hung */
  71. #define TX_TIMEOUT (5*HZ)
  72. static char version[] __devinitdata =
  73. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  74. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  75. MODULE_AUTHOR("Eliezer Tamir");
  76. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  77. "BCM57710/57711/57711E/"
  78. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  79. "57840/57840_MF Driver");
  80. MODULE_LICENSE("GPL");
  81. MODULE_VERSION(DRV_MODULE_VERSION);
  82. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  83. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  84. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  85. static int multi_mode = 1;
  86. module_param(multi_mode, int, 0);
  87. MODULE_PARM_DESC(multi_mode, " Multi queue mode "
  88. "(0 Disable; 1 Enable (default))");
  89. int num_queues;
  90. module_param(num_queues, int, 0);
  91. MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
  92. " (default is as a number of CPUs)");
  93. static int disable_tpa;
  94. module_param(disable_tpa, int, 0);
  95. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  96. #define INT_MODE_INTx 1
  97. #define INT_MODE_MSI 2
  98. static int int_mode;
  99. module_param(int_mode, int, 0);
  100. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  101. "(1 INT#x; 2 MSI)");
  102. static int dropless_fc;
  103. module_param(dropless_fc, int, 0);
  104. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  105. static int poll;
  106. module_param(poll, int, 0);
  107. MODULE_PARM_DESC(poll, " Use polling (for debug)");
  108. static int mrrs = -1;
  109. module_param(mrrs, int, 0);
  110. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  111. static int debug;
  112. module_param(debug, int, 0);
  113. MODULE_PARM_DESC(debug, " Default debug msglevel");
  114. struct workqueue_struct *bnx2x_wq;
  115. enum bnx2x_board_type {
  116. BCM57710 = 0,
  117. BCM57711,
  118. BCM57711E,
  119. BCM57712,
  120. BCM57712_MF,
  121. BCM57800,
  122. BCM57800_MF,
  123. BCM57810,
  124. BCM57810_MF,
  125. BCM57840,
  126. BCM57840_MF
  127. };
  128. /* indexed by board_type, above */
  129. static struct {
  130. char *name;
  131. } board_info[] __devinitdata = {
  132. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  133. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  134. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  135. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  136. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  137. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  138. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  139. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  140. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  141. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  142. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit "
  143. "Ethernet Multi Function"}
  144. };
  145. #ifndef PCI_DEVICE_ID_NX2_57710
  146. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  147. #endif
  148. #ifndef PCI_DEVICE_ID_NX2_57711
  149. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  150. #endif
  151. #ifndef PCI_DEVICE_ID_NX2_57711E
  152. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  153. #endif
  154. #ifndef PCI_DEVICE_ID_NX2_57712
  155. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  156. #endif
  157. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  158. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  159. #endif
  160. #ifndef PCI_DEVICE_ID_NX2_57800
  161. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  162. #endif
  163. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  164. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  165. #endif
  166. #ifndef PCI_DEVICE_ID_NX2_57810
  167. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  168. #endif
  169. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  170. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  171. #endif
  172. #ifndef PCI_DEVICE_ID_NX2_57840
  173. #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
  174. #endif
  175. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  176. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  177. #endif
  178. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  179. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  180. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  181. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  182. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  183. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  184. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  185. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  186. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  187. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  188. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
  189. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  190. { 0 }
  191. };
  192. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  193. /****************************************************************************
  194. * General service functions
  195. ****************************************************************************/
  196. static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
  197. u32 addr, dma_addr_t mapping)
  198. {
  199. REG_WR(bp, addr, U64_LO(mapping));
  200. REG_WR(bp, addr + 4, U64_HI(mapping));
  201. }
  202. static inline void storm_memset_spq_addr(struct bnx2x *bp,
  203. dma_addr_t mapping, u16 abs_fid)
  204. {
  205. u32 addr = XSEM_REG_FAST_MEMORY +
  206. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  207. __storm_memset_dma_mapping(bp, addr, mapping);
  208. }
  209. static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  210. u16 pf_id)
  211. {
  212. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  213. pf_id);
  214. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  215. pf_id);
  216. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  217. pf_id);
  218. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  219. pf_id);
  220. }
  221. static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  222. u8 enable)
  223. {
  224. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  225. enable);
  226. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  227. enable);
  228. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  229. enable);
  230. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  231. enable);
  232. }
  233. static inline void storm_memset_eq_data(struct bnx2x *bp,
  234. struct event_ring_data *eq_data,
  235. u16 pfid)
  236. {
  237. size_t size = sizeof(struct event_ring_data);
  238. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  239. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  240. }
  241. static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  242. u16 pfid)
  243. {
  244. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  245. REG_WR16(bp, addr, eq_prod);
  246. }
  247. /* used only at init
  248. * locking is done by mcp
  249. */
  250. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  251. {
  252. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  253. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  254. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  255. PCICFG_VENDOR_ID_OFFSET);
  256. }
  257. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  258. {
  259. u32 val;
  260. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  261. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  262. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  263. PCICFG_VENDOR_ID_OFFSET);
  264. return val;
  265. }
  266. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  267. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  268. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  269. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  270. #define DMAE_DP_DST_NONE "dst_addr [none]"
  271. static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae,
  272. int msglvl)
  273. {
  274. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  275. switch (dmae->opcode & DMAE_COMMAND_DST) {
  276. case DMAE_CMD_DST_PCI:
  277. if (src_type == DMAE_CMD_SRC_PCI)
  278. DP(msglvl, "DMAE: opcode 0x%08x\n"
  279. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  280. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  281. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  282. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  283. dmae->comp_addr_hi, dmae->comp_addr_lo,
  284. dmae->comp_val);
  285. else
  286. DP(msglvl, "DMAE: opcode 0x%08x\n"
  287. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  288. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  289. dmae->opcode, dmae->src_addr_lo >> 2,
  290. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  291. dmae->comp_addr_hi, dmae->comp_addr_lo,
  292. dmae->comp_val);
  293. break;
  294. case DMAE_CMD_DST_GRC:
  295. if (src_type == DMAE_CMD_SRC_PCI)
  296. DP(msglvl, "DMAE: opcode 0x%08x\n"
  297. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  298. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  299. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  300. dmae->len, dmae->dst_addr_lo >> 2,
  301. dmae->comp_addr_hi, dmae->comp_addr_lo,
  302. dmae->comp_val);
  303. else
  304. DP(msglvl, "DMAE: opcode 0x%08x\n"
  305. "src [%08x], len [%d*4], dst [%08x]\n"
  306. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  307. dmae->opcode, dmae->src_addr_lo >> 2,
  308. dmae->len, dmae->dst_addr_lo >> 2,
  309. dmae->comp_addr_hi, dmae->comp_addr_lo,
  310. dmae->comp_val);
  311. break;
  312. default:
  313. if (src_type == DMAE_CMD_SRC_PCI)
  314. DP(msglvl, "DMAE: opcode 0x%08x\n"
  315. DP_LEVEL "src_addr [%x:%08x] len [%d * 4] "
  316. "dst_addr [none]\n"
  317. DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
  318. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  319. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  320. dmae->comp_val);
  321. else
  322. DP(msglvl, "DMAE: opcode 0x%08x\n"
  323. DP_LEVEL "src_addr [%08x] len [%d * 4] "
  324. "dst_addr [none]\n"
  325. DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
  326. dmae->opcode, dmae->src_addr_lo >> 2,
  327. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  328. dmae->comp_val);
  329. break;
  330. }
  331. }
  332. /* copy command into DMAE command memory and set DMAE command go */
  333. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  334. {
  335. u32 cmd_offset;
  336. int i;
  337. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  338. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  339. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  340. DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
  341. idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
  342. }
  343. REG_WR(bp, dmae_reg_go_c[idx], 1);
  344. }
  345. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  346. {
  347. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  348. DMAE_CMD_C_ENABLE);
  349. }
  350. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  351. {
  352. return opcode & ~DMAE_CMD_SRC_RESET;
  353. }
  354. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  355. bool with_comp, u8 comp_type)
  356. {
  357. u32 opcode = 0;
  358. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  359. (dst_type << DMAE_COMMAND_DST_SHIFT));
  360. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  361. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  362. opcode |= ((BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  363. (BP_E1HVN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  364. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  365. #ifdef __BIG_ENDIAN
  366. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  367. #else
  368. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  369. #endif
  370. if (with_comp)
  371. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  372. return opcode;
  373. }
  374. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  375. struct dmae_command *dmae,
  376. u8 src_type, u8 dst_type)
  377. {
  378. memset(dmae, 0, sizeof(struct dmae_command));
  379. /* set the opcode */
  380. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  381. true, DMAE_COMP_PCI);
  382. /* fill in the completion parameters */
  383. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  384. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  385. dmae->comp_val = DMAE_COMP_VAL;
  386. }
  387. /* issue a dmae command over the init-channel and wailt for completion */
  388. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  389. struct dmae_command *dmae)
  390. {
  391. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  392. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  393. int rc = 0;
  394. DP(BNX2X_MSG_OFF, "data before [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  395. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  396. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  397. /*
  398. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  399. * as long as this code is called both from syscall context and
  400. * from ndo_set_rx_mode() flow that may be called from BH.
  401. */
  402. spin_lock_bh(&bp->dmae_lock);
  403. /* reset completion */
  404. *wb_comp = 0;
  405. /* post the command on the channel used for initializations */
  406. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  407. /* wait for completion */
  408. udelay(5);
  409. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  410. DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
  411. if (!cnt) {
  412. BNX2X_ERR("DMAE timeout!\n");
  413. rc = DMAE_TIMEOUT;
  414. goto unlock;
  415. }
  416. cnt--;
  417. udelay(50);
  418. }
  419. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  420. BNX2X_ERR("DMAE PCI error!\n");
  421. rc = DMAE_PCI_ERROR;
  422. }
  423. DP(BNX2X_MSG_OFF, "data after [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  424. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  425. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  426. unlock:
  427. spin_unlock_bh(&bp->dmae_lock);
  428. return rc;
  429. }
  430. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  431. u32 len32)
  432. {
  433. struct dmae_command dmae;
  434. if (!bp->dmae_ready) {
  435. u32 *data = bnx2x_sp(bp, wb_data[0]);
  436. DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
  437. " using indirect\n", dst_addr, len32);
  438. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  439. return;
  440. }
  441. /* set opcode and fixed command fields */
  442. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  443. /* fill in addresses and len */
  444. dmae.src_addr_lo = U64_LO(dma_addr);
  445. dmae.src_addr_hi = U64_HI(dma_addr);
  446. dmae.dst_addr_lo = dst_addr >> 2;
  447. dmae.dst_addr_hi = 0;
  448. dmae.len = len32;
  449. bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
  450. /* issue the command and wait for completion */
  451. bnx2x_issue_dmae_with_comp(bp, &dmae);
  452. }
  453. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  454. {
  455. struct dmae_command dmae;
  456. if (!bp->dmae_ready) {
  457. u32 *data = bnx2x_sp(bp, wb_data[0]);
  458. int i;
  459. DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
  460. " using indirect\n", src_addr, len32);
  461. for (i = 0; i < len32; i++)
  462. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  463. return;
  464. }
  465. /* set opcode and fixed command fields */
  466. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  467. /* fill in addresses and len */
  468. dmae.src_addr_lo = src_addr >> 2;
  469. dmae.src_addr_hi = 0;
  470. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  471. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  472. dmae.len = len32;
  473. bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
  474. /* issue the command and wait for completion */
  475. bnx2x_issue_dmae_with_comp(bp, &dmae);
  476. }
  477. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  478. u32 addr, u32 len)
  479. {
  480. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  481. int offset = 0;
  482. while (len > dmae_wr_max) {
  483. bnx2x_write_dmae(bp, phys_addr + offset,
  484. addr + offset, dmae_wr_max);
  485. offset += dmae_wr_max * 4;
  486. len -= dmae_wr_max;
  487. }
  488. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  489. }
  490. /* used only for slowpath so not inlined */
  491. static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
  492. {
  493. u32 wb_write[2];
  494. wb_write[0] = val_hi;
  495. wb_write[1] = val_lo;
  496. REG_WR_DMAE(bp, reg, wb_write, 2);
  497. }
  498. #ifdef USE_WB_RD
  499. static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
  500. {
  501. u32 wb_data[2];
  502. REG_RD_DMAE(bp, reg, wb_data, 2);
  503. return HILO_U64(wb_data[0], wb_data[1]);
  504. }
  505. #endif
  506. static int bnx2x_mc_assert(struct bnx2x *bp)
  507. {
  508. char last_idx;
  509. int i, rc = 0;
  510. u32 row0, row1, row2, row3;
  511. /* XSTORM */
  512. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  513. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  514. if (last_idx)
  515. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  516. /* print the asserts */
  517. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  518. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  519. XSTORM_ASSERT_LIST_OFFSET(i));
  520. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  521. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  522. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  523. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  524. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  525. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  526. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  527. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  528. " 0x%08x 0x%08x 0x%08x\n",
  529. i, row3, row2, row1, row0);
  530. rc++;
  531. } else {
  532. break;
  533. }
  534. }
  535. /* TSTORM */
  536. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  537. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  538. if (last_idx)
  539. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  540. /* print the asserts */
  541. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  542. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  543. TSTORM_ASSERT_LIST_OFFSET(i));
  544. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  545. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  546. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  547. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  548. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  549. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  550. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  551. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  552. " 0x%08x 0x%08x 0x%08x\n",
  553. i, row3, row2, row1, row0);
  554. rc++;
  555. } else {
  556. break;
  557. }
  558. }
  559. /* CSTORM */
  560. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  561. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  562. if (last_idx)
  563. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  564. /* print the asserts */
  565. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  566. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  567. CSTORM_ASSERT_LIST_OFFSET(i));
  568. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  569. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  570. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  571. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  572. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  573. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  574. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  575. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  576. " 0x%08x 0x%08x 0x%08x\n",
  577. i, row3, row2, row1, row0);
  578. rc++;
  579. } else {
  580. break;
  581. }
  582. }
  583. /* USTORM */
  584. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  585. USTORM_ASSERT_LIST_INDEX_OFFSET);
  586. if (last_idx)
  587. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  588. /* print the asserts */
  589. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  590. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  591. USTORM_ASSERT_LIST_OFFSET(i));
  592. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  593. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  594. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  595. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  596. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  597. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  598. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  599. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
  600. " 0x%08x 0x%08x 0x%08x\n",
  601. i, row3, row2, row1, row0);
  602. rc++;
  603. } else {
  604. break;
  605. }
  606. }
  607. return rc;
  608. }
  609. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  610. {
  611. u32 addr, val;
  612. u32 mark, offset;
  613. __be32 data[9];
  614. int word;
  615. u32 trace_shmem_base;
  616. if (BP_NOMCP(bp)) {
  617. BNX2X_ERR("NO MCP - can not dump\n");
  618. return;
  619. }
  620. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  621. (bp->common.bc_ver & 0xff0000) >> 16,
  622. (bp->common.bc_ver & 0xff00) >> 8,
  623. (bp->common.bc_ver & 0xff));
  624. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  625. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  626. printk("%s" "MCP PC at 0x%x\n", lvl, val);
  627. if (BP_PATH(bp) == 0)
  628. trace_shmem_base = bp->common.shmem_base;
  629. else
  630. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  631. addr = trace_shmem_base - 0x0800 + 4;
  632. mark = REG_RD(bp, addr);
  633. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  634. + ((mark + 0x3) & ~0x3) - 0x08000000;
  635. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  636. printk("%s", lvl);
  637. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  638. for (word = 0; word < 8; word++)
  639. data[word] = htonl(REG_RD(bp, offset + 4*word));
  640. data[8] = 0x0;
  641. pr_cont("%s", (char *)data);
  642. }
  643. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  644. for (word = 0; word < 8; word++)
  645. data[word] = htonl(REG_RD(bp, offset + 4*word));
  646. data[8] = 0x0;
  647. pr_cont("%s", (char *)data);
  648. }
  649. printk("%s" "end of fw dump\n", lvl);
  650. }
  651. static inline void bnx2x_fw_dump(struct bnx2x *bp)
  652. {
  653. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  654. }
  655. void bnx2x_panic_dump(struct bnx2x *bp)
  656. {
  657. int i;
  658. u16 j;
  659. struct hc_sp_status_block_data sp_sb_data;
  660. int func = BP_FUNC(bp);
  661. #ifdef BNX2X_STOP_ON_ERROR
  662. u16 start = 0, end = 0;
  663. u8 cos;
  664. #endif
  665. bp->stats_state = STATS_STATE_DISABLED;
  666. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  667. BNX2X_ERR("begin crash dump -----------------\n");
  668. /* Indices */
  669. /* Common */
  670. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x)"
  671. " spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  672. bp->def_idx, bp->def_att_idx, bp->attn_state,
  673. bp->spq_prod_idx, bp->stats_counter);
  674. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  675. bp->def_status_blk->atten_status_block.attn_bits,
  676. bp->def_status_blk->atten_status_block.attn_bits_ack,
  677. bp->def_status_blk->atten_status_block.status_block_id,
  678. bp->def_status_blk->atten_status_block.attn_bits_index);
  679. BNX2X_ERR(" def (");
  680. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  681. pr_cont("0x%x%s",
  682. bp->def_status_blk->sp_sb.index_values[i],
  683. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  684. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  685. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  686. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  687. i*sizeof(u32));
  688. pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) "
  689. "pf_id(0x%x) vnic_id(0x%x) "
  690. "vf_id(0x%x) vf_valid (0x%x) "
  691. "state(0x%x)\n",
  692. sp_sb_data.igu_sb_id,
  693. sp_sb_data.igu_seg_id,
  694. sp_sb_data.p_func.pf_id,
  695. sp_sb_data.p_func.vnic_id,
  696. sp_sb_data.p_func.vf_id,
  697. sp_sb_data.p_func.vf_valid,
  698. sp_sb_data.state);
  699. for_each_eth_queue(bp, i) {
  700. struct bnx2x_fastpath *fp = &bp->fp[i];
  701. int loop;
  702. struct hc_status_block_data_e2 sb_data_e2;
  703. struct hc_status_block_data_e1x sb_data_e1x;
  704. struct hc_status_block_sm *hc_sm_p =
  705. CHIP_IS_E1x(bp) ?
  706. sb_data_e1x.common.state_machine :
  707. sb_data_e2.common.state_machine;
  708. struct hc_index_data *hc_index_p =
  709. CHIP_IS_E1x(bp) ?
  710. sb_data_e1x.index_data :
  711. sb_data_e2.index_data;
  712. u8 data_size, cos;
  713. u32 *sb_data_p;
  714. struct bnx2x_fp_txdata txdata;
  715. /* Rx */
  716. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x)"
  717. " rx_comp_prod(0x%x)"
  718. " rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  719. i, fp->rx_bd_prod, fp->rx_bd_cons,
  720. fp->rx_comp_prod,
  721. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  722. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x)"
  723. " fp_hc_idx(0x%x)\n",
  724. fp->rx_sge_prod, fp->last_max_sge,
  725. le16_to_cpu(fp->fp_hc_idx));
  726. /* Tx */
  727. for_each_cos_in_tx_queue(fp, cos)
  728. {
  729. txdata = fp->txdata[cos];
  730. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x)"
  731. " tx_bd_prod(0x%x) tx_bd_cons(0x%x)"
  732. " *tx_cons_sb(0x%x)\n",
  733. i, txdata.tx_pkt_prod,
  734. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  735. txdata.tx_bd_cons,
  736. le16_to_cpu(*txdata.tx_cons_sb));
  737. }
  738. loop = CHIP_IS_E1x(bp) ?
  739. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  740. /* host sb data */
  741. #ifdef BCM_CNIC
  742. if (IS_FCOE_FP(fp))
  743. continue;
  744. #endif
  745. BNX2X_ERR(" run indexes (");
  746. for (j = 0; j < HC_SB_MAX_SM; j++)
  747. pr_cont("0x%x%s",
  748. fp->sb_running_index[j],
  749. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  750. BNX2X_ERR(" indexes (");
  751. for (j = 0; j < loop; j++)
  752. pr_cont("0x%x%s",
  753. fp->sb_index_values[j],
  754. (j == loop - 1) ? ")" : " ");
  755. /* fw sb data */
  756. data_size = CHIP_IS_E1x(bp) ?
  757. sizeof(struct hc_status_block_data_e1x) :
  758. sizeof(struct hc_status_block_data_e2);
  759. data_size /= sizeof(u32);
  760. sb_data_p = CHIP_IS_E1x(bp) ?
  761. (u32 *)&sb_data_e1x :
  762. (u32 *)&sb_data_e2;
  763. /* copy sb data in here */
  764. for (j = 0; j < data_size; j++)
  765. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  766. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  767. j * sizeof(u32));
  768. if (!CHIP_IS_E1x(bp)) {
  769. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
  770. "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
  771. "state(0x%x)\n",
  772. sb_data_e2.common.p_func.pf_id,
  773. sb_data_e2.common.p_func.vf_id,
  774. sb_data_e2.common.p_func.vf_valid,
  775. sb_data_e2.common.p_func.vnic_id,
  776. sb_data_e2.common.same_igu_sb_1b,
  777. sb_data_e2.common.state);
  778. } else {
  779. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) "
  780. "vnic_id(0x%x) same_igu_sb_1b(0x%x) "
  781. "state(0x%x)\n",
  782. sb_data_e1x.common.p_func.pf_id,
  783. sb_data_e1x.common.p_func.vf_id,
  784. sb_data_e1x.common.p_func.vf_valid,
  785. sb_data_e1x.common.p_func.vnic_id,
  786. sb_data_e1x.common.same_igu_sb_1b,
  787. sb_data_e1x.common.state);
  788. }
  789. /* SB_SMs data */
  790. for (j = 0; j < HC_SB_MAX_SM; j++) {
  791. pr_cont("SM[%d] __flags (0x%x) "
  792. "igu_sb_id (0x%x) igu_seg_id(0x%x) "
  793. "time_to_expire (0x%x) "
  794. "timer_value(0x%x)\n", j,
  795. hc_sm_p[j].__flags,
  796. hc_sm_p[j].igu_sb_id,
  797. hc_sm_p[j].igu_seg_id,
  798. hc_sm_p[j].time_to_expire,
  799. hc_sm_p[j].timer_value);
  800. }
  801. /* Indecies data */
  802. for (j = 0; j < loop; j++) {
  803. pr_cont("INDEX[%d] flags (0x%x) "
  804. "timeout (0x%x)\n", j,
  805. hc_index_p[j].flags,
  806. hc_index_p[j].timeout);
  807. }
  808. }
  809. #ifdef BNX2X_STOP_ON_ERROR
  810. /* Rings */
  811. /* Rx */
  812. for_each_rx_queue(bp, i) {
  813. struct bnx2x_fastpath *fp = &bp->fp[i];
  814. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  815. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  816. for (j = start; j != end; j = RX_BD(j + 1)) {
  817. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  818. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  819. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  820. i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
  821. }
  822. start = RX_SGE(fp->rx_sge_prod);
  823. end = RX_SGE(fp->last_max_sge);
  824. for (j = start; j != end; j = RX_SGE(j + 1)) {
  825. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  826. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  827. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  828. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  829. }
  830. start = RCQ_BD(fp->rx_comp_cons - 10);
  831. end = RCQ_BD(fp->rx_comp_cons + 503);
  832. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  833. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  834. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  835. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  836. }
  837. }
  838. /* Tx */
  839. for_each_tx_queue(bp, i) {
  840. struct bnx2x_fastpath *fp = &bp->fp[i];
  841. for_each_cos_in_tx_queue(fp, cos) {
  842. struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
  843. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  844. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  845. for (j = start; j != end; j = TX_BD(j + 1)) {
  846. struct sw_tx_bd *sw_bd =
  847. &txdata->tx_buf_ring[j];
  848. BNX2X_ERR("fp%d: txdata %d, "
  849. "packet[%x]=[%p,%x]\n",
  850. i, cos, j, sw_bd->skb,
  851. sw_bd->first_bd);
  852. }
  853. start = TX_BD(txdata->tx_bd_cons - 10);
  854. end = TX_BD(txdata->tx_bd_cons + 254);
  855. for (j = start; j != end; j = TX_BD(j + 1)) {
  856. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  857. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]="
  858. "[%x:%x:%x:%x]\n",
  859. i, cos, j, tx_bd[0], tx_bd[1],
  860. tx_bd[2], tx_bd[3]);
  861. }
  862. }
  863. }
  864. #endif
  865. bnx2x_fw_dump(bp);
  866. bnx2x_mc_assert(bp);
  867. BNX2X_ERR("end crash dump -----------------\n");
  868. }
  869. /*
  870. * FLR Support for E2
  871. *
  872. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  873. * initialization.
  874. */
  875. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  876. #define FLR_WAIT_INTERAVAL 50 /* usec */
  877. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERAVAL) /* 200 */
  878. struct pbf_pN_buf_regs {
  879. int pN;
  880. u32 init_crd;
  881. u32 crd;
  882. u32 crd_freed;
  883. };
  884. struct pbf_pN_cmd_regs {
  885. int pN;
  886. u32 lines_occup;
  887. u32 lines_freed;
  888. };
  889. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  890. struct pbf_pN_buf_regs *regs,
  891. u32 poll_count)
  892. {
  893. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  894. u32 cur_cnt = poll_count;
  895. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  896. crd = crd_start = REG_RD(bp, regs->crd);
  897. init_crd = REG_RD(bp, regs->init_crd);
  898. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  899. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  900. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  901. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  902. (init_crd - crd_start))) {
  903. if (cur_cnt--) {
  904. udelay(FLR_WAIT_INTERAVAL);
  905. crd = REG_RD(bp, regs->crd);
  906. crd_freed = REG_RD(bp, regs->crd_freed);
  907. } else {
  908. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  909. regs->pN);
  910. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  911. regs->pN, crd);
  912. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  913. regs->pN, crd_freed);
  914. break;
  915. }
  916. }
  917. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  918. poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
  919. }
  920. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  921. struct pbf_pN_cmd_regs *regs,
  922. u32 poll_count)
  923. {
  924. u32 occup, to_free, freed, freed_start;
  925. u32 cur_cnt = poll_count;
  926. occup = to_free = REG_RD(bp, regs->lines_occup);
  927. freed = freed_start = REG_RD(bp, regs->lines_freed);
  928. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  929. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  930. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  931. if (cur_cnt--) {
  932. udelay(FLR_WAIT_INTERAVAL);
  933. occup = REG_RD(bp, regs->lines_occup);
  934. freed = REG_RD(bp, regs->lines_freed);
  935. } else {
  936. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  937. regs->pN);
  938. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  939. regs->pN, occup);
  940. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  941. regs->pN, freed);
  942. break;
  943. }
  944. }
  945. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  946. poll_count-cur_cnt, FLR_WAIT_INTERAVAL, regs->pN);
  947. }
  948. static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  949. u32 expected, u32 poll_count)
  950. {
  951. u32 cur_cnt = poll_count;
  952. u32 val;
  953. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  954. udelay(FLR_WAIT_INTERAVAL);
  955. return val;
  956. }
  957. static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  958. char *msg, u32 poll_cnt)
  959. {
  960. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  961. if (val != 0) {
  962. BNX2X_ERR("%s usage count=%d\n", msg, val);
  963. return 1;
  964. }
  965. return 0;
  966. }
  967. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  968. {
  969. /* adjust polling timeout */
  970. if (CHIP_REV_IS_EMUL(bp))
  971. return FLR_POLL_CNT * 2000;
  972. if (CHIP_REV_IS_FPGA(bp))
  973. return FLR_POLL_CNT * 120;
  974. return FLR_POLL_CNT;
  975. }
  976. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  977. {
  978. struct pbf_pN_cmd_regs cmd_regs[] = {
  979. {0, (CHIP_IS_E3B0(bp)) ?
  980. PBF_REG_TQ_OCCUPANCY_Q0 :
  981. PBF_REG_P0_TQ_OCCUPANCY,
  982. (CHIP_IS_E3B0(bp)) ?
  983. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  984. PBF_REG_P0_TQ_LINES_FREED_CNT},
  985. {1, (CHIP_IS_E3B0(bp)) ?
  986. PBF_REG_TQ_OCCUPANCY_Q1 :
  987. PBF_REG_P1_TQ_OCCUPANCY,
  988. (CHIP_IS_E3B0(bp)) ?
  989. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  990. PBF_REG_P1_TQ_LINES_FREED_CNT},
  991. {4, (CHIP_IS_E3B0(bp)) ?
  992. PBF_REG_TQ_OCCUPANCY_LB_Q :
  993. PBF_REG_P4_TQ_OCCUPANCY,
  994. (CHIP_IS_E3B0(bp)) ?
  995. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  996. PBF_REG_P4_TQ_LINES_FREED_CNT}
  997. };
  998. struct pbf_pN_buf_regs buf_regs[] = {
  999. {0, (CHIP_IS_E3B0(bp)) ?
  1000. PBF_REG_INIT_CRD_Q0 :
  1001. PBF_REG_P0_INIT_CRD ,
  1002. (CHIP_IS_E3B0(bp)) ?
  1003. PBF_REG_CREDIT_Q0 :
  1004. PBF_REG_P0_CREDIT,
  1005. (CHIP_IS_E3B0(bp)) ?
  1006. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1007. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1008. {1, (CHIP_IS_E3B0(bp)) ?
  1009. PBF_REG_INIT_CRD_Q1 :
  1010. PBF_REG_P1_INIT_CRD,
  1011. (CHIP_IS_E3B0(bp)) ?
  1012. PBF_REG_CREDIT_Q1 :
  1013. PBF_REG_P1_CREDIT,
  1014. (CHIP_IS_E3B0(bp)) ?
  1015. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1016. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1017. {4, (CHIP_IS_E3B0(bp)) ?
  1018. PBF_REG_INIT_CRD_LB_Q :
  1019. PBF_REG_P4_INIT_CRD,
  1020. (CHIP_IS_E3B0(bp)) ?
  1021. PBF_REG_CREDIT_LB_Q :
  1022. PBF_REG_P4_CREDIT,
  1023. (CHIP_IS_E3B0(bp)) ?
  1024. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1025. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1026. };
  1027. int i;
  1028. /* Verify the command queues are flushed P0, P1, P4 */
  1029. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1030. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1031. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1032. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1033. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1034. }
  1035. #define OP_GEN_PARAM(param) \
  1036. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1037. #define OP_GEN_TYPE(type) \
  1038. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1039. #define OP_GEN_AGG_VECT(index) \
  1040. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1041. static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  1042. u32 poll_cnt)
  1043. {
  1044. struct sdm_op_gen op_gen = {0};
  1045. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1046. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1047. int ret = 0;
  1048. if (REG_RD(bp, comp_addr)) {
  1049. BNX2X_ERR("Cleanup complete is not 0\n");
  1050. return 1;
  1051. }
  1052. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1053. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1054. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  1055. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1056. DP(BNX2X_MSG_SP, "FW Final cleanup\n");
  1057. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1058. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1059. BNX2X_ERR("FW final cleanup did not succeed\n");
  1060. ret = 1;
  1061. }
  1062. /* Zero completion for nxt FLR */
  1063. REG_WR(bp, comp_addr, 0);
  1064. return ret;
  1065. }
  1066. static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1067. {
  1068. int pos;
  1069. u16 status;
  1070. pos = pci_pcie_cap(dev);
  1071. if (!pos)
  1072. return false;
  1073. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  1074. return status & PCI_EXP_DEVSTA_TRPND;
  1075. }
  1076. /* PF FLR specific routines
  1077. */
  1078. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1079. {
  1080. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1081. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1082. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1083. "CFC PF usage counter timed out",
  1084. poll_cnt))
  1085. return 1;
  1086. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1087. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1088. DORQ_REG_PF_USAGE_CNT,
  1089. "DQ PF usage counter timed out",
  1090. poll_cnt))
  1091. return 1;
  1092. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1093. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1094. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1095. "QM PF usage counter timed out",
  1096. poll_cnt))
  1097. return 1;
  1098. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1099. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1100. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1101. "Timers VNIC usage counter timed out",
  1102. poll_cnt))
  1103. return 1;
  1104. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1105. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1106. "Timers NUM_SCANS usage counter timed out",
  1107. poll_cnt))
  1108. return 1;
  1109. /* Wait DMAE PF usage counter to zero */
  1110. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1111. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1112. "DMAE dommand register timed out",
  1113. poll_cnt))
  1114. return 1;
  1115. return 0;
  1116. }
  1117. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1118. {
  1119. u32 val;
  1120. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1121. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1122. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1123. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1124. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1125. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1126. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1127. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1128. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1129. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1130. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1131. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1132. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1133. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1134. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1135. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1136. val);
  1137. }
  1138. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1139. {
  1140. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1141. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1142. /* Re-enable PF target read access */
  1143. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1144. /* Poll HW usage counters */
  1145. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1146. return -EBUSY;
  1147. /* Zero the igu 'trailing edge' and 'leading edge' */
  1148. /* Send the FW cleanup command */
  1149. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1150. return -EBUSY;
  1151. /* ATC cleanup */
  1152. /* Verify TX hw is flushed */
  1153. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1154. /* Wait 100ms (not adjusted according to platform) */
  1155. msleep(100);
  1156. /* Verify no pending pci transactions */
  1157. if (bnx2x_is_pcie_pending(bp->pdev))
  1158. BNX2X_ERR("PCIE Transactions still pending\n");
  1159. /* Debug */
  1160. bnx2x_hw_enable_status(bp);
  1161. /*
  1162. * Master enable - Due to WB DMAE writes performed before this
  1163. * register is re-initialized as part of the regular function init
  1164. */
  1165. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1166. return 0;
  1167. }
  1168. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1169. {
  1170. int port = BP_PORT(bp);
  1171. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1172. u32 val = REG_RD(bp, addr);
  1173. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1174. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1175. if (msix) {
  1176. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1177. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1178. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1179. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1180. } else if (msi) {
  1181. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1182. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1183. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1184. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1185. } else {
  1186. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1187. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1188. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1189. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1190. if (!CHIP_IS_E1(bp)) {
  1191. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  1192. val, port, addr);
  1193. REG_WR(bp, addr, val);
  1194. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1195. }
  1196. }
  1197. if (CHIP_IS_E1(bp))
  1198. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1199. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
  1200. val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1201. REG_WR(bp, addr, val);
  1202. /*
  1203. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1204. */
  1205. mmiowb();
  1206. barrier();
  1207. if (!CHIP_IS_E1(bp)) {
  1208. /* init leading/trailing edge */
  1209. if (IS_MF(bp)) {
  1210. val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
  1211. if (bp->port.pmf)
  1212. /* enable nig and gpio3 attention */
  1213. val |= 0x1100;
  1214. } else
  1215. val = 0xffff;
  1216. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1217. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1218. }
  1219. /* Make sure that interrupts are indeed enabled from here on */
  1220. mmiowb();
  1221. }
  1222. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1223. {
  1224. u32 val;
  1225. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1226. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1227. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1228. if (msix) {
  1229. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1230. IGU_PF_CONF_SINGLE_ISR_EN);
  1231. val |= (IGU_PF_CONF_FUNC_EN |
  1232. IGU_PF_CONF_MSI_MSIX_EN |
  1233. IGU_PF_CONF_ATTN_BIT_EN);
  1234. } else if (msi) {
  1235. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1236. val |= (IGU_PF_CONF_FUNC_EN |
  1237. IGU_PF_CONF_MSI_MSIX_EN |
  1238. IGU_PF_CONF_ATTN_BIT_EN |
  1239. IGU_PF_CONF_SINGLE_ISR_EN);
  1240. } else {
  1241. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1242. val |= (IGU_PF_CONF_FUNC_EN |
  1243. IGU_PF_CONF_INT_LINE_EN |
  1244. IGU_PF_CONF_ATTN_BIT_EN |
  1245. IGU_PF_CONF_SINGLE_ISR_EN);
  1246. }
  1247. DP(NETIF_MSG_INTR, "write 0x%x to IGU mode %s\n",
  1248. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1249. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1250. barrier();
  1251. /* init leading/trailing edge */
  1252. if (IS_MF(bp)) {
  1253. val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
  1254. if (bp->port.pmf)
  1255. /* enable nig and gpio3 attention */
  1256. val |= 0x1100;
  1257. } else
  1258. val = 0xffff;
  1259. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1260. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1261. /* Make sure that interrupts are indeed enabled from here on */
  1262. mmiowb();
  1263. }
  1264. void bnx2x_int_enable(struct bnx2x *bp)
  1265. {
  1266. if (bp->common.int_block == INT_BLOCK_HC)
  1267. bnx2x_hc_int_enable(bp);
  1268. else
  1269. bnx2x_igu_int_enable(bp);
  1270. }
  1271. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1272. {
  1273. int port = BP_PORT(bp);
  1274. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1275. u32 val = REG_RD(bp, addr);
  1276. /*
  1277. * in E1 we must use only PCI configuration space to disable
  1278. * MSI/MSIX capablility
  1279. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1280. */
  1281. if (CHIP_IS_E1(bp)) {
  1282. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1283. * Use mask register to prevent from HC sending interrupts
  1284. * after we exit the function
  1285. */
  1286. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1287. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1288. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1289. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1290. } else
  1291. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1292. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1293. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1294. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1295. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  1296. val, port, addr);
  1297. /* flush all outstanding writes */
  1298. mmiowb();
  1299. REG_WR(bp, addr, val);
  1300. if (REG_RD(bp, addr) != val)
  1301. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1302. }
  1303. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1304. {
  1305. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1306. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1307. IGU_PF_CONF_INT_LINE_EN |
  1308. IGU_PF_CONF_ATTN_BIT_EN);
  1309. DP(NETIF_MSG_INTR, "write %x to IGU\n", val);
  1310. /* flush all outstanding writes */
  1311. mmiowb();
  1312. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1313. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1314. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1315. }
  1316. void bnx2x_int_disable(struct bnx2x *bp)
  1317. {
  1318. if (bp->common.int_block == INT_BLOCK_HC)
  1319. bnx2x_hc_int_disable(bp);
  1320. else
  1321. bnx2x_igu_int_disable(bp);
  1322. }
  1323. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1324. {
  1325. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1326. int i, offset;
  1327. if (disable_hw)
  1328. /* prevent the HW from sending interrupts */
  1329. bnx2x_int_disable(bp);
  1330. /* make sure all ISRs are done */
  1331. if (msix) {
  1332. synchronize_irq(bp->msix_table[0].vector);
  1333. offset = 1;
  1334. #ifdef BCM_CNIC
  1335. offset++;
  1336. #endif
  1337. for_each_eth_queue(bp, i)
  1338. synchronize_irq(bp->msix_table[offset++].vector);
  1339. } else
  1340. synchronize_irq(bp->pdev->irq);
  1341. /* make sure sp_task is not running */
  1342. cancel_delayed_work(&bp->sp_task);
  1343. cancel_delayed_work(&bp->period_task);
  1344. flush_workqueue(bnx2x_wq);
  1345. }
  1346. /* fast path */
  1347. /*
  1348. * General service functions
  1349. */
  1350. /* Return true if succeeded to acquire the lock */
  1351. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1352. {
  1353. u32 lock_status;
  1354. u32 resource_bit = (1 << resource);
  1355. int func = BP_FUNC(bp);
  1356. u32 hw_lock_control_reg;
  1357. DP(NETIF_MSG_HW, "Trying to take a lock on resource %d\n", resource);
  1358. /* Validating that the resource is within range */
  1359. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1360. DP(NETIF_MSG_HW,
  1361. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1362. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1363. return false;
  1364. }
  1365. if (func <= 5)
  1366. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1367. else
  1368. hw_lock_control_reg =
  1369. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1370. /* Try to acquire the lock */
  1371. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1372. lock_status = REG_RD(bp, hw_lock_control_reg);
  1373. if (lock_status & resource_bit)
  1374. return true;
  1375. DP(NETIF_MSG_HW, "Failed to get a lock on resource %d\n", resource);
  1376. return false;
  1377. }
  1378. /**
  1379. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1380. *
  1381. * @bp: driver handle
  1382. *
  1383. * Returns the recovery leader resource id according to the engine this function
  1384. * belongs to. Currently only only 2 engines is supported.
  1385. */
  1386. static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1387. {
  1388. if (BP_PATH(bp))
  1389. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1390. else
  1391. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1392. }
  1393. /**
  1394. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1395. *
  1396. * @bp: driver handle
  1397. *
  1398. * Tries to aquire a leader lock for cuurent engine.
  1399. */
  1400. static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1401. {
  1402. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1403. }
  1404. #ifdef BCM_CNIC
  1405. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1406. #endif
  1407. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1408. {
  1409. struct bnx2x *bp = fp->bp;
  1410. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1411. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1412. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1413. struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
  1414. DP(BNX2X_MSG_SP,
  1415. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1416. fp->index, cid, command, bp->state,
  1417. rr_cqe->ramrod_cqe.ramrod_type);
  1418. switch (command) {
  1419. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1420. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1421. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1422. break;
  1423. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1424. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1425. drv_cmd = BNX2X_Q_CMD_SETUP;
  1426. break;
  1427. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1428. DP(NETIF_MSG_IFUP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1429. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1430. break;
  1431. case (RAMROD_CMD_ID_ETH_HALT):
  1432. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1433. drv_cmd = BNX2X_Q_CMD_HALT;
  1434. break;
  1435. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1436. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1437. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1438. break;
  1439. case (RAMROD_CMD_ID_ETH_EMPTY):
  1440. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1441. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1442. break;
  1443. default:
  1444. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1445. command, fp->index);
  1446. return;
  1447. }
  1448. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1449. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1450. /* q_obj->complete_cmd() failure means that this was
  1451. * an unexpected completion.
  1452. *
  1453. * In this case we don't want to increase the bp->spq_left
  1454. * because apparently we haven't sent this command the first
  1455. * place.
  1456. */
  1457. #ifdef BNX2X_STOP_ON_ERROR
  1458. bnx2x_panic();
  1459. #else
  1460. return;
  1461. #endif
  1462. smp_mb__before_atomic_inc();
  1463. atomic_inc(&bp->cq_spq_left);
  1464. /* push the change in bp->spq_left and towards the memory */
  1465. smp_mb__after_atomic_inc();
  1466. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1467. return;
  1468. }
  1469. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1470. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1471. {
  1472. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1473. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1474. start);
  1475. }
  1476. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1477. {
  1478. struct bnx2x *bp = netdev_priv(dev_instance);
  1479. u16 status = bnx2x_ack_int(bp);
  1480. u16 mask;
  1481. int i;
  1482. u8 cos;
  1483. /* Return here if interrupt is shared and it's not for us */
  1484. if (unlikely(status == 0)) {
  1485. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1486. return IRQ_NONE;
  1487. }
  1488. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1489. #ifdef BNX2X_STOP_ON_ERROR
  1490. if (unlikely(bp->panic))
  1491. return IRQ_HANDLED;
  1492. #endif
  1493. for_each_eth_queue(bp, i) {
  1494. struct bnx2x_fastpath *fp = &bp->fp[i];
  1495. mask = 0x2 << (fp->index + CNIC_PRESENT);
  1496. if (status & mask) {
  1497. /* Handle Rx or Tx according to SB id */
  1498. prefetch(fp->rx_cons_sb);
  1499. for_each_cos_in_tx_queue(fp, cos)
  1500. prefetch(fp->txdata[cos].tx_cons_sb);
  1501. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1502. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1503. status &= ~mask;
  1504. }
  1505. }
  1506. #ifdef BCM_CNIC
  1507. mask = 0x2;
  1508. if (status & (mask | 0x1)) {
  1509. struct cnic_ops *c_ops = NULL;
  1510. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1511. rcu_read_lock();
  1512. c_ops = rcu_dereference(bp->cnic_ops);
  1513. if (c_ops)
  1514. c_ops->cnic_handler(bp->cnic_data, NULL);
  1515. rcu_read_unlock();
  1516. }
  1517. status &= ~mask;
  1518. }
  1519. #endif
  1520. if (unlikely(status & 0x1)) {
  1521. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1522. status &= ~0x1;
  1523. if (!status)
  1524. return IRQ_HANDLED;
  1525. }
  1526. if (unlikely(status))
  1527. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1528. status);
  1529. return IRQ_HANDLED;
  1530. }
  1531. /* Link */
  1532. /*
  1533. * General service functions
  1534. */
  1535. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1536. {
  1537. u32 lock_status;
  1538. u32 resource_bit = (1 << resource);
  1539. int func = BP_FUNC(bp);
  1540. u32 hw_lock_control_reg;
  1541. int cnt;
  1542. /* Validating that the resource is within range */
  1543. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1544. DP(NETIF_MSG_HW,
  1545. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1546. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1547. return -EINVAL;
  1548. }
  1549. if (func <= 5) {
  1550. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1551. } else {
  1552. hw_lock_control_reg =
  1553. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1554. }
  1555. /* Validating that the resource is not already taken */
  1556. lock_status = REG_RD(bp, hw_lock_control_reg);
  1557. if (lock_status & resource_bit) {
  1558. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1559. lock_status, resource_bit);
  1560. return -EEXIST;
  1561. }
  1562. /* Try for 5 second every 5ms */
  1563. for (cnt = 0; cnt < 1000; cnt++) {
  1564. /* Try to acquire the lock */
  1565. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1566. lock_status = REG_RD(bp, hw_lock_control_reg);
  1567. if (lock_status & resource_bit)
  1568. return 0;
  1569. msleep(5);
  1570. }
  1571. DP(NETIF_MSG_HW, "Timeout\n");
  1572. return -EAGAIN;
  1573. }
  1574. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1575. {
  1576. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1577. }
  1578. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1579. {
  1580. u32 lock_status;
  1581. u32 resource_bit = (1 << resource);
  1582. int func = BP_FUNC(bp);
  1583. u32 hw_lock_control_reg;
  1584. DP(NETIF_MSG_HW, "Releasing a lock on resource %d\n", resource);
  1585. /* Validating that the resource is within range */
  1586. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1587. DP(NETIF_MSG_HW,
  1588. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1589. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1590. return -EINVAL;
  1591. }
  1592. if (func <= 5) {
  1593. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1594. } else {
  1595. hw_lock_control_reg =
  1596. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1597. }
  1598. /* Validating that the resource is currently taken */
  1599. lock_status = REG_RD(bp, hw_lock_control_reg);
  1600. if (!(lock_status & resource_bit)) {
  1601. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1602. lock_status, resource_bit);
  1603. return -EFAULT;
  1604. }
  1605. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1606. return 0;
  1607. }
  1608. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1609. {
  1610. /* The GPIO should be swapped if swap register is set and active */
  1611. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1612. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1613. int gpio_shift = gpio_num +
  1614. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1615. u32 gpio_mask = (1 << gpio_shift);
  1616. u32 gpio_reg;
  1617. int value;
  1618. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1619. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1620. return -EINVAL;
  1621. }
  1622. /* read GPIO value */
  1623. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1624. /* get the requested pin value */
  1625. if ((gpio_reg & gpio_mask) == gpio_mask)
  1626. value = 1;
  1627. else
  1628. value = 0;
  1629. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1630. return value;
  1631. }
  1632. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1633. {
  1634. /* The GPIO should be swapped if swap register is set and active */
  1635. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1636. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1637. int gpio_shift = gpio_num +
  1638. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1639. u32 gpio_mask = (1 << gpio_shift);
  1640. u32 gpio_reg;
  1641. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1642. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1643. return -EINVAL;
  1644. }
  1645. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1646. /* read GPIO and mask except the float bits */
  1647. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1648. switch (mode) {
  1649. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1650. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
  1651. gpio_num, gpio_shift);
  1652. /* clear FLOAT and set CLR */
  1653. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1654. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1655. break;
  1656. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1657. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
  1658. gpio_num, gpio_shift);
  1659. /* clear FLOAT and set SET */
  1660. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1661. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1662. break;
  1663. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1664. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
  1665. gpio_num, gpio_shift);
  1666. /* set FLOAT */
  1667. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1668. break;
  1669. default:
  1670. break;
  1671. }
  1672. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1673. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1674. return 0;
  1675. }
  1676. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1677. {
  1678. u32 gpio_reg = 0;
  1679. int rc = 0;
  1680. /* Any port swapping should be handled by caller. */
  1681. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1682. /* read GPIO and mask except the float bits */
  1683. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1684. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1685. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1686. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1687. switch (mode) {
  1688. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1689. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1690. /* set CLR */
  1691. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1692. break;
  1693. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1694. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1695. /* set SET */
  1696. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1697. break;
  1698. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1699. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1700. /* set FLOAT */
  1701. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1702. break;
  1703. default:
  1704. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1705. rc = -EINVAL;
  1706. break;
  1707. }
  1708. if (rc == 0)
  1709. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1710. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1711. return rc;
  1712. }
  1713. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1714. {
  1715. /* The GPIO should be swapped if swap register is set and active */
  1716. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1717. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1718. int gpio_shift = gpio_num +
  1719. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1720. u32 gpio_mask = (1 << gpio_shift);
  1721. u32 gpio_reg;
  1722. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1723. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1724. return -EINVAL;
  1725. }
  1726. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1727. /* read GPIO int */
  1728. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1729. switch (mode) {
  1730. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1731. DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
  1732. "output low\n", gpio_num, gpio_shift);
  1733. /* clear SET and set CLR */
  1734. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1735. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1736. break;
  1737. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1738. DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
  1739. "output high\n", gpio_num, gpio_shift);
  1740. /* clear CLR and set SET */
  1741. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1742. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1743. break;
  1744. default:
  1745. break;
  1746. }
  1747. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1748. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1749. return 0;
  1750. }
  1751. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1752. {
  1753. u32 spio_mask = (1 << spio_num);
  1754. u32 spio_reg;
  1755. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1756. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1757. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1758. return -EINVAL;
  1759. }
  1760. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1761. /* read SPIO and mask except the float bits */
  1762. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1763. switch (mode) {
  1764. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1765. DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
  1766. /* clear FLOAT and set CLR */
  1767. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1768. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1769. break;
  1770. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1771. DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
  1772. /* clear FLOAT and set SET */
  1773. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1774. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1775. break;
  1776. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1777. DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
  1778. /* set FLOAT */
  1779. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1780. break;
  1781. default:
  1782. break;
  1783. }
  1784. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1785. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1786. return 0;
  1787. }
  1788. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1789. {
  1790. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1791. switch (bp->link_vars.ieee_fc &
  1792. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1793. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1794. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1795. ADVERTISED_Pause);
  1796. break;
  1797. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1798. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1799. ADVERTISED_Pause);
  1800. break;
  1801. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1802. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1803. break;
  1804. default:
  1805. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1806. ADVERTISED_Pause);
  1807. break;
  1808. }
  1809. }
  1810. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1811. {
  1812. if (!BP_NOMCP(bp)) {
  1813. u8 rc;
  1814. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1815. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1816. /*
  1817. * Initialize link parameters structure variables
  1818. * It is recommended to turn off RX FC for jumbo frames
  1819. * for better performance
  1820. */
  1821. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1822. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1823. else
  1824. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1825. bnx2x_acquire_phy_lock(bp);
  1826. if (load_mode == LOAD_DIAG) {
  1827. struct link_params *lp = &bp->link_params;
  1828. lp->loopback_mode = LOOPBACK_XGXS;
  1829. /* do PHY loopback at 10G speed, if possible */
  1830. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1831. if (lp->speed_cap_mask[cfx_idx] &
  1832. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1833. lp->req_line_speed[cfx_idx] =
  1834. SPEED_10000;
  1835. else
  1836. lp->req_line_speed[cfx_idx] =
  1837. SPEED_1000;
  1838. }
  1839. }
  1840. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1841. bnx2x_release_phy_lock(bp);
  1842. bnx2x_calc_fc_adv(bp);
  1843. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1844. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1845. bnx2x_link_report(bp);
  1846. } else
  1847. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1848. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1849. return rc;
  1850. }
  1851. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1852. return -EINVAL;
  1853. }
  1854. void bnx2x_link_set(struct bnx2x *bp)
  1855. {
  1856. if (!BP_NOMCP(bp)) {
  1857. bnx2x_acquire_phy_lock(bp);
  1858. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1859. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1860. bnx2x_release_phy_lock(bp);
  1861. bnx2x_calc_fc_adv(bp);
  1862. } else
  1863. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1864. }
  1865. static void bnx2x__link_reset(struct bnx2x *bp)
  1866. {
  1867. if (!BP_NOMCP(bp)) {
  1868. bnx2x_acquire_phy_lock(bp);
  1869. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1870. bnx2x_release_phy_lock(bp);
  1871. } else
  1872. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1873. }
  1874. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1875. {
  1876. u8 rc = 0;
  1877. if (!BP_NOMCP(bp)) {
  1878. bnx2x_acquire_phy_lock(bp);
  1879. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1880. is_serdes);
  1881. bnx2x_release_phy_lock(bp);
  1882. } else
  1883. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1884. return rc;
  1885. }
  1886. static void bnx2x_init_port_minmax(struct bnx2x *bp)
  1887. {
  1888. u32 r_param = bp->link_vars.line_speed / 8;
  1889. u32 fair_periodic_timeout_usec;
  1890. u32 t_fair;
  1891. memset(&(bp->cmng.rs_vars), 0,
  1892. sizeof(struct rate_shaping_vars_per_port));
  1893. memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
  1894. /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
  1895. bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
  1896. /* this is the threshold below which no timer arming will occur
  1897. 1.25 coefficient is for the threshold to be a little bigger
  1898. than the real time, to compensate for timer in-accuracy */
  1899. bp->cmng.rs_vars.rs_threshold =
  1900. (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
  1901. /* resolution of fairness timer */
  1902. fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
  1903. /* for 10G it is 1000usec. for 1G it is 10000usec. */
  1904. t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
  1905. /* this is the threshold below which we won't arm the timer anymore */
  1906. bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
  1907. /* we multiply by 1e3/8 to get bytes/msec.
  1908. We don't want the credits to pass a credit
  1909. of the t_fair*FAIR_MEM (algorithm resolution) */
  1910. bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
  1911. /* since each tick is 4 usec */
  1912. bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
  1913. }
  1914. /* Calculates the sum of vn_min_rates.
  1915. It's needed for further normalizing of the min_rates.
  1916. Returns:
  1917. sum of vn_min_rates.
  1918. or
  1919. 0 - if all the min_rates are 0.
  1920. In the later case fainess algorithm should be deactivated.
  1921. If not all min_rates are zero then those that are zeroes will be set to 1.
  1922. */
  1923. static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
  1924. {
  1925. int all_zero = 1;
  1926. int vn;
  1927. bp->vn_weight_sum = 0;
  1928. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  1929. u32 vn_cfg = bp->mf_config[vn];
  1930. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1931. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1932. /* Skip hidden vns */
  1933. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1934. continue;
  1935. /* If min rate is zero - set it to 1 */
  1936. if (!vn_min_rate)
  1937. vn_min_rate = DEF_MIN_RATE;
  1938. else
  1939. all_zero = 0;
  1940. bp->vn_weight_sum += vn_min_rate;
  1941. }
  1942. /* if ETS or all min rates are zeros - disable fairness */
  1943. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1944. bp->cmng.flags.cmng_enables &=
  1945. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1946. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1947. } else if (all_zero) {
  1948. bp->cmng.flags.cmng_enables &=
  1949. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1950. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  1951. " fairness will be disabled\n");
  1952. } else
  1953. bp->cmng.flags.cmng_enables |=
  1954. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1955. }
  1956. static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
  1957. {
  1958. struct rate_shaping_vars_per_vn m_rs_vn;
  1959. struct fairness_vars_per_vn m_fair_vn;
  1960. u32 vn_cfg = bp->mf_config[vn];
  1961. int func = 2*vn + BP_PORT(bp);
  1962. u16 vn_min_rate, vn_max_rate;
  1963. int i;
  1964. /* If function is hidden - set min and max to zeroes */
  1965. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
  1966. vn_min_rate = 0;
  1967. vn_max_rate = 0;
  1968. } else {
  1969. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1970. vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1971. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1972. /* If fairness is enabled (not all min rates are zeroes) and
  1973. if current min rate is zero - set it to 1.
  1974. This is a requirement of the algorithm. */
  1975. if (bp->vn_weight_sum && (vn_min_rate == 0))
  1976. vn_min_rate = DEF_MIN_RATE;
  1977. if (IS_MF_SI(bp))
  1978. /* maxCfg in percents of linkspeed */
  1979. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1980. else
  1981. /* maxCfg is absolute in 100Mb units */
  1982. vn_max_rate = maxCfg * 100;
  1983. }
  1984. DP(NETIF_MSG_IFUP,
  1985. "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
  1986. func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
  1987. memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
  1988. memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
  1989. /* global vn counter - maximal Mbps for this vn */
  1990. m_rs_vn.vn_counter.rate = vn_max_rate;
  1991. /* quota - number of bytes transmitted in this period */
  1992. m_rs_vn.vn_counter.quota =
  1993. (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
  1994. if (bp->vn_weight_sum) {
  1995. /* credit for each period of the fairness algorithm:
  1996. number of bytes in T_FAIR (the vn share the port rate).
  1997. vn_weight_sum should not be larger than 10000, thus
  1998. T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
  1999. than zero */
  2000. m_fair_vn.vn_credit_delta =
  2001. max_t(u32, (vn_min_rate * (T_FAIR_COEF /
  2002. (8 * bp->vn_weight_sum))),
  2003. (bp->cmng.fair_vars.fair_threshold +
  2004. MIN_ABOVE_THRESH));
  2005. DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
  2006. m_fair_vn.vn_credit_delta);
  2007. }
  2008. /* Store it to internal memory */
  2009. for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
  2010. REG_WR(bp, BAR_XSTRORM_INTMEM +
  2011. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
  2012. ((u32 *)(&m_rs_vn))[i]);
  2013. for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
  2014. REG_WR(bp, BAR_XSTRORM_INTMEM +
  2015. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
  2016. ((u32 *)(&m_fair_vn))[i]);
  2017. }
  2018. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2019. {
  2020. if (CHIP_REV_IS_SLOW(bp))
  2021. return CMNG_FNS_NONE;
  2022. if (IS_MF(bp))
  2023. return CMNG_FNS_MINMAX;
  2024. return CMNG_FNS_NONE;
  2025. }
  2026. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2027. {
  2028. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2029. if (BP_NOMCP(bp))
  2030. return; /* what should be the default bvalue in this case */
  2031. /* For 2 port configuration the absolute function number formula
  2032. * is:
  2033. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2034. *
  2035. * and there are 4 functions per port
  2036. *
  2037. * For 4 port configuration it is
  2038. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2039. *
  2040. * and there are 2 functions per port
  2041. */
  2042. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  2043. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2044. if (func >= E1H_FUNC_MAX)
  2045. break;
  2046. bp->mf_config[vn] =
  2047. MF_CFG_RD(bp, func_mf_config[func].config);
  2048. }
  2049. }
  2050. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2051. {
  2052. if (cmng_type == CMNG_FNS_MINMAX) {
  2053. int vn;
  2054. /* clear cmng_enables */
  2055. bp->cmng.flags.cmng_enables = 0;
  2056. /* read mf conf from shmem */
  2057. if (read_cfg)
  2058. bnx2x_read_mf_cfg(bp);
  2059. /* Init rate shaping and fairness contexts */
  2060. bnx2x_init_port_minmax(bp);
  2061. /* vn_weight_sum and enable fairness if not 0 */
  2062. bnx2x_calc_vn_weight_sum(bp);
  2063. /* calculate and set min-max rate for each vn */
  2064. if (bp->port.pmf)
  2065. for (vn = VN_0; vn < E1HVN_MAX; vn++)
  2066. bnx2x_init_vn_minmax(bp, vn);
  2067. /* always enable rate shaping and fairness */
  2068. bp->cmng.flags.cmng_enables |=
  2069. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2070. if (!bp->vn_weight_sum)
  2071. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  2072. " fairness will be disabled\n");
  2073. return;
  2074. }
  2075. /* rate shaping and fairness are disabled */
  2076. DP(NETIF_MSG_IFUP,
  2077. "rate shaping and fairness are disabled\n");
  2078. }
  2079. static inline void bnx2x_link_sync_notify(struct bnx2x *bp)
  2080. {
  2081. int port = BP_PORT(bp);
  2082. int func;
  2083. int vn;
  2084. /* Set the attention towards other drivers on the same port */
  2085. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  2086. if (vn == BP_E1HVN(bp))
  2087. continue;
  2088. func = ((vn << 1) | port);
  2089. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
  2090. (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
  2091. }
  2092. }
  2093. /* This function is called upon link interrupt */
  2094. static void bnx2x_link_attn(struct bnx2x *bp)
  2095. {
  2096. /* Make sure that we are synced with the current statistics */
  2097. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2098. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2099. if (bp->link_vars.link_up) {
  2100. /* dropless flow control */
  2101. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2102. int port = BP_PORT(bp);
  2103. u32 pause_enabled = 0;
  2104. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2105. pause_enabled = 1;
  2106. REG_WR(bp, BAR_USTRORM_INTMEM +
  2107. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2108. pause_enabled);
  2109. }
  2110. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2111. struct host_port_stats *pstats;
  2112. pstats = bnx2x_sp(bp, port_stats);
  2113. /* reset old mac stats */
  2114. memset(&(pstats->mac_stx[0]), 0,
  2115. sizeof(struct mac_stx));
  2116. }
  2117. if (bp->state == BNX2X_STATE_OPEN)
  2118. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2119. }
  2120. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2121. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2122. if (cmng_fns != CMNG_FNS_NONE) {
  2123. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2124. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2125. } else
  2126. /* rate shaping and fairness are disabled */
  2127. DP(NETIF_MSG_IFUP,
  2128. "single function mode without fairness\n");
  2129. }
  2130. __bnx2x_link_report(bp);
  2131. if (IS_MF(bp))
  2132. bnx2x_link_sync_notify(bp);
  2133. }
  2134. void bnx2x__link_status_update(struct bnx2x *bp)
  2135. {
  2136. if (bp->state != BNX2X_STATE_OPEN)
  2137. return;
  2138. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2139. if (bp->link_vars.link_up)
  2140. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2141. else
  2142. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2143. /* indicate link status */
  2144. bnx2x_link_report(bp);
  2145. }
  2146. static void bnx2x_pmf_update(struct bnx2x *bp)
  2147. {
  2148. int port = BP_PORT(bp);
  2149. u32 val;
  2150. bp->port.pmf = 1;
  2151. DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
  2152. /*
  2153. * We need the mb() to ensure the ordering between the writing to
  2154. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2155. */
  2156. smp_mb();
  2157. /* queue a periodic task */
  2158. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2159. bnx2x_dcbx_pmf_update(bp);
  2160. /* enable nig attention */
  2161. val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
  2162. if (bp->common.int_block == INT_BLOCK_HC) {
  2163. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2164. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2165. } else if (!CHIP_IS_E1x(bp)) {
  2166. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2167. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2168. }
  2169. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2170. }
  2171. /* end of Link */
  2172. /* slow path */
  2173. /*
  2174. * General service functions
  2175. */
  2176. /* send the MCP a request, block until there is a reply */
  2177. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2178. {
  2179. int mb_idx = BP_FW_MB_IDX(bp);
  2180. u32 seq;
  2181. u32 rc = 0;
  2182. u32 cnt = 1;
  2183. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2184. mutex_lock(&bp->fw_mb_mutex);
  2185. seq = ++bp->fw_seq;
  2186. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2187. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2188. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2189. (command | seq), param);
  2190. do {
  2191. /* let the FW do it's magic ... */
  2192. msleep(delay);
  2193. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2194. /* Give the FW up to 5 second (500*10ms) */
  2195. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2196. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2197. cnt*delay, rc, seq);
  2198. /* is this a reply to our command? */
  2199. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2200. rc &= FW_MSG_CODE_MASK;
  2201. else {
  2202. /* FW BUG! */
  2203. BNX2X_ERR("FW failed to respond!\n");
  2204. bnx2x_fw_dump(bp);
  2205. rc = 0;
  2206. }
  2207. mutex_unlock(&bp->fw_mb_mutex);
  2208. return rc;
  2209. }
  2210. static u8 stat_counter_valid(struct bnx2x *bp, struct bnx2x_fastpath *fp)
  2211. {
  2212. #ifdef BCM_CNIC
  2213. /* Statistics are not supported for CNIC Clients at the moment */
  2214. if (IS_FCOE_FP(fp))
  2215. return false;
  2216. #endif
  2217. return true;
  2218. }
  2219. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2220. {
  2221. if (CHIP_IS_E1x(bp)) {
  2222. struct tstorm_eth_function_common_config tcfg = {0};
  2223. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2224. }
  2225. /* Enable the function in the FW */
  2226. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2227. storm_memset_func_en(bp, p->func_id, 1);
  2228. /* spq */
  2229. if (p->func_flgs & FUNC_FLG_SPQ) {
  2230. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2231. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2232. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2233. }
  2234. }
  2235. /**
  2236. * bnx2x_get_tx_only_flags - Return common flags
  2237. *
  2238. * @bp device handle
  2239. * @fp queue handle
  2240. * @zero_stats TRUE if statistics zeroing is needed
  2241. *
  2242. * Return the flags that are common for the Tx-only and not normal connections.
  2243. */
  2244. static inline unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2245. struct bnx2x_fastpath *fp,
  2246. bool zero_stats)
  2247. {
  2248. unsigned long flags = 0;
  2249. /* PF driver will always initialize the Queue to an ACTIVE state */
  2250. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2251. /* tx only connections collect statistics (on the same index as the
  2252. * parent connection). The statistics are zeroed when the parent
  2253. * connection is initialized.
  2254. */
  2255. if (stat_counter_valid(bp, fp)) {
  2256. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2257. if (zero_stats)
  2258. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2259. }
  2260. return flags;
  2261. }
  2262. static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2263. struct bnx2x_fastpath *fp,
  2264. bool leading)
  2265. {
  2266. unsigned long flags = 0;
  2267. /* calculate other queue flags */
  2268. if (IS_MF_SD(bp))
  2269. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2270. if (IS_FCOE_FP(fp))
  2271. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2272. if (!fp->disable_tpa) {
  2273. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2274. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2275. }
  2276. if (leading) {
  2277. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2278. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2279. }
  2280. /* Always set HW VLAN stripping */
  2281. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2282. return flags | bnx2x_get_common_flags(bp, fp, true);
  2283. }
  2284. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2285. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2286. u8 cos)
  2287. {
  2288. gen_init->stat_id = bnx2x_stats_id(fp);
  2289. gen_init->spcl_id = fp->cl_id;
  2290. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2291. if (IS_FCOE_FP(fp))
  2292. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2293. else
  2294. gen_init->mtu = bp->dev->mtu;
  2295. gen_init->cos = cos;
  2296. }
  2297. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2298. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2299. struct bnx2x_rxq_setup_params *rxq_init)
  2300. {
  2301. u8 max_sge = 0;
  2302. u16 sge_sz = 0;
  2303. u16 tpa_agg_size = 0;
  2304. if (!fp->disable_tpa) {
  2305. pause->sge_th_hi = 250;
  2306. pause->sge_th_lo = 150;
  2307. tpa_agg_size = min_t(u32,
  2308. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2309. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2310. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2311. SGE_PAGE_SHIFT;
  2312. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2313. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2314. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2315. 0xffff);
  2316. }
  2317. /* pause - not for e1 */
  2318. if (!CHIP_IS_E1(bp)) {
  2319. pause->bd_th_hi = 350;
  2320. pause->bd_th_lo = 250;
  2321. pause->rcq_th_hi = 350;
  2322. pause->rcq_th_lo = 250;
  2323. pause->pri_map = 1;
  2324. }
  2325. /* rxq setup */
  2326. rxq_init->dscr_map = fp->rx_desc_mapping;
  2327. rxq_init->sge_map = fp->rx_sge_mapping;
  2328. rxq_init->rcq_map = fp->rx_comp_mapping;
  2329. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2330. /* This should be a maximum number of data bytes that may be
  2331. * placed on the BD (not including paddings).
  2332. */
  2333. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN -
  2334. IP_HEADER_ALIGNMENT_PADDING;
  2335. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2336. rxq_init->tpa_agg_sz = tpa_agg_size;
  2337. rxq_init->sge_buf_sz = sge_sz;
  2338. rxq_init->max_sges_pkt = max_sge;
  2339. rxq_init->rss_engine_id = BP_FUNC(bp);
  2340. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2341. *
  2342. * For PF Clients it should be the maximum avaliable number.
  2343. * VF driver(s) may want to define it to a smaller value.
  2344. */
  2345. rxq_init->max_tpa_queues =
  2346. (CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
  2347. ETH_MAX_AGGREGATION_QUEUES_E1H_E2);
  2348. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2349. rxq_init->fw_sb_id = fp->fw_sb_id;
  2350. if (IS_FCOE_FP(fp))
  2351. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2352. else
  2353. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2354. }
  2355. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2356. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2357. u8 cos)
  2358. {
  2359. txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
  2360. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2361. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2362. txq_init->fw_sb_id = fp->fw_sb_id;
  2363. /*
  2364. * set the tss leading client id for TX classfication ==
  2365. * leading RSS client id
  2366. */
  2367. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2368. if (IS_FCOE_FP(fp)) {
  2369. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2370. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2371. }
  2372. }
  2373. static void bnx2x_pf_init(struct bnx2x *bp)
  2374. {
  2375. struct bnx2x_func_init_params func_init = {0};
  2376. struct event_ring_data eq_data = { {0} };
  2377. u16 flags;
  2378. if (!CHIP_IS_E1x(bp)) {
  2379. /* reset IGU PF statistics: MSIX + ATTN */
  2380. /* PF */
  2381. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2382. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2383. (CHIP_MODE_IS_4_PORT(bp) ?
  2384. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2385. /* ATTN */
  2386. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2387. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2388. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2389. (CHIP_MODE_IS_4_PORT(bp) ?
  2390. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2391. }
  2392. /* function setup flags */
  2393. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2394. /* This flag is relevant for E1x only.
  2395. * E2 doesn't have a TPA configuration in a function level.
  2396. */
  2397. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2398. func_init.func_flgs = flags;
  2399. func_init.pf_id = BP_FUNC(bp);
  2400. func_init.func_id = BP_FUNC(bp);
  2401. func_init.spq_map = bp->spq_mapping;
  2402. func_init.spq_prod = bp->spq_prod_idx;
  2403. bnx2x_func_init(bp, &func_init);
  2404. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2405. /*
  2406. * Congestion management values depend on the link rate
  2407. * There is no active link so initial link rate is set to 10 Gbps.
  2408. * When the link comes up The congestion management values are
  2409. * re-calculated according to the actual link rate.
  2410. */
  2411. bp->link_vars.line_speed = SPEED_10000;
  2412. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2413. /* Only the PMF sets the HW */
  2414. if (bp->port.pmf)
  2415. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2416. /* init Event Queue */
  2417. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2418. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2419. eq_data.producer = bp->eq_prod;
  2420. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2421. eq_data.sb_id = DEF_SB_ID;
  2422. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2423. }
  2424. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2425. {
  2426. int port = BP_PORT(bp);
  2427. bnx2x_tx_disable(bp);
  2428. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2429. }
  2430. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2431. {
  2432. int port = BP_PORT(bp);
  2433. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2434. /* Tx queue should be only reenabled */
  2435. netif_tx_wake_all_queues(bp->dev);
  2436. /*
  2437. * Should not call netif_carrier_on since it will be called if the link
  2438. * is up when checking for link state
  2439. */
  2440. }
  2441. /* called due to MCP event (on pmf):
  2442. * reread new bandwidth configuration
  2443. * configure FW
  2444. * notify others function about the change
  2445. */
  2446. static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
  2447. {
  2448. if (bp->link_vars.link_up) {
  2449. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2450. bnx2x_link_sync_notify(bp);
  2451. }
  2452. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2453. }
  2454. static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
  2455. {
  2456. bnx2x_config_mf_bw(bp);
  2457. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2458. }
  2459. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2460. {
  2461. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2462. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2463. /*
  2464. * This is the only place besides the function initialization
  2465. * where the bp->flags can change so it is done without any
  2466. * locks
  2467. */
  2468. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2469. DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
  2470. bp->flags |= MF_FUNC_DIS;
  2471. bnx2x_e1h_disable(bp);
  2472. } else {
  2473. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2474. bp->flags &= ~MF_FUNC_DIS;
  2475. bnx2x_e1h_enable(bp);
  2476. }
  2477. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2478. }
  2479. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2480. bnx2x_config_mf_bw(bp);
  2481. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2482. }
  2483. /* Report results to MCP */
  2484. if (dcc_event)
  2485. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2486. else
  2487. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2488. }
  2489. /* must be called under the spq lock */
  2490. static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2491. {
  2492. struct eth_spe *next_spe = bp->spq_prod_bd;
  2493. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2494. bp->spq_prod_bd = bp->spq;
  2495. bp->spq_prod_idx = 0;
  2496. DP(NETIF_MSG_TIMER, "end of spq\n");
  2497. } else {
  2498. bp->spq_prod_bd++;
  2499. bp->spq_prod_idx++;
  2500. }
  2501. return next_spe;
  2502. }
  2503. /* must be called under the spq lock */
  2504. static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
  2505. {
  2506. int func = BP_FUNC(bp);
  2507. /*
  2508. * Make sure that BD data is updated before writing the producer:
  2509. * BD data is written to the memory, the producer is read from the
  2510. * memory, thus we need a full memory barrier to ensure the ordering.
  2511. */
  2512. mb();
  2513. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2514. bp->spq_prod_idx);
  2515. mmiowb();
  2516. }
  2517. /**
  2518. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2519. *
  2520. * @cmd: command to check
  2521. * @cmd_type: command type
  2522. */
  2523. static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2524. {
  2525. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2526. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2527. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2528. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2529. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2530. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2531. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2532. return true;
  2533. else
  2534. return false;
  2535. }
  2536. /**
  2537. * bnx2x_sp_post - place a single command on an SP ring
  2538. *
  2539. * @bp: driver handle
  2540. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2541. * @cid: SW CID the command is related to
  2542. * @data_hi: command private data address (high 32 bits)
  2543. * @data_lo: command private data address (low 32 bits)
  2544. * @cmd_type: command type (e.g. NONE, ETH)
  2545. *
  2546. * SP data is handled as if it's always an address pair, thus data fields are
  2547. * not swapped to little endian in upper functions. Instead this function swaps
  2548. * data as if it's two u32 fields.
  2549. */
  2550. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2551. u32 data_hi, u32 data_lo, int cmd_type)
  2552. {
  2553. struct eth_spe *spe;
  2554. u16 type;
  2555. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2556. #ifdef BNX2X_STOP_ON_ERROR
  2557. if (unlikely(bp->panic))
  2558. return -EIO;
  2559. #endif
  2560. spin_lock_bh(&bp->spq_lock);
  2561. if (common) {
  2562. if (!atomic_read(&bp->eq_spq_left)) {
  2563. BNX2X_ERR("BUG! EQ ring full!\n");
  2564. spin_unlock_bh(&bp->spq_lock);
  2565. bnx2x_panic();
  2566. return -EBUSY;
  2567. }
  2568. } else if (!atomic_read(&bp->cq_spq_left)) {
  2569. BNX2X_ERR("BUG! SPQ ring full!\n");
  2570. spin_unlock_bh(&bp->spq_lock);
  2571. bnx2x_panic();
  2572. return -EBUSY;
  2573. }
  2574. spe = bnx2x_sp_get_next(bp);
  2575. /* CID needs port number to be encoded int it */
  2576. spe->hdr.conn_and_cmd_data =
  2577. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2578. HW_CID(bp, cid));
  2579. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2580. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2581. SPE_HDR_FUNCTION_ID);
  2582. spe->hdr.type = cpu_to_le16(type);
  2583. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2584. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2585. /*
  2586. * It's ok if the actual decrement is issued towards the memory
  2587. * somewhere between the spin_lock and spin_unlock. Thus no
  2588. * more explict memory barrier is needed.
  2589. */
  2590. if (common)
  2591. atomic_dec(&bp->eq_spq_left);
  2592. else
  2593. atomic_dec(&bp->cq_spq_left);
  2594. DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
  2595. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) "
  2596. "type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2597. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2598. (u32)(U64_LO(bp->spq_mapping) +
  2599. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2600. HW_CID(bp, cid), data_hi, data_lo, type,
  2601. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2602. bnx2x_sp_prod_update(bp);
  2603. spin_unlock_bh(&bp->spq_lock);
  2604. return 0;
  2605. }
  2606. /* acquire split MCP access lock register */
  2607. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2608. {
  2609. u32 j, val;
  2610. int rc = 0;
  2611. might_sleep();
  2612. for (j = 0; j < 1000; j++) {
  2613. val = (1UL << 31);
  2614. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2615. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2616. if (val & (1L << 31))
  2617. break;
  2618. msleep(5);
  2619. }
  2620. if (!(val & (1L << 31))) {
  2621. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2622. rc = -EBUSY;
  2623. }
  2624. return rc;
  2625. }
  2626. /* release split MCP access lock register */
  2627. static void bnx2x_release_alr(struct bnx2x *bp)
  2628. {
  2629. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2630. }
  2631. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2632. #define BNX2X_DEF_SB_IDX 0x0002
  2633. static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2634. {
  2635. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2636. u16 rc = 0;
  2637. barrier(); /* status block is written to by the chip */
  2638. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2639. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2640. rc |= BNX2X_DEF_SB_ATT_IDX;
  2641. }
  2642. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2643. bp->def_idx = def_sb->sp_sb.running_index;
  2644. rc |= BNX2X_DEF_SB_IDX;
  2645. }
  2646. /* Do not reorder: indecies reading should complete before handling */
  2647. barrier();
  2648. return rc;
  2649. }
  2650. /*
  2651. * slow path service functions
  2652. */
  2653. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2654. {
  2655. int port = BP_PORT(bp);
  2656. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2657. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2658. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2659. NIG_REG_MASK_INTERRUPT_PORT0;
  2660. u32 aeu_mask;
  2661. u32 nig_mask = 0;
  2662. u32 reg_addr;
  2663. if (bp->attn_state & asserted)
  2664. BNX2X_ERR("IGU ERROR\n");
  2665. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2666. aeu_mask = REG_RD(bp, aeu_addr);
  2667. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2668. aeu_mask, asserted);
  2669. aeu_mask &= ~(asserted & 0x3ff);
  2670. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2671. REG_WR(bp, aeu_addr, aeu_mask);
  2672. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2673. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2674. bp->attn_state |= asserted;
  2675. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2676. if (asserted & ATTN_HARD_WIRED_MASK) {
  2677. if (asserted & ATTN_NIG_FOR_FUNC) {
  2678. bnx2x_acquire_phy_lock(bp);
  2679. /* save nig interrupt mask */
  2680. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2681. /* If nig_mask is not set, no need to call the update
  2682. * function.
  2683. */
  2684. if (nig_mask) {
  2685. REG_WR(bp, nig_int_mask_addr, 0);
  2686. bnx2x_link_attn(bp);
  2687. }
  2688. /* handle unicore attn? */
  2689. }
  2690. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2691. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2692. if (asserted & GPIO_2_FUNC)
  2693. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2694. if (asserted & GPIO_3_FUNC)
  2695. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2696. if (asserted & GPIO_4_FUNC)
  2697. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2698. if (port == 0) {
  2699. if (asserted & ATTN_GENERAL_ATTN_1) {
  2700. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2701. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2702. }
  2703. if (asserted & ATTN_GENERAL_ATTN_2) {
  2704. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2705. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2706. }
  2707. if (asserted & ATTN_GENERAL_ATTN_3) {
  2708. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2709. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2710. }
  2711. } else {
  2712. if (asserted & ATTN_GENERAL_ATTN_4) {
  2713. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2714. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2715. }
  2716. if (asserted & ATTN_GENERAL_ATTN_5) {
  2717. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2718. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2719. }
  2720. if (asserted & ATTN_GENERAL_ATTN_6) {
  2721. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2722. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2723. }
  2724. }
  2725. } /* if hardwired */
  2726. if (bp->common.int_block == INT_BLOCK_HC)
  2727. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2728. COMMAND_REG_ATTN_BITS_SET);
  2729. else
  2730. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2731. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2732. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2733. REG_WR(bp, reg_addr, asserted);
  2734. /* now set back the mask */
  2735. if (asserted & ATTN_NIG_FOR_FUNC) {
  2736. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2737. bnx2x_release_phy_lock(bp);
  2738. }
  2739. }
  2740. static inline void bnx2x_fan_failure(struct bnx2x *bp)
  2741. {
  2742. int port = BP_PORT(bp);
  2743. u32 ext_phy_config;
  2744. /* mark the failure */
  2745. ext_phy_config =
  2746. SHMEM_RD(bp,
  2747. dev_info.port_hw_config[port].external_phy_config);
  2748. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2749. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2750. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2751. ext_phy_config);
  2752. /* log the failure */
  2753. netdev_err(bp->dev, "Fan Failure on Network Controller has caused"
  2754. " the driver to shutdown the card to prevent permanent"
  2755. " damage. Please contact OEM Support for assistance\n");
  2756. }
  2757. static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  2758. {
  2759. int port = BP_PORT(bp);
  2760. int reg_offset;
  2761. u32 val;
  2762. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  2763. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  2764. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  2765. val = REG_RD(bp, reg_offset);
  2766. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  2767. REG_WR(bp, reg_offset, val);
  2768. BNX2X_ERR("SPIO5 hw attention\n");
  2769. /* Fan failure attention */
  2770. bnx2x_hw_reset_phy(&bp->link_params);
  2771. bnx2x_fan_failure(bp);
  2772. }
  2773. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  2774. bnx2x_acquire_phy_lock(bp);
  2775. bnx2x_handle_module_detect_int(&bp->link_params);
  2776. bnx2x_release_phy_lock(bp);
  2777. }
  2778. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  2779. val = REG_RD(bp, reg_offset);
  2780. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  2781. REG_WR(bp, reg_offset, val);
  2782. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  2783. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  2784. bnx2x_panic();
  2785. }
  2786. }
  2787. static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  2788. {
  2789. u32 val;
  2790. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  2791. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  2792. BNX2X_ERR("DB hw attention 0x%x\n", val);
  2793. /* DORQ discard attention */
  2794. if (val & 0x2)
  2795. BNX2X_ERR("FATAL error from DORQ\n");
  2796. }
  2797. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  2798. int port = BP_PORT(bp);
  2799. int reg_offset;
  2800. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  2801. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  2802. val = REG_RD(bp, reg_offset);
  2803. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  2804. REG_WR(bp, reg_offset, val);
  2805. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  2806. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  2807. bnx2x_panic();
  2808. }
  2809. }
  2810. static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  2811. {
  2812. u32 val;
  2813. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  2814. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  2815. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  2816. /* CFC error attention */
  2817. if (val & 0x2)
  2818. BNX2X_ERR("FATAL error from CFC\n");
  2819. }
  2820. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  2821. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  2822. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  2823. /* RQ_USDMDP_FIFO_OVERFLOW */
  2824. if (val & 0x18000)
  2825. BNX2X_ERR("FATAL error from PXP\n");
  2826. if (!CHIP_IS_E1x(bp)) {
  2827. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  2828. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  2829. }
  2830. }
  2831. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  2832. int port = BP_PORT(bp);
  2833. int reg_offset;
  2834. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  2835. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  2836. val = REG_RD(bp, reg_offset);
  2837. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  2838. REG_WR(bp, reg_offset, val);
  2839. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  2840. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  2841. bnx2x_panic();
  2842. }
  2843. }
  2844. static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  2845. {
  2846. u32 val;
  2847. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  2848. if (attn & BNX2X_PMF_LINK_ASSERT) {
  2849. int func = BP_FUNC(bp);
  2850. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  2851. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  2852. func_mf_config[BP_ABS_FUNC(bp)].config);
  2853. val = SHMEM_RD(bp,
  2854. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  2855. if (val & DRV_STATUS_DCC_EVENT_MASK)
  2856. bnx2x_dcc_event(bp,
  2857. (val & DRV_STATUS_DCC_EVENT_MASK));
  2858. if (val & DRV_STATUS_SET_MF_BW)
  2859. bnx2x_set_mf_bw(bp);
  2860. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  2861. bnx2x_pmf_update(bp);
  2862. if (bp->port.pmf &&
  2863. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  2864. bp->dcbx_enabled > 0)
  2865. /* start dcbx state machine */
  2866. bnx2x_dcbx_set_params(bp,
  2867. BNX2X_DCBX_STATE_NEG_RECEIVED);
  2868. if (bp->link_vars.periodic_flags &
  2869. PERIODIC_FLAGS_LINK_EVENT) {
  2870. /* sync with link */
  2871. bnx2x_acquire_phy_lock(bp);
  2872. bp->link_vars.periodic_flags &=
  2873. ~PERIODIC_FLAGS_LINK_EVENT;
  2874. bnx2x_release_phy_lock(bp);
  2875. if (IS_MF(bp))
  2876. bnx2x_link_sync_notify(bp);
  2877. bnx2x_link_report(bp);
  2878. }
  2879. /* Always call it here: bnx2x_link_report() will
  2880. * prevent the link indication duplication.
  2881. */
  2882. bnx2x__link_status_update(bp);
  2883. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  2884. BNX2X_ERR("MC assert!\n");
  2885. bnx2x_mc_assert(bp);
  2886. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  2887. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  2888. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  2889. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  2890. bnx2x_panic();
  2891. } else if (attn & BNX2X_MCP_ASSERT) {
  2892. BNX2X_ERR("MCP assert!\n");
  2893. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  2894. bnx2x_fw_dump(bp);
  2895. } else
  2896. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  2897. }
  2898. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  2899. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  2900. if (attn & BNX2X_GRC_TIMEOUT) {
  2901. val = CHIP_IS_E1(bp) ? 0 :
  2902. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  2903. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  2904. }
  2905. if (attn & BNX2X_GRC_RSV) {
  2906. val = CHIP_IS_E1(bp) ? 0 :
  2907. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  2908. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  2909. }
  2910. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  2911. }
  2912. }
  2913. /*
  2914. * Bits map:
  2915. * 0-7 - Engine0 load counter.
  2916. * 8-15 - Engine1 load counter.
  2917. * 16 - Engine0 RESET_IN_PROGRESS bit.
  2918. * 17 - Engine1 RESET_IN_PROGRESS bit.
  2919. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  2920. * on the engine
  2921. * 19 - Engine1 ONE_IS_LOADED.
  2922. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  2923. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  2924. * just the one belonging to its engine).
  2925. *
  2926. */
  2927. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  2928. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  2929. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  2930. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  2931. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  2932. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  2933. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  2934. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  2935. /*
  2936. * Set the GLOBAL_RESET bit.
  2937. *
  2938. * Should be run under rtnl lock
  2939. */
  2940. void bnx2x_set_reset_global(struct bnx2x *bp)
  2941. {
  2942. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2943. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  2944. barrier();
  2945. mmiowb();
  2946. }
  2947. /*
  2948. * Clear the GLOBAL_RESET bit.
  2949. *
  2950. * Should be run under rtnl lock
  2951. */
  2952. static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
  2953. {
  2954. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2955. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  2956. barrier();
  2957. mmiowb();
  2958. }
  2959. /*
  2960. * Checks the GLOBAL_RESET bit.
  2961. *
  2962. * should be run under rtnl lock
  2963. */
  2964. static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
  2965. {
  2966. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2967. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  2968. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  2969. }
  2970. /*
  2971. * Clear RESET_IN_PROGRESS bit for the current engine.
  2972. *
  2973. * Should be run under rtnl lock
  2974. */
  2975. static inline void bnx2x_set_reset_done(struct bnx2x *bp)
  2976. {
  2977. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2978. u32 bit = BP_PATH(bp) ?
  2979. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  2980. /* Clear the bit */
  2981. val &= ~bit;
  2982. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  2983. barrier();
  2984. mmiowb();
  2985. }
  2986. /*
  2987. * Set RESET_IN_PROGRESS for the current engine.
  2988. *
  2989. * should be run under rtnl lock
  2990. */
  2991. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  2992. {
  2993. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  2994. u32 bit = BP_PATH(bp) ?
  2995. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  2996. /* Set the bit */
  2997. val |= bit;
  2998. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  2999. barrier();
  3000. mmiowb();
  3001. }
  3002. /*
  3003. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3004. * should be run under rtnl lock
  3005. */
  3006. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3007. {
  3008. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3009. u32 bit = engine ?
  3010. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3011. /* return false if bit is set */
  3012. return (val & bit) ? false : true;
  3013. }
  3014. /*
  3015. * Increment the load counter for the current engine.
  3016. *
  3017. * should be run under rtnl lock
  3018. */
  3019. void bnx2x_inc_load_cnt(struct bnx2x *bp)
  3020. {
  3021. u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3022. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3023. BNX2X_PATH0_LOAD_CNT_MASK;
  3024. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3025. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3026. DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
  3027. /* get the current counter value */
  3028. val1 = (val & mask) >> shift;
  3029. /* increment... */
  3030. val1++;
  3031. /* clear the old value */
  3032. val &= ~mask;
  3033. /* set the new one */
  3034. val |= ((val1 << shift) & mask);
  3035. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3036. barrier();
  3037. mmiowb();
  3038. }
  3039. /**
  3040. * bnx2x_dec_load_cnt - decrement the load counter
  3041. *
  3042. * @bp: driver handle
  3043. *
  3044. * Should be run under rtnl lock.
  3045. * Decrements the load counter for the current engine. Returns
  3046. * the new counter value.
  3047. */
  3048. u32 bnx2x_dec_load_cnt(struct bnx2x *bp)
  3049. {
  3050. u32 val1, val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3051. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3052. BNX2X_PATH0_LOAD_CNT_MASK;
  3053. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3054. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3055. DP(NETIF_MSG_HW, "Old GEN_REG_VAL=0x%08x\n", val);
  3056. /* get the current counter value */
  3057. val1 = (val & mask) >> shift;
  3058. /* decrement... */
  3059. val1--;
  3060. /* clear the old value */
  3061. val &= ~mask;
  3062. /* set the new one */
  3063. val |= ((val1 << shift) & mask);
  3064. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3065. barrier();
  3066. mmiowb();
  3067. return val1;
  3068. }
  3069. /*
  3070. * Read the load counter for the current engine.
  3071. *
  3072. * should be run under rtnl lock
  3073. */
  3074. static inline u32 bnx2x_get_load_cnt(struct bnx2x *bp, int engine)
  3075. {
  3076. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3077. BNX2X_PATH0_LOAD_CNT_MASK);
  3078. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3079. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3080. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3081. DP(NETIF_MSG_HW, "GLOB_REG=0x%08x\n", val);
  3082. val = (val & mask) >> shift;
  3083. DP(NETIF_MSG_HW, "load_cnt for engine %d = %d\n", engine, val);
  3084. return val;
  3085. }
  3086. /*
  3087. * Reset the load counter for the current engine.
  3088. *
  3089. * should be run under rtnl lock
  3090. */
  3091. static inline void bnx2x_clear_load_cnt(struct bnx2x *bp)
  3092. {
  3093. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3094. u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3095. BNX2X_PATH0_LOAD_CNT_MASK);
  3096. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
  3097. }
  3098. static inline void _print_next_block(int idx, const char *blk)
  3099. {
  3100. if (idx)
  3101. pr_cont(", ");
  3102. pr_cont("%s", blk);
  3103. }
  3104. static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3105. bool print)
  3106. {
  3107. int i = 0;
  3108. u32 cur_bit = 0;
  3109. for (i = 0; sig; i++) {
  3110. cur_bit = ((u32)0x1 << i);
  3111. if (sig & cur_bit) {
  3112. switch (cur_bit) {
  3113. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3114. if (print)
  3115. _print_next_block(par_num++, "BRB");
  3116. break;
  3117. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3118. if (print)
  3119. _print_next_block(par_num++, "PARSER");
  3120. break;
  3121. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3122. if (print)
  3123. _print_next_block(par_num++, "TSDM");
  3124. break;
  3125. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3126. if (print)
  3127. _print_next_block(par_num++,
  3128. "SEARCHER");
  3129. break;
  3130. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3131. if (print)
  3132. _print_next_block(par_num++, "TCM");
  3133. break;
  3134. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3135. if (print)
  3136. _print_next_block(par_num++, "TSEMI");
  3137. break;
  3138. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3139. if (print)
  3140. _print_next_block(par_num++, "XPB");
  3141. break;
  3142. }
  3143. /* Clear the bit */
  3144. sig &= ~cur_bit;
  3145. }
  3146. }
  3147. return par_num;
  3148. }
  3149. static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3150. bool *global, bool print)
  3151. {
  3152. int i = 0;
  3153. u32 cur_bit = 0;
  3154. for (i = 0; sig; i++) {
  3155. cur_bit = ((u32)0x1 << i);
  3156. if (sig & cur_bit) {
  3157. switch (cur_bit) {
  3158. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3159. if (print)
  3160. _print_next_block(par_num++, "PBF");
  3161. break;
  3162. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3163. if (print)
  3164. _print_next_block(par_num++, "QM");
  3165. break;
  3166. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3167. if (print)
  3168. _print_next_block(par_num++, "TM");
  3169. break;
  3170. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3171. if (print)
  3172. _print_next_block(par_num++, "XSDM");
  3173. break;
  3174. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3175. if (print)
  3176. _print_next_block(par_num++, "XCM");
  3177. break;
  3178. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3179. if (print)
  3180. _print_next_block(par_num++, "XSEMI");
  3181. break;
  3182. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3183. if (print)
  3184. _print_next_block(par_num++,
  3185. "DOORBELLQ");
  3186. break;
  3187. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3188. if (print)
  3189. _print_next_block(par_num++, "NIG");
  3190. break;
  3191. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3192. if (print)
  3193. _print_next_block(par_num++,
  3194. "VAUX PCI CORE");
  3195. *global = true;
  3196. break;
  3197. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3198. if (print)
  3199. _print_next_block(par_num++, "DEBUG");
  3200. break;
  3201. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3202. if (print)
  3203. _print_next_block(par_num++, "USDM");
  3204. break;
  3205. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3206. if (print)
  3207. _print_next_block(par_num++, "UCM");
  3208. break;
  3209. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3210. if (print)
  3211. _print_next_block(par_num++, "USEMI");
  3212. break;
  3213. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3214. if (print)
  3215. _print_next_block(par_num++, "UPB");
  3216. break;
  3217. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3218. if (print)
  3219. _print_next_block(par_num++, "CSDM");
  3220. break;
  3221. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3222. if (print)
  3223. _print_next_block(par_num++, "CCM");
  3224. break;
  3225. }
  3226. /* Clear the bit */
  3227. sig &= ~cur_bit;
  3228. }
  3229. }
  3230. return par_num;
  3231. }
  3232. static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3233. bool print)
  3234. {
  3235. int i = 0;
  3236. u32 cur_bit = 0;
  3237. for (i = 0; sig; i++) {
  3238. cur_bit = ((u32)0x1 << i);
  3239. if (sig & cur_bit) {
  3240. switch (cur_bit) {
  3241. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3242. if (print)
  3243. _print_next_block(par_num++, "CSEMI");
  3244. break;
  3245. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3246. if (print)
  3247. _print_next_block(par_num++, "PXP");
  3248. break;
  3249. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3250. if (print)
  3251. _print_next_block(par_num++,
  3252. "PXPPCICLOCKCLIENT");
  3253. break;
  3254. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3255. if (print)
  3256. _print_next_block(par_num++, "CFC");
  3257. break;
  3258. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3259. if (print)
  3260. _print_next_block(par_num++, "CDU");
  3261. break;
  3262. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3263. if (print)
  3264. _print_next_block(par_num++, "DMAE");
  3265. break;
  3266. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3267. if (print)
  3268. _print_next_block(par_num++, "IGU");
  3269. break;
  3270. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3271. if (print)
  3272. _print_next_block(par_num++, "MISC");
  3273. break;
  3274. }
  3275. /* Clear the bit */
  3276. sig &= ~cur_bit;
  3277. }
  3278. }
  3279. return par_num;
  3280. }
  3281. static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3282. bool *global, bool print)
  3283. {
  3284. int i = 0;
  3285. u32 cur_bit = 0;
  3286. for (i = 0; sig; i++) {
  3287. cur_bit = ((u32)0x1 << i);
  3288. if (sig & cur_bit) {
  3289. switch (cur_bit) {
  3290. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3291. if (print)
  3292. _print_next_block(par_num++, "MCP ROM");
  3293. *global = true;
  3294. break;
  3295. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3296. if (print)
  3297. _print_next_block(par_num++,
  3298. "MCP UMP RX");
  3299. *global = true;
  3300. break;
  3301. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3302. if (print)
  3303. _print_next_block(par_num++,
  3304. "MCP UMP TX");
  3305. *global = true;
  3306. break;
  3307. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3308. if (print)
  3309. _print_next_block(par_num++,
  3310. "MCP SCPAD");
  3311. *global = true;
  3312. break;
  3313. }
  3314. /* Clear the bit */
  3315. sig &= ~cur_bit;
  3316. }
  3317. }
  3318. return par_num;
  3319. }
  3320. static inline int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3321. bool print)
  3322. {
  3323. int i = 0;
  3324. u32 cur_bit = 0;
  3325. for (i = 0; sig; i++) {
  3326. cur_bit = ((u32)0x1 << i);
  3327. if (sig & cur_bit) {
  3328. switch (cur_bit) {
  3329. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3330. if (print)
  3331. _print_next_block(par_num++, "PGLUE_B");
  3332. break;
  3333. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3334. if (print)
  3335. _print_next_block(par_num++, "ATC");
  3336. break;
  3337. }
  3338. /* Clear the bit */
  3339. sig &= ~cur_bit;
  3340. }
  3341. }
  3342. return par_num;
  3343. }
  3344. static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3345. u32 *sig)
  3346. {
  3347. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3348. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3349. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3350. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3351. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3352. int par_num = 0;
  3353. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention: "
  3354. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x "
  3355. "[4]:0x%08x\n",
  3356. sig[0] & HW_PRTY_ASSERT_SET_0,
  3357. sig[1] & HW_PRTY_ASSERT_SET_1,
  3358. sig[2] & HW_PRTY_ASSERT_SET_2,
  3359. sig[3] & HW_PRTY_ASSERT_SET_3,
  3360. sig[4] & HW_PRTY_ASSERT_SET_4);
  3361. if (print)
  3362. netdev_err(bp->dev,
  3363. "Parity errors detected in blocks: ");
  3364. par_num = bnx2x_check_blocks_with_parity0(
  3365. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3366. par_num = bnx2x_check_blocks_with_parity1(
  3367. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3368. par_num = bnx2x_check_blocks_with_parity2(
  3369. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3370. par_num = bnx2x_check_blocks_with_parity3(
  3371. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3372. par_num = bnx2x_check_blocks_with_parity4(
  3373. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3374. if (print)
  3375. pr_cont("\n");
  3376. return true;
  3377. } else
  3378. return false;
  3379. }
  3380. /**
  3381. * bnx2x_chk_parity_attn - checks for parity attentions.
  3382. *
  3383. * @bp: driver handle
  3384. * @global: true if there was a global attention
  3385. * @print: show parity attention in syslog
  3386. */
  3387. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3388. {
  3389. struct attn_route attn = { {0} };
  3390. int port = BP_PORT(bp);
  3391. attn.sig[0] = REG_RD(bp,
  3392. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3393. port*4);
  3394. attn.sig[1] = REG_RD(bp,
  3395. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3396. port*4);
  3397. attn.sig[2] = REG_RD(bp,
  3398. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3399. port*4);
  3400. attn.sig[3] = REG_RD(bp,
  3401. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3402. port*4);
  3403. if (!CHIP_IS_E1x(bp))
  3404. attn.sig[4] = REG_RD(bp,
  3405. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3406. port*4);
  3407. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3408. }
  3409. static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3410. {
  3411. u32 val;
  3412. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3413. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3414. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3415. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3416. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3417. "ADDRESS_ERROR\n");
  3418. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3419. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3420. "INCORRECT_RCV_BEHAVIOR\n");
  3421. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3422. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3423. "WAS_ERROR_ATTN\n");
  3424. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3425. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3426. "VF_LENGTH_VIOLATION_ATTN\n");
  3427. if (val &
  3428. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3429. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3430. "VF_GRC_SPACE_VIOLATION_ATTN\n");
  3431. if (val &
  3432. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3433. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3434. "VF_MSIX_BAR_VIOLATION_ATTN\n");
  3435. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3436. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3437. "TCPL_ERROR_ATTN\n");
  3438. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3439. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3440. "TCPL_IN_TWO_RCBS_ATTN\n");
  3441. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3442. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_"
  3443. "CSSNOOP_FIFO_OVERFLOW\n");
  3444. }
  3445. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3446. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3447. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3448. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3449. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3450. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3451. BNX2X_ERR("ATC_ATC_INT_STS_REG"
  3452. "_ATC_TCPL_TO_NOT_PEND\n");
  3453. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3454. BNX2X_ERR("ATC_ATC_INT_STS_REG_"
  3455. "ATC_GPA_MULTIPLE_HITS\n");
  3456. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3457. BNX2X_ERR("ATC_ATC_INT_STS_REG_"
  3458. "ATC_RCPL_TO_EMPTY_CNT\n");
  3459. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3460. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3461. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3462. BNX2X_ERR("ATC_ATC_INT_STS_REG_"
  3463. "ATC_IREQ_LESS_THAN_STU\n");
  3464. }
  3465. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3466. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3467. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3468. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3469. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3470. }
  3471. }
  3472. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3473. {
  3474. struct attn_route attn, *group_mask;
  3475. int port = BP_PORT(bp);
  3476. int index;
  3477. u32 reg_addr;
  3478. u32 val;
  3479. u32 aeu_mask;
  3480. bool global = false;
  3481. /* need to take HW lock because MCP or other port might also
  3482. try to handle this event */
  3483. bnx2x_acquire_alr(bp);
  3484. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3485. #ifndef BNX2X_STOP_ON_ERROR
  3486. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3487. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3488. /* Disable HW interrupts */
  3489. bnx2x_int_disable(bp);
  3490. /* In case of parity errors don't handle attentions so that
  3491. * other function would "see" parity errors.
  3492. */
  3493. #else
  3494. bnx2x_panic();
  3495. #endif
  3496. bnx2x_release_alr(bp);
  3497. return;
  3498. }
  3499. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3500. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3501. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3502. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3503. if (!CHIP_IS_E1x(bp))
  3504. attn.sig[4] =
  3505. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3506. else
  3507. attn.sig[4] = 0;
  3508. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3509. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3510. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3511. if (deasserted & (1 << index)) {
  3512. group_mask = &bp->attn_group[index];
  3513. DP(NETIF_MSG_HW, "group[%d]: %08x %08x "
  3514. "%08x %08x %08x\n",
  3515. index,
  3516. group_mask->sig[0], group_mask->sig[1],
  3517. group_mask->sig[2], group_mask->sig[3],
  3518. group_mask->sig[4]);
  3519. bnx2x_attn_int_deasserted4(bp,
  3520. attn.sig[4] & group_mask->sig[4]);
  3521. bnx2x_attn_int_deasserted3(bp,
  3522. attn.sig[3] & group_mask->sig[3]);
  3523. bnx2x_attn_int_deasserted1(bp,
  3524. attn.sig[1] & group_mask->sig[1]);
  3525. bnx2x_attn_int_deasserted2(bp,
  3526. attn.sig[2] & group_mask->sig[2]);
  3527. bnx2x_attn_int_deasserted0(bp,
  3528. attn.sig[0] & group_mask->sig[0]);
  3529. }
  3530. }
  3531. bnx2x_release_alr(bp);
  3532. if (bp->common.int_block == INT_BLOCK_HC)
  3533. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3534. COMMAND_REG_ATTN_BITS_CLR);
  3535. else
  3536. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3537. val = ~deasserted;
  3538. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3539. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3540. REG_WR(bp, reg_addr, val);
  3541. if (~bp->attn_state & deasserted)
  3542. BNX2X_ERR("IGU ERROR\n");
  3543. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3544. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3545. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3546. aeu_mask = REG_RD(bp, reg_addr);
  3547. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3548. aeu_mask, deasserted);
  3549. aeu_mask |= (deasserted & 0x3ff);
  3550. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3551. REG_WR(bp, reg_addr, aeu_mask);
  3552. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3553. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3554. bp->attn_state &= ~deasserted;
  3555. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3556. }
  3557. static void bnx2x_attn_int(struct bnx2x *bp)
  3558. {
  3559. /* read local copy of bits */
  3560. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3561. attn_bits);
  3562. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3563. attn_bits_ack);
  3564. u32 attn_state = bp->attn_state;
  3565. /* look for changed bits */
  3566. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3567. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3568. DP(NETIF_MSG_HW,
  3569. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3570. attn_bits, attn_ack, asserted, deasserted);
  3571. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3572. BNX2X_ERR("BAD attention state\n");
  3573. /* handle bits that were raised */
  3574. if (asserted)
  3575. bnx2x_attn_int_asserted(bp, asserted);
  3576. if (deasserted)
  3577. bnx2x_attn_int_deasserted(bp, deasserted);
  3578. }
  3579. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3580. u16 index, u8 op, u8 update)
  3581. {
  3582. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3583. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3584. igu_addr);
  3585. }
  3586. static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3587. {
  3588. /* No memory barriers */
  3589. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3590. mmiowb(); /* keep prod updates ordered */
  3591. }
  3592. #ifdef BCM_CNIC
  3593. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3594. union event_ring_elem *elem)
  3595. {
  3596. u8 err = elem->message.error;
  3597. if (!bp->cnic_eth_dev.starting_cid ||
  3598. (cid < bp->cnic_eth_dev.starting_cid &&
  3599. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3600. return 1;
  3601. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3602. if (unlikely(err)) {
  3603. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3604. cid);
  3605. bnx2x_panic_dump(bp);
  3606. }
  3607. bnx2x_cnic_cfc_comp(bp, cid, err);
  3608. return 0;
  3609. }
  3610. #endif
  3611. static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3612. {
  3613. struct bnx2x_mcast_ramrod_params rparam;
  3614. int rc;
  3615. memset(&rparam, 0, sizeof(rparam));
  3616. rparam.mcast_obj = &bp->mcast_obj;
  3617. netif_addr_lock_bh(bp->dev);
  3618. /* Clear pending state for the last command */
  3619. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3620. /* If there are pending mcast commands - send them */
  3621. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3622. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3623. if (rc < 0)
  3624. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3625. rc);
  3626. }
  3627. netif_addr_unlock_bh(bp->dev);
  3628. }
  3629. static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3630. union event_ring_elem *elem)
  3631. {
  3632. unsigned long ramrod_flags = 0;
  3633. int rc = 0;
  3634. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3635. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3636. /* Always push next commands out, don't wait here */
  3637. __set_bit(RAMROD_CONT, &ramrod_flags);
  3638. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3639. case BNX2X_FILTER_MAC_PENDING:
  3640. #ifdef BCM_CNIC
  3641. if (cid == BNX2X_ISCSI_ETH_CID)
  3642. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3643. else
  3644. #endif
  3645. vlan_mac_obj = &bp->fp[cid].mac_obj;
  3646. break;
  3647. vlan_mac_obj = &bp->fp[cid].mac_obj;
  3648. case BNX2X_FILTER_MCAST_PENDING:
  3649. /* This is only relevant for 57710 where multicast MACs are
  3650. * configured as unicast MACs using the same ramrod.
  3651. */
  3652. bnx2x_handle_mcast_eqe(bp);
  3653. return;
  3654. default:
  3655. BNX2X_ERR("Unsupported classification command: %d\n",
  3656. elem->message.data.eth_event.echo);
  3657. return;
  3658. }
  3659. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3660. if (rc < 0)
  3661. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3662. else if (rc > 0)
  3663. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3664. }
  3665. #ifdef BCM_CNIC
  3666. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3667. #endif
  3668. static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3669. {
  3670. netif_addr_lock_bh(bp->dev);
  3671. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3672. /* Send rx_mode command again if was requested */
  3673. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3674. bnx2x_set_storm_rx_mode(bp);
  3675. #ifdef BCM_CNIC
  3676. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3677. &bp->sp_state))
  3678. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3679. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3680. &bp->sp_state))
  3681. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3682. #endif
  3683. netif_addr_unlock_bh(bp->dev);
  3684. }
  3685. static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  3686. struct bnx2x *bp, u32 cid)
  3687. {
  3688. DP(BNX2X_MSG_SP, "retrieving fp from cid %d", cid);
  3689. #ifdef BCM_CNIC
  3690. if (cid == BNX2X_FCOE_ETH_CID)
  3691. return &bnx2x_fcoe(bp, q_obj);
  3692. else
  3693. #endif
  3694. return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
  3695. }
  3696. static void bnx2x_eq_int(struct bnx2x *bp)
  3697. {
  3698. u16 hw_cons, sw_cons, sw_prod;
  3699. union event_ring_elem *elem;
  3700. u32 cid;
  3701. u8 opcode;
  3702. int spqe_cnt = 0;
  3703. struct bnx2x_queue_sp_obj *q_obj;
  3704. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  3705. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  3706. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  3707. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  3708. * when we get the the next-page we nned to adjust so the loop
  3709. * condition below will be met. The next element is the size of a
  3710. * regular element and hence incrementing by 1
  3711. */
  3712. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  3713. hw_cons++;
  3714. /* This function may never run in parallel with itself for a
  3715. * specific bp, thus there is no need in "paired" read memory
  3716. * barrier here.
  3717. */
  3718. sw_cons = bp->eq_cons;
  3719. sw_prod = bp->eq_prod;
  3720. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  3721. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  3722. for (; sw_cons != hw_cons;
  3723. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  3724. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  3725. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  3726. opcode = elem->message.opcode;
  3727. /* handle eq element */
  3728. switch (opcode) {
  3729. case EVENT_RING_OPCODE_STAT_QUERY:
  3730. DP(NETIF_MSG_TIMER, "got statistics comp event %d\n",
  3731. bp->stats_comp++);
  3732. /* nothing to do with stats comp */
  3733. goto next_spqe;
  3734. case EVENT_RING_OPCODE_CFC_DEL:
  3735. /* handle according to cid range */
  3736. /*
  3737. * we may want to verify here that the bp state is
  3738. * HALTING
  3739. */
  3740. DP(BNX2X_MSG_SP,
  3741. "got delete ramrod for MULTI[%d]\n", cid);
  3742. #ifdef BCM_CNIC
  3743. if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  3744. goto next_spqe;
  3745. #endif
  3746. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  3747. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  3748. break;
  3749. goto next_spqe;
  3750. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  3751. DP(BNX2X_MSG_SP, "got STOP TRAFFIC\n");
  3752. if (f_obj->complete_cmd(bp, f_obj,
  3753. BNX2X_F_CMD_TX_STOP))
  3754. break;
  3755. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  3756. goto next_spqe;
  3757. case EVENT_RING_OPCODE_START_TRAFFIC:
  3758. DP(BNX2X_MSG_SP, "got START TRAFFIC\n");
  3759. if (f_obj->complete_cmd(bp, f_obj,
  3760. BNX2X_F_CMD_TX_START))
  3761. break;
  3762. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  3763. goto next_spqe;
  3764. case EVENT_RING_OPCODE_FUNCTION_START:
  3765. DP(BNX2X_MSG_SP, "got FUNC_START ramrod\n");
  3766. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  3767. break;
  3768. goto next_spqe;
  3769. case EVENT_RING_OPCODE_FUNCTION_STOP:
  3770. DP(BNX2X_MSG_SP, "got FUNC_STOP ramrod\n");
  3771. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  3772. break;
  3773. goto next_spqe;
  3774. }
  3775. switch (opcode | bp->state) {
  3776. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3777. BNX2X_STATE_OPEN):
  3778. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3779. BNX2X_STATE_OPENING_WAIT4_PORT):
  3780. cid = elem->message.data.eth_event.echo &
  3781. BNX2X_SWCID_MASK;
  3782. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  3783. cid);
  3784. rss_raw->clear_pending(rss_raw);
  3785. break;
  3786. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  3787. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  3788. case (EVENT_RING_OPCODE_SET_MAC |
  3789. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3790. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3791. BNX2X_STATE_OPEN):
  3792. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3793. BNX2X_STATE_DIAG):
  3794. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3795. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3796. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  3797. bnx2x_handle_classification_eqe(bp, elem);
  3798. break;
  3799. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3800. BNX2X_STATE_OPEN):
  3801. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3802. BNX2X_STATE_DIAG):
  3803. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3804. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3805. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  3806. bnx2x_handle_mcast_eqe(bp);
  3807. break;
  3808. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3809. BNX2X_STATE_OPEN):
  3810. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3811. BNX2X_STATE_DIAG):
  3812. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3813. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3814. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  3815. bnx2x_handle_rx_mode_eqe(bp);
  3816. break;
  3817. default:
  3818. /* unknown event log error and continue */
  3819. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  3820. elem->message.opcode, bp->state);
  3821. }
  3822. next_spqe:
  3823. spqe_cnt++;
  3824. } /* for */
  3825. smp_mb__before_atomic_inc();
  3826. atomic_add(spqe_cnt, &bp->eq_spq_left);
  3827. bp->eq_cons = sw_cons;
  3828. bp->eq_prod = sw_prod;
  3829. /* Make sure that above mem writes were issued towards the memory */
  3830. smp_wmb();
  3831. /* update producer */
  3832. bnx2x_update_eq_prod(bp, bp->eq_prod);
  3833. }
  3834. static void bnx2x_sp_task(struct work_struct *work)
  3835. {
  3836. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  3837. u16 status;
  3838. status = bnx2x_update_dsb_idx(bp);
  3839. /* if (status == 0) */
  3840. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  3841. DP(NETIF_MSG_INTR, "got a slowpath interrupt (status 0x%x)\n", status);
  3842. /* HW attentions */
  3843. if (status & BNX2X_DEF_SB_ATT_IDX) {
  3844. bnx2x_attn_int(bp);
  3845. status &= ~BNX2X_DEF_SB_ATT_IDX;
  3846. }
  3847. /* SP events: STAT_QUERY and others */
  3848. if (status & BNX2X_DEF_SB_IDX) {
  3849. #ifdef BCM_CNIC
  3850. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  3851. if ((!NO_FCOE(bp)) &&
  3852. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  3853. /*
  3854. * Prevent local bottom-halves from running as
  3855. * we are going to change the local NAPI list.
  3856. */
  3857. local_bh_disable();
  3858. napi_schedule(&bnx2x_fcoe(bp, napi));
  3859. local_bh_enable();
  3860. }
  3861. #endif
  3862. /* Handle EQ completions */
  3863. bnx2x_eq_int(bp);
  3864. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  3865. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  3866. status &= ~BNX2X_DEF_SB_IDX;
  3867. }
  3868. if (unlikely(status))
  3869. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  3870. status);
  3871. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  3872. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  3873. }
  3874. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  3875. {
  3876. struct net_device *dev = dev_instance;
  3877. struct bnx2x *bp = netdev_priv(dev);
  3878. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  3879. IGU_INT_DISABLE, 0);
  3880. #ifdef BNX2X_STOP_ON_ERROR
  3881. if (unlikely(bp->panic))
  3882. return IRQ_HANDLED;
  3883. #endif
  3884. #ifdef BCM_CNIC
  3885. {
  3886. struct cnic_ops *c_ops;
  3887. rcu_read_lock();
  3888. c_ops = rcu_dereference(bp->cnic_ops);
  3889. if (c_ops)
  3890. c_ops->cnic_handler(bp->cnic_data, NULL);
  3891. rcu_read_unlock();
  3892. }
  3893. #endif
  3894. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  3895. return IRQ_HANDLED;
  3896. }
  3897. /* end of slow path */
  3898. void bnx2x_drv_pulse(struct bnx2x *bp)
  3899. {
  3900. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  3901. bp->fw_drv_pulse_wr_seq);
  3902. }
  3903. static void bnx2x_timer(unsigned long data)
  3904. {
  3905. u8 cos;
  3906. struct bnx2x *bp = (struct bnx2x *) data;
  3907. if (!netif_running(bp->dev))
  3908. return;
  3909. if (poll) {
  3910. struct bnx2x_fastpath *fp = &bp->fp[0];
  3911. for_each_cos_in_tx_queue(fp, cos)
  3912. bnx2x_tx_int(bp, &fp->txdata[cos]);
  3913. bnx2x_rx_int(fp, 1000);
  3914. }
  3915. if (!BP_NOMCP(bp)) {
  3916. int mb_idx = BP_FW_MB_IDX(bp);
  3917. u32 drv_pulse;
  3918. u32 mcp_pulse;
  3919. ++bp->fw_drv_pulse_wr_seq;
  3920. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  3921. /* TBD - add SYSTEM_TIME */
  3922. drv_pulse = bp->fw_drv_pulse_wr_seq;
  3923. bnx2x_drv_pulse(bp);
  3924. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  3925. MCP_PULSE_SEQ_MASK);
  3926. /* The delta between driver pulse and mcp response
  3927. * should be 1 (before mcp response) or 0 (after mcp response)
  3928. */
  3929. if ((drv_pulse != mcp_pulse) &&
  3930. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  3931. /* someone lost a heartbeat... */
  3932. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  3933. drv_pulse, mcp_pulse);
  3934. }
  3935. }
  3936. if (bp->state == BNX2X_STATE_OPEN)
  3937. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  3938. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3939. }
  3940. /* end of Statistics */
  3941. /* nic init */
  3942. /*
  3943. * nic init service functions
  3944. */
  3945. static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  3946. {
  3947. u32 i;
  3948. if (!(len%4) && !(addr%4))
  3949. for (i = 0; i < len; i += 4)
  3950. REG_WR(bp, addr + i, fill);
  3951. else
  3952. for (i = 0; i < len; i++)
  3953. REG_WR8(bp, addr + i, fill);
  3954. }
  3955. /* helper: writes FP SP data to FW - data_size in dwords */
  3956. static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  3957. int fw_sb_id,
  3958. u32 *sb_data_p,
  3959. u32 data_size)
  3960. {
  3961. int index;
  3962. for (index = 0; index < data_size; index++)
  3963. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3964. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  3965. sizeof(u32)*index,
  3966. *(sb_data_p + index));
  3967. }
  3968. static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  3969. {
  3970. u32 *sb_data_p;
  3971. u32 data_size = 0;
  3972. struct hc_status_block_data_e2 sb_data_e2;
  3973. struct hc_status_block_data_e1x sb_data_e1x;
  3974. /* disable the function first */
  3975. if (!CHIP_IS_E1x(bp)) {
  3976. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  3977. sb_data_e2.common.state = SB_DISABLED;
  3978. sb_data_e2.common.p_func.vf_valid = false;
  3979. sb_data_p = (u32 *)&sb_data_e2;
  3980. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  3981. } else {
  3982. memset(&sb_data_e1x, 0,
  3983. sizeof(struct hc_status_block_data_e1x));
  3984. sb_data_e1x.common.state = SB_DISABLED;
  3985. sb_data_e1x.common.p_func.vf_valid = false;
  3986. sb_data_p = (u32 *)&sb_data_e1x;
  3987. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  3988. }
  3989. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  3990. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  3991. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  3992. CSTORM_STATUS_BLOCK_SIZE);
  3993. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  3994. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  3995. CSTORM_SYNC_BLOCK_SIZE);
  3996. }
  3997. /* helper: writes SP SB data to FW */
  3998. static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  3999. struct hc_sp_status_block_data *sp_sb_data)
  4000. {
  4001. int func = BP_FUNC(bp);
  4002. int i;
  4003. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4004. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4005. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4006. i*sizeof(u32),
  4007. *((u32 *)sp_sb_data + i));
  4008. }
  4009. static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4010. {
  4011. int func = BP_FUNC(bp);
  4012. struct hc_sp_status_block_data sp_sb_data;
  4013. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4014. sp_sb_data.state = SB_DISABLED;
  4015. sp_sb_data.p_func.vf_valid = false;
  4016. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4017. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4018. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4019. CSTORM_SP_STATUS_BLOCK_SIZE);
  4020. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4021. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4022. CSTORM_SP_SYNC_BLOCK_SIZE);
  4023. }
  4024. static inline
  4025. void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4026. int igu_sb_id, int igu_seg_id)
  4027. {
  4028. hc_sm->igu_sb_id = igu_sb_id;
  4029. hc_sm->igu_seg_id = igu_seg_id;
  4030. hc_sm->timer_value = 0xFF;
  4031. hc_sm->time_to_expire = 0xFFFFFFFF;
  4032. }
  4033. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4034. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4035. {
  4036. int igu_seg_id;
  4037. struct hc_status_block_data_e2 sb_data_e2;
  4038. struct hc_status_block_data_e1x sb_data_e1x;
  4039. struct hc_status_block_sm *hc_sm_p;
  4040. int data_size;
  4041. u32 *sb_data_p;
  4042. if (CHIP_INT_MODE_IS_BC(bp))
  4043. igu_seg_id = HC_SEG_ACCESS_NORM;
  4044. else
  4045. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4046. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4047. if (!CHIP_IS_E1x(bp)) {
  4048. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4049. sb_data_e2.common.state = SB_ENABLED;
  4050. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4051. sb_data_e2.common.p_func.vf_id = vfid;
  4052. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4053. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4054. sb_data_e2.common.same_igu_sb_1b = true;
  4055. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4056. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4057. hc_sm_p = sb_data_e2.common.state_machine;
  4058. sb_data_p = (u32 *)&sb_data_e2;
  4059. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4060. } else {
  4061. memset(&sb_data_e1x, 0,
  4062. sizeof(struct hc_status_block_data_e1x));
  4063. sb_data_e1x.common.state = SB_ENABLED;
  4064. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4065. sb_data_e1x.common.p_func.vf_id = 0xff;
  4066. sb_data_e1x.common.p_func.vf_valid = false;
  4067. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4068. sb_data_e1x.common.same_igu_sb_1b = true;
  4069. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4070. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4071. hc_sm_p = sb_data_e1x.common.state_machine;
  4072. sb_data_p = (u32 *)&sb_data_e1x;
  4073. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4074. }
  4075. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4076. igu_sb_id, igu_seg_id);
  4077. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4078. igu_sb_id, igu_seg_id);
  4079. DP(NETIF_MSG_HW, "Init FW SB %d\n", fw_sb_id);
  4080. /* write indecies to HW */
  4081. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4082. }
  4083. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4084. u16 tx_usec, u16 rx_usec)
  4085. {
  4086. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4087. false, rx_usec);
  4088. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4089. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4090. tx_usec);
  4091. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4092. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4093. tx_usec);
  4094. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4095. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4096. tx_usec);
  4097. }
  4098. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4099. {
  4100. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4101. dma_addr_t mapping = bp->def_status_blk_mapping;
  4102. int igu_sp_sb_index;
  4103. int igu_seg_id;
  4104. int port = BP_PORT(bp);
  4105. int func = BP_FUNC(bp);
  4106. int reg_offset;
  4107. u64 section;
  4108. int index;
  4109. struct hc_sp_status_block_data sp_sb_data;
  4110. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4111. if (CHIP_INT_MODE_IS_BC(bp)) {
  4112. igu_sp_sb_index = DEF_SB_IGU_ID;
  4113. igu_seg_id = HC_SEG_ACCESS_DEF;
  4114. } else {
  4115. igu_sp_sb_index = bp->igu_dsb_id;
  4116. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4117. }
  4118. /* ATTN */
  4119. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4120. atten_status_block);
  4121. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4122. bp->attn_state = 0;
  4123. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4124. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4125. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4126. int sindex;
  4127. /* take care of sig[0]..sig[4] */
  4128. for (sindex = 0; sindex < 4; sindex++)
  4129. bp->attn_group[index].sig[sindex] =
  4130. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4131. if (!CHIP_IS_E1x(bp))
  4132. /*
  4133. * enable5 is separate from the rest of the registers,
  4134. * and therefore the address skip is 4
  4135. * and not 16 between the different groups
  4136. */
  4137. bp->attn_group[index].sig[4] = REG_RD(bp,
  4138. reg_offset + 0x10 + 0x4*index);
  4139. else
  4140. bp->attn_group[index].sig[4] = 0;
  4141. }
  4142. if (bp->common.int_block == INT_BLOCK_HC) {
  4143. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4144. HC_REG_ATTN_MSG0_ADDR_L);
  4145. REG_WR(bp, reg_offset, U64_LO(section));
  4146. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4147. } else if (!CHIP_IS_E1x(bp)) {
  4148. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4149. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4150. }
  4151. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4152. sp_sb);
  4153. bnx2x_zero_sp_sb(bp);
  4154. sp_sb_data.state = SB_ENABLED;
  4155. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4156. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4157. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4158. sp_sb_data.igu_seg_id = igu_seg_id;
  4159. sp_sb_data.p_func.pf_id = func;
  4160. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4161. sp_sb_data.p_func.vf_id = 0xff;
  4162. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4163. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4164. }
  4165. void bnx2x_update_coalesce(struct bnx2x *bp)
  4166. {
  4167. int i;
  4168. for_each_eth_queue(bp, i)
  4169. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4170. bp->tx_ticks, bp->rx_ticks);
  4171. }
  4172. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4173. {
  4174. spin_lock_init(&bp->spq_lock);
  4175. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4176. bp->spq_prod_idx = 0;
  4177. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4178. bp->spq_prod_bd = bp->spq;
  4179. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4180. }
  4181. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4182. {
  4183. int i;
  4184. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4185. union event_ring_elem *elem =
  4186. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4187. elem->next_page.addr.hi =
  4188. cpu_to_le32(U64_HI(bp->eq_mapping +
  4189. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4190. elem->next_page.addr.lo =
  4191. cpu_to_le32(U64_LO(bp->eq_mapping +
  4192. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4193. }
  4194. bp->eq_cons = 0;
  4195. bp->eq_prod = NUM_EQ_DESC;
  4196. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4197. /* we want a warning message before it gets rought... */
  4198. atomic_set(&bp->eq_spq_left,
  4199. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4200. }
  4201. /* called with netif_addr_lock_bh() */
  4202. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4203. unsigned long rx_mode_flags,
  4204. unsigned long rx_accept_flags,
  4205. unsigned long tx_accept_flags,
  4206. unsigned long ramrod_flags)
  4207. {
  4208. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4209. int rc;
  4210. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4211. /* Prepare ramrod parameters */
  4212. ramrod_param.cid = 0;
  4213. ramrod_param.cl_id = cl_id;
  4214. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4215. ramrod_param.func_id = BP_FUNC(bp);
  4216. ramrod_param.pstate = &bp->sp_state;
  4217. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4218. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4219. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4220. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4221. ramrod_param.ramrod_flags = ramrod_flags;
  4222. ramrod_param.rx_mode_flags = rx_mode_flags;
  4223. ramrod_param.rx_accept_flags = rx_accept_flags;
  4224. ramrod_param.tx_accept_flags = tx_accept_flags;
  4225. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4226. if (rc < 0) {
  4227. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4228. return;
  4229. }
  4230. }
  4231. /* called with netif_addr_lock_bh() */
  4232. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4233. {
  4234. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4235. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4236. #ifdef BCM_CNIC
  4237. if (!NO_FCOE(bp))
  4238. /* Configure rx_mode of FCoE Queue */
  4239. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4240. #endif
  4241. switch (bp->rx_mode) {
  4242. case BNX2X_RX_MODE_NONE:
  4243. /*
  4244. * 'drop all' supersedes any accept flags that may have been
  4245. * passed to the function.
  4246. */
  4247. break;
  4248. case BNX2X_RX_MODE_NORMAL:
  4249. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4250. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4251. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4252. /* internal switching mode */
  4253. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4254. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4255. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4256. break;
  4257. case BNX2X_RX_MODE_ALLMULTI:
  4258. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4259. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4260. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4261. /* internal switching mode */
  4262. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4263. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4264. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4265. break;
  4266. case BNX2X_RX_MODE_PROMISC:
  4267. /* According to deffinition of SI mode, iface in promisc mode
  4268. * should receive matched and unmatched (in resolution of port)
  4269. * unicast packets.
  4270. */
  4271. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4272. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4273. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4274. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4275. /* internal switching mode */
  4276. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4277. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4278. if (IS_MF_SI(bp))
  4279. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4280. else
  4281. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4282. break;
  4283. default:
  4284. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4285. return;
  4286. }
  4287. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4288. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4289. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4290. }
  4291. __set_bit(RAMROD_RX, &ramrod_flags);
  4292. __set_bit(RAMROD_TX, &ramrod_flags);
  4293. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4294. tx_accept_flags, ramrod_flags);
  4295. }
  4296. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4297. {
  4298. int i;
  4299. if (IS_MF_SI(bp))
  4300. /*
  4301. * In switch independent mode, the TSTORM needs to accept
  4302. * packets that failed classification, since approximate match
  4303. * mac addresses aren't written to NIG LLH
  4304. */
  4305. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4306. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4307. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4308. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4309. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4310. /* Zero this manually as its initialization is
  4311. currently missing in the initTool */
  4312. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4313. REG_WR(bp, BAR_USTRORM_INTMEM +
  4314. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4315. if (!CHIP_IS_E1x(bp)) {
  4316. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4317. CHIP_INT_MODE_IS_BC(bp) ?
  4318. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4319. }
  4320. }
  4321. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4322. {
  4323. switch (load_code) {
  4324. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4325. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4326. bnx2x_init_internal_common(bp);
  4327. /* no break */
  4328. case FW_MSG_CODE_DRV_LOAD_PORT:
  4329. /* nothing to do */
  4330. /* no break */
  4331. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4332. /* internal memory per function is
  4333. initialized inside bnx2x_pf_init */
  4334. break;
  4335. default:
  4336. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4337. break;
  4338. }
  4339. }
  4340. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4341. {
  4342. return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
  4343. }
  4344. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4345. {
  4346. return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
  4347. }
  4348. static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4349. {
  4350. if (CHIP_IS_E1x(fp->bp))
  4351. return BP_L_ID(fp->bp) + fp->index;
  4352. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4353. return bnx2x_fp_igu_sb_id(fp);
  4354. }
  4355. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4356. {
  4357. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4358. u8 cos;
  4359. unsigned long q_type = 0;
  4360. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4361. fp->cid = fp_idx;
  4362. fp->cl_id = bnx2x_fp_cl_id(fp);
  4363. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4364. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4365. /* qZone id equals to FW (per path) client id */
  4366. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4367. /* init shortcut */
  4368. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4369. /* Setup SB indicies */
  4370. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4371. /* Configure Queue State object */
  4372. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4373. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4374. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4375. /* init tx data */
  4376. for_each_cos_in_tx_queue(fp, cos) {
  4377. bnx2x_init_txdata(bp, &fp->txdata[cos],
  4378. CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
  4379. FP_COS_TO_TXQ(fp, cos),
  4380. BNX2X_TX_SB_INDEX_BASE + cos);
  4381. cids[cos] = fp->txdata[cos].cid;
  4382. }
  4383. bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
  4384. BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4385. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4386. /**
  4387. * Configure classification DBs: Always enable Tx switching
  4388. */
  4389. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4390. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) "
  4391. "cl_id %d fw_sb %d igu_sb %d\n",
  4392. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4393. fp->igu_sb_id);
  4394. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4395. fp->fw_sb_id, fp->igu_sb_id);
  4396. bnx2x_update_fpsb_idx(fp);
  4397. }
  4398. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4399. {
  4400. int i;
  4401. for_each_eth_queue(bp, i)
  4402. bnx2x_init_eth_fp(bp, i);
  4403. #ifdef BCM_CNIC
  4404. if (!NO_FCOE(bp))
  4405. bnx2x_init_fcoe_fp(bp);
  4406. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4407. BNX2X_VF_ID_INVALID, false,
  4408. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4409. #endif
  4410. /* Initialize MOD_ABS interrupts */
  4411. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4412. bp->common.shmem_base, bp->common.shmem2_base,
  4413. BP_PORT(bp));
  4414. /* ensure status block indices were read */
  4415. rmb();
  4416. bnx2x_init_def_sb(bp);
  4417. bnx2x_update_dsb_idx(bp);
  4418. bnx2x_init_rx_rings(bp);
  4419. bnx2x_init_tx_rings(bp);
  4420. bnx2x_init_sp_ring(bp);
  4421. bnx2x_init_eq_ring(bp);
  4422. bnx2x_init_internal(bp, load_code);
  4423. bnx2x_pf_init(bp);
  4424. bnx2x_stats_init(bp);
  4425. /* flush all before enabling interrupts */
  4426. mb();
  4427. mmiowb();
  4428. bnx2x_int_enable(bp);
  4429. /* Check for SPIO5 */
  4430. bnx2x_attn_int_deasserted0(bp,
  4431. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4432. AEU_INPUTS_ATTN_BITS_SPIO5);
  4433. }
  4434. /* end of nic init */
  4435. /*
  4436. * gzip service functions
  4437. */
  4438. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4439. {
  4440. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4441. &bp->gunzip_mapping, GFP_KERNEL);
  4442. if (bp->gunzip_buf == NULL)
  4443. goto gunzip_nomem1;
  4444. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4445. if (bp->strm == NULL)
  4446. goto gunzip_nomem2;
  4447. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4448. if (bp->strm->workspace == NULL)
  4449. goto gunzip_nomem3;
  4450. return 0;
  4451. gunzip_nomem3:
  4452. kfree(bp->strm);
  4453. bp->strm = NULL;
  4454. gunzip_nomem2:
  4455. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4456. bp->gunzip_mapping);
  4457. bp->gunzip_buf = NULL;
  4458. gunzip_nomem1:
  4459. netdev_err(bp->dev, "Cannot allocate firmware buffer for"
  4460. " un-compression\n");
  4461. return -ENOMEM;
  4462. }
  4463. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4464. {
  4465. if (bp->strm) {
  4466. vfree(bp->strm->workspace);
  4467. kfree(bp->strm);
  4468. bp->strm = NULL;
  4469. }
  4470. if (bp->gunzip_buf) {
  4471. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4472. bp->gunzip_mapping);
  4473. bp->gunzip_buf = NULL;
  4474. }
  4475. }
  4476. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4477. {
  4478. int n, rc;
  4479. /* check gzip header */
  4480. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4481. BNX2X_ERR("Bad gzip header\n");
  4482. return -EINVAL;
  4483. }
  4484. n = 10;
  4485. #define FNAME 0x8
  4486. if (zbuf[3] & FNAME)
  4487. while ((zbuf[n++] != 0) && (n < len));
  4488. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4489. bp->strm->avail_in = len - n;
  4490. bp->strm->next_out = bp->gunzip_buf;
  4491. bp->strm->avail_out = FW_BUF_SIZE;
  4492. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4493. if (rc != Z_OK)
  4494. return rc;
  4495. rc = zlib_inflate(bp->strm, Z_FINISH);
  4496. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4497. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4498. bp->strm->msg);
  4499. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4500. if (bp->gunzip_outlen & 0x3)
  4501. netdev_err(bp->dev, "Firmware decompression error:"
  4502. " gunzip_outlen (%d) not aligned\n",
  4503. bp->gunzip_outlen);
  4504. bp->gunzip_outlen >>= 2;
  4505. zlib_inflateEnd(bp->strm);
  4506. if (rc == Z_STREAM_END)
  4507. return 0;
  4508. return rc;
  4509. }
  4510. /* nic load/unload */
  4511. /*
  4512. * General service functions
  4513. */
  4514. /* send a NIG loopback debug packet */
  4515. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4516. {
  4517. u32 wb_write[3];
  4518. /* Ethernet source and destination addresses */
  4519. wb_write[0] = 0x55555555;
  4520. wb_write[1] = 0x55555555;
  4521. wb_write[2] = 0x20; /* SOP */
  4522. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4523. /* NON-IP protocol */
  4524. wb_write[0] = 0x09000000;
  4525. wb_write[1] = 0x55555555;
  4526. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4527. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4528. }
  4529. /* some of the internal memories
  4530. * are not directly readable from the driver
  4531. * to test them we send debug packets
  4532. */
  4533. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4534. {
  4535. int factor;
  4536. int count, i;
  4537. u32 val = 0;
  4538. if (CHIP_REV_IS_FPGA(bp))
  4539. factor = 120;
  4540. else if (CHIP_REV_IS_EMUL(bp))
  4541. factor = 200;
  4542. else
  4543. factor = 1;
  4544. /* Disable inputs of parser neighbor blocks */
  4545. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4546. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4547. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4548. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4549. /* Write 0 to parser credits for CFC search request */
  4550. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4551. /* send Ethernet packet */
  4552. bnx2x_lb_pckt(bp);
  4553. /* TODO do i reset NIG statistic? */
  4554. /* Wait until NIG register shows 1 packet of size 0x10 */
  4555. count = 1000 * factor;
  4556. while (count) {
  4557. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4558. val = *bnx2x_sp(bp, wb_data[0]);
  4559. if (val == 0x10)
  4560. break;
  4561. msleep(10);
  4562. count--;
  4563. }
  4564. if (val != 0x10) {
  4565. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4566. return -1;
  4567. }
  4568. /* Wait until PRS register shows 1 packet */
  4569. count = 1000 * factor;
  4570. while (count) {
  4571. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4572. if (val == 1)
  4573. break;
  4574. msleep(10);
  4575. count--;
  4576. }
  4577. if (val != 0x1) {
  4578. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4579. return -2;
  4580. }
  4581. /* Reset and init BRB, PRS */
  4582. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4583. msleep(50);
  4584. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4585. msleep(50);
  4586. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4587. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4588. DP(NETIF_MSG_HW, "part2\n");
  4589. /* Disable inputs of parser neighbor blocks */
  4590. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4591. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4592. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4593. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4594. /* Write 0 to parser credits for CFC search request */
  4595. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4596. /* send 10 Ethernet packets */
  4597. for (i = 0; i < 10; i++)
  4598. bnx2x_lb_pckt(bp);
  4599. /* Wait until NIG register shows 10 + 1
  4600. packets of size 11*0x10 = 0xb0 */
  4601. count = 1000 * factor;
  4602. while (count) {
  4603. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4604. val = *bnx2x_sp(bp, wb_data[0]);
  4605. if (val == 0xb0)
  4606. break;
  4607. msleep(10);
  4608. count--;
  4609. }
  4610. if (val != 0xb0) {
  4611. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4612. return -3;
  4613. }
  4614. /* Wait until PRS register shows 2 packets */
  4615. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4616. if (val != 2)
  4617. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4618. /* Write 1 to parser credits for CFC search request */
  4619. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  4620. /* Wait until PRS register shows 3 packets */
  4621. msleep(10 * factor);
  4622. /* Wait until NIG register shows 1 packet of size 0x10 */
  4623. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4624. if (val != 3)
  4625. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4626. /* clear NIG EOP FIFO */
  4627. for (i = 0; i < 11; i++)
  4628. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  4629. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  4630. if (val != 1) {
  4631. BNX2X_ERR("clear of NIG failed\n");
  4632. return -4;
  4633. }
  4634. /* Reset and init BRB, PRS, NIG */
  4635. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4636. msleep(50);
  4637. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4638. msleep(50);
  4639. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4640. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4641. #ifndef BCM_CNIC
  4642. /* set NIC mode */
  4643. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  4644. #endif
  4645. /* Enable inputs of parser neighbor blocks */
  4646. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  4647. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  4648. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  4649. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  4650. DP(NETIF_MSG_HW, "done\n");
  4651. return 0; /* OK */
  4652. }
  4653. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  4654. {
  4655. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4656. if (!CHIP_IS_E1x(bp))
  4657. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  4658. else
  4659. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  4660. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  4661. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  4662. /*
  4663. * mask read length error interrupts in brb for parser
  4664. * (parsing unit and 'checksum and crc' unit)
  4665. * these errors are legal (PU reads fixed length and CAC can cause
  4666. * read length error on truncated packets)
  4667. */
  4668. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  4669. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  4670. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  4671. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  4672. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  4673. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  4674. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  4675. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  4676. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  4677. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  4678. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  4679. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  4680. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  4681. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  4682. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  4683. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  4684. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  4685. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  4686. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  4687. if (CHIP_REV_IS_FPGA(bp))
  4688. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  4689. else if (!CHIP_IS_E1x(bp))
  4690. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  4691. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  4692. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  4693. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  4694. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  4695. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  4696. else
  4697. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  4698. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  4699. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  4700. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  4701. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  4702. if (!CHIP_IS_E1x(bp))
  4703. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  4704. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  4705. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  4706. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  4707. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  4708. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  4709. }
  4710. static void bnx2x_reset_common(struct bnx2x *bp)
  4711. {
  4712. u32 val = 0x1400;
  4713. /* reset_common */
  4714. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  4715. 0xd3ffff7f);
  4716. if (CHIP_IS_E3(bp)) {
  4717. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  4718. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  4719. }
  4720. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  4721. }
  4722. static void bnx2x_setup_dmae(struct bnx2x *bp)
  4723. {
  4724. bp->dmae_ready = 0;
  4725. spin_lock_init(&bp->dmae_lock);
  4726. }
  4727. static void bnx2x_init_pxp(struct bnx2x *bp)
  4728. {
  4729. u16 devctl;
  4730. int r_order, w_order;
  4731. pci_read_config_word(bp->pdev,
  4732. pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
  4733. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  4734. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  4735. if (bp->mrrs == -1)
  4736. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  4737. else {
  4738. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  4739. r_order = bp->mrrs;
  4740. }
  4741. bnx2x_init_pxp_arb(bp, r_order, w_order);
  4742. }
  4743. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  4744. {
  4745. int is_required;
  4746. u32 val;
  4747. int port;
  4748. if (BP_NOMCP(bp))
  4749. return;
  4750. is_required = 0;
  4751. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  4752. SHARED_HW_CFG_FAN_FAILURE_MASK;
  4753. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  4754. is_required = 1;
  4755. /*
  4756. * The fan failure mechanism is usually related to the PHY type since
  4757. * the power consumption of the board is affected by the PHY. Currently,
  4758. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  4759. */
  4760. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  4761. for (port = PORT_0; port < PORT_MAX; port++) {
  4762. is_required |=
  4763. bnx2x_fan_failure_det_req(
  4764. bp,
  4765. bp->common.shmem_base,
  4766. bp->common.shmem2_base,
  4767. port);
  4768. }
  4769. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  4770. if (is_required == 0)
  4771. return;
  4772. /* Fan failure is indicated by SPIO 5 */
  4773. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  4774. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  4775. /* set to active low mode */
  4776. val = REG_RD(bp, MISC_REG_SPIO_INT);
  4777. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  4778. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  4779. REG_WR(bp, MISC_REG_SPIO_INT, val);
  4780. /* enable interrupt to signal the IGU */
  4781. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  4782. val |= (1 << MISC_REGISTERS_SPIO_5);
  4783. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  4784. }
  4785. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  4786. {
  4787. u32 offset = 0;
  4788. if (CHIP_IS_E1(bp))
  4789. return;
  4790. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  4791. return;
  4792. switch (BP_ABS_FUNC(bp)) {
  4793. case 0:
  4794. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  4795. break;
  4796. case 1:
  4797. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  4798. break;
  4799. case 2:
  4800. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  4801. break;
  4802. case 3:
  4803. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  4804. break;
  4805. case 4:
  4806. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  4807. break;
  4808. case 5:
  4809. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  4810. break;
  4811. case 6:
  4812. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  4813. break;
  4814. case 7:
  4815. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  4816. break;
  4817. default:
  4818. return;
  4819. }
  4820. REG_WR(bp, offset, pretend_func_num);
  4821. REG_RD(bp, offset);
  4822. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  4823. }
  4824. void bnx2x_pf_disable(struct bnx2x *bp)
  4825. {
  4826. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  4827. val &= ~IGU_PF_CONF_FUNC_EN;
  4828. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  4829. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  4830. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  4831. }
  4832. static inline void bnx2x__common_init_phy(struct bnx2x *bp)
  4833. {
  4834. u32 shmem_base[2], shmem2_base[2];
  4835. shmem_base[0] = bp->common.shmem_base;
  4836. shmem2_base[0] = bp->common.shmem2_base;
  4837. if (!CHIP_IS_E1x(bp)) {
  4838. shmem_base[1] =
  4839. SHMEM2_RD(bp, other_shmem_base_addr);
  4840. shmem2_base[1] =
  4841. SHMEM2_RD(bp, other_shmem2_base_addr);
  4842. }
  4843. bnx2x_acquire_phy_lock(bp);
  4844. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  4845. bp->common.chip_id);
  4846. bnx2x_release_phy_lock(bp);
  4847. }
  4848. /**
  4849. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  4850. *
  4851. * @bp: driver handle
  4852. */
  4853. static int bnx2x_init_hw_common(struct bnx2x *bp)
  4854. {
  4855. u32 val;
  4856. DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_ABS_FUNC(bp));
  4857. bnx2x_reset_common(bp);
  4858. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  4859. val = 0xfffc;
  4860. if (CHIP_IS_E3(bp)) {
  4861. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  4862. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  4863. }
  4864. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  4865. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  4866. if (!CHIP_IS_E1x(bp)) {
  4867. u8 abs_func_id;
  4868. /**
  4869. * 4-port mode or 2-port mode we need to turn of master-enable
  4870. * for everyone, after that, turn it back on for self.
  4871. * so, we disregard multi-function or not, and always disable
  4872. * for all functions on the given path, this means 0,2,4,6 for
  4873. * path 0 and 1,3,5,7 for path 1
  4874. */
  4875. for (abs_func_id = BP_PATH(bp);
  4876. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  4877. if (abs_func_id == BP_ABS_FUNC(bp)) {
  4878. REG_WR(bp,
  4879. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  4880. 1);
  4881. continue;
  4882. }
  4883. bnx2x_pretend_func(bp, abs_func_id);
  4884. /* clear pf enable */
  4885. bnx2x_pf_disable(bp);
  4886. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  4887. }
  4888. }
  4889. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  4890. if (CHIP_IS_E1(bp)) {
  4891. /* enable HW interrupt from PXP on USDM overflow
  4892. bit 16 on INT_MASK_0 */
  4893. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4894. }
  4895. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  4896. bnx2x_init_pxp(bp);
  4897. #ifdef __BIG_ENDIAN
  4898. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  4899. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  4900. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  4901. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  4902. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  4903. /* make sure this value is 0 */
  4904. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  4905. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  4906. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  4907. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  4908. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  4909. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  4910. #endif
  4911. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  4912. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  4913. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  4914. /* let the HW do it's magic ... */
  4915. msleep(100);
  4916. /* finish PXP init */
  4917. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  4918. if (val != 1) {
  4919. BNX2X_ERR("PXP2 CFG failed\n");
  4920. return -EBUSY;
  4921. }
  4922. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  4923. if (val != 1) {
  4924. BNX2X_ERR("PXP2 RD_INIT failed\n");
  4925. return -EBUSY;
  4926. }
  4927. /* Timers bug workaround E2 only. We need to set the entire ILT to
  4928. * have entries with value "0" and valid bit on.
  4929. * This needs to be done by the first PF that is loaded in a path
  4930. * (i.e. common phase)
  4931. */
  4932. if (!CHIP_IS_E1x(bp)) {
  4933. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  4934. * (i.e. vnic3) to start even if it is marked as "scan-off".
  4935. * This occurs when a different function (func2,3) is being marked
  4936. * as "scan-off". Real-life scenario for example: if a driver is being
  4937. * load-unloaded while func6,7 are down. This will cause the timer to access
  4938. * the ilt, translate to a logical address and send a request to read/write.
  4939. * Since the ilt for the function that is down is not valid, this will cause
  4940. * a translation error which is unrecoverable.
  4941. * The Workaround is intended to make sure that when this happens nothing fatal
  4942. * will occur. The workaround:
  4943. * 1. First PF driver which loads on a path will:
  4944. * a. After taking the chip out of reset, by using pretend,
  4945. * it will write "0" to the following registers of
  4946. * the other vnics.
  4947. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  4948. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  4949. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  4950. * And for itself it will write '1' to
  4951. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  4952. * dmae-operations (writing to pram for example.)
  4953. * note: can be done for only function 6,7 but cleaner this
  4954. * way.
  4955. * b. Write zero+valid to the entire ILT.
  4956. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  4957. * VNIC3 (of that port). The range allocated will be the
  4958. * entire ILT. This is needed to prevent ILT range error.
  4959. * 2. Any PF driver load flow:
  4960. * a. ILT update with the physical addresses of the allocated
  4961. * logical pages.
  4962. * b. Wait 20msec. - note that this timeout is needed to make
  4963. * sure there are no requests in one of the PXP internal
  4964. * queues with "old" ILT addresses.
  4965. * c. PF enable in the PGLC.
  4966. * d. Clear the was_error of the PF in the PGLC. (could have
  4967. * occured while driver was down)
  4968. * e. PF enable in the CFC (WEAK + STRONG)
  4969. * f. Timers scan enable
  4970. * 3. PF driver unload flow:
  4971. * a. Clear the Timers scan_en.
  4972. * b. Polling for scan_on=0 for that PF.
  4973. * c. Clear the PF enable bit in the PXP.
  4974. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  4975. * e. Write zero+valid to all ILT entries (The valid bit must
  4976. * stay set)
  4977. * f. If this is VNIC 3 of a port then also init
  4978. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  4979. * to the last enrty in the ILT.
  4980. *
  4981. * Notes:
  4982. * Currently the PF error in the PGLC is non recoverable.
  4983. * In the future the there will be a recovery routine for this error.
  4984. * Currently attention is masked.
  4985. * Having an MCP lock on the load/unload process does not guarantee that
  4986. * there is no Timer disable during Func6/7 enable. This is because the
  4987. * Timers scan is currently being cleared by the MCP on FLR.
  4988. * Step 2.d can be done only for PF6/7 and the driver can also check if
  4989. * there is error before clearing it. But the flow above is simpler and
  4990. * more general.
  4991. * All ILT entries are written by zero+valid and not just PF6/7
  4992. * ILT entries since in the future the ILT entries allocation for
  4993. * PF-s might be dynamic.
  4994. */
  4995. struct ilt_client_info ilt_cli;
  4996. struct bnx2x_ilt ilt;
  4997. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  4998. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  4999. /* initialize dummy TM client */
  5000. ilt_cli.start = 0;
  5001. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5002. ilt_cli.client_num = ILT_CLIENT_TM;
  5003. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5004. * Step 2: set the timers first/last ilt entry to point
  5005. * to the entire range to prevent ILT range error for 3rd/4th
  5006. * vnic (this code assumes existance of the vnic)
  5007. *
  5008. * both steps performed by call to bnx2x_ilt_client_init_op()
  5009. * with dummy TM client
  5010. *
  5011. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5012. * and his brother are split registers
  5013. */
  5014. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5015. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5016. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5017. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5018. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5019. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5020. }
  5021. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5022. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5023. if (!CHIP_IS_E1x(bp)) {
  5024. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5025. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5026. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5027. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5028. /* let the HW do it's magic ... */
  5029. do {
  5030. msleep(200);
  5031. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5032. } while (factor-- && (val != 1));
  5033. if (val != 1) {
  5034. BNX2X_ERR("ATC_INIT failed\n");
  5035. return -EBUSY;
  5036. }
  5037. }
  5038. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5039. /* clean the DMAE memory */
  5040. bp->dmae_ready = 1;
  5041. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5042. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5043. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5044. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5045. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5046. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5047. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5048. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5049. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5050. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5051. /* QM queues pointers table */
  5052. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5053. /* soft reset pulse */
  5054. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5055. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5056. #ifdef BCM_CNIC
  5057. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5058. #endif
  5059. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5060. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5061. if (!CHIP_REV_IS_SLOW(bp))
  5062. /* enable hw interrupt from doorbell Q */
  5063. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5064. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5065. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5066. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5067. if (!CHIP_IS_E1(bp))
  5068. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5069. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
  5070. /* Bit-map indicating which L2 hdrs may appear
  5071. * after the basic Ethernet header
  5072. */
  5073. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5074. bp->path_has_ovlan ? 7 : 6);
  5075. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5076. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5077. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5078. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5079. if (!CHIP_IS_E1x(bp)) {
  5080. /* reset VFC memories */
  5081. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5082. VFC_MEMORIES_RST_REG_CAM_RST |
  5083. VFC_MEMORIES_RST_REG_RAM_RST);
  5084. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5085. VFC_MEMORIES_RST_REG_CAM_RST |
  5086. VFC_MEMORIES_RST_REG_RAM_RST);
  5087. msleep(20);
  5088. }
  5089. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5090. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5091. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5092. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5093. /* sync semi rtc */
  5094. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5095. 0x80000000);
  5096. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5097. 0x80000000);
  5098. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5099. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5100. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5101. if (!CHIP_IS_E1x(bp))
  5102. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5103. bp->path_has_ovlan ? 7 : 6);
  5104. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5105. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5106. #ifdef BCM_CNIC
  5107. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5108. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5109. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5110. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5111. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5112. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5113. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5114. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5115. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5116. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5117. #endif
  5118. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5119. if (sizeof(union cdu_context) != 1024)
  5120. /* we currently assume that a context is 1024 bytes */
  5121. dev_alert(&bp->pdev->dev, "please adjust the size "
  5122. "of cdu_context(%ld)\n",
  5123. (long)sizeof(union cdu_context));
  5124. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5125. val = (4 << 24) + (0 << 12) + 1024;
  5126. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5127. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5128. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5129. /* enable context validation interrupt from CFC */
  5130. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5131. /* set the thresholds to prevent CFC/CDU race */
  5132. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5133. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5134. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5135. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5136. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5137. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5138. /* Reset PCIE errors for debug */
  5139. REG_WR(bp, 0x2814, 0xffffffff);
  5140. REG_WR(bp, 0x3820, 0xffffffff);
  5141. if (!CHIP_IS_E1x(bp)) {
  5142. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5143. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5144. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5145. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5146. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5147. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5148. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5149. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5150. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5151. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5152. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5153. }
  5154. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5155. if (!CHIP_IS_E1(bp)) {
  5156. /* in E3 this done in per-port section */
  5157. if (!CHIP_IS_E3(bp))
  5158. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5159. }
  5160. if (CHIP_IS_E1H(bp))
  5161. /* not applicable for E2 (and above ...) */
  5162. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5163. if (CHIP_REV_IS_SLOW(bp))
  5164. msleep(200);
  5165. /* finish CFC init */
  5166. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5167. if (val != 1) {
  5168. BNX2X_ERR("CFC LL_INIT failed\n");
  5169. return -EBUSY;
  5170. }
  5171. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5172. if (val != 1) {
  5173. BNX2X_ERR("CFC AC_INIT failed\n");
  5174. return -EBUSY;
  5175. }
  5176. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5177. if (val != 1) {
  5178. BNX2X_ERR("CFC CAM_INIT failed\n");
  5179. return -EBUSY;
  5180. }
  5181. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5182. if (CHIP_IS_E1(bp)) {
  5183. /* read NIG statistic
  5184. to see if this is our first up since powerup */
  5185. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5186. val = *bnx2x_sp(bp, wb_data[0]);
  5187. /* do internal memory self test */
  5188. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5189. BNX2X_ERR("internal mem self test failed\n");
  5190. return -EBUSY;
  5191. }
  5192. }
  5193. bnx2x_setup_fan_failure_detection(bp);
  5194. /* clear PXP2 attentions */
  5195. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5196. bnx2x_enable_blocks_attention(bp);
  5197. bnx2x_enable_blocks_parity(bp);
  5198. if (!BP_NOMCP(bp)) {
  5199. if (CHIP_IS_E1x(bp))
  5200. bnx2x__common_init_phy(bp);
  5201. } else
  5202. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5203. return 0;
  5204. }
  5205. /**
  5206. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5207. *
  5208. * @bp: driver handle
  5209. */
  5210. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5211. {
  5212. int rc = bnx2x_init_hw_common(bp);
  5213. if (rc)
  5214. return rc;
  5215. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5216. if (!BP_NOMCP(bp))
  5217. bnx2x__common_init_phy(bp);
  5218. return 0;
  5219. }
  5220. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5221. {
  5222. int port = BP_PORT(bp);
  5223. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5224. u32 low, high;
  5225. u32 val;
  5226. bnx2x__link_reset(bp);
  5227. DP(BNX2X_MSG_MCP, "starting port init port %d\n", port);
  5228. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5229. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5230. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5231. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5232. /* Timers bug workaround: disables the pf_master bit in pglue at
  5233. * common phase, we need to enable it here before any dmae access are
  5234. * attempted. Therefore we manually added the enable-master to the
  5235. * port phase (it also happens in the function phase)
  5236. */
  5237. if (!CHIP_IS_E1x(bp))
  5238. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5239. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5240. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5241. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5242. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5243. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5244. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5245. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5246. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5247. /* QM cid (connection) count */
  5248. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5249. #ifdef BCM_CNIC
  5250. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5251. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5252. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5253. #endif
  5254. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5255. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5256. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5257. if (IS_MF(bp))
  5258. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5259. else if (bp->dev->mtu > 4096) {
  5260. if (bp->flags & ONE_PORT_FLAG)
  5261. low = 160;
  5262. else {
  5263. val = bp->dev->mtu;
  5264. /* (24*1024 + val*4)/256 */
  5265. low = 96 + (val/64) +
  5266. ((val % 64) ? 1 : 0);
  5267. }
  5268. } else
  5269. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5270. high = low + 56; /* 14*1024/256 */
  5271. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5272. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5273. }
  5274. if (CHIP_MODE_IS_4_PORT(bp))
  5275. REG_WR(bp, (BP_PORT(bp) ?
  5276. BRB1_REG_MAC_GUARANTIED_1 :
  5277. BRB1_REG_MAC_GUARANTIED_0), 40);
  5278. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5279. if (CHIP_IS_E3B0(bp))
  5280. /* Ovlan exists only if we are in multi-function +
  5281. * switch-dependent mode, in switch-independent there
  5282. * is no ovlan headers
  5283. */
  5284. REG_WR(bp, BP_PORT(bp) ?
  5285. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5286. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5287. (bp->path_has_ovlan ? 7 : 6));
  5288. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5289. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5290. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5291. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5292. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5293. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5294. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5295. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5296. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5297. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5298. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5299. if (CHIP_IS_E1x(bp)) {
  5300. /* configure PBF to work without PAUSE mtu 9000 */
  5301. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5302. /* update threshold */
  5303. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5304. /* update init credit */
  5305. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5306. /* probe changes */
  5307. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5308. udelay(50);
  5309. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5310. }
  5311. #ifdef BCM_CNIC
  5312. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5313. #endif
  5314. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5315. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5316. if (CHIP_IS_E1(bp)) {
  5317. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5318. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5319. }
  5320. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5321. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5322. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5323. /* init aeu_mask_attn_func_0/1:
  5324. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5325. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5326. * bits 4-7 are used for "per vn group attention" */
  5327. val = IS_MF(bp) ? 0xF7 : 0x7;
  5328. /* Enable DCBX attention for all but E1 */
  5329. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5330. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5331. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5332. if (!CHIP_IS_E1x(bp)) {
  5333. /* Bit-map indicating which L2 hdrs may appear after the
  5334. * basic Ethernet header
  5335. */
  5336. REG_WR(bp, BP_PORT(bp) ?
  5337. NIG_REG_P1_HDRS_AFTER_BASIC :
  5338. NIG_REG_P0_HDRS_AFTER_BASIC,
  5339. IS_MF_SD(bp) ? 7 : 6);
  5340. if (CHIP_IS_E3(bp))
  5341. REG_WR(bp, BP_PORT(bp) ?
  5342. NIG_REG_LLH1_MF_MODE :
  5343. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5344. }
  5345. if (!CHIP_IS_E3(bp))
  5346. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5347. if (!CHIP_IS_E1(bp)) {
  5348. /* 0x2 disable mf_ov, 0x1 enable */
  5349. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5350. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5351. if (!CHIP_IS_E1x(bp)) {
  5352. val = 0;
  5353. switch (bp->mf_mode) {
  5354. case MULTI_FUNCTION_SD:
  5355. val = 1;
  5356. break;
  5357. case MULTI_FUNCTION_SI:
  5358. val = 2;
  5359. break;
  5360. }
  5361. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5362. NIG_REG_LLH0_CLS_TYPE), val);
  5363. }
  5364. {
  5365. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5366. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5367. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5368. }
  5369. }
  5370. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5371. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5372. if (val & (1 << MISC_REGISTERS_SPIO_5)) {
  5373. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5374. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5375. val = REG_RD(bp, reg_addr);
  5376. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5377. REG_WR(bp, reg_addr, val);
  5378. }
  5379. return 0;
  5380. }
  5381. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5382. {
  5383. int reg;
  5384. if (CHIP_IS_E1(bp))
  5385. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5386. else
  5387. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5388. bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
  5389. }
  5390. static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5391. {
  5392. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5393. }
  5394. static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5395. {
  5396. u32 i, base = FUNC_ILT_BASE(func);
  5397. for (i = base; i < base + ILT_PER_FUNC; i++)
  5398. bnx2x_ilt_wr(bp, i, 0);
  5399. }
  5400. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5401. {
  5402. int port = BP_PORT(bp);
  5403. int func = BP_FUNC(bp);
  5404. int init_phase = PHASE_PF0 + func;
  5405. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5406. u16 cdu_ilt_start;
  5407. u32 addr, val;
  5408. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5409. int i, main_mem_width;
  5410. DP(BNX2X_MSG_MCP, "starting func init func %d\n", func);
  5411. /* FLR cleanup - hmmm */
  5412. if (!CHIP_IS_E1x(bp))
  5413. bnx2x_pf_flr_clnup(bp);
  5414. /* set MSI reconfigure capability */
  5415. if (bp->common.int_block == INT_BLOCK_HC) {
  5416. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5417. val = REG_RD(bp, addr);
  5418. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5419. REG_WR(bp, addr, val);
  5420. }
  5421. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5422. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5423. ilt = BP_ILT(bp);
  5424. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  5425. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  5426. ilt->lines[cdu_ilt_start + i].page =
  5427. bp->context.vcxt + (ILT_PAGE_CIDS * i);
  5428. ilt->lines[cdu_ilt_start + i].page_mapping =
  5429. bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
  5430. /* cdu ilt pages are allocated manually so there's no need to
  5431. set the size */
  5432. }
  5433. bnx2x_ilt_init_op(bp, INITOP_SET);
  5434. #ifdef BCM_CNIC
  5435. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5436. /* T1 hash bits value determines the T1 number of entries */
  5437. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5438. #endif
  5439. #ifndef BCM_CNIC
  5440. /* set NIC mode */
  5441. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5442. #endif /* BCM_CNIC */
  5443. if (!CHIP_IS_E1x(bp)) {
  5444. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  5445. /* Turn on a single ISR mode in IGU if driver is going to use
  5446. * INT#x or MSI
  5447. */
  5448. if (!(bp->flags & USING_MSIX_FLAG))
  5449. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  5450. /*
  5451. * Timers workaround bug: function init part.
  5452. * Need to wait 20msec after initializing ILT,
  5453. * needed to make sure there are no requests in
  5454. * one of the PXP internal queues with "old" ILT addresses
  5455. */
  5456. msleep(20);
  5457. /*
  5458. * Master enable - Due to WB DMAE writes performed before this
  5459. * register is re-initialized as part of the regular function
  5460. * init
  5461. */
  5462. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5463. /* Enable the function in IGU */
  5464. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  5465. }
  5466. bp->dmae_ready = 1;
  5467. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5468. if (!CHIP_IS_E1x(bp))
  5469. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  5470. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5471. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5472. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5473. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5474. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5475. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5476. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5477. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5478. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5479. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5480. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5481. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5482. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5483. if (!CHIP_IS_E1x(bp))
  5484. REG_WR(bp, QM_REG_PF_EN, 1);
  5485. if (!CHIP_IS_E1x(bp)) {
  5486. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5487. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5488. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5489. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5490. }
  5491. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5492. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5493. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5494. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5495. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5496. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5497. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5498. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5499. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5500. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5501. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5502. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5503. if (!CHIP_IS_E1x(bp))
  5504. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  5505. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5506. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5507. if (!CHIP_IS_E1x(bp))
  5508. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  5509. if (IS_MF(bp)) {
  5510. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  5511. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  5512. }
  5513. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5514. /* HC init per function */
  5515. if (bp->common.int_block == INT_BLOCK_HC) {
  5516. if (CHIP_IS_E1H(bp)) {
  5517. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5518. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5519. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5520. }
  5521. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5522. } else {
  5523. int num_segs, sb_idx, prod_offset;
  5524. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5525. if (!CHIP_IS_E1x(bp)) {
  5526. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  5527. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  5528. }
  5529. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5530. if (!CHIP_IS_E1x(bp)) {
  5531. int dsb_idx = 0;
  5532. /**
  5533. * Producer memory:
  5534. * E2 mode: address 0-135 match to the mapping memory;
  5535. * 136 - PF0 default prod; 137 - PF1 default prod;
  5536. * 138 - PF2 default prod; 139 - PF3 default prod;
  5537. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  5538. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  5539. * 144-147 reserved.
  5540. *
  5541. * E1.5 mode - In backward compatible mode;
  5542. * for non default SB; each even line in the memory
  5543. * holds the U producer and each odd line hold
  5544. * the C producer. The first 128 producers are for
  5545. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  5546. * producers are for the DSB for each PF.
  5547. * Each PF has five segments: (the order inside each
  5548. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  5549. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  5550. * 144-147 attn prods;
  5551. */
  5552. /* non-default-status-blocks */
  5553. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5554. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  5555. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  5556. prod_offset = (bp->igu_base_sb + sb_idx) *
  5557. num_segs;
  5558. for (i = 0; i < num_segs; i++) {
  5559. addr = IGU_REG_PROD_CONS_MEMORY +
  5560. (prod_offset + i) * 4;
  5561. REG_WR(bp, addr, 0);
  5562. }
  5563. /* send consumer update with value 0 */
  5564. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  5565. USTORM_ID, 0, IGU_INT_NOP, 1);
  5566. bnx2x_igu_clear_sb(bp,
  5567. bp->igu_base_sb + sb_idx);
  5568. }
  5569. /* default-status-blocks */
  5570. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5571. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  5572. if (CHIP_MODE_IS_4_PORT(bp))
  5573. dsb_idx = BP_FUNC(bp);
  5574. else
  5575. dsb_idx = BP_E1HVN(bp);
  5576. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  5577. IGU_BC_BASE_DSB_PROD + dsb_idx :
  5578. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  5579. for (i = 0; i < (num_segs * E1HVN_MAX);
  5580. i += E1HVN_MAX) {
  5581. addr = IGU_REG_PROD_CONS_MEMORY +
  5582. (prod_offset + i)*4;
  5583. REG_WR(bp, addr, 0);
  5584. }
  5585. /* send consumer update with 0 */
  5586. if (CHIP_INT_MODE_IS_BC(bp)) {
  5587. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5588. USTORM_ID, 0, IGU_INT_NOP, 1);
  5589. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5590. CSTORM_ID, 0, IGU_INT_NOP, 1);
  5591. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5592. XSTORM_ID, 0, IGU_INT_NOP, 1);
  5593. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5594. TSTORM_ID, 0, IGU_INT_NOP, 1);
  5595. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5596. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5597. } else {
  5598. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5599. USTORM_ID, 0, IGU_INT_NOP, 1);
  5600. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5601. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5602. }
  5603. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  5604. /* !!! these should become driver const once
  5605. rf-tool supports split-68 const */
  5606. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  5607. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  5608. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  5609. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  5610. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  5611. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  5612. }
  5613. }
  5614. /* Reset PCIE errors for debug */
  5615. REG_WR(bp, 0x2114, 0xffffffff);
  5616. REG_WR(bp, 0x2120, 0xffffffff);
  5617. if (CHIP_IS_E1x(bp)) {
  5618. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  5619. main_mem_base = HC_REG_MAIN_MEMORY +
  5620. BP_PORT(bp) * (main_mem_size * 4);
  5621. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  5622. main_mem_width = 8;
  5623. val = REG_RD(bp, main_mem_prty_clr);
  5624. if (val)
  5625. DP(BNX2X_MSG_MCP, "Hmmm... Parity errors in HC "
  5626. "block during "
  5627. "function init (0x%x)!\n", val);
  5628. /* Clear "false" parity errors in MSI-X table */
  5629. for (i = main_mem_base;
  5630. i < main_mem_base + main_mem_size * 4;
  5631. i += main_mem_width) {
  5632. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  5633. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  5634. i, main_mem_width / 4);
  5635. }
  5636. /* Clear HC parity attention */
  5637. REG_RD(bp, main_mem_prty_clr);
  5638. }
  5639. #ifdef BNX2X_STOP_ON_ERROR
  5640. /* Enable STORMs SP logging */
  5641. REG_WR8(bp, BAR_USTRORM_INTMEM +
  5642. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5643. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5644. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5645. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  5646. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5647. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  5648. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5649. #endif
  5650. bnx2x_phy_probe(&bp->link_params);
  5651. return 0;
  5652. }
  5653. void bnx2x_free_mem(struct bnx2x *bp)
  5654. {
  5655. /* fastpath */
  5656. bnx2x_free_fp_mem(bp);
  5657. /* end of fastpath */
  5658. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  5659. sizeof(struct host_sp_status_block));
  5660. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5661. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5662. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  5663. sizeof(struct bnx2x_slowpath));
  5664. BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
  5665. bp->context.size);
  5666. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  5667. BNX2X_FREE(bp->ilt->lines);
  5668. #ifdef BCM_CNIC
  5669. if (!CHIP_IS_E1x(bp))
  5670. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  5671. sizeof(struct host_hc_status_block_e2));
  5672. else
  5673. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  5674. sizeof(struct host_hc_status_block_e1x));
  5675. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  5676. #endif
  5677. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  5678. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  5679. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5680. }
  5681. static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  5682. {
  5683. int num_groups;
  5684. /* number of eth_queues */
  5685. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp);
  5686. /* Total number of FW statistics requests =
  5687. * 1 for port stats + 1 for PF stats + num_eth_queues */
  5688. bp->fw_stats_num = 2 + num_queue_stats;
  5689. /* Request is built from stats_query_header and an array of
  5690. * stats_query_cmd_group each of which contains
  5691. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  5692. * configured in the stats_query_header.
  5693. */
  5694. num_groups = (2 + num_queue_stats) / STATS_QUERY_CMD_COUNT +
  5695. (((2 + num_queue_stats) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  5696. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  5697. num_groups * sizeof(struct stats_query_cmd_group);
  5698. /* Data for statistics requests + stats_conter
  5699. *
  5700. * stats_counter holds per-STORM counters that are incremented
  5701. * when STORM has finished with the current request.
  5702. */
  5703. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  5704. sizeof(struct per_pf_stats) +
  5705. sizeof(struct per_queue_stats) * num_queue_stats +
  5706. sizeof(struct stats_counter);
  5707. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  5708. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5709. /* Set shortcuts */
  5710. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  5711. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  5712. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  5713. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  5714. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  5715. bp->fw_stats_req_sz;
  5716. return 0;
  5717. alloc_mem_err:
  5718. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5719. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5720. return -ENOMEM;
  5721. }
  5722. int bnx2x_alloc_mem(struct bnx2x *bp)
  5723. {
  5724. #ifdef BCM_CNIC
  5725. if (!CHIP_IS_E1x(bp))
  5726. /* size = the status block + ramrod buffers */
  5727. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  5728. sizeof(struct host_hc_status_block_e2));
  5729. else
  5730. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
  5731. sizeof(struct host_hc_status_block_e1x));
  5732. /* allocate searcher T2 table */
  5733. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  5734. #endif
  5735. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  5736. sizeof(struct host_sp_status_block));
  5737. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  5738. sizeof(struct bnx2x_slowpath));
  5739. /* Allocated memory for FW statistics */
  5740. if (bnx2x_alloc_fw_stats_mem(bp))
  5741. goto alloc_mem_err;
  5742. bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  5743. BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
  5744. bp->context.size);
  5745. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  5746. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  5747. goto alloc_mem_err;
  5748. /* Slow path ring */
  5749. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  5750. /* EQ */
  5751. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  5752. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5753. /* fastpath */
  5754. /* need to be done at the end, since it's self adjusting to amount
  5755. * of memory available for RSS queues
  5756. */
  5757. if (bnx2x_alloc_fp_mem(bp))
  5758. goto alloc_mem_err;
  5759. return 0;
  5760. alloc_mem_err:
  5761. bnx2x_free_mem(bp);
  5762. return -ENOMEM;
  5763. }
  5764. /*
  5765. * Init service functions
  5766. */
  5767. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  5768. struct bnx2x_vlan_mac_obj *obj, bool set,
  5769. int mac_type, unsigned long *ramrod_flags)
  5770. {
  5771. int rc;
  5772. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  5773. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5774. /* Fill general parameters */
  5775. ramrod_param.vlan_mac_obj = obj;
  5776. ramrod_param.ramrod_flags = *ramrod_flags;
  5777. /* Fill a user request section if needed */
  5778. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  5779. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  5780. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  5781. /* Set the command: ADD or DEL */
  5782. if (set)
  5783. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  5784. else
  5785. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  5786. }
  5787. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  5788. if (rc < 0)
  5789. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  5790. return rc;
  5791. }
  5792. int bnx2x_del_all_macs(struct bnx2x *bp,
  5793. struct bnx2x_vlan_mac_obj *mac_obj,
  5794. int mac_type, bool wait_for_comp)
  5795. {
  5796. int rc;
  5797. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  5798. /* Wait for completion of requested */
  5799. if (wait_for_comp)
  5800. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5801. /* Set the mac type of addresses we want to clear */
  5802. __set_bit(mac_type, &vlan_mac_flags);
  5803. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  5804. if (rc < 0)
  5805. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  5806. return rc;
  5807. }
  5808. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  5809. {
  5810. unsigned long ramrod_flags = 0;
  5811. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  5812. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5813. /* Eth MAC is set on RSS leading client (fp[0]) */
  5814. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
  5815. BNX2X_ETH_MAC, &ramrod_flags);
  5816. }
  5817. int bnx2x_setup_leading(struct bnx2x *bp)
  5818. {
  5819. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  5820. }
  5821. /**
  5822. * bnx2x_set_int_mode - configure interrupt mode
  5823. *
  5824. * @bp: driver handle
  5825. *
  5826. * In case of MSI-X it will also try to enable MSI-X.
  5827. */
  5828. static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
  5829. {
  5830. switch (int_mode) {
  5831. case INT_MODE_MSI:
  5832. bnx2x_enable_msi(bp);
  5833. /* falling through... */
  5834. case INT_MODE_INTx:
  5835. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  5836. DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
  5837. break;
  5838. default:
  5839. /* Set number of queues according to bp->multi_mode value */
  5840. bnx2x_set_num_queues(bp);
  5841. DP(NETIF_MSG_IFUP, "set number of queues to %d\n",
  5842. bp->num_queues);
  5843. /* if we can't use MSI-X we only need one fp,
  5844. * so try to enable MSI-X with the requested number of fp's
  5845. * and fallback to MSI or legacy INTx with one fp
  5846. */
  5847. if (bnx2x_enable_msix(bp)) {
  5848. /* failed to enable MSI-X */
  5849. if (bp->multi_mode)
  5850. DP(NETIF_MSG_IFUP,
  5851. "Multi requested but failed to "
  5852. "enable MSI-X (%d), "
  5853. "set number of queues to %d\n",
  5854. bp->num_queues,
  5855. 1 + NON_ETH_CONTEXT_USE);
  5856. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  5857. /* Try to enable MSI */
  5858. if (!(bp->flags & DISABLE_MSI_FLAG))
  5859. bnx2x_enable_msi(bp);
  5860. }
  5861. break;
  5862. }
  5863. }
  5864. /* must be called prioir to any HW initializations */
  5865. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  5866. {
  5867. return L2_ILT_LINES(bp);
  5868. }
  5869. void bnx2x_ilt_set_info(struct bnx2x *bp)
  5870. {
  5871. struct ilt_client_info *ilt_client;
  5872. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5873. u16 line = 0;
  5874. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  5875. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  5876. /* CDU */
  5877. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  5878. ilt_client->client_num = ILT_CLIENT_CDU;
  5879. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  5880. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  5881. ilt_client->start = line;
  5882. line += bnx2x_cid_ilt_lines(bp);
  5883. #ifdef BCM_CNIC
  5884. line += CNIC_ILT_LINES;
  5885. #endif
  5886. ilt_client->end = line - 1;
  5887. DP(BNX2X_MSG_SP, "ilt client[CDU]: start %d, end %d, psz 0x%x, "
  5888. "flags 0x%x, hw psz %d\n",
  5889. ilt_client->start,
  5890. ilt_client->end,
  5891. ilt_client->page_size,
  5892. ilt_client->flags,
  5893. ilog2(ilt_client->page_size >> 12));
  5894. /* QM */
  5895. if (QM_INIT(bp->qm_cid_count)) {
  5896. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  5897. ilt_client->client_num = ILT_CLIENT_QM;
  5898. ilt_client->page_size = QM_ILT_PAGE_SZ;
  5899. ilt_client->flags = 0;
  5900. ilt_client->start = line;
  5901. /* 4 bytes for each cid */
  5902. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  5903. QM_ILT_PAGE_SZ);
  5904. ilt_client->end = line - 1;
  5905. DP(BNX2X_MSG_SP, "ilt client[QM]: start %d, end %d, psz 0x%x, "
  5906. "flags 0x%x, hw psz %d\n",
  5907. ilt_client->start,
  5908. ilt_client->end,
  5909. ilt_client->page_size,
  5910. ilt_client->flags,
  5911. ilog2(ilt_client->page_size >> 12));
  5912. }
  5913. /* SRC */
  5914. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  5915. #ifdef BCM_CNIC
  5916. ilt_client->client_num = ILT_CLIENT_SRC;
  5917. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  5918. ilt_client->flags = 0;
  5919. ilt_client->start = line;
  5920. line += SRC_ILT_LINES;
  5921. ilt_client->end = line - 1;
  5922. DP(BNX2X_MSG_SP, "ilt client[SRC]: start %d, end %d, psz 0x%x, "
  5923. "flags 0x%x, hw psz %d\n",
  5924. ilt_client->start,
  5925. ilt_client->end,
  5926. ilt_client->page_size,
  5927. ilt_client->flags,
  5928. ilog2(ilt_client->page_size >> 12));
  5929. #else
  5930. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  5931. #endif
  5932. /* TM */
  5933. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  5934. #ifdef BCM_CNIC
  5935. ilt_client->client_num = ILT_CLIENT_TM;
  5936. ilt_client->page_size = TM_ILT_PAGE_SZ;
  5937. ilt_client->flags = 0;
  5938. ilt_client->start = line;
  5939. line += TM_ILT_LINES;
  5940. ilt_client->end = line - 1;
  5941. DP(BNX2X_MSG_SP, "ilt client[TM]: start %d, end %d, psz 0x%x, "
  5942. "flags 0x%x, hw psz %d\n",
  5943. ilt_client->start,
  5944. ilt_client->end,
  5945. ilt_client->page_size,
  5946. ilt_client->flags,
  5947. ilog2(ilt_client->page_size >> 12));
  5948. #else
  5949. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  5950. #endif
  5951. BUG_ON(line > ILT_MAX_LINES);
  5952. }
  5953. /**
  5954. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  5955. *
  5956. * @bp: driver handle
  5957. * @fp: pointer to fastpath
  5958. * @init_params: pointer to parameters structure
  5959. *
  5960. * parameters configured:
  5961. * - HC configuration
  5962. * - Queue's CDU context
  5963. */
  5964. static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  5965. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  5966. {
  5967. u8 cos;
  5968. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  5969. if (!IS_FCOE_FP(fp)) {
  5970. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  5971. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  5972. /* If HC is supporterd, enable host coalescing in the transition
  5973. * to INIT state.
  5974. */
  5975. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  5976. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  5977. /* HC rate */
  5978. init_params->rx.hc_rate = bp->rx_ticks ?
  5979. (1000000 / bp->rx_ticks) : 0;
  5980. init_params->tx.hc_rate = bp->tx_ticks ?
  5981. (1000000 / bp->tx_ticks) : 0;
  5982. /* FW SB ID */
  5983. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  5984. fp->fw_sb_id;
  5985. /*
  5986. * CQ index among the SB indices: FCoE clients uses the default
  5987. * SB, therefore it's different.
  5988. */
  5989. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  5990. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  5991. }
  5992. /* set maximum number of COSs supported by this queue */
  5993. init_params->max_cos = fp->max_cos;
  5994. DP(BNX2X_MSG_SP, "fp: %d setting queue params max cos to: %d",
  5995. fp->index, init_params->max_cos);
  5996. /* set the context pointers queue object */
  5997. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
  5998. init_params->cxts[cos] =
  5999. &bp->context.vcxt[fp->txdata[cos].cid].eth;
  6000. }
  6001. int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6002. struct bnx2x_queue_state_params *q_params,
  6003. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6004. int tx_index, bool leading)
  6005. {
  6006. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6007. /* Set the command */
  6008. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6009. /* Set tx-only QUEUE flags: don't zero statistics */
  6010. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6011. /* choose the index of the cid to send the slow path on */
  6012. tx_only_params->cid_index = tx_index;
  6013. /* Set general TX_ONLY_SETUP parameters */
  6014. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6015. /* Set Tx TX_ONLY_SETUP parameters */
  6016. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6017. DP(BNX2X_MSG_SP, "preparing to send tx-only ramrod for connection:"
  6018. "cos %d, primary cid %d, cid %d, "
  6019. "client id %d, sp-client id %d, flags %lx",
  6020. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6021. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6022. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6023. /* send the ramrod */
  6024. return bnx2x_queue_state_change(bp, q_params);
  6025. }
  6026. /**
  6027. * bnx2x_setup_queue - setup queue
  6028. *
  6029. * @bp: driver handle
  6030. * @fp: pointer to fastpath
  6031. * @leading: is leading
  6032. *
  6033. * This function performs 2 steps in a Queue state machine
  6034. * actually: 1) RESET->INIT 2) INIT->SETUP
  6035. */
  6036. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6037. bool leading)
  6038. {
  6039. struct bnx2x_queue_state_params q_params = {0};
  6040. struct bnx2x_queue_setup_params *setup_params =
  6041. &q_params.params.setup;
  6042. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6043. &q_params.params.tx_only;
  6044. int rc;
  6045. u8 tx_index;
  6046. DP(BNX2X_MSG_SP, "setting up queue %d", fp->index);
  6047. /* reset IGU state skip FCoE L2 queue */
  6048. if (!IS_FCOE_FP(fp))
  6049. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6050. IGU_INT_ENABLE, 0);
  6051. q_params.q_obj = &fp->q_obj;
  6052. /* We want to wait for completion in this context */
  6053. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6054. /* Prepare the INIT parameters */
  6055. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6056. /* Set the command */
  6057. q_params.cmd = BNX2X_Q_CMD_INIT;
  6058. /* Change the state to INIT */
  6059. rc = bnx2x_queue_state_change(bp, &q_params);
  6060. if (rc) {
  6061. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6062. return rc;
  6063. }
  6064. DP(BNX2X_MSG_SP, "init complete");
  6065. /* Now move the Queue to the SETUP state... */
  6066. memset(setup_params, 0, sizeof(*setup_params));
  6067. /* Set QUEUE flags */
  6068. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6069. /* Set general SETUP parameters */
  6070. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6071. FIRST_TX_COS_INDEX);
  6072. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6073. &setup_params->rxq_params);
  6074. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6075. FIRST_TX_COS_INDEX);
  6076. /* Set the command */
  6077. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6078. /* Change the state to SETUP */
  6079. rc = bnx2x_queue_state_change(bp, &q_params);
  6080. if (rc) {
  6081. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6082. return rc;
  6083. }
  6084. /* loop through the relevant tx-only indices */
  6085. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6086. tx_index < fp->max_cos;
  6087. tx_index++) {
  6088. /* prepare and send tx-only ramrod*/
  6089. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6090. tx_only_params, tx_index, leading);
  6091. if (rc) {
  6092. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6093. fp->index, tx_index);
  6094. return rc;
  6095. }
  6096. }
  6097. return rc;
  6098. }
  6099. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6100. {
  6101. struct bnx2x_fastpath *fp = &bp->fp[index];
  6102. struct bnx2x_fp_txdata *txdata;
  6103. struct bnx2x_queue_state_params q_params = {0};
  6104. int rc, tx_index;
  6105. DP(BNX2X_MSG_SP, "stopping queue %d cid %d", index, fp->cid);
  6106. q_params.q_obj = &fp->q_obj;
  6107. /* We want to wait for completion in this context */
  6108. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6109. /* close tx-only connections */
  6110. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6111. tx_index < fp->max_cos;
  6112. tx_index++){
  6113. /* ascertain this is a normal queue*/
  6114. txdata = &fp->txdata[tx_index];
  6115. DP(BNX2X_MSG_SP, "stopping tx-only queue %d",
  6116. txdata->txq_index);
  6117. /* send halt terminate on tx-only connection */
  6118. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6119. memset(&q_params.params.terminate, 0,
  6120. sizeof(q_params.params.terminate));
  6121. q_params.params.terminate.cid_index = tx_index;
  6122. rc = bnx2x_queue_state_change(bp, &q_params);
  6123. if (rc)
  6124. return rc;
  6125. /* send halt terminate on tx-only connection */
  6126. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6127. memset(&q_params.params.cfc_del, 0,
  6128. sizeof(q_params.params.cfc_del));
  6129. q_params.params.cfc_del.cid_index = tx_index;
  6130. rc = bnx2x_queue_state_change(bp, &q_params);
  6131. if (rc)
  6132. return rc;
  6133. }
  6134. /* Stop the primary connection: */
  6135. /* ...halt the connection */
  6136. q_params.cmd = BNX2X_Q_CMD_HALT;
  6137. rc = bnx2x_queue_state_change(bp, &q_params);
  6138. if (rc)
  6139. return rc;
  6140. /* ...terminate the connection */
  6141. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6142. memset(&q_params.params.terminate, 0,
  6143. sizeof(q_params.params.terminate));
  6144. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6145. rc = bnx2x_queue_state_change(bp, &q_params);
  6146. if (rc)
  6147. return rc;
  6148. /* ...delete cfc entry */
  6149. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6150. memset(&q_params.params.cfc_del, 0,
  6151. sizeof(q_params.params.cfc_del));
  6152. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6153. return bnx2x_queue_state_change(bp, &q_params);
  6154. }
  6155. static void bnx2x_reset_func(struct bnx2x *bp)
  6156. {
  6157. int port = BP_PORT(bp);
  6158. int func = BP_FUNC(bp);
  6159. int i;
  6160. /* Disable the function in the FW */
  6161. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6162. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6163. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6164. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6165. /* FP SBs */
  6166. for_each_eth_queue(bp, i) {
  6167. struct bnx2x_fastpath *fp = &bp->fp[i];
  6168. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6169. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6170. SB_DISABLED);
  6171. }
  6172. #ifdef BCM_CNIC
  6173. /* CNIC SB */
  6174. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6175. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
  6176. SB_DISABLED);
  6177. #endif
  6178. /* SP SB */
  6179. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6180. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6181. SB_DISABLED);
  6182. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6183. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6184. 0);
  6185. /* Configure IGU */
  6186. if (bp->common.int_block == INT_BLOCK_HC) {
  6187. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6188. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6189. } else {
  6190. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6191. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6192. }
  6193. #ifdef BCM_CNIC
  6194. /* Disable Timer scan */
  6195. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6196. /*
  6197. * Wait for at least 10ms and up to 2 second for the timers scan to
  6198. * complete
  6199. */
  6200. for (i = 0; i < 200; i++) {
  6201. msleep(10);
  6202. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6203. break;
  6204. }
  6205. #endif
  6206. /* Clear ILT */
  6207. bnx2x_clear_func_ilt(bp, func);
  6208. /* Timers workaround bug for E2: if this is vnic-3,
  6209. * we need to set the entire ilt range for this timers.
  6210. */
  6211. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6212. struct ilt_client_info ilt_cli;
  6213. /* use dummy TM client */
  6214. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6215. ilt_cli.start = 0;
  6216. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6217. ilt_cli.client_num = ILT_CLIENT_TM;
  6218. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6219. }
  6220. /* this assumes that reset_port() called before reset_func()*/
  6221. if (!CHIP_IS_E1x(bp))
  6222. bnx2x_pf_disable(bp);
  6223. bp->dmae_ready = 0;
  6224. }
  6225. static void bnx2x_reset_port(struct bnx2x *bp)
  6226. {
  6227. int port = BP_PORT(bp);
  6228. u32 val;
  6229. /* Reset physical Link */
  6230. bnx2x__link_reset(bp);
  6231. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6232. /* Do not rcv packets to BRB */
  6233. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6234. /* Do not direct rcv packets that are not for MCP to the BRB */
  6235. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6236. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6237. /* Configure AEU */
  6238. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6239. msleep(100);
  6240. /* Check for BRB port occupancy */
  6241. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6242. if (val)
  6243. DP(NETIF_MSG_IFDOWN,
  6244. "BRB1 is not empty %d blocks are occupied\n", val);
  6245. /* TODO: Close Doorbell port? */
  6246. }
  6247. static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6248. {
  6249. struct bnx2x_func_state_params func_params = {0};
  6250. /* Prepare parameters for function state transitions */
  6251. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6252. func_params.f_obj = &bp->func_obj;
  6253. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6254. func_params.params.hw_init.load_phase = load_code;
  6255. return bnx2x_func_state_change(bp, &func_params);
  6256. }
  6257. static inline int bnx2x_func_stop(struct bnx2x *bp)
  6258. {
  6259. struct bnx2x_func_state_params func_params = {0};
  6260. int rc;
  6261. /* Prepare parameters for function state transitions */
  6262. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6263. func_params.f_obj = &bp->func_obj;
  6264. func_params.cmd = BNX2X_F_CMD_STOP;
  6265. /*
  6266. * Try to stop the function the 'good way'. If fails (in case
  6267. * of a parity error during bnx2x_chip_cleanup()) and we are
  6268. * not in a debug mode, perform a state transaction in order to
  6269. * enable further HW_RESET transaction.
  6270. */
  6271. rc = bnx2x_func_state_change(bp, &func_params);
  6272. if (rc) {
  6273. #ifdef BNX2X_STOP_ON_ERROR
  6274. return rc;
  6275. #else
  6276. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry "
  6277. "transaction\n");
  6278. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6279. return bnx2x_func_state_change(bp, &func_params);
  6280. #endif
  6281. }
  6282. return 0;
  6283. }
  6284. /**
  6285. * bnx2x_send_unload_req - request unload mode from the MCP.
  6286. *
  6287. * @bp: driver handle
  6288. * @unload_mode: requested function's unload mode
  6289. *
  6290. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6291. */
  6292. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6293. {
  6294. u32 reset_code = 0;
  6295. int port = BP_PORT(bp);
  6296. /* Select the UNLOAD request mode */
  6297. if (unload_mode == UNLOAD_NORMAL)
  6298. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6299. else if (bp->flags & NO_WOL_FLAG)
  6300. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6301. else if (bp->wol) {
  6302. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6303. u8 *mac_addr = bp->dev->dev_addr;
  6304. u32 val;
  6305. /* The mac address is written to entries 1-4 to
  6306. preserve entry 0 which is used by the PMF */
  6307. u8 entry = (BP_E1HVN(bp) + 1)*8;
  6308. val = (mac_addr[0] << 8) | mac_addr[1];
  6309. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6310. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6311. (mac_addr[4] << 8) | mac_addr[5];
  6312. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6313. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6314. } else
  6315. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6316. /* Send the request to the MCP */
  6317. if (!BP_NOMCP(bp))
  6318. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6319. else {
  6320. int path = BP_PATH(bp);
  6321. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] "
  6322. "%d, %d, %d\n",
  6323. path, load_count[path][0], load_count[path][1],
  6324. load_count[path][2]);
  6325. load_count[path][0]--;
  6326. load_count[path][1 + port]--;
  6327. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] "
  6328. "%d, %d, %d\n",
  6329. path, load_count[path][0], load_count[path][1],
  6330. load_count[path][2]);
  6331. if (load_count[path][0] == 0)
  6332. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6333. else if (load_count[path][1 + port] == 0)
  6334. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6335. else
  6336. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6337. }
  6338. return reset_code;
  6339. }
  6340. /**
  6341. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6342. *
  6343. * @bp: driver handle
  6344. */
  6345. void bnx2x_send_unload_done(struct bnx2x *bp)
  6346. {
  6347. /* Report UNLOAD_DONE to MCP */
  6348. if (!BP_NOMCP(bp))
  6349. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6350. }
  6351. static inline int bnx2x_func_wait_started(struct bnx2x *bp)
  6352. {
  6353. int tout = 50;
  6354. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  6355. if (!bp->port.pmf)
  6356. return 0;
  6357. /*
  6358. * (assumption: No Attention from MCP at this stage)
  6359. * PMF probably in the middle of TXdisable/enable transaction
  6360. * 1. Sync IRS for default SB
  6361. * 2. Sync SP queue - this guarantes us that attention handling started
  6362. * 3. Wait, that TXdisable/enable transaction completes
  6363. *
  6364. * 1+2 guranty that if DCBx attention was scheduled it already changed
  6365. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  6366. * received complettion for the transaction the state is TX_STOPPED.
  6367. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  6368. * transaction.
  6369. */
  6370. /* make sure default SB ISR is done */
  6371. if (msix)
  6372. synchronize_irq(bp->msix_table[0].vector);
  6373. else
  6374. synchronize_irq(bp->pdev->irq);
  6375. flush_workqueue(bnx2x_wq);
  6376. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6377. BNX2X_F_STATE_STARTED && tout--)
  6378. msleep(20);
  6379. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6380. BNX2X_F_STATE_STARTED) {
  6381. #ifdef BNX2X_STOP_ON_ERROR
  6382. return -EBUSY;
  6383. #else
  6384. /*
  6385. * Failed to complete the transaction in a "good way"
  6386. * Force both transactions with CLR bit
  6387. */
  6388. struct bnx2x_func_state_params func_params = {0};
  6389. DP(BNX2X_MSG_SP, "Hmmm... unexpected function state! "
  6390. "Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  6391. func_params.f_obj = &bp->func_obj;
  6392. __set_bit(RAMROD_DRV_CLR_ONLY,
  6393. &func_params.ramrod_flags);
  6394. /* STARTED-->TX_ST0PPED */
  6395. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  6396. bnx2x_func_state_change(bp, &func_params);
  6397. /* TX_ST0PPED-->STARTED */
  6398. func_params.cmd = BNX2X_F_CMD_TX_START;
  6399. return bnx2x_func_state_change(bp, &func_params);
  6400. #endif
  6401. }
  6402. return 0;
  6403. }
  6404. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
  6405. {
  6406. int port = BP_PORT(bp);
  6407. int i, rc = 0;
  6408. u8 cos;
  6409. struct bnx2x_mcast_ramrod_params rparam = {0};
  6410. u32 reset_code;
  6411. /* Wait until tx fastpath tasks complete */
  6412. for_each_tx_queue(bp, i) {
  6413. struct bnx2x_fastpath *fp = &bp->fp[i];
  6414. for_each_cos_in_tx_queue(fp, cos)
  6415. rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
  6416. #ifdef BNX2X_STOP_ON_ERROR
  6417. if (rc)
  6418. return;
  6419. #endif
  6420. }
  6421. /* Give HW time to discard old tx messages */
  6422. usleep_range(1000, 1000);
  6423. /* Clean all ETH MACs */
  6424. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
  6425. if (rc < 0)
  6426. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  6427. /* Clean up UC list */
  6428. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
  6429. true);
  6430. if (rc < 0)
  6431. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: "
  6432. "%d\n", rc);
  6433. /* Disable LLH */
  6434. if (!CHIP_IS_E1(bp))
  6435. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6436. /* Set "drop all" (stop Rx).
  6437. * We need to take a netif_addr_lock() here in order to prevent
  6438. * a race between the completion code and this code.
  6439. */
  6440. netif_addr_lock_bh(bp->dev);
  6441. /* Schedule the rx_mode command */
  6442. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  6443. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  6444. else
  6445. bnx2x_set_storm_rx_mode(bp);
  6446. /* Cleanup multicast configuration */
  6447. rparam.mcast_obj = &bp->mcast_obj;
  6448. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  6449. if (rc < 0)
  6450. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  6451. netif_addr_unlock_bh(bp->dev);
  6452. /*
  6453. * Send the UNLOAD_REQUEST to the MCP. This will return if
  6454. * this function should perform FUNC, PORT or COMMON HW
  6455. * reset.
  6456. */
  6457. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  6458. /*
  6459. * (assumption: No Attention from MCP at this stage)
  6460. * PMF probably in the middle of TXdisable/enable transaction
  6461. */
  6462. rc = bnx2x_func_wait_started(bp);
  6463. if (rc) {
  6464. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  6465. #ifdef BNX2X_STOP_ON_ERROR
  6466. return;
  6467. #endif
  6468. }
  6469. /* Close multi and leading connections
  6470. * Completions for ramrods are collected in a synchronous way
  6471. */
  6472. for_each_queue(bp, i)
  6473. if (bnx2x_stop_queue(bp, i))
  6474. #ifdef BNX2X_STOP_ON_ERROR
  6475. return;
  6476. #else
  6477. goto unload_error;
  6478. #endif
  6479. /* If SP settings didn't get completed so far - something
  6480. * very wrong has happen.
  6481. */
  6482. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  6483. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  6484. #ifndef BNX2X_STOP_ON_ERROR
  6485. unload_error:
  6486. #endif
  6487. rc = bnx2x_func_stop(bp);
  6488. if (rc) {
  6489. BNX2X_ERR("Function stop failed!\n");
  6490. #ifdef BNX2X_STOP_ON_ERROR
  6491. return;
  6492. #endif
  6493. }
  6494. /* Disable HW interrupts, NAPI */
  6495. bnx2x_netif_stop(bp, 1);
  6496. /* Release IRQs */
  6497. bnx2x_free_irq(bp);
  6498. /* Reset the chip */
  6499. rc = bnx2x_reset_hw(bp, reset_code);
  6500. if (rc)
  6501. BNX2X_ERR("HW_RESET failed\n");
  6502. /* Report UNLOAD_DONE to MCP */
  6503. bnx2x_send_unload_done(bp);
  6504. }
  6505. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  6506. {
  6507. u32 val;
  6508. DP(NETIF_MSG_HW, "Disabling \"close the gates\"\n");
  6509. if (CHIP_IS_E1(bp)) {
  6510. int port = BP_PORT(bp);
  6511. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  6512. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  6513. val = REG_RD(bp, addr);
  6514. val &= ~(0x300);
  6515. REG_WR(bp, addr, val);
  6516. } else {
  6517. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  6518. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  6519. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  6520. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  6521. }
  6522. }
  6523. /* Close gates #2, #3 and #4: */
  6524. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  6525. {
  6526. u32 val;
  6527. /* Gates #2 and #4a are closed/opened for "not E1" only */
  6528. if (!CHIP_IS_E1(bp)) {
  6529. /* #4 */
  6530. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  6531. /* #2 */
  6532. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  6533. }
  6534. /* #3 */
  6535. if (CHIP_IS_E1x(bp)) {
  6536. /* Prevent interrupts from HC on both ports */
  6537. val = REG_RD(bp, HC_REG_CONFIG_1);
  6538. REG_WR(bp, HC_REG_CONFIG_1,
  6539. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  6540. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  6541. val = REG_RD(bp, HC_REG_CONFIG_0);
  6542. REG_WR(bp, HC_REG_CONFIG_0,
  6543. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  6544. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  6545. } else {
  6546. /* Prevent incomming interrupts in IGU */
  6547. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  6548. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  6549. (!close) ?
  6550. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  6551. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  6552. }
  6553. DP(NETIF_MSG_HW, "%s gates #2, #3 and #4\n",
  6554. close ? "closing" : "opening");
  6555. mmiowb();
  6556. }
  6557. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  6558. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  6559. {
  6560. /* Do some magic... */
  6561. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6562. *magic_val = val & SHARED_MF_CLP_MAGIC;
  6563. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  6564. }
  6565. /**
  6566. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  6567. *
  6568. * @bp: driver handle
  6569. * @magic_val: old value of the `magic' bit.
  6570. */
  6571. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  6572. {
  6573. /* Restore the `magic' bit value... */
  6574. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6575. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  6576. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  6577. }
  6578. /**
  6579. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  6580. *
  6581. * @bp: driver handle
  6582. * @magic_val: old value of 'magic' bit.
  6583. *
  6584. * Takes care of CLP configurations.
  6585. */
  6586. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  6587. {
  6588. u32 shmem;
  6589. u32 validity_offset;
  6590. DP(NETIF_MSG_HW, "Starting\n");
  6591. /* Set `magic' bit in order to save MF config */
  6592. if (!CHIP_IS_E1(bp))
  6593. bnx2x_clp_reset_prep(bp, magic_val);
  6594. /* Get shmem offset */
  6595. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6596. validity_offset = offsetof(struct shmem_region, validity_map[0]);
  6597. /* Clear validity map flags */
  6598. if (shmem > 0)
  6599. REG_WR(bp, shmem + validity_offset, 0);
  6600. }
  6601. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  6602. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  6603. /**
  6604. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  6605. *
  6606. * @bp: driver handle
  6607. */
  6608. static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
  6609. {
  6610. /* special handling for emulation and FPGA,
  6611. wait 10 times longer */
  6612. if (CHIP_REV_IS_SLOW(bp))
  6613. msleep(MCP_ONE_TIMEOUT*10);
  6614. else
  6615. msleep(MCP_ONE_TIMEOUT);
  6616. }
  6617. /*
  6618. * initializes bp->common.shmem_base and waits for validity signature to appear
  6619. */
  6620. static int bnx2x_init_shmem(struct bnx2x *bp)
  6621. {
  6622. int cnt = 0;
  6623. u32 val = 0;
  6624. do {
  6625. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6626. if (bp->common.shmem_base) {
  6627. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  6628. if (val & SHR_MEM_VALIDITY_MB)
  6629. return 0;
  6630. }
  6631. bnx2x_mcp_wait_one(bp);
  6632. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  6633. BNX2X_ERR("BAD MCP validity signature\n");
  6634. return -ENODEV;
  6635. }
  6636. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  6637. {
  6638. int rc = bnx2x_init_shmem(bp);
  6639. /* Restore the `magic' bit value */
  6640. if (!CHIP_IS_E1(bp))
  6641. bnx2x_clp_reset_done(bp, magic_val);
  6642. return rc;
  6643. }
  6644. static void bnx2x_pxp_prep(struct bnx2x *bp)
  6645. {
  6646. if (!CHIP_IS_E1(bp)) {
  6647. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  6648. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  6649. mmiowb();
  6650. }
  6651. }
  6652. /*
  6653. * Reset the whole chip except for:
  6654. * - PCIE core
  6655. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  6656. * one reset bit)
  6657. * - IGU
  6658. * - MISC (including AEU)
  6659. * - GRC
  6660. * - RBCN, RBCP
  6661. */
  6662. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  6663. {
  6664. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  6665. u32 global_bits2, stay_reset2;
  6666. /*
  6667. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  6668. * (per chip) blocks.
  6669. */
  6670. global_bits2 =
  6671. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  6672. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  6673. /* Don't reset the following blocks */
  6674. not_reset_mask1 =
  6675. MISC_REGISTERS_RESET_REG_1_RST_HC |
  6676. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  6677. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  6678. not_reset_mask2 =
  6679. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  6680. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  6681. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  6682. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  6683. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  6684. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  6685. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  6686. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  6687. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  6688. MISC_REGISTERS_RESET_REG_2_PGLC;
  6689. /*
  6690. * Keep the following blocks in reset:
  6691. * - all xxMACs are handled by the bnx2x_link code.
  6692. */
  6693. stay_reset2 =
  6694. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  6695. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  6696. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  6697. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  6698. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  6699. MISC_REGISTERS_RESET_REG_2_UMAC1 |
  6700. MISC_REGISTERS_RESET_REG_2_XMAC |
  6701. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  6702. /* Full reset masks according to the chip */
  6703. reset_mask1 = 0xffffffff;
  6704. if (CHIP_IS_E1(bp))
  6705. reset_mask2 = 0xffff;
  6706. else if (CHIP_IS_E1H(bp))
  6707. reset_mask2 = 0x1ffff;
  6708. else if (CHIP_IS_E2(bp))
  6709. reset_mask2 = 0xfffff;
  6710. else /* CHIP_IS_E3 */
  6711. reset_mask2 = 0x3ffffff;
  6712. /* Don't reset global blocks unless we need to */
  6713. if (!global)
  6714. reset_mask2 &= ~global_bits2;
  6715. /*
  6716. * In case of attention in the QM, we need to reset PXP
  6717. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  6718. * because otherwise QM reset would release 'close the gates' shortly
  6719. * before resetting the PXP, then the PSWRQ would send a write
  6720. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  6721. * read the payload data from PSWWR, but PSWWR would not
  6722. * respond. The write queue in PGLUE would stuck, dmae commands
  6723. * would not return. Therefore it's important to reset the second
  6724. * reset register (containing the
  6725. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  6726. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  6727. * bit).
  6728. */
  6729. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  6730. reset_mask2 & (~not_reset_mask2));
  6731. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6732. reset_mask1 & (~not_reset_mask1));
  6733. barrier();
  6734. mmiowb();
  6735. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  6736. reset_mask2 & (~stay_reset2));
  6737. barrier();
  6738. mmiowb();
  6739. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  6740. mmiowb();
  6741. }
  6742. /**
  6743. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  6744. * It should get cleared in no more than 1s.
  6745. *
  6746. * @bp: driver handle
  6747. *
  6748. * It should get cleared in no more than 1s. Returns 0 if
  6749. * pending writes bit gets cleared.
  6750. */
  6751. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  6752. {
  6753. u32 cnt = 1000;
  6754. u32 pend_bits = 0;
  6755. do {
  6756. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  6757. if (pend_bits == 0)
  6758. break;
  6759. usleep_range(1000, 1000);
  6760. } while (cnt-- > 0);
  6761. if (cnt <= 0) {
  6762. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  6763. pend_bits);
  6764. return -EBUSY;
  6765. }
  6766. return 0;
  6767. }
  6768. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  6769. {
  6770. int cnt = 1000;
  6771. u32 val = 0;
  6772. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  6773. /* Empty the Tetris buffer, wait for 1s */
  6774. do {
  6775. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  6776. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  6777. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  6778. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  6779. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  6780. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  6781. ((port_is_idle_0 & 0x1) == 0x1) &&
  6782. ((port_is_idle_1 & 0x1) == 0x1) &&
  6783. (pgl_exp_rom2 == 0xffffffff))
  6784. break;
  6785. usleep_range(1000, 1000);
  6786. } while (cnt-- > 0);
  6787. if (cnt <= 0) {
  6788. DP(NETIF_MSG_HW, "Tetris buffer didn't get empty or there"
  6789. " are still"
  6790. " outstanding read requests after 1s!\n");
  6791. DP(NETIF_MSG_HW, "sr_cnt=0x%08x, blk_cnt=0x%08x,"
  6792. " port_is_idle_0=0x%08x,"
  6793. " port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
  6794. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  6795. pgl_exp_rom2);
  6796. return -EAGAIN;
  6797. }
  6798. barrier();
  6799. /* Close gates #2, #3 and #4 */
  6800. bnx2x_set_234_gates(bp, true);
  6801. /* Poll for IGU VQs for 57712 and newer chips */
  6802. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  6803. return -EAGAIN;
  6804. /* TBD: Indicate that "process kill" is in progress to MCP */
  6805. /* Clear "unprepared" bit */
  6806. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  6807. barrier();
  6808. /* Make sure all is written to the chip before the reset */
  6809. mmiowb();
  6810. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  6811. * PSWHST, GRC and PSWRD Tetris buffer.
  6812. */
  6813. usleep_range(1000, 1000);
  6814. /* Prepare to chip reset: */
  6815. /* MCP */
  6816. if (global)
  6817. bnx2x_reset_mcp_prep(bp, &val);
  6818. /* PXP */
  6819. bnx2x_pxp_prep(bp);
  6820. barrier();
  6821. /* reset the chip */
  6822. bnx2x_process_kill_chip_reset(bp, global);
  6823. barrier();
  6824. /* Recover after reset: */
  6825. /* MCP */
  6826. if (global && bnx2x_reset_mcp_comp(bp, val))
  6827. return -EAGAIN;
  6828. /* TBD: Add resetting the NO_MCP mode DB here */
  6829. /* PXP */
  6830. bnx2x_pxp_prep(bp);
  6831. /* Open the gates #2, #3 and #4 */
  6832. bnx2x_set_234_gates(bp, false);
  6833. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  6834. * reset state, re-enable attentions. */
  6835. return 0;
  6836. }
  6837. int bnx2x_leader_reset(struct bnx2x *bp)
  6838. {
  6839. int rc = 0;
  6840. bool global = bnx2x_reset_is_global(bp);
  6841. /* Try to recover after the failure */
  6842. if (bnx2x_process_kill(bp, global)) {
  6843. netdev_err(bp->dev, "Something bad had happen on engine %d! "
  6844. "Aii!\n", BP_PATH(bp));
  6845. rc = -EAGAIN;
  6846. goto exit_leader_reset;
  6847. }
  6848. /*
  6849. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  6850. * state.
  6851. */
  6852. bnx2x_set_reset_done(bp);
  6853. if (global)
  6854. bnx2x_clear_reset_global(bp);
  6855. exit_leader_reset:
  6856. bp->is_leader = 0;
  6857. bnx2x_release_leader_lock(bp);
  6858. smp_mb();
  6859. return rc;
  6860. }
  6861. static inline void bnx2x_recovery_failed(struct bnx2x *bp)
  6862. {
  6863. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  6864. /* Disconnect this device */
  6865. netif_device_detach(bp->dev);
  6866. /*
  6867. * Block ifup for all function on this engine until "process kill"
  6868. * or power cycle.
  6869. */
  6870. bnx2x_set_reset_in_progress(bp);
  6871. /* Shut down the power */
  6872. bnx2x_set_power_state(bp, PCI_D3hot);
  6873. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  6874. smp_mb();
  6875. }
  6876. /*
  6877. * Assumption: runs under rtnl lock. This together with the fact
  6878. * that it's called only from bnx2x_sp_rtnl() ensure that it
  6879. * will never be called when netif_running(bp->dev) is false.
  6880. */
  6881. static void bnx2x_parity_recover(struct bnx2x *bp)
  6882. {
  6883. bool global = false;
  6884. DP(NETIF_MSG_HW, "Handling parity\n");
  6885. while (1) {
  6886. switch (bp->recovery_state) {
  6887. case BNX2X_RECOVERY_INIT:
  6888. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  6889. bnx2x_chk_parity_attn(bp, &global, false);
  6890. /* Try to get a LEADER_LOCK HW lock */
  6891. if (bnx2x_trylock_leader_lock(bp)) {
  6892. bnx2x_set_reset_in_progress(bp);
  6893. /*
  6894. * Check if there is a global attention and if
  6895. * there was a global attention, set the global
  6896. * reset bit.
  6897. */
  6898. if (global)
  6899. bnx2x_set_reset_global(bp);
  6900. bp->is_leader = 1;
  6901. }
  6902. /* Stop the driver */
  6903. /* If interface has been removed - break */
  6904. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
  6905. return;
  6906. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  6907. /*
  6908. * Reset MCP command sequence number and MCP mail box
  6909. * sequence as we are going to reset the MCP.
  6910. */
  6911. if (global) {
  6912. bp->fw_seq = 0;
  6913. bp->fw_drv_pulse_wr_seq = 0;
  6914. }
  6915. /* Ensure "is_leader", MCP command sequence and
  6916. * "recovery_state" update values are seen on other
  6917. * CPUs.
  6918. */
  6919. smp_mb();
  6920. break;
  6921. case BNX2X_RECOVERY_WAIT:
  6922. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  6923. if (bp->is_leader) {
  6924. int other_engine = BP_PATH(bp) ? 0 : 1;
  6925. u32 other_load_counter =
  6926. bnx2x_get_load_cnt(bp, other_engine);
  6927. u32 load_counter =
  6928. bnx2x_get_load_cnt(bp, BP_PATH(bp));
  6929. global = bnx2x_reset_is_global(bp);
  6930. /*
  6931. * In case of a parity in a global block, let
  6932. * the first leader that performs a
  6933. * leader_reset() reset the global blocks in
  6934. * order to clear global attentions. Otherwise
  6935. * the the gates will remain closed for that
  6936. * engine.
  6937. */
  6938. if (load_counter ||
  6939. (global && other_load_counter)) {
  6940. /* Wait until all other functions get
  6941. * down.
  6942. */
  6943. schedule_delayed_work(&bp->sp_rtnl_task,
  6944. HZ/10);
  6945. return;
  6946. } else {
  6947. /* If all other functions got down -
  6948. * try to bring the chip back to
  6949. * normal. In any case it's an exit
  6950. * point for a leader.
  6951. */
  6952. if (bnx2x_leader_reset(bp)) {
  6953. bnx2x_recovery_failed(bp);
  6954. return;
  6955. }
  6956. /* If we are here, means that the
  6957. * leader has succeeded and doesn't
  6958. * want to be a leader any more. Try
  6959. * to continue as a none-leader.
  6960. */
  6961. break;
  6962. }
  6963. } else { /* non-leader */
  6964. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  6965. /* Try to get a LEADER_LOCK HW lock as
  6966. * long as a former leader may have
  6967. * been unloaded by the user or
  6968. * released a leadership by another
  6969. * reason.
  6970. */
  6971. if (bnx2x_trylock_leader_lock(bp)) {
  6972. /* I'm a leader now! Restart a
  6973. * switch case.
  6974. */
  6975. bp->is_leader = 1;
  6976. break;
  6977. }
  6978. schedule_delayed_work(&bp->sp_rtnl_task,
  6979. HZ/10);
  6980. return;
  6981. } else {
  6982. /*
  6983. * If there was a global attention, wait
  6984. * for it to be cleared.
  6985. */
  6986. if (bnx2x_reset_is_global(bp)) {
  6987. schedule_delayed_work(
  6988. &bp->sp_rtnl_task,
  6989. HZ/10);
  6990. return;
  6991. }
  6992. if (bnx2x_nic_load(bp, LOAD_NORMAL))
  6993. bnx2x_recovery_failed(bp);
  6994. else {
  6995. bp->recovery_state =
  6996. BNX2X_RECOVERY_DONE;
  6997. smp_mb();
  6998. }
  6999. return;
  7000. }
  7001. }
  7002. default:
  7003. return;
  7004. }
  7005. }
  7006. }
  7007. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7008. * scheduled on a general queue in order to prevent a dead lock.
  7009. */
  7010. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7011. {
  7012. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7013. rtnl_lock();
  7014. if (!netif_running(bp->dev))
  7015. goto sp_rtnl_exit;
  7016. /* if stop on error is defined no recovery flows should be executed */
  7017. #ifdef BNX2X_STOP_ON_ERROR
  7018. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined "
  7019. "so reset not done to allow debug dump,\n"
  7020. "you will need to reboot when done\n");
  7021. goto sp_rtnl_not_reset;
  7022. #endif
  7023. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7024. /*
  7025. * Clear all pending SP commands as we are going to reset the
  7026. * function anyway.
  7027. */
  7028. bp->sp_rtnl_state = 0;
  7029. smp_mb();
  7030. bnx2x_parity_recover(bp);
  7031. goto sp_rtnl_exit;
  7032. }
  7033. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7034. /*
  7035. * Clear all pending SP commands as we are going to reset the
  7036. * function anyway.
  7037. */
  7038. bp->sp_rtnl_state = 0;
  7039. smp_mb();
  7040. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7041. bnx2x_nic_load(bp, LOAD_NORMAL);
  7042. goto sp_rtnl_exit;
  7043. }
  7044. #ifdef BNX2X_STOP_ON_ERROR
  7045. sp_rtnl_not_reset:
  7046. #endif
  7047. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7048. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7049. sp_rtnl_exit:
  7050. rtnl_unlock();
  7051. }
  7052. /* end of nic load/unload */
  7053. static void bnx2x_period_task(struct work_struct *work)
  7054. {
  7055. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7056. if (!netif_running(bp->dev))
  7057. goto period_task_exit;
  7058. if (CHIP_REV_IS_SLOW(bp)) {
  7059. BNX2X_ERR("period task called on emulation, ignoring\n");
  7060. goto period_task_exit;
  7061. }
  7062. bnx2x_acquire_phy_lock(bp);
  7063. /*
  7064. * The barrier is needed to ensure the ordering between the writing to
  7065. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7066. * the reading here.
  7067. */
  7068. smp_mb();
  7069. if (bp->port.pmf) {
  7070. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7071. /* Re-queue task in 1 sec */
  7072. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7073. }
  7074. bnx2x_release_phy_lock(bp);
  7075. period_task_exit:
  7076. return;
  7077. }
  7078. /*
  7079. * Init service functions
  7080. */
  7081. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7082. {
  7083. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7084. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7085. return base + (BP_ABS_FUNC(bp)) * stride;
  7086. }
  7087. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7088. {
  7089. u32 reg = bnx2x_get_pretend_reg(bp);
  7090. /* Flush all outstanding writes */
  7091. mmiowb();
  7092. /* Pretend to be function 0 */
  7093. REG_WR(bp, reg, 0);
  7094. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7095. /* From now we are in the "like-E1" mode */
  7096. bnx2x_int_disable(bp);
  7097. /* Flush all outstanding writes */
  7098. mmiowb();
  7099. /* Restore the original function */
  7100. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7101. REG_RD(bp, reg);
  7102. }
  7103. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7104. {
  7105. if (CHIP_IS_E1(bp))
  7106. bnx2x_int_disable(bp);
  7107. else
  7108. bnx2x_undi_int_disable_e1h(bp);
  7109. }
  7110. static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
  7111. {
  7112. u32 val;
  7113. /* Check if there is any driver already loaded */
  7114. val = REG_RD(bp, MISC_REG_UNPREPARED);
  7115. if (val == 0x1) {
  7116. /* Check if it is the UNDI driver
  7117. * UNDI driver initializes CID offset for normal bell to 0x7
  7118. */
  7119. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  7120. val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  7121. if (val == 0x7) {
  7122. u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7123. /* save our pf_num */
  7124. int orig_pf_num = bp->pf_num;
  7125. int port;
  7126. u32 swap_en, swap_val, value;
  7127. /* clear the UNDI indication */
  7128. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  7129. BNX2X_DEV_INFO("UNDI is active! reset device\n");
  7130. /* try unload UNDI on port 0 */
  7131. bp->pf_num = 0;
  7132. bp->fw_seq =
  7133. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  7134. DRV_MSG_SEQ_NUMBER_MASK);
  7135. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7136. /* if UNDI is loaded on the other port */
  7137. if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  7138. /* send "DONE" for previous unload */
  7139. bnx2x_fw_command(bp,
  7140. DRV_MSG_CODE_UNLOAD_DONE, 0);
  7141. /* unload UNDI on port 1 */
  7142. bp->pf_num = 1;
  7143. bp->fw_seq =
  7144. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  7145. DRV_MSG_SEQ_NUMBER_MASK);
  7146. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7147. bnx2x_fw_command(bp, reset_code, 0);
  7148. }
  7149. /* now it's safe to release the lock */
  7150. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  7151. bnx2x_undi_int_disable(bp);
  7152. port = BP_PORT(bp);
  7153. /* close input traffic and wait for it */
  7154. /* Do not rcv packets to BRB */
  7155. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
  7156. NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
  7157. /* Do not direct rcv packets that are not for MCP to
  7158. * the BRB */
  7159. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7160. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7161. /* clear AEU */
  7162. REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7163. MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
  7164. msleep(10);
  7165. /* save NIG port swap info */
  7166. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  7167. swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  7168. /* reset device */
  7169. REG_WR(bp,
  7170. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7171. 0xd3ffffff);
  7172. value = 0x1400;
  7173. if (CHIP_IS_E3(bp)) {
  7174. value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  7175. value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  7176. }
  7177. REG_WR(bp,
  7178. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7179. value);
  7180. /* take the NIG out of reset and restore swap values */
  7181. REG_WR(bp,
  7182. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  7183. MISC_REGISTERS_RESET_REG_1_RST_NIG);
  7184. REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
  7185. REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
  7186. /* send unload done to the MCP */
  7187. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7188. /* restore our func and fw_seq */
  7189. bp->pf_num = orig_pf_num;
  7190. bp->fw_seq =
  7191. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  7192. DRV_MSG_SEQ_NUMBER_MASK);
  7193. } else
  7194. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  7195. }
  7196. }
  7197. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  7198. {
  7199. u32 val, val2, val3, val4, id;
  7200. u16 pmc;
  7201. /* Get the chip revision id and number. */
  7202. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  7203. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  7204. id = ((val & 0xffff) << 16);
  7205. val = REG_RD(bp, MISC_REG_CHIP_REV);
  7206. id |= ((val & 0xf) << 12);
  7207. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  7208. id |= ((val & 0xff) << 4);
  7209. val = REG_RD(bp, MISC_REG_BOND_ID);
  7210. id |= (val & 0xf);
  7211. bp->common.chip_id = id;
  7212. /* Set doorbell size */
  7213. bp->db_size = (1 << BNX2X_DB_SHIFT);
  7214. if (!CHIP_IS_E1x(bp)) {
  7215. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  7216. if ((val & 1) == 0)
  7217. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  7218. else
  7219. val = (val >> 1) & 1;
  7220. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  7221. "2_PORT_MODE");
  7222. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  7223. CHIP_2_PORT_MODE;
  7224. if (CHIP_MODE_IS_4_PORT(bp))
  7225. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  7226. else
  7227. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  7228. } else {
  7229. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  7230. bp->pfid = bp->pf_num; /* 0..7 */
  7231. }
  7232. bp->link_params.chip_id = bp->common.chip_id;
  7233. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  7234. val = (REG_RD(bp, 0x2874) & 0x55);
  7235. if ((bp->common.chip_id & 0x1) ||
  7236. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  7237. bp->flags |= ONE_PORT_FLAG;
  7238. BNX2X_DEV_INFO("single port device\n");
  7239. }
  7240. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  7241. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  7242. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  7243. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  7244. bp->common.flash_size, bp->common.flash_size);
  7245. bnx2x_init_shmem(bp);
  7246. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  7247. MISC_REG_GENERIC_CR_1 :
  7248. MISC_REG_GENERIC_CR_0));
  7249. bp->link_params.shmem_base = bp->common.shmem_base;
  7250. bp->link_params.shmem2_base = bp->common.shmem2_base;
  7251. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  7252. bp->common.shmem_base, bp->common.shmem2_base);
  7253. if (!bp->common.shmem_base) {
  7254. BNX2X_DEV_INFO("MCP not active\n");
  7255. bp->flags |= NO_MCP_FLAG;
  7256. return;
  7257. }
  7258. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  7259. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  7260. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  7261. SHARED_HW_CFG_LED_MODE_MASK) >>
  7262. SHARED_HW_CFG_LED_MODE_SHIFT);
  7263. bp->link_params.feature_config_flags = 0;
  7264. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  7265. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  7266. bp->link_params.feature_config_flags |=
  7267. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  7268. else
  7269. bp->link_params.feature_config_flags &=
  7270. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  7271. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  7272. bp->common.bc_ver = val;
  7273. BNX2X_DEV_INFO("bc_ver %X\n", val);
  7274. if (val < BNX2X_BC_VER) {
  7275. /* for now only warn
  7276. * later we might need to enforce this */
  7277. BNX2X_ERR("This driver needs bc_ver %X but found %X, "
  7278. "please upgrade BC\n", BNX2X_BC_VER, val);
  7279. }
  7280. bp->link_params.feature_config_flags |=
  7281. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  7282. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  7283. bp->link_params.feature_config_flags |=
  7284. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  7285. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  7286. bp->link_params.feature_config_flags |=
  7287. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  7288. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  7289. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  7290. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  7291. BNX2X_DEV_INFO("%sWoL capable\n",
  7292. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  7293. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  7294. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  7295. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  7296. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  7297. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  7298. val, val2, val3, val4);
  7299. }
  7300. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  7301. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  7302. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  7303. {
  7304. int pfid = BP_FUNC(bp);
  7305. int vn = BP_E1HVN(bp);
  7306. int igu_sb_id;
  7307. u32 val;
  7308. u8 fid, igu_sb_cnt = 0;
  7309. bp->igu_base_sb = 0xff;
  7310. if (CHIP_INT_MODE_IS_BC(bp)) {
  7311. igu_sb_cnt = bp->igu_sb_cnt;
  7312. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  7313. FP_SB_MAX_E1x;
  7314. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  7315. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  7316. return;
  7317. }
  7318. /* IGU in normal mode - read CAM */
  7319. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  7320. igu_sb_id++) {
  7321. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  7322. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  7323. continue;
  7324. fid = IGU_FID(val);
  7325. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  7326. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  7327. continue;
  7328. if (IGU_VEC(val) == 0)
  7329. /* default status block */
  7330. bp->igu_dsb_id = igu_sb_id;
  7331. else {
  7332. if (bp->igu_base_sb == 0xff)
  7333. bp->igu_base_sb = igu_sb_id;
  7334. igu_sb_cnt++;
  7335. }
  7336. }
  7337. }
  7338. #ifdef CONFIG_PCI_MSI
  7339. /*
  7340. * It's expected that number of CAM entries for this functions is equal
  7341. * to the number evaluated based on the MSI-X table size. We want a
  7342. * harsh warning if these values are different!
  7343. */
  7344. WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
  7345. #endif
  7346. if (igu_sb_cnt == 0)
  7347. BNX2X_ERR("CAM configuration error\n");
  7348. }
  7349. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  7350. u32 switch_cfg)
  7351. {
  7352. int cfg_size = 0, idx, port = BP_PORT(bp);
  7353. /* Aggregation of supported attributes of all external phys */
  7354. bp->port.supported[0] = 0;
  7355. bp->port.supported[1] = 0;
  7356. switch (bp->link_params.num_phys) {
  7357. case 1:
  7358. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  7359. cfg_size = 1;
  7360. break;
  7361. case 2:
  7362. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  7363. cfg_size = 1;
  7364. break;
  7365. case 3:
  7366. if (bp->link_params.multi_phy_config &
  7367. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  7368. bp->port.supported[1] =
  7369. bp->link_params.phy[EXT_PHY1].supported;
  7370. bp->port.supported[0] =
  7371. bp->link_params.phy[EXT_PHY2].supported;
  7372. } else {
  7373. bp->port.supported[0] =
  7374. bp->link_params.phy[EXT_PHY1].supported;
  7375. bp->port.supported[1] =
  7376. bp->link_params.phy[EXT_PHY2].supported;
  7377. }
  7378. cfg_size = 2;
  7379. break;
  7380. }
  7381. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  7382. BNX2X_ERR("NVRAM config error. BAD phy config."
  7383. "PHY1 config 0x%x, PHY2 config 0x%x\n",
  7384. SHMEM_RD(bp,
  7385. dev_info.port_hw_config[port].external_phy_config),
  7386. SHMEM_RD(bp,
  7387. dev_info.port_hw_config[port].external_phy_config2));
  7388. return;
  7389. }
  7390. if (CHIP_IS_E3(bp))
  7391. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  7392. else {
  7393. switch (switch_cfg) {
  7394. case SWITCH_CFG_1G:
  7395. bp->port.phy_addr = REG_RD(
  7396. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  7397. break;
  7398. case SWITCH_CFG_10G:
  7399. bp->port.phy_addr = REG_RD(
  7400. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  7401. break;
  7402. default:
  7403. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  7404. bp->port.link_config[0]);
  7405. return;
  7406. }
  7407. }
  7408. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  7409. /* mask what we support according to speed_cap_mask per configuration */
  7410. for (idx = 0; idx < cfg_size; idx++) {
  7411. if (!(bp->link_params.speed_cap_mask[idx] &
  7412. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  7413. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  7414. if (!(bp->link_params.speed_cap_mask[idx] &
  7415. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  7416. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  7417. if (!(bp->link_params.speed_cap_mask[idx] &
  7418. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  7419. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  7420. if (!(bp->link_params.speed_cap_mask[idx] &
  7421. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  7422. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  7423. if (!(bp->link_params.speed_cap_mask[idx] &
  7424. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  7425. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  7426. SUPPORTED_1000baseT_Full);
  7427. if (!(bp->link_params.speed_cap_mask[idx] &
  7428. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  7429. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  7430. if (!(bp->link_params.speed_cap_mask[idx] &
  7431. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  7432. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  7433. }
  7434. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  7435. bp->port.supported[1]);
  7436. }
  7437. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  7438. {
  7439. u32 link_config, idx, cfg_size = 0;
  7440. bp->port.advertising[0] = 0;
  7441. bp->port.advertising[1] = 0;
  7442. switch (bp->link_params.num_phys) {
  7443. case 1:
  7444. case 2:
  7445. cfg_size = 1;
  7446. break;
  7447. case 3:
  7448. cfg_size = 2;
  7449. break;
  7450. }
  7451. for (idx = 0; idx < cfg_size; idx++) {
  7452. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  7453. link_config = bp->port.link_config[idx];
  7454. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  7455. case PORT_FEATURE_LINK_SPEED_AUTO:
  7456. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  7457. bp->link_params.req_line_speed[idx] =
  7458. SPEED_AUTO_NEG;
  7459. bp->port.advertising[idx] |=
  7460. bp->port.supported[idx];
  7461. } else {
  7462. /* force 10G, no AN */
  7463. bp->link_params.req_line_speed[idx] =
  7464. SPEED_10000;
  7465. bp->port.advertising[idx] |=
  7466. (ADVERTISED_10000baseT_Full |
  7467. ADVERTISED_FIBRE);
  7468. continue;
  7469. }
  7470. break;
  7471. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  7472. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  7473. bp->link_params.req_line_speed[idx] =
  7474. SPEED_10;
  7475. bp->port.advertising[idx] |=
  7476. (ADVERTISED_10baseT_Full |
  7477. ADVERTISED_TP);
  7478. } else {
  7479. BNX2X_ERR("NVRAM config error. "
  7480. "Invalid link_config 0x%x"
  7481. " speed_cap_mask 0x%x\n",
  7482. link_config,
  7483. bp->link_params.speed_cap_mask[idx]);
  7484. return;
  7485. }
  7486. break;
  7487. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  7488. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  7489. bp->link_params.req_line_speed[idx] =
  7490. SPEED_10;
  7491. bp->link_params.req_duplex[idx] =
  7492. DUPLEX_HALF;
  7493. bp->port.advertising[idx] |=
  7494. (ADVERTISED_10baseT_Half |
  7495. ADVERTISED_TP);
  7496. } else {
  7497. BNX2X_ERR("NVRAM config error. "
  7498. "Invalid link_config 0x%x"
  7499. " speed_cap_mask 0x%x\n",
  7500. link_config,
  7501. bp->link_params.speed_cap_mask[idx]);
  7502. return;
  7503. }
  7504. break;
  7505. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  7506. if (bp->port.supported[idx] &
  7507. SUPPORTED_100baseT_Full) {
  7508. bp->link_params.req_line_speed[idx] =
  7509. SPEED_100;
  7510. bp->port.advertising[idx] |=
  7511. (ADVERTISED_100baseT_Full |
  7512. ADVERTISED_TP);
  7513. } else {
  7514. BNX2X_ERR("NVRAM config error. "
  7515. "Invalid link_config 0x%x"
  7516. " speed_cap_mask 0x%x\n",
  7517. link_config,
  7518. bp->link_params.speed_cap_mask[idx]);
  7519. return;
  7520. }
  7521. break;
  7522. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  7523. if (bp->port.supported[idx] &
  7524. SUPPORTED_100baseT_Half) {
  7525. bp->link_params.req_line_speed[idx] =
  7526. SPEED_100;
  7527. bp->link_params.req_duplex[idx] =
  7528. DUPLEX_HALF;
  7529. bp->port.advertising[idx] |=
  7530. (ADVERTISED_100baseT_Half |
  7531. ADVERTISED_TP);
  7532. } else {
  7533. BNX2X_ERR("NVRAM config error. "
  7534. "Invalid link_config 0x%x"
  7535. " speed_cap_mask 0x%x\n",
  7536. link_config,
  7537. bp->link_params.speed_cap_mask[idx]);
  7538. return;
  7539. }
  7540. break;
  7541. case PORT_FEATURE_LINK_SPEED_1G:
  7542. if (bp->port.supported[idx] &
  7543. SUPPORTED_1000baseT_Full) {
  7544. bp->link_params.req_line_speed[idx] =
  7545. SPEED_1000;
  7546. bp->port.advertising[idx] |=
  7547. (ADVERTISED_1000baseT_Full |
  7548. ADVERTISED_TP);
  7549. } else {
  7550. BNX2X_ERR("NVRAM config error. "
  7551. "Invalid link_config 0x%x"
  7552. " speed_cap_mask 0x%x\n",
  7553. link_config,
  7554. bp->link_params.speed_cap_mask[idx]);
  7555. return;
  7556. }
  7557. break;
  7558. case PORT_FEATURE_LINK_SPEED_2_5G:
  7559. if (bp->port.supported[idx] &
  7560. SUPPORTED_2500baseX_Full) {
  7561. bp->link_params.req_line_speed[idx] =
  7562. SPEED_2500;
  7563. bp->port.advertising[idx] |=
  7564. (ADVERTISED_2500baseX_Full |
  7565. ADVERTISED_TP);
  7566. } else {
  7567. BNX2X_ERR("NVRAM config error. "
  7568. "Invalid link_config 0x%x"
  7569. " speed_cap_mask 0x%x\n",
  7570. link_config,
  7571. bp->link_params.speed_cap_mask[idx]);
  7572. return;
  7573. }
  7574. break;
  7575. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  7576. if (bp->port.supported[idx] &
  7577. SUPPORTED_10000baseT_Full) {
  7578. bp->link_params.req_line_speed[idx] =
  7579. SPEED_10000;
  7580. bp->port.advertising[idx] |=
  7581. (ADVERTISED_10000baseT_Full |
  7582. ADVERTISED_FIBRE);
  7583. } else {
  7584. BNX2X_ERR("NVRAM config error. "
  7585. "Invalid link_config 0x%x"
  7586. " speed_cap_mask 0x%x\n",
  7587. link_config,
  7588. bp->link_params.speed_cap_mask[idx]);
  7589. return;
  7590. }
  7591. break;
  7592. case PORT_FEATURE_LINK_SPEED_20G:
  7593. bp->link_params.req_line_speed[idx] = SPEED_20000;
  7594. break;
  7595. default:
  7596. BNX2X_ERR("NVRAM config error. "
  7597. "BAD link speed link_config 0x%x\n",
  7598. link_config);
  7599. bp->link_params.req_line_speed[idx] =
  7600. SPEED_AUTO_NEG;
  7601. bp->port.advertising[idx] =
  7602. bp->port.supported[idx];
  7603. break;
  7604. }
  7605. bp->link_params.req_flow_ctrl[idx] = (link_config &
  7606. PORT_FEATURE_FLOW_CONTROL_MASK);
  7607. if ((bp->link_params.req_flow_ctrl[idx] ==
  7608. BNX2X_FLOW_CTRL_AUTO) &&
  7609. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  7610. bp->link_params.req_flow_ctrl[idx] =
  7611. BNX2X_FLOW_CTRL_NONE;
  7612. }
  7613. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl"
  7614. " 0x%x advertising 0x%x\n",
  7615. bp->link_params.req_line_speed[idx],
  7616. bp->link_params.req_duplex[idx],
  7617. bp->link_params.req_flow_ctrl[idx],
  7618. bp->port.advertising[idx]);
  7619. }
  7620. }
  7621. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  7622. {
  7623. mac_hi = cpu_to_be16(mac_hi);
  7624. mac_lo = cpu_to_be32(mac_lo);
  7625. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  7626. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  7627. }
  7628. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  7629. {
  7630. int port = BP_PORT(bp);
  7631. u32 config;
  7632. u32 ext_phy_type, ext_phy_config;
  7633. bp->link_params.bp = bp;
  7634. bp->link_params.port = port;
  7635. bp->link_params.lane_config =
  7636. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  7637. bp->link_params.speed_cap_mask[0] =
  7638. SHMEM_RD(bp,
  7639. dev_info.port_hw_config[port].speed_capability_mask);
  7640. bp->link_params.speed_cap_mask[1] =
  7641. SHMEM_RD(bp,
  7642. dev_info.port_hw_config[port].speed_capability_mask2);
  7643. bp->port.link_config[0] =
  7644. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  7645. bp->port.link_config[1] =
  7646. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  7647. bp->link_params.multi_phy_config =
  7648. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  7649. /* If the device is capable of WoL, set the default state according
  7650. * to the HW
  7651. */
  7652. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  7653. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  7654. (config & PORT_FEATURE_WOL_ENABLED));
  7655. BNX2X_DEV_INFO("lane_config 0x%08x "
  7656. "speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  7657. bp->link_params.lane_config,
  7658. bp->link_params.speed_cap_mask[0],
  7659. bp->port.link_config[0]);
  7660. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  7661. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  7662. bnx2x_phy_probe(&bp->link_params);
  7663. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  7664. bnx2x_link_settings_requested(bp);
  7665. /*
  7666. * If connected directly, work with the internal PHY, otherwise, work
  7667. * with the external PHY
  7668. */
  7669. ext_phy_config =
  7670. SHMEM_RD(bp,
  7671. dev_info.port_hw_config[port].external_phy_config);
  7672. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  7673. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  7674. bp->mdio.prtad = bp->port.phy_addr;
  7675. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  7676. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  7677. bp->mdio.prtad =
  7678. XGXS_EXT_PHY_ADDR(ext_phy_config);
  7679. /*
  7680. * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
  7681. * In MF mode, it is set to cover self test cases
  7682. */
  7683. if (IS_MF(bp))
  7684. bp->port.need_hw_lock = 1;
  7685. else
  7686. bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
  7687. bp->common.shmem_base,
  7688. bp->common.shmem2_base);
  7689. }
  7690. #ifdef BCM_CNIC
  7691. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  7692. {
  7693. int port = BP_PORT(bp);
  7694. int func = BP_ABS_FUNC(bp);
  7695. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  7696. drv_lic_key[port].max_iscsi_conn);
  7697. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  7698. drv_lic_key[port].max_fcoe_conn);
  7699. /* Get the number of maximum allowed iSCSI and FCoE connections */
  7700. bp->cnic_eth_dev.max_iscsi_conn =
  7701. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  7702. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  7703. bp->cnic_eth_dev.max_fcoe_conn =
  7704. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  7705. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  7706. /* Read the WWN: */
  7707. if (!IS_MF(bp)) {
  7708. /* Port info */
  7709. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  7710. SHMEM_RD(bp,
  7711. dev_info.port_hw_config[port].
  7712. fcoe_wwn_port_name_upper);
  7713. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  7714. SHMEM_RD(bp,
  7715. dev_info.port_hw_config[port].
  7716. fcoe_wwn_port_name_lower);
  7717. /* Node info */
  7718. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  7719. SHMEM_RD(bp,
  7720. dev_info.port_hw_config[port].
  7721. fcoe_wwn_node_name_upper);
  7722. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  7723. SHMEM_RD(bp,
  7724. dev_info.port_hw_config[port].
  7725. fcoe_wwn_node_name_lower);
  7726. } else if (!IS_MF_SD(bp)) {
  7727. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  7728. /*
  7729. * Read the WWN info only if the FCoE feature is enabled for
  7730. * this function.
  7731. */
  7732. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  7733. /* Port info */
  7734. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  7735. MF_CFG_RD(bp, func_ext_config[func].
  7736. fcoe_wwn_port_name_upper);
  7737. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  7738. MF_CFG_RD(bp, func_ext_config[func].
  7739. fcoe_wwn_port_name_lower);
  7740. /* Node info */
  7741. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  7742. MF_CFG_RD(bp, func_ext_config[func].
  7743. fcoe_wwn_node_name_upper);
  7744. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  7745. MF_CFG_RD(bp, func_ext_config[func].
  7746. fcoe_wwn_node_name_lower);
  7747. }
  7748. }
  7749. BNX2X_DEV_INFO("max_iscsi_conn 0x%x max_fcoe_conn 0x%x\n",
  7750. bp->cnic_eth_dev.max_iscsi_conn,
  7751. bp->cnic_eth_dev.max_fcoe_conn);
  7752. /*
  7753. * If maximum allowed number of connections is zero -
  7754. * disable the feature.
  7755. */
  7756. if (!bp->cnic_eth_dev.max_iscsi_conn)
  7757. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  7758. if (!bp->cnic_eth_dev.max_fcoe_conn)
  7759. bp->flags |= NO_FCOE_FLAG;
  7760. }
  7761. #endif
  7762. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  7763. {
  7764. u32 val, val2;
  7765. int func = BP_ABS_FUNC(bp);
  7766. int port = BP_PORT(bp);
  7767. #ifdef BCM_CNIC
  7768. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  7769. u8 *fip_mac = bp->fip_mac;
  7770. #endif
  7771. /* Zero primary MAC configuration */
  7772. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  7773. if (BP_NOMCP(bp)) {
  7774. BNX2X_ERROR("warning: random MAC workaround active\n");
  7775. random_ether_addr(bp->dev->dev_addr);
  7776. } else if (IS_MF(bp)) {
  7777. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  7778. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  7779. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  7780. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  7781. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  7782. #ifdef BCM_CNIC
  7783. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  7784. * FCoE MAC then the appropriate feature should be disabled.
  7785. */
  7786. if (IS_MF_SI(bp)) {
  7787. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  7788. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  7789. val2 = MF_CFG_RD(bp, func_ext_config[func].
  7790. iscsi_mac_addr_upper);
  7791. val = MF_CFG_RD(bp, func_ext_config[func].
  7792. iscsi_mac_addr_lower);
  7793. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  7794. BNX2X_DEV_INFO("Read iSCSI MAC: "
  7795. BNX2X_MAC_FMT"\n",
  7796. BNX2X_MAC_PRN_LIST(iscsi_mac));
  7797. } else
  7798. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  7799. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  7800. val2 = MF_CFG_RD(bp, func_ext_config[func].
  7801. fcoe_mac_addr_upper);
  7802. val = MF_CFG_RD(bp, func_ext_config[func].
  7803. fcoe_mac_addr_lower);
  7804. bnx2x_set_mac_buf(fip_mac, val, val2);
  7805. BNX2X_DEV_INFO("Read FCoE L2 MAC to "
  7806. BNX2X_MAC_FMT"\n",
  7807. BNX2X_MAC_PRN_LIST(fip_mac));
  7808. } else
  7809. bp->flags |= NO_FCOE_FLAG;
  7810. }
  7811. #endif
  7812. } else {
  7813. /* in SF read MACs from port configuration */
  7814. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  7815. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  7816. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  7817. #ifdef BCM_CNIC
  7818. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7819. iscsi_mac_upper);
  7820. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7821. iscsi_mac_lower);
  7822. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  7823. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7824. fcoe_fip_mac_upper);
  7825. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  7826. fcoe_fip_mac_lower);
  7827. bnx2x_set_mac_buf(fip_mac, val, val2);
  7828. #endif
  7829. }
  7830. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  7831. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  7832. #ifdef BCM_CNIC
  7833. /* Set the FCoE MAC in MF_SD mode */
  7834. if (!CHIP_IS_E1x(bp) && IS_MF_SD(bp))
  7835. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  7836. /* Disable iSCSI if MAC configuration is
  7837. * invalid.
  7838. */
  7839. if (!is_valid_ether_addr(iscsi_mac)) {
  7840. bp->flags |= NO_ISCSI_FLAG;
  7841. memset(iscsi_mac, 0, ETH_ALEN);
  7842. }
  7843. /* Disable FCoE if MAC configuration is
  7844. * invalid.
  7845. */
  7846. if (!is_valid_ether_addr(fip_mac)) {
  7847. bp->flags |= NO_FCOE_FLAG;
  7848. memset(bp->fip_mac, 0, ETH_ALEN);
  7849. }
  7850. #endif
  7851. if (!is_valid_ether_addr(bp->dev->dev_addr))
  7852. dev_err(&bp->pdev->dev,
  7853. "bad Ethernet MAC address configuration: "
  7854. BNX2X_MAC_FMT", change it manually before bringing up "
  7855. "the appropriate network interface\n",
  7856. BNX2X_MAC_PRN_LIST(bp->dev->dev_addr));
  7857. }
  7858. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  7859. {
  7860. int /*abs*/func = BP_ABS_FUNC(bp);
  7861. int vn;
  7862. u32 val = 0;
  7863. int rc = 0;
  7864. bnx2x_get_common_hwinfo(bp);
  7865. /*
  7866. * initialize IGU parameters
  7867. */
  7868. if (CHIP_IS_E1x(bp)) {
  7869. bp->common.int_block = INT_BLOCK_HC;
  7870. bp->igu_dsb_id = DEF_SB_IGU_ID;
  7871. bp->igu_base_sb = 0;
  7872. } else {
  7873. bp->common.int_block = INT_BLOCK_IGU;
  7874. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7875. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  7876. int tout = 5000;
  7877. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  7878. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  7879. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  7880. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  7881. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  7882. tout--;
  7883. usleep_range(1000, 1000);
  7884. }
  7885. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  7886. dev_err(&bp->pdev->dev,
  7887. "FORCING Normal Mode failed!!!\n");
  7888. return -EPERM;
  7889. }
  7890. }
  7891. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  7892. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  7893. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  7894. } else
  7895. BNX2X_DEV_INFO("IGU Normal Mode\n");
  7896. bnx2x_get_igu_cam_info(bp);
  7897. }
  7898. /*
  7899. * set base FW non-default (fast path) status block id, this value is
  7900. * used to initialize the fw_sb_id saved on the fp/queue structure to
  7901. * determine the id used by the FW.
  7902. */
  7903. if (CHIP_IS_E1x(bp))
  7904. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  7905. else /*
  7906. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  7907. * the same queue are indicated on the same IGU SB). So we prefer
  7908. * FW and IGU SBs to be the same value.
  7909. */
  7910. bp->base_fw_ndsb = bp->igu_base_sb;
  7911. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  7912. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  7913. bp->igu_sb_cnt, bp->base_fw_ndsb);
  7914. /*
  7915. * Initialize MF configuration
  7916. */
  7917. bp->mf_ov = 0;
  7918. bp->mf_mode = 0;
  7919. vn = BP_E1HVN(bp);
  7920. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  7921. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  7922. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  7923. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  7924. if (SHMEM2_HAS(bp, mf_cfg_addr))
  7925. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  7926. else
  7927. bp->common.mf_cfg_base = bp->common.shmem_base +
  7928. offsetof(struct shmem_region, func_mb) +
  7929. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  7930. /*
  7931. * get mf configuration:
  7932. * 1. existence of MF configuration
  7933. * 2. MAC address must be legal (check only upper bytes)
  7934. * for Switch-Independent mode;
  7935. * OVLAN must be legal for Switch-Dependent mode
  7936. * 3. SF_MODE configures specific MF mode
  7937. */
  7938. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  7939. /* get mf configuration */
  7940. val = SHMEM_RD(bp,
  7941. dev_info.shared_feature_config.config);
  7942. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  7943. switch (val) {
  7944. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  7945. val = MF_CFG_RD(bp, func_mf_config[func].
  7946. mac_upper);
  7947. /* check for legal mac (upper bytes)*/
  7948. if (val != 0xffff) {
  7949. bp->mf_mode = MULTI_FUNCTION_SI;
  7950. bp->mf_config[vn] = MF_CFG_RD(bp,
  7951. func_mf_config[func].config);
  7952. } else
  7953. BNX2X_DEV_INFO("illegal MAC address "
  7954. "for SI\n");
  7955. break;
  7956. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  7957. /* get OV configuration */
  7958. val = MF_CFG_RD(bp,
  7959. func_mf_config[FUNC_0].e1hov_tag);
  7960. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  7961. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  7962. bp->mf_mode = MULTI_FUNCTION_SD;
  7963. bp->mf_config[vn] = MF_CFG_RD(bp,
  7964. func_mf_config[func].config);
  7965. } else
  7966. BNX2X_DEV_INFO("illegal OV for SD\n");
  7967. break;
  7968. default:
  7969. /* Unknown configuration: reset mf_config */
  7970. bp->mf_config[vn] = 0;
  7971. BNX2X_DEV_INFO("unkown MF mode 0x%x\n", val);
  7972. }
  7973. }
  7974. BNX2X_DEV_INFO("%s function mode\n",
  7975. IS_MF(bp) ? "multi" : "single");
  7976. switch (bp->mf_mode) {
  7977. case MULTI_FUNCTION_SD:
  7978. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  7979. FUNC_MF_CFG_E1HOV_TAG_MASK;
  7980. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  7981. bp->mf_ov = val;
  7982. bp->path_has_ovlan = true;
  7983. BNX2X_DEV_INFO("MF OV for func %d is %d "
  7984. "(0x%04x)\n", func, bp->mf_ov,
  7985. bp->mf_ov);
  7986. } else {
  7987. dev_err(&bp->pdev->dev,
  7988. "No valid MF OV for func %d, "
  7989. "aborting\n", func);
  7990. return -EPERM;
  7991. }
  7992. break;
  7993. case MULTI_FUNCTION_SI:
  7994. BNX2X_DEV_INFO("func %d is in MF "
  7995. "switch-independent mode\n", func);
  7996. break;
  7997. default:
  7998. if (vn) {
  7999. dev_err(&bp->pdev->dev,
  8000. "VN %d is in a single function mode, "
  8001. "aborting\n", vn);
  8002. return -EPERM;
  8003. }
  8004. break;
  8005. }
  8006. /* check if other port on the path needs ovlan:
  8007. * Since MF configuration is shared between ports
  8008. * Possible mixed modes are only
  8009. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  8010. */
  8011. if (CHIP_MODE_IS_4_PORT(bp) &&
  8012. !bp->path_has_ovlan &&
  8013. !IS_MF(bp) &&
  8014. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8015. u8 other_port = !BP_PORT(bp);
  8016. u8 other_func = BP_PATH(bp) + 2*other_port;
  8017. val = MF_CFG_RD(bp,
  8018. func_mf_config[other_func].e1hov_tag);
  8019. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  8020. bp->path_has_ovlan = true;
  8021. }
  8022. }
  8023. /* adjust igu_sb_cnt to MF for E1x */
  8024. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  8025. bp->igu_sb_cnt /= E1HVN_MAX;
  8026. /* port info */
  8027. bnx2x_get_port_hwinfo(bp);
  8028. if (!BP_NOMCP(bp)) {
  8029. bp->fw_seq =
  8030. (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  8031. DRV_MSG_SEQ_NUMBER_MASK);
  8032. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  8033. }
  8034. /* Get MAC addresses */
  8035. bnx2x_get_mac_hwinfo(bp);
  8036. #ifdef BCM_CNIC
  8037. bnx2x_get_cnic_info(bp);
  8038. #endif
  8039. /* Get current FW pulse sequence */
  8040. if (!BP_NOMCP(bp)) {
  8041. int mb_idx = BP_FW_MB_IDX(bp);
  8042. bp->fw_drv_pulse_wr_seq =
  8043. (SHMEM_RD(bp, func_mb[mb_idx].drv_pulse_mb) &
  8044. DRV_PULSE_SEQ_MASK);
  8045. BNX2X_DEV_INFO("drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
  8046. }
  8047. return rc;
  8048. }
  8049. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  8050. {
  8051. int cnt, i, block_end, rodi;
  8052. char vpd_data[BNX2X_VPD_LEN+1];
  8053. char str_id_reg[VENDOR_ID_LEN+1];
  8054. char str_id_cap[VENDOR_ID_LEN+1];
  8055. u8 len;
  8056. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_data);
  8057. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  8058. if (cnt < BNX2X_VPD_LEN)
  8059. goto out_not_found;
  8060. i = pci_vpd_find_tag(vpd_data, 0, BNX2X_VPD_LEN,
  8061. PCI_VPD_LRDT_RO_DATA);
  8062. if (i < 0)
  8063. goto out_not_found;
  8064. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  8065. pci_vpd_lrdt_size(&vpd_data[i]);
  8066. i += PCI_VPD_LRDT_TAG_SIZE;
  8067. if (block_end > BNX2X_VPD_LEN)
  8068. goto out_not_found;
  8069. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8070. PCI_VPD_RO_KEYWORD_MFR_ID);
  8071. if (rodi < 0)
  8072. goto out_not_found;
  8073. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8074. if (len != VENDOR_ID_LEN)
  8075. goto out_not_found;
  8076. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8077. /* vendor specific info */
  8078. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  8079. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  8080. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  8081. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  8082. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8083. PCI_VPD_RO_KEYWORD_VENDOR0);
  8084. if (rodi >= 0) {
  8085. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8086. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8087. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  8088. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  8089. bp->fw_ver[len] = ' ';
  8090. }
  8091. }
  8092. return;
  8093. }
  8094. out_not_found:
  8095. return;
  8096. }
  8097. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  8098. {
  8099. u32 flags = 0;
  8100. if (CHIP_REV_IS_FPGA(bp))
  8101. SET_FLAGS(flags, MODE_FPGA);
  8102. else if (CHIP_REV_IS_EMUL(bp))
  8103. SET_FLAGS(flags, MODE_EMUL);
  8104. else
  8105. SET_FLAGS(flags, MODE_ASIC);
  8106. if (CHIP_MODE_IS_4_PORT(bp))
  8107. SET_FLAGS(flags, MODE_PORT4);
  8108. else
  8109. SET_FLAGS(flags, MODE_PORT2);
  8110. if (CHIP_IS_E2(bp))
  8111. SET_FLAGS(flags, MODE_E2);
  8112. else if (CHIP_IS_E3(bp)) {
  8113. SET_FLAGS(flags, MODE_E3);
  8114. if (CHIP_REV(bp) == CHIP_REV_Ax)
  8115. SET_FLAGS(flags, MODE_E3_A0);
  8116. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  8117. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  8118. }
  8119. if (IS_MF(bp)) {
  8120. SET_FLAGS(flags, MODE_MF);
  8121. switch (bp->mf_mode) {
  8122. case MULTI_FUNCTION_SD:
  8123. SET_FLAGS(flags, MODE_MF_SD);
  8124. break;
  8125. case MULTI_FUNCTION_SI:
  8126. SET_FLAGS(flags, MODE_MF_SI);
  8127. break;
  8128. }
  8129. } else
  8130. SET_FLAGS(flags, MODE_SF);
  8131. #if defined(__LITTLE_ENDIAN)
  8132. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  8133. #else /*(__BIG_ENDIAN)*/
  8134. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  8135. #endif
  8136. INIT_MODE_FLAGS(bp) = flags;
  8137. }
  8138. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  8139. {
  8140. int func;
  8141. int timer_interval;
  8142. int rc;
  8143. mutex_init(&bp->port.phy_mutex);
  8144. mutex_init(&bp->fw_mb_mutex);
  8145. spin_lock_init(&bp->stats_lock);
  8146. #ifdef BCM_CNIC
  8147. mutex_init(&bp->cnic_mutex);
  8148. #endif
  8149. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  8150. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  8151. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  8152. rc = bnx2x_get_hwinfo(bp);
  8153. if (rc)
  8154. return rc;
  8155. bnx2x_set_modes_bitmap(bp);
  8156. rc = bnx2x_alloc_mem_bp(bp);
  8157. if (rc)
  8158. return rc;
  8159. bnx2x_read_fwinfo(bp);
  8160. func = BP_FUNC(bp);
  8161. /* need to reset chip if undi was active */
  8162. if (!BP_NOMCP(bp))
  8163. bnx2x_undi_unload(bp);
  8164. if (CHIP_REV_IS_FPGA(bp))
  8165. dev_err(&bp->pdev->dev, "FPGA detected\n");
  8166. if (BP_NOMCP(bp) && (func == 0))
  8167. dev_err(&bp->pdev->dev, "MCP disabled, "
  8168. "must load devices in order!\n");
  8169. bp->multi_mode = multi_mode;
  8170. /* Set TPA flags */
  8171. if (disable_tpa) {
  8172. bp->flags &= ~TPA_ENABLE_FLAG;
  8173. bp->dev->features &= ~NETIF_F_LRO;
  8174. } else {
  8175. bp->flags |= TPA_ENABLE_FLAG;
  8176. bp->dev->features |= NETIF_F_LRO;
  8177. }
  8178. bp->disable_tpa = disable_tpa;
  8179. if (CHIP_IS_E1(bp))
  8180. bp->dropless_fc = 0;
  8181. else
  8182. bp->dropless_fc = dropless_fc;
  8183. bp->mrrs = mrrs;
  8184. bp->tx_ring_size = MAX_TX_AVAIL;
  8185. /* make sure that the numbers are in the right granularity */
  8186. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  8187. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  8188. timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
  8189. bp->current_interval = (poll ? poll : timer_interval);
  8190. init_timer(&bp->timer);
  8191. bp->timer.expires = jiffies + bp->current_interval;
  8192. bp->timer.data = (unsigned long) bp;
  8193. bp->timer.function = bnx2x_timer;
  8194. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  8195. bnx2x_dcbx_init_params(bp);
  8196. #ifdef BCM_CNIC
  8197. if (CHIP_IS_E1x(bp))
  8198. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  8199. else
  8200. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  8201. #endif
  8202. /* multiple tx priority */
  8203. if (CHIP_IS_E1x(bp))
  8204. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  8205. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  8206. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  8207. if (CHIP_IS_E3B0(bp))
  8208. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  8209. return rc;
  8210. }
  8211. /****************************************************************************
  8212. * General service functions
  8213. ****************************************************************************/
  8214. /*
  8215. * net_device service functions
  8216. */
  8217. /* called with rtnl_lock */
  8218. static int bnx2x_open(struct net_device *dev)
  8219. {
  8220. struct bnx2x *bp = netdev_priv(dev);
  8221. bool global = false;
  8222. int other_engine = BP_PATH(bp) ? 0 : 1;
  8223. u32 other_load_counter, load_counter;
  8224. netif_carrier_off(dev);
  8225. bnx2x_set_power_state(bp, PCI_D0);
  8226. other_load_counter = bnx2x_get_load_cnt(bp, other_engine);
  8227. load_counter = bnx2x_get_load_cnt(bp, BP_PATH(bp));
  8228. /*
  8229. * If parity had happen during the unload, then attentions
  8230. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  8231. * want the first function loaded on the current engine to
  8232. * complete the recovery.
  8233. */
  8234. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  8235. bnx2x_chk_parity_attn(bp, &global, true))
  8236. do {
  8237. /*
  8238. * If there are attentions and they are in a global
  8239. * blocks, set the GLOBAL_RESET bit regardless whether
  8240. * it will be this function that will complete the
  8241. * recovery or not.
  8242. */
  8243. if (global)
  8244. bnx2x_set_reset_global(bp);
  8245. /*
  8246. * Only the first function on the current engine should
  8247. * try to recover in open. In case of attentions in
  8248. * global blocks only the first in the chip should try
  8249. * to recover.
  8250. */
  8251. if ((!load_counter &&
  8252. (!global || !other_load_counter)) &&
  8253. bnx2x_trylock_leader_lock(bp) &&
  8254. !bnx2x_leader_reset(bp)) {
  8255. netdev_info(bp->dev, "Recovered in open\n");
  8256. break;
  8257. }
  8258. /* recovery has failed... */
  8259. bnx2x_set_power_state(bp, PCI_D3hot);
  8260. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8261. netdev_err(bp->dev, "Recovery flow hasn't been properly"
  8262. " completed yet. Try again later. If u still see this"
  8263. " message after a few retries then power cycle is"
  8264. " required.\n");
  8265. return -EAGAIN;
  8266. } while (0);
  8267. bp->recovery_state = BNX2X_RECOVERY_DONE;
  8268. return bnx2x_nic_load(bp, LOAD_OPEN);
  8269. }
  8270. /* called with rtnl_lock */
  8271. static int bnx2x_close(struct net_device *dev)
  8272. {
  8273. struct bnx2x *bp = netdev_priv(dev);
  8274. /* Unload the driver, release IRQs */
  8275. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  8276. /* Power off */
  8277. bnx2x_set_power_state(bp, PCI_D3hot);
  8278. return 0;
  8279. }
  8280. static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  8281. struct bnx2x_mcast_ramrod_params *p)
  8282. {
  8283. int mc_count = netdev_mc_count(bp->dev);
  8284. struct bnx2x_mcast_list_elem *mc_mac =
  8285. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  8286. struct netdev_hw_addr *ha;
  8287. if (!mc_mac)
  8288. return -ENOMEM;
  8289. INIT_LIST_HEAD(&p->mcast_list);
  8290. netdev_for_each_mc_addr(ha, bp->dev) {
  8291. mc_mac->mac = bnx2x_mc_addr(ha);
  8292. list_add_tail(&mc_mac->link, &p->mcast_list);
  8293. mc_mac++;
  8294. }
  8295. p->mcast_list_len = mc_count;
  8296. return 0;
  8297. }
  8298. static inline void bnx2x_free_mcast_macs_list(
  8299. struct bnx2x_mcast_ramrod_params *p)
  8300. {
  8301. struct bnx2x_mcast_list_elem *mc_mac =
  8302. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  8303. link);
  8304. WARN_ON(!mc_mac);
  8305. kfree(mc_mac);
  8306. }
  8307. /**
  8308. * bnx2x_set_uc_list - configure a new unicast MACs list.
  8309. *
  8310. * @bp: driver handle
  8311. *
  8312. * We will use zero (0) as a MAC type for these MACs.
  8313. */
  8314. static inline int bnx2x_set_uc_list(struct bnx2x *bp)
  8315. {
  8316. int rc;
  8317. struct net_device *dev = bp->dev;
  8318. struct netdev_hw_addr *ha;
  8319. struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
  8320. unsigned long ramrod_flags = 0;
  8321. /* First schedule a cleanup up of old configuration */
  8322. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  8323. if (rc < 0) {
  8324. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  8325. return rc;
  8326. }
  8327. netdev_for_each_uc_addr(ha, dev) {
  8328. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  8329. BNX2X_UC_LIST_MAC, &ramrod_flags);
  8330. if (rc < 0) {
  8331. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  8332. rc);
  8333. return rc;
  8334. }
  8335. }
  8336. /* Execute the pending commands */
  8337. __set_bit(RAMROD_CONT, &ramrod_flags);
  8338. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  8339. BNX2X_UC_LIST_MAC, &ramrod_flags);
  8340. }
  8341. static inline int bnx2x_set_mc_list(struct bnx2x *bp)
  8342. {
  8343. struct net_device *dev = bp->dev;
  8344. struct bnx2x_mcast_ramrod_params rparam = {0};
  8345. int rc = 0;
  8346. rparam.mcast_obj = &bp->mcast_obj;
  8347. /* first, clear all configured multicast MACs */
  8348. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  8349. if (rc < 0) {
  8350. BNX2X_ERR("Failed to clear multicast "
  8351. "configuration: %d\n", rc);
  8352. return rc;
  8353. }
  8354. /* then, configure a new MACs list */
  8355. if (netdev_mc_count(dev)) {
  8356. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  8357. if (rc) {
  8358. BNX2X_ERR("Failed to create multicast MACs "
  8359. "list: %d\n", rc);
  8360. return rc;
  8361. }
  8362. /* Now add the new MACs */
  8363. rc = bnx2x_config_mcast(bp, &rparam,
  8364. BNX2X_MCAST_CMD_ADD);
  8365. if (rc < 0)
  8366. BNX2X_ERR("Failed to set a new multicast "
  8367. "configuration: %d\n", rc);
  8368. bnx2x_free_mcast_macs_list(&rparam);
  8369. }
  8370. return rc;
  8371. }
  8372. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  8373. void bnx2x_set_rx_mode(struct net_device *dev)
  8374. {
  8375. struct bnx2x *bp = netdev_priv(dev);
  8376. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  8377. if (bp->state != BNX2X_STATE_OPEN) {
  8378. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  8379. return;
  8380. }
  8381. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  8382. if (dev->flags & IFF_PROMISC)
  8383. rx_mode = BNX2X_RX_MODE_PROMISC;
  8384. else if ((dev->flags & IFF_ALLMULTI) ||
  8385. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  8386. CHIP_IS_E1(bp)))
  8387. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  8388. else {
  8389. /* some multicasts */
  8390. if (bnx2x_set_mc_list(bp) < 0)
  8391. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  8392. if (bnx2x_set_uc_list(bp) < 0)
  8393. rx_mode = BNX2X_RX_MODE_PROMISC;
  8394. }
  8395. bp->rx_mode = rx_mode;
  8396. /* Schedule the rx_mode command */
  8397. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  8398. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  8399. return;
  8400. }
  8401. bnx2x_set_storm_rx_mode(bp);
  8402. }
  8403. /* called with rtnl_lock */
  8404. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  8405. int devad, u16 addr)
  8406. {
  8407. struct bnx2x *bp = netdev_priv(netdev);
  8408. u16 value;
  8409. int rc;
  8410. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  8411. prtad, devad, addr);
  8412. /* The HW expects different devad if CL22 is used */
  8413. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  8414. bnx2x_acquire_phy_lock(bp);
  8415. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  8416. bnx2x_release_phy_lock(bp);
  8417. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  8418. if (!rc)
  8419. rc = value;
  8420. return rc;
  8421. }
  8422. /* called with rtnl_lock */
  8423. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  8424. u16 addr, u16 value)
  8425. {
  8426. struct bnx2x *bp = netdev_priv(netdev);
  8427. int rc;
  8428. DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
  8429. " value 0x%x\n", prtad, devad, addr, value);
  8430. /* The HW expects different devad if CL22 is used */
  8431. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  8432. bnx2x_acquire_phy_lock(bp);
  8433. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  8434. bnx2x_release_phy_lock(bp);
  8435. return rc;
  8436. }
  8437. /* called with rtnl_lock */
  8438. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  8439. {
  8440. struct bnx2x *bp = netdev_priv(dev);
  8441. struct mii_ioctl_data *mdio = if_mii(ifr);
  8442. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  8443. mdio->phy_id, mdio->reg_num, mdio->val_in);
  8444. if (!netif_running(dev))
  8445. return -EAGAIN;
  8446. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  8447. }
  8448. #ifdef CONFIG_NET_POLL_CONTROLLER
  8449. static void poll_bnx2x(struct net_device *dev)
  8450. {
  8451. struct bnx2x *bp = netdev_priv(dev);
  8452. disable_irq(bp->pdev->irq);
  8453. bnx2x_interrupt(bp->pdev->irq, dev);
  8454. enable_irq(bp->pdev->irq);
  8455. }
  8456. #endif
  8457. static const struct net_device_ops bnx2x_netdev_ops = {
  8458. .ndo_open = bnx2x_open,
  8459. .ndo_stop = bnx2x_close,
  8460. .ndo_start_xmit = bnx2x_start_xmit,
  8461. .ndo_select_queue = bnx2x_select_queue,
  8462. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  8463. .ndo_set_mac_address = bnx2x_change_mac_addr,
  8464. .ndo_validate_addr = eth_validate_addr,
  8465. .ndo_do_ioctl = bnx2x_ioctl,
  8466. .ndo_change_mtu = bnx2x_change_mtu,
  8467. .ndo_fix_features = bnx2x_fix_features,
  8468. .ndo_set_features = bnx2x_set_features,
  8469. .ndo_tx_timeout = bnx2x_tx_timeout,
  8470. #ifdef CONFIG_NET_POLL_CONTROLLER
  8471. .ndo_poll_controller = poll_bnx2x,
  8472. #endif
  8473. .ndo_setup_tc = bnx2x_setup_tc,
  8474. #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
  8475. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  8476. #endif
  8477. };
  8478. static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
  8479. {
  8480. struct device *dev = &bp->pdev->dev;
  8481. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  8482. bp->flags |= USING_DAC_FLAG;
  8483. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  8484. dev_err(dev, "dma_set_coherent_mask failed, "
  8485. "aborting\n");
  8486. return -EIO;
  8487. }
  8488. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  8489. dev_err(dev, "System does not support DMA, aborting\n");
  8490. return -EIO;
  8491. }
  8492. return 0;
  8493. }
  8494. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  8495. struct net_device *dev,
  8496. unsigned long board_type)
  8497. {
  8498. struct bnx2x *bp;
  8499. int rc;
  8500. SET_NETDEV_DEV(dev, &pdev->dev);
  8501. bp = netdev_priv(dev);
  8502. bp->dev = dev;
  8503. bp->pdev = pdev;
  8504. bp->flags = 0;
  8505. bp->pf_num = PCI_FUNC(pdev->devfn);
  8506. rc = pci_enable_device(pdev);
  8507. if (rc) {
  8508. dev_err(&bp->pdev->dev,
  8509. "Cannot enable PCI device, aborting\n");
  8510. goto err_out;
  8511. }
  8512. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  8513. dev_err(&bp->pdev->dev,
  8514. "Cannot find PCI device base address, aborting\n");
  8515. rc = -ENODEV;
  8516. goto err_out_disable;
  8517. }
  8518. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  8519. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  8520. " base address, aborting\n");
  8521. rc = -ENODEV;
  8522. goto err_out_disable;
  8523. }
  8524. if (atomic_read(&pdev->enable_cnt) == 1) {
  8525. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  8526. if (rc) {
  8527. dev_err(&bp->pdev->dev,
  8528. "Cannot obtain PCI resources, aborting\n");
  8529. goto err_out_disable;
  8530. }
  8531. pci_set_master(pdev);
  8532. pci_save_state(pdev);
  8533. }
  8534. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  8535. if (bp->pm_cap == 0) {
  8536. dev_err(&bp->pdev->dev,
  8537. "Cannot find power management capability, aborting\n");
  8538. rc = -EIO;
  8539. goto err_out_release;
  8540. }
  8541. if (!pci_is_pcie(pdev)) {
  8542. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  8543. rc = -EIO;
  8544. goto err_out_release;
  8545. }
  8546. rc = bnx2x_set_coherency_mask(bp);
  8547. if (rc)
  8548. goto err_out_release;
  8549. dev->mem_start = pci_resource_start(pdev, 0);
  8550. dev->base_addr = dev->mem_start;
  8551. dev->mem_end = pci_resource_end(pdev, 0);
  8552. dev->irq = pdev->irq;
  8553. bp->regview = pci_ioremap_bar(pdev, 0);
  8554. if (!bp->regview) {
  8555. dev_err(&bp->pdev->dev,
  8556. "Cannot map register space, aborting\n");
  8557. rc = -ENOMEM;
  8558. goto err_out_release;
  8559. }
  8560. bnx2x_set_power_state(bp, PCI_D0);
  8561. /* clean indirect addresses */
  8562. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  8563. PCICFG_VENDOR_ID_OFFSET);
  8564. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
  8565. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
  8566. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
  8567. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
  8568. /*
  8569. * Enable internal target-read (in case we are probed after PF FLR).
  8570. * Must be done prior to any BAR read access. Only for 57712 and up
  8571. */
  8572. if (board_type != BCM57710 &&
  8573. board_type != BCM57711 &&
  8574. board_type != BCM57711E)
  8575. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  8576. /* Reset the load counter */
  8577. bnx2x_clear_load_cnt(bp);
  8578. dev->watchdog_timeo = TX_TIMEOUT;
  8579. dev->netdev_ops = &bnx2x_netdev_ops;
  8580. bnx2x_set_ethtool_ops(dev);
  8581. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  8582. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  8583. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_HW_VLAN_TX;
  8584. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  8585. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  8586. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  8587. if (bp->flags & USING_DAC_FLAG)
  8588. dev->features |= NETIF_F_HIGHDMA;
  8589. /* Add Loopback capability to the device */
  8590. dev->hw_features |= NETIF_F_LOOPBACK;
  8591. #ifdef BCM_DCBNL
  8592. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  8593. #endif
  8594. /* get_port_hwinfo() will set prtad and mmds properly */
  8595. bp->mdio.prtad = MDIO_PRTAD_NONE;
  8596. bp->mdio.mmds = 0;
  8597. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  8598. bp->mdio.dev = dev;
  8599. bp->mdio.mdio_read = bnx2x_mdio_read;
  8600. bp->mdio.mdio_write = bnx2x_mdio_write;
  8601. return 0;
  8602. err_out_release:
  8603. if (atomic_read(&pdev->enable_cnt) == 1)
  8604. pci_release_regions(pdev);
  8605. err_out_disable:
  8606. pci_disable_device(pdev);
  8607. pci_set_drvdata(pdev, NULL);
  8608. err_out:
  8609. return rc;
  8610. }
  8611. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  8612. int *width, int *speed)
  8613. {
  8614. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  8615. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  8616. /* return value of 1=2.5GHz 2=5GHz */
  8617. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  8618. }
  8619. static int bnx2x_check_firmware(struct bnx2x *bp)
  8620. {
  8621. const struct firmware *firmware = bp->firmware;
  8622. struct bnx2x_fw_file_hdr *fw_hdr;
  8623. struct bnx2x_fw_file_section *sections;
  8624. u32 offset, len, num_ops;
  8625. u16 *ops_offsets;
  8626. int i;
  8627. const u8 *fw_ver;
  8628. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
  8629. return -EINVAL;
  8630. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  8631. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  8632. /* Make sure none of the offsets and sizes make us read beyond
  8633. * the end of the firmware data */
  8634. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  8635. offset = be32_to_cpu(sections[i].offset);
  8636. len = be32_to_cpu(sections[i].len);
  8637. if (offset + len > firmware->size) {
  8638. dev_err(&bp->pdev->dev,
  8639. "Section %d length is out of bounds\n", i);
  8640. return -EINVAL;
  8641. }
  8642. }
  8643. /* Likewise for the init_ops offsets */
  8644. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  8645. ops_offsets = (u16 *)(firmware->data + offset);
  8646. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  8647. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  8648. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  8649. dev_err(&bp->pdev->dev,
  8650. "Section offset %d is out of bounds\n", i);
  8651. return -EINVAL;
  8652. }
  8653. }
  8654. /* Check FW version */
  8655. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  8656. fw_ver = firmware->data + offset;
  8657. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  8658. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  8659. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  8660. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  8661. dev_err(&bp->pdev->dev,
  8662. "Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  8663. fw_ver[0], fw_ver[1], fw_ver[2],
  8664. fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
  8665. BCM_5710_FW_MINOR_VERSION,
  8666. BCM_5710_FW_REVISION_VERSION,
  8667. BCM_5710_FW_ENGINEERING_VERSION);
  8668. return -EINVAL;
  8669. }
  8670. return 0;
  8671. }
  8672. static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  8673. {
  8674. const __be32 *source = (const __be32 *)_source;
  8675. u32 *target = (u32 *)_target;
  8676. u32 i;
  8677. for (i = 0; i < n/4; i++)
  8678. target[i] = be32_to_cpu(source[i]);
  8679. }
  8680. /*
  8681. Ops array is stored in the following format:
  8682. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  8683. */
  8684. static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  8685. {
  8686. const __be32 *source = (const __be32 *)_source;
  8687. struct raw_op *target = (struct raw_op *)_target;
  8688. u32 i, j, tmp;
  8689. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  8690. tmp = be32_to_cpu(source[j]);
  8691. target[i].op = (tmp >> 24) & 0xff;
  8692. target[i].offset = tmp & 0xffffff;
  8693. target[i].raw_data = be32_to_cpu(source[j + 1]);
  8694. }
  8695. }
  8696. /**
  8697. * IRO array is stored in the following format:
  8698. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  8699. */
  8700. static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  8701. {
  8702. const __be32 *source = (const __be32 *)_source;
  8703. struct iro *target = (struct iro *)_target;
  8704. u32 i, j, tmp;
  8705. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  8706. target[i].base = be32_to_cpu(source[j]);
  8707. j++;
  8708. tmp = be32_to_cpu(source[j]);
  8709. target[i].m1 = (tmp >> 16) & 0xffff;
  8710. target[i].m2 = tmp & 0xffff;
  8711. j++;
  8712. tmp = be32_to_cpu(source[j]);
  8713. target[i].m3 = (tmp >> 16) & 0xffff;
  8714. target[i].size = tmp & 0xffff;
  8715. j++;
  8716. }
  8717. }
  8718. static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  8719. {
  8720. const __be16 *source = (const __be16 *)_source;
  8721. u16 *target = (u16 *)_target;
  8722. u32 i;
  8723. for (i = 0; i < n/2; i++)
  8724. target[i] = be16_to_cpu(source[i]);
  8725. }
  8726. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  8727. do { \
  8728. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  8729. bp->arr = kmalloc(len, GFP_KERNEL); \
  8730. if (!bp->arr) { \
  8731. pr_err("Failed to allocate %d bytes for "#arr"\n", len); \
  8732. goto lbl; \
  8733. } \
  8734. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  8735. (u8 *)bp->arr, len); \
  8736. } while (0)
  8737. int bnx2x_init_firmware(struct bnx2x *bp)
  8738. {
  8739. const char *fw_file_name;
  8740. struct bnx2x_fw_file_hdr *fw_hdr;
  8741. int rc;
  8742. if (CHIP_IS_E1(bp))
  8743. fw_file_name = FW_FILE_NAME_E1;
  8744. else if (CHIP_IS_E1H(bp))
  8745. fw_file_name = FW_FILE_NAME_E1H;
  8746. else if (!CHIP_IS_E1x(bp))
  8747. fw_file_name = FW_FILE_NAME_E2;
  8748. else {
  8749. BNX2X_ERR("Unsupported chip revision\n");
  8750. return -EINVAL;
  8751. }
  8752. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  8753. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  8754. if (rc) {
  8755. BNX2X_ERR("Can't load firmware file %s\n", fw_file_name);
  8756. goto request_firmware_exit;
  8757. }
  8758. rc = bnx2x_check_firmware(bp);
  8759. if (rc) {
  8760. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  8761. goto request_firmware_exit;
  8762. }
  8763. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  8764. /* Initialize the pointers to the init arrays */
  8765. /* Blob */
  8766. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  8767. /* Opcodes */
  8768. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  8769. /* Offsets */
  8770. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  8771. be16_to_cpu_n);
  8772. /* STORMs firmware */
  8773. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8774. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  8775. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  8776. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  8777. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8778. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  8779. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  8780. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  8781. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8782. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  8783. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  8784. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  8785. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  8786. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  8787. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  8788. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  8789. /* IRO */
  8790. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  8791. return 0;
  8792. iro_alloc_err:
  8793. kfree(bp->init_ops_offsets);
  8794. init_offsets_alloc_err:
  8795. kfree(bp->init_ops);
  8796. init_ops_alloc_err:
  8797. kfree(bp->init_data);
  8798. request_firmware_exit:
  8799. release_firmware(bp->firmware);
  8800. return rc;
  8801. }
  8802. static void bnx2x_release_firmware(struct bnx2x *bp)
  8803. {
  8804. kfree(bp->init_ops_offsets);
  8805. kfree(bp->init_ops);
  8806. kfree(bp->init_data);
  8807. release_firmware(bp->firmware);
  8808. }
  8809. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  8810. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  8811. .init_hw_cmn = bnx2x_init_hw_common,
  8812. .init_hw_port = bnx2x_init_hw_port,
  8813. .init_hw_func = bnx2x_init_hw_func,
  8814. .reset_hw_cmn = bnx2x_reset_common,
  8815. .reset_hw_port = bnx2x_reset_port,
  8816. .reset_hw_func = bnx2x_reset_func,
  8817. .gunzip_init = bnx2x_gunzip_init,
  8818. .gunzip_end = bnx2x_gunzip_end,
  8819. .init_fw = bnx2x_init_firmware,
  8820. .release_fw = bnx2x_release_firmware,
  8821. };
  8822. void bnx2x__init_func_obj(struct bnx2x *bp)
  8823. {
  8824. /* Prepare DMAE related driver resources */
  8825. bnx2x_setup_dmae(bp);
  8826. bnx2x_init_func_obj(bp, &bp->func_obj,
  8827. bnx2x_sp(bp, func_rdata),
  8828. bnx2x_sp_mapping(bp, func_rdata),
  8829. &bnx2x_func_sp_drv);
  8830. }
  8831. /* must be called after sriov-enable */
  8832. static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  8833. {
  8834. int cid_count = BNX2X_L2_CID_COUNT(bp);
  8835. #ifdef BCM_CNIC
  8836. cid_count += CNIC_CID_MAX;
  8837. #endif
  8838. return roundup(cid_count, QM_CID_ROUND);
  8839. }
  8840. /**
  8841. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  8842. *
  8843. * @dev: pci device
  8844. *
  8845. */
  8846. static inline int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
  8847. {
  8848. int pos;
  8849. u16 control;
  8850. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  8851. /*
  8852. * If MSI-X is not supported - return number of SBs needed to support
  8853. * one fast path queue: one FP queue + SB for CNIC
  8854. */
  8855. if (!pos)
  8856. return 1 + CNIC_PRESENT;
  8857. /*
  8858. * The value in the PCI configuration space is the index of the last
  8859. * entry, namely one less than the actual size of the table, which is
  8860. * exactly what we want to return from this function: number of all SBs
  8861. * without the default SB.
  8862. */
  8863. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  8864. return control & PCI_MSIX_FLAGS_QSIZE;
  8865. }
  8866. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  8867. const struct pci_device_id *ent)
  8868. {
  8869. struct net_device *dev = NULL;
  8870. struct bnx2x *bp;
  8871. int pcie_width, pcie_speed;
  8872. int rc, max_non_def_sbs;
  8873. int rx_count, tx_count, rss_count;
  8874. /*
  8875. * An estimated maximum supported CoS number according to the chip
  8876. * version.
  8877. * We will try to roughly estimate the maximum number of CoSes this chip
  8878. * may support in order to minimize the memory allocated for Tx
  8879. * netdev_queue's. This number will be accurately calculated during the
  8880. * initialization of bp->max_cos based on the chip versions AND chip
  8881. * revision in the bnx2x_init_bp().
  8882. */
  8883. u8 max_cos_est = 0;
  8884. switch (ent->driver_data) {
  8885. case BCM57710:
  8886. case BCM57711:
  8887. case BCM57711E:
  8888. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  8889. break;
  8890. case BCM57712:
  8891. case BCM57712_MF:
  8892. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  8893. break;
  8894. case BCM57800:
  8895. case BCM57800_MF:
  8896. case BCM57810:
  8897. case BCM57810_MF:
  8898. case BCM57840:
  8899. case BCM57840_MF:
  8900. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  8901. break;
  8902. default:
  8903. pr_err("Unknown board_type (%ld), aborting\n",
  8904. ent->driver_data);
  8905. return -ENODEV;
  8906. }
  8907. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
  8908. /* !!! FIXME !!!
  8909. * Do not allow the maximum SB count to grow above 16
  8910. * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
  8911. * We will use the FP_SB_MAX_E1x macro for this matter.
  8912. */
  8913. max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
  8914. WARN_ON(!max_non_def_sbs);
  8915. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  8916. rss_count = max_non_def_sbs - CNIC_PRESENT;
  8917. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  8918. rx_count = rss_count + FCOE_PRESENT;
  8919. /*
  8920. * Maximum number of netdev Tx queues:
  8921. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  8922. */
  8923. tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
  8924. /* dev zeroed in init_etherdev */
  8925. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  8926. if (!dev) {
  8927. dev_err(&pdev->dev, "Cannot allocate net device\n");
  8928. return -ENOMEM;
  8929. }
  8930. bp = netdev_priv(dev);
  8931. DP(NETIF_MSG_DRV, "Allocated netdev with %d tx and %d rx queues\n",
  8932. tx_count, rx_count);
  8933. bp->igu_sb_cnt = max_non_def_sbs;
  8934. bp->msg_enable = debug;
  8935. pci_set_drvdata(pdev, dev);
  8936. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  8937. if (rc < 0) {
  8938. free_netdev(dev);
  8939. return rc;
  8940. }
  8941. DP(NETIF_MSG_DRV, "max_non_def_sbs %d", max_non_def_sbs);
  8942. rc = bnx2x_init_bp(bp);
  8943. if (rc)
  8944. goto init_one_exit;
  8945. /*
  8946. * Map doorbels here as we need the real value of bp->max_cos which
  8947. * is initialized in bnx2x_init_bp().
  8948. */
  8949. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  8950. min_t(u64, BNX2X_DB_SIZE(bp),
  8951. pci_resource_len(pdev, 2)));
  8952. if (!bp->doorbells) {
  8953. dev_err(&bp->pdev->dev,
  8954. "Cannot map doorbell space, aborting\n");
  8955. rc = -ENOMEM;
  8956. goto init_one_exit;
  8957. }
  8958. /* calc qm_cid_count */
  8959. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  8960. #ifdef BCM_CNIC
  8961. /* disable FCOE L2 queue for E1x and E3*/
  8962. if (CHIP_IS_E1x(bp) || CHIP_IS_E3(bp))
  8963. bp->flags |= NO_FCOE_FLAG;
  8964. #endif
  8965. /* Configure interrupt mode: try to enable MSI-X/MSI if
  8966. * needed, set bp->num_queues appropriately.
  8967. */
  8968. bnx2x_set_int_mode(bp);
  8969. /* Add all NAPI objects */
  8970. bnx2x_add_all_napi(bp);
  8971. rc = register_netdev(dev);
  8972. if (rc) {
  8973. dev_err(&pdev->dev, "Cannot register net device\n");
  8974. goto init_one_exit;
  8975. }
  8976. #ifdef BCM_CNIC
  8977. if (!NO_FCOE(bp)) {
  8978. /* Add storage MAC address */
  8979. rtnl_lock();
  8980. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  8981. rtnl_unlock();
  8982. }
  8983. #endif
  8984. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  8985. netdev_info(dev, "%s (%c%d) PCI-E x%d %s found at mem %lx,"
  8986. " IRQ %d, ", board_info[ent->driver_data].name,
  8987. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  8988. pcie_width,
  8989. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  8990. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  8991. "5GHz (Gen2)" : "2.5GHz",
  8992. dev->base_addr, bp->pdev->irq);
  8993. pr_cont("node addr %pM\n", dev->dev_addr);
  8994. return 0;
  8995. init_one_exit:
  8996. if (bp->regview)
  8997. iounmap(bp->regview);
  8998. if (bp->doorbells)
  8999. iounmap(bp->doorbells);
  9000. free_netdev(dev);
  9001. if (atomic_read(&pdev->enable_cnt) == 1)
  9002. pci_release_regions(pdev);
  9003. pci_disable_device(pdev);
  9004. pci_set_drvdata(pdev, NULL);
  9005. return rc;
  9006. }
  9007. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  9008. {
  9009. struct net_device *dev = pci_get_drvdata(pdev);
  9010. struct bnx2x *bp;
  9011. if (!dev) {
  9012. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  9013. return;
  9014. }
  9015. bp = netdev_priv(dev);
  9016. #ifdef BCM_CNIC
  9017. /* Delete storage MAC address */
  9018. if (!NO_FCOE(bp)) {
  9019. rtnl_lock();
  9020. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9021. rtnl_unlock();
  9022. }
  9023. #endif
  9024. #ifdef BCM_DCBNL
  9025. /* Delete app tlvs from dcbnl */
  9026. bnx2x_dcbnl_update_applist(bp, true);
  9027. #endif
  9028. unregister_netdev(dev);
  9029. /* Delete all NAPI objects */
  9030. bnx2x_del_all_napi(bp);
  9031. /* Power on: we can't let PCI layer write to us while we are in D3 */
  9032. bnx2x_set_power_state(bp, PCI_D0);
  9033. /* Disable MSI/MSI-X */
  9034. bnx2x_disable_msi(bp);
  9035. /* Power off */
  9036. bnx2x_set_power_state(bp, PCI_D3hot);
  9037. /* Make sure RESET task is not scheduled before continuing */
  9038. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  9039. if (bp->regview)
  9040. iounmap(bp->regview);
  9041. if (bp->doorbells)
  9042. iounmap(bp->doorbells);
  9043. bnx2x_free_mem_bp(bp);
  9044. free_netdev(dev);
  9045. if (atomic_read(&pdev->enable_cnt) == 1)
  9046. pci_release_regions(pdev);
  9047. pci_disable_device(pdev);
  9048. pci_set_drvdata(pdev, NULL);
  9049. }
  9050. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  9051. {
  9052. int i;
  9053. bp->state = BNX2X_STATE_ERROR;
  9054. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9055. #ifdef BCM_CNIC
  9056. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  9057. #endif
  9058. /* Stop Tx */
  9059. bnx2x_tx_disable(bp);
  9060. bnx2x_netif_stop(bp, 0);
  9061. del_timer_sync(&bp->timer);
  9062. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  9063. /* Release IRQs */
  9064. bnx2x_free_irq(bp);
  9065. /* Free SKBs, SGEs, TPA pool and driver internals */
  9066. bnx2x_free_skbs(bp);
  9067. for_each_rx_queue(bp, i)
  9068. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  9069. bnx2x_free_mem(bp);
  9070. bp->state = BNX2X_STATE_CLOSED;
  9071. netif_carrier_off(bp->dev);
  9072. return 0;
  9073. }
  9074. static void bnx2x_eeh_recover(struct bnx2x *bp)
  9075. {
  9076. u32 val;
  9077. mutex_init(&bp->port.phy_mutex);
  9078. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  9079. bp->link_params.shmem_base = bp->common.shmem_base;
  9080. BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
  9081. if (!bp->common.shmem_base ||
  9082. (bp->common.shmem_base < 0xA0000) ||
  9083. (bp->common.shmem_base >= 0xC0000)) {
  9084. BNX2X_DEV_INFO("MCP not active\n");
  9085. bp->flags |= NO_MCP_FLAG;
  9086. return;
  9087. }
  9088. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  9089. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9090. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9091. BNX2X_ERR("BAD MCP validity signature\n");
  9092. if (!BP_NOMCP(bp)) {
  9093. bp->fw_seq =
  9094. (SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9095. DRV_MSG_SEQ_NUMBER_MASK);
  9096. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9097. }
  9098. }
  9099. /**
  9100. * bnx2x_io_error_detected - called when PCI error is detected
  9101. * @pdev: Pointer to PCI device
  9102. * @state: The current pci connection state
  9103. *
  9104. * This function is called after a PCI bus error affecting
  9105. * this device has been detected.
  9106. */
  9107. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  9108. pci_channel_state_t state)
  9109. {
  9110. struct net_device *dev = pci_get_drvdata(pdev);
  9111. struct bnx2x *bp = netdev_priv(dev);
  9112. rtnl_lock();
  9113. netif_device_detach(dev);
  9114. if (state == pci_channel_io_perm_failure) {
  9115. rtnl_unlock();
  9116. return PCI_ERS_RESULT_DISCONNECT;
  9117. }
  9118. if (netif_running(dev))
  9119. bnx2x_eeh_nic_unload(bp);
  9120. pci_disable_device(pdev);
  9121. rtnl_unlock();
  9122. /* Request a slot reset */
  9123. return PCI_ERS_RESULT_NEED_RESET;
  9124. }
  9125. /**
  9126. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  9127. * @pdev: Pointer to PCI device
  9128. *
  9129. * Restart the card from scratch, as if from a cold-boot.
  9130. */
  9131. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  9132. {
  9133. struct net_device *dev = pci_get_drvdata(pdev);
  9134. struct bnx2x *bp = netdev_priv(dev);
  9135. rtnl_lock();
  9136. if (pci_enable_device(pdev)) {
  9137. dev_err(&pdev->dev,
  9138. "Cannot re-enable PCI device after reset\n");
  9139. rtnl_unlock();
  9140. return PCI_ERS_RESULT_DISCONNECT;
  9141. }
  9142. pci_set_master(pdev);
  9143. pci_restore_state(pdev);
  9144. if (netif_running(dev))
  9145. bnx2x_set_power_state(bp, PCI_D0);
  9146. rtnl_unlock();
  9147. return PCI_ERS_RESULT_RECOVERED;
  9148. }
  9149. /**
  9150. * bnx2x_io_resume - called when traffic can start flowing again
  9151. * @pdev: Pointer to PCI device
  9152. *
  9153. * This callback is called when the error recovery driver tells us that
  9154. * its OK to resume normal operation.
  9155. */
  9156. static void bnx2x_io_resume(struct pci_dev *pdev)
  9157. {
  9158. struct net_device *dev = pci_get_drvdata(pdev);
  9159. struct bnx2x *bp = netdev_priv(dev);
  9160. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  9161. netdev_err(bp->dev, "Handling parity error recovery. "
  9162. "Try again later\n");
  9163. return;
  9164. }
  9165. rtnl_lock();
  9166. bnx2x_eeh_recover(bp);
  9167. if (netif_running(dev))
  9168. bnx2x_nic_load(bp, LOAD_NORMAL);
  9169. netif_device_attach(dev);
  9170. rtnl_unlock();
  9171. }
  9172. static struct pci_error_handlers bnx2x_err_handler = {
  9173. .error_detected = bnx2x_io_error_detected,
  9174. .slot_reset = bnx2x_io_slot_reset,
  9175. .resume = bnx2x_io_resume,
  9176. };
  9177. static struct pci_driver bnx2x_pci_driver = {
  9178. .name = DRV_MODULE_NAME,
  9179. .id_table = bnx2x_pci_tbl,
  9180. .probe = bnx2x_init_one,
  9181. .remove = __devexit_p(bnx2x_remove_one),
  9182. .suspend = bnx2x_suspend,
  9183. .resume = bnx2x_resume,
  9184. .err_handler = &bnx2x_err_handler,
  9185. };
  9186. static int __init bnx2x_init(void)
  9187. {
  9188. int ret;
  9189. pr_info("%s", version);
  9190. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  9191. if (bnx2x_wq == NULL) {
  9192. pr_err("Cannot create workqueue\n");
  9193. return -ENOMEM;
  9194. }
  9195. ret = pci_register_driver(&bnx2x_pci_driver);
  9196. if (ret) {
  9197. pr_err("Cannot register driver\n");
  9198. destroy_workqueue(bnx2x_wq);
  9199. }
  9200. return ret;
  9201. }
  9202. static void __exit bnx2x_cleanup(void)
  9203. {
  9204. pci_unregister_driver(&bnx2x_pci_driver);
  9205. destroy_workqueue(bnx2x_wq);
  9206. }
  9207. void bnx2x_notify_link_changed(struct bnx2x *bp)
  9208. {
  9209. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  9210. }
  9211. module_init(bnx2x_init);
  9212. module_exit(bnx2x_cleanup);
  9213. #ifdef BCM_CNIC
  9214. /**
  9215. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  9216. *
  9217. * @bp: driver handle
  9218. * @set: set or clear the CAM entry
  9219. *
  9220. * This function will wait until the ramdord completion returns.
  9221. * Return 0 if success, -ENODEV if ramrod doesn't return.
  9222. */
  9223. static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  9224. {
  9225. unsigned long ramrod_flags = 0;
  9226. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  9227. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  9228. &bp->iscsi_l2_mac_obj, true,
  9229. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  9230. }
  9231. /* count denotes the number of new completions we have seen */
  9232. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  9233. {
  9234. struct eth_spe *spe;
  9235. #ifdef BNX2X_STOP_ON_ERROR
  9236. if (unlikely(bp->panic))
  9237. return;
  9238. #endif
  9239. spin_lock_bh(&bp->spq_lock);
  9240. BUG_ON(bp->cnic_spq_pending < count);
  9241. bp->cnic_spq_pending -= count;
  9242. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  9243. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  9244. & SPE_HDR_CONN_TYPE) >>
  9245. SPE_HDR_CONN_TYPE_SHIFT;
  9246. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  9247. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  9248. /* Set validation for iSCSI L2 client before sending SETUP
  9249. * ramrod
  9250. */
  9251. if (type == ETH_CONNECTION_TYPE) {
  9252. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
  9253. bnx2x_set_ctx_validation(bp, &bp->context.
  9254. vcxt[BNX2X_ISCSI_ETH_CID].eth,
  9255. BNX2X_ISCSI_ETH_CID);
  9256. }
  9257. /*
  9258. * There may be not more than 8 L2, not more than 8 L5 SPEs
  9259. * and in the air. We also check that number of outstanding
  9260. * COMMON ramrods is not more than the EQ and SPQ can
  9261. * accommodate.
  9262. */
  9263. if (type == ETH_CONNECTION_TYPE) {
  9264. if (!atomic_read(&bp->cq_spq_left))
  9265. break;
  9266. else
  9267. atomic_dec(&bp->cq_spq_left);
  9268. } else if (type == NONE_CONNECTION_TYPE) {
  9269. if (!atomic_read(&bp->eq_spq_left))
  9270. break;
  9271. else
  9272. atomic_dec(&bp->eq_spq_left);
  9273. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  9274. (type == FCOE_CONNECTION_TYPE)) {
  9275. if (bp->cnic_spq_pending >=
  9276. bp->cnic_eth_dev.max_kwqe_pending)
  9277. break;
  9278. else
  9279. bp->cnic_spq_pending++;
  9280. } else {
  9281. BNX2X_ERR("Unknown SPE type: %d\n", type);
  9282. bnx2x_panic();
  9283. break;
  9284. }
  9285. spe = bnx2x_sp_get_next(bp);
  9286. *spe = *bp->cnic_kwq_cons;
  9287. DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
  9288. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  9289. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  9290. bp->cnic_kwq_cons = bp->cnic_kwq;
  9291. else
  9292. bp->cnic_kwq_cons++;
  9293. }
  9294. bnx2x_sp_prod_update(bp);
  9295. spin_unlock_bh(&bp->spq_lock);
  9296. }
  9297. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  9298. struct kwqe_16 *kwqes[], u32 count)
  9299. {
  9300. struct bnx2x *bp = netdev_priv(dev);
  9301. int i;
  9302. #ifdef BNX2X_STOP_ON_ERROR
  9303. if (unlikely(bp->panic))
  9304. return -EIO;
  9305. #endif
  9306. spin_lock_bh(&bp->spq_lock);
  9307. for (i = 0; i < count; i++) {
  9308. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  9309. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  9310. break;
  9311. *bp->cnic_kwq_prod = *spe;
  9312. bp->cnic_kwq_pending++;
  9313. DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
  9314. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  9315. spe->data.update_data_addr.hi,
  9316. spe->data.update_data_addr.lo,
  9317. bp->cnic_kwq_pending);
  9318. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  9319. bp->cnic_kwq_prod = bp->cnic_kwq;
  9320. else
  9321. bp->cnic_kwq_prod++;
  9322. }
  9323. spin_unlock_bh(&bp->spq_lock);
  9324. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  9325. bnx2x_cnic_sp_post(bp, 0);
  9326. return i;
  9327. }
  9328. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  9329. {
  9330. struct cnic_ops *c_ops;
  9331. int rc = 0;
  9332. mutex_lock(&bp->cnic_mutex);
  9333. c_ops = rcu_dereference_protected(bp->cnic_ops,
  9334. lockdep_is_held(&bp->cnic_mutex));
  9335. if (c_ops)
  9336. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  9337. mutex_unlock(&bp->cnic_mutex);
  9338. return rc;
  9339. }
  9340. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  9341. {
  9342. struct cnic_ops *c_ops;
  9343. int rc = 0;
  9344. rcu_read_lock();
  9345. c_ops = rcu_dereference(bp->cnic_ops);
  9346. if (c_ops)
  9347. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  9348. rcu_read_unlock();
  9349. return rc;
  9350. }
  9351. /*
  9352. * for commands that have no data
  9353. */
  9354. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  9355. {
  9356. struct cnic_ctl_info ctl = {0};
  9357. ctl.cmd = cmd;
  9358. return bnx2x_cnic_ctl_send(bp, &ctl);
  9359. }
  9360. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  9361. {
  9362. struct cnic_ctl_info ctl = {0};
  9363. /* first we tell CNIC and only then we count this as a completion */
  9364. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  9365. ctl.data.comp.cid = cid;
  9366. ctl.data.comp.error = err;
  9367. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  9368. bnx2x_cnic_sp_post(bp, 0);
  9369. }
  9370. /* Called with netif_addr_lock_bh() taken.
  9371. * Sets an rx_mode config for an iSCSI ETH client.
  9372. * Doesn't block.
  9373. * Completion should be checked outside.
  9374. */
  9375. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  9376. {
  9377. unsigned long accept_flags = 0, ramrod_flags = 0;
  9378. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  9379. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  9380. if (start) {
  9381. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  9382. * because it's the only way for UIO Queue to accept
  9383. * multicasts (in non-promiscuous mode only one Queue per
  9384. * function will receive multicast packets (leading in our
  9385. * case).
  9386. */
  9387. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  9388. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  9389. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  9390. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  9391. /* Clear STOP_PENDING bit if START is requested */
  9392. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  9393. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  9394. } else
  9395. /* Clear START_PENDING bit if STOP is requested */
  9396. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  9397. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  9398. set_bit(sched_state, &bp->sp_state);
  9399. else {
  9400. __set_bit(RAMROD_RX, &ramrod_flags);
  9401. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  9402. ramrod_flags);
  9403. }
  9404. }
  9405. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  9406. {
  9407. struct bnx2x *bp = netdev_priv(dev);
  9408. int rc = 0;
  9409. switch (ctl->cmd) {
  9410. case DRV_CTL_CTXTBL_WR_CMD: {
  9411. u32 index = ctl->data.io.offset;
  9412. dma_addr_t addr = ctl->data.io.dma_addr;
  9413. bnx2x_ilt_wr(bp, index, addr);
  9414. break;
  9415. }
  9416. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  9417. int count = ctl->data.credit.credit_count;
  9418. bnx2x_cnic_sp_post(bp, count);
  9419. break;
  9420. }
  9421. /* rtnl_lock is held. */
  9422. case DRV_CTL_START_L2_CMD: {
  9423. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9424. unsigned long sp_bits = 0;
  9425. /* Configure the iSCSI classification object */
  9426. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  9427. cp->iscsi_l2_client_id,
  9428. cp->iscsi_l2_cid, BP_FUNC(bp),
  9429. bnx2x_sp(bp, mac_rdata),
  9430. bnx2x_sp_mapping(bp, mac_rdata),
  9431. BNX2X_FILTER_MAC_PENDING,
  9432. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  9433. &bp->macs_pool);
  9434. /* Set iSCSI MAC address */
  9435. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  9436. if (rc)
  9437. break;
  9438. mmiowb();
  9439. barrier();
  9440. /* Start accepting on iSCSI L2 ring */
  9441. netif_addr_lock_bh(dev);
  9442. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  9443. netif_addr_unlock_bh(dev);
  9444. /* bits to wait on */
  9445. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  9446. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  9447. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  9448. BNX2X_ERR("rx_mode completion timed out!\n");
  9449. break;
  9450. }
  9451. /* rtnl_lock is held. */
  9452. case DRV_CTL_STOP_L2_CMD: {
  9453. unsigned long sp_bits = 0;
  9454. /* Stop accepting on iSCSI L2 ring */
  9455. netif_addr_lock_bh(dev);
  9456. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  9457. netif_addr_unlock_bh(dev);
  9458. /* bits to wait on */
  9459. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  9460. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  9461. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  9462. BNX2X_ERR("rx_mode completion timed out!\n");
  9463. mmiowb();
  9464. barrier();
  9465. /* Unset iSCSI L2 MAC */
  9466. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  9467. BNX2X_ISCSI_ETH_MAC, true);
  9468. break;
  9469. }
  9470. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  9471. int count = ctl->data.credit.credit_count;
  9472. smp_mb__before_atomic_inc();
  9473. atomic_add(count, &bp->cq_spq_left);
  9474. smp_mb__after_atomic_inc();
  9475. break;
  9476. }
  9477. default:
  9478. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  9479. rc = -EINVAL;
  9480. }
  9481. return rc;
  9482. }
  9483. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  9484. {
  9485. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9486. if (bp->flags & USING_MSIX_FLAG) {
  9487. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  9488. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  9489. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  9490. } else {
  9491. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  9492. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  9493. }
  9494. if (!CHIP_IS_E1x(bp))
  9495. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  9496. else
  9497. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  9498. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  9499. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  9500. cp->irq_arr[1].status_blk = bp->def_status_blk;
  9501. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  9502. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  9503. cp->num_irq = 2;
  9504. }
  9505. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  9506. void *data)
  9507. {
  9508. struct bnx2x *bp = netdev_priv(dev);
  9509. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9510. if (ops == NULL)
  9511. return -EINVAL;
  9512. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  9513. if (!bp->cnic_kwq)
  9514. return -ENOMEM;
  9515. bp->cnic_kwq_cons = bp->cnic_kwq;
  9516. bp->cnic_kwq_prod = bp->cnic_kwq;
  9517. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  9518. bp->cnic_spq_pending = 0;
  9519. bp->cnic_kwq_pending = 0;
  9520. bp->cnic_data = data;
  9521. cp->num_irq = 0;
  9522. cp->drv_state |= CNIC_DRV_STATE_REGD;
  9523. cp->iro_arr = bp->iro_arr;
  9524. bnx2x_setup_cnic_irq_info(bp);
  9525. rcu_assign_pointer(bp->cnic_ops, ops);
  9526. return 0;
  9527. }
  9528. static int bnx2x_unregister_cnic(struct net_device *dev)
  9529. {
  9530. struct bnx2x *bp = netdev_priv(dev);
  9531. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9532. mutex_lock(&bp->cnic_mutex);
  9533. cp->drv_state = 0;
  9534. rcu_assign_pointer(bp->cnic_ops, NULL);
  9535. mutex_unlock(&bp->cnic_mutex);
  9536. synchronize_rcu();
  9537. kfree(bp->cnic_kwq);
  9538. bp->cnic_kwq = NULL;
  9539. return 0;
  9540. }
  9541. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  9542. {
  9543. struct bnx2x *bp = netdev_priv(dev);
  9544. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9545. /* If both iSCSI and FCoE are disabled - return NULL in
  9546. * order to indicate CNIC that it should not try to work
  9547. * with this device.
  9548. */
  9549. if (NO_ISCSI(bp) && NO_FCOE(bp))
  9550. return NULL;
  9551. cp->drv_owner = THIS_MODULE;
  9552. cp->chip_id = CHIP_ID(bp);
  9553. cp->pdev = bp->pdev;
  9554. cp->io_base = bp->regview;
  9555. cp->io_base2 = bp->doorbells;
  9556. cp->max_kwqe_pending = 8;
  9557. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  9558. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  9559. bnx2x_cid_ilt_lines(bp);
  9560. cp->ctx_tbl_len = CNIC_ILT_LINES;
  9561. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  9562. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  9563. cp->drv_ctl = bnx2x_drv_ctl;
  9564. cp->drv_register_cnic = bnx2x_register_cnic;
  9565. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  9566. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
  9567. cp->iscsi_l2_client_id =
  9568. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  9569. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
  9570. if (NO_ISCSI_OOO(bp))
  9571. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  9572. if (NO_ISCSI(bp))
  9573. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  9574. if (NO_FCOE(bp))
  9575. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  9576. DP(BNX2X_MSG_SP, "page_size %d, tbl_offset %d, tbl_lines %d, "
  9577. "starting cid %d\n",
  9578. cp->ctx_blk_size,
  9579. cp->ctx_tbl_offset,
  9580. cp->ctx_tbl_len,
  9581. cp->starting_cid);
  9582. return cp;
  9583. }
  9584. EXPORT_SYMBOL(bnx2x_cnic_probe);
  9585. #endif /* BCM_CNIC */