bnx2x_main.c 339 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_dcb.h"
  60. #include "bnx2x_sp.h"
  61. #include <linux/firmware.h>
  62. #include "bnx2x_fw_file_hdr.h"
  63. /* FW files */
  64. #define FW_FILE_VERSION \
  65. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  66. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  68. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  69. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  70. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  72. /* Time in jiffies before concluding the transmitter is hung */
  73. #define TX_TIMEOUT (5*HZ)
  74. static char version[] __devinitdata =
  75. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  76. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  77. MODULE_AUTHOR("Eliezer Tamir");
  78. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  79. "BCM57710/57711/57711E/"
  80. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  81. "57840/57840_MF Driver");
  82. MODULE_LICENSE("GPL");
  83. MODULE_VERSION(DRV_MODULE_VERSION);
  84. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  87. int num_queues;
  88. module_param(num_queues, int, 0);
  89. MODULE_PARM_DESC(num_queues,
  90. " Set number of queues (default is as a number of CPUs)");
  91. static int disable_tpa;
  92. module_param(disable_tpa, int, 0);
  93. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  94. #define INT_MODE_INTx 1
  95. #define INT_MODE_MSI 2
  96. static int int_mode;
  97. module_param(int_mode, int, 0);
  98. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  99. "(1 INT#x; 2 MSI)");
  100. static int dropless_fc;
  101. module_param(dropless_fc, int, 0);
  102. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  103. static int mrrs = -1;
  104. module_param(mrrs, int, 0);
  105. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  106. static int debug;
  107. module_param(debug, int, 0);
  108. MODULE_PARM_DESC(debug, " Default debug msglevel");
  109. struct workqueue_struct *bnx2x_wq;
  110. enum bnx2x_board_type {
  111. BCM57710 = 0,
  112. BCM57711,
  113. BCM57711E,
  114. BCM57712,
  115. BCM57712_MF,
  116. BCM57800,
  117. BCM57800_MF,
  118. BCM57810,
  119. BCM57810_MF,
  120. BCM57840,
  121. BCM57840_MF,
  122. BCM57811,
  123. BCM57811_MF
  124. };
  125. /* indexed by board_type, above */
  126. static struct {
  127. char *name;
  128. } board_info[] __devinitdata = {
  129. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  130. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  131. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  132. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  133. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  134. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  135. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  136. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  137. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  138. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  139. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  140. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
  141. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
  142. };
  143. #ifndef PCI_DEVICE_ID_NX2_57710
  144. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  145. #endif
  146. #ifndef PCI_DEVICE_ID_NX2_57711
  147. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  148. #endif
  149. #ifndef PCI_DEVICE_ID_NX2_57711E
  150. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  151. #endif
  152. #ifndef PCI_DEVICE_ID_NX2_57712
  153. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  154. #endif
  155. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  156. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  157. #endif
  158. #ifndef PCI_DEVICE_ID_NX2_57800
  159. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  160. #endif
  161. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  162. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  163. #endif
  164. #ifndef PCI_DEVICE_ID_NX2_57810
  165. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  166. #endif
  167. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  168. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  169. #endif
  170. #ifndef PCI_DEVICE_ID_NX2_57840
  171. #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
  172. #endif
  173. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  174. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  175. #endif
  176. #ifndef PCI_DEVICE_ID_NX2_57811
  177. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  178. #endif
  179. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  180. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  181. #endif
  182. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  183. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  184. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  185. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  186. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  187. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  188. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  189. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  190. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  191. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  192. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
  193. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  194. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  195. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  196. { 0 }
  197. };
  198. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  199. /* Global resources for unloading a previously loaded device */
  200. #define BNX2X_PREV_WAIT_NEEDED 1
  201. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  202. static LIST_HEAD(bnx2x_prev_list);
  203. /****************************************************************************
  204. * General service functions
  205. ****************************************************************************/
  206. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  207. u32 addr, dma_addr_t mapping)
  208. {
  209. REG_WR(bp, addr, U64_LO(mapping));
  210. REG_WR(bp, addr + 4, U64_HI(mapping));
  211. }
  212. static void storm_memset_spq_addr(struct bnx2x *bp,
  213. dma_addr_t mapping, u16 abs_fid)
  214. {
  215. u32 addr = XSEM_REG_FAST_MEMORY +
  216. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  217. __storm_memset_dma_mapping(bp, addr, mapping);
  218. }
  219. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  220. u16 pf_id)
  221. {
  222. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  223. pf_id);
  224. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  225. pf_id);
  226. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  227. pf_id);
  228. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  229. pf_id);
  230. }
  231. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  232. u8 enable)
  233. {
  234. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  235. enable);
  236. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  237. enable);
  238. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  239. enable);
  240. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  241. enable);
  242. }
  243. static void storm_memset_eq_data(struct bnx2x *bp,
  244. struct event_ring_data *eq_data,
  245. u16 pfid)
  246. {
  247. size_t size = sizeof(struct event_ring_data);
  248. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  249. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  250. }
  251. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  252. u16 pfid)
  253. {
  254. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  255. REG_WR16(bp, addr, eq_prod);
  256. }
  257. /* used only at init
  258. * locking is done by mcp
  259. */
  260. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  261. {
  262. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  263. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  264. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  265. PCICFG_VENDOR_ID_OFFSET);
  266. }
  267. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  268. {
  269. u32 val;
  270. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  271. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  272. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  273. PCICFG_VENDOR_ID_OFFSET);
  274. return val;
  275. }
  276. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  277. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  278. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  279. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  280. #define DMAE_DP_DST_NONE "dst_addr [none]"
  281. /* copy command into DMAE command memory and set DMAE command go */
  282. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  283. {
  284. u32 cmd_offset;
  285. int i;
  286. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  287. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  288. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  289. }
  290. REG_WR(bp, dmae_reg_go_c[idx], 1);
  291. }
  292. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  293. {
  294. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  295. DMAE_CMD_C_ENABLE);
  296. }
  297. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  298. {
  299. return opcode & ~DMAE_CMD_SRC_RESET;
  300. }
  301. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  302. bool with_comp, u8 comp_type)
  303. {
  304. u32 opcode = 0;
  305. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  306. (dst_type << DMAE_COMMAND_DST_SHIFT));
  307. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  308. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  309. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  310. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  311. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  312. #ifdef __BIG_ENDIAN
  313. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  314. #else
  315. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  316. #endif
  317. if (with_comp)
  318. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  319. return opcode;
  320. }
  321. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  322. struct dmae_command *dmae,
  323. u8 src_type, u8 dst_type)
  324. {
  325. memset(dmae, 0, sizeof(struct dmae_command));
  326. /* set the opcode */
  327. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  328. true, DMAE_COMP_PCI);
  329. /* fill in the completion parameters */
  330. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  331. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  332. dmae->comp_val = DMAE_COMP_VAL;
  333. }
  334. /* issue a dmae command over the init-channel and wailt for completion */
  335. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  336. struct dmae_command *dmae)
  337. {
  338. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  339. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  340. int rc = 0;
  341. /*
  342. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  343. * as long as this code is called both from syscall context and
  344. * from ndo_set_rx_mode() flow that may be called from BH.
  345. */
  346. spin_lock_bh(&bp->dmae_lock);
  347. /* reset completion */
  348. *wb_comp = 0;
  349. /* post the command on the channel used for initializations */
  350. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  351. /* wait for completion */
  352. udelay(5);
  353. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  354. if (!cnt ||
  355. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  356. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  357. BNX2X_ERR("DMAE timeout!\n");
  358. rc = DMAE_TIMEOUT;
  359. goto unlock;
  360. }
  361. cnt--;
  362. udelay(50);
  363. }
  364. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  365. BNX2X_ERR("DMAE PCI error!\n");
  366. rc = DMAE_PCI_ERROR;
  367. }
  368. unlock:
  369. spin_unlock_bh(&bp->dmae_lock);
  370. return rc;
  371. }
  372. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  373. u32 len32)
  374. {
  375. struct dmae_command dmae;
  376. if (!bp->dmae_ready) {
  377. u32 *data = bnx2x_sp(bp, wb_data[0]);
  378. if (CHIP_IS_E1(bp))
  379. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  380. else
  381. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  382. return;
  383. }
  384. /* set opcode and fixed command fields */
  385. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  386. /* fill in addresses and len */
  387. dmae.src_addr_lo = U64_LO(dma_addr);
  388. dmae.src_addr_hi = U64_HI(dma_addr);
  389. dmae.dst_addr_lo = dst_addr >> 2;
  390. dmae.dst_addr_hi = 0;
  391. dmae.len = len32;
  392. /* issue the command and wait for completion */
  393. bnx2x_issue_dmae_with_comp(bp, &dmae);
  394. }
  395. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  396. {
  397. struct dmae_command dmae;
  398. if (!bp->dmae_ready) {
  399. u32 *data = bnx2x_sp(bp, wb_data[0]);
  400. int i;
  401. if (CHIP_IS_E1(bp))
  402. for (i = 0; i < len32; i++)
  403. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  404. else
  405. for (i = 0; i < len32; i++)
  406. data[i] = REG_RD(bp, src_addr + i*4);
  407. return;
  408. }
  409. /* set opcode and fixed command fields */
  410. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  411. /* fill in addresses and len */
  412. dmae.src_addr_lo = src_addr >> 2;
  413. dmae.src_addr_hi = 0;
  414. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  415. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  416. dmae.len = len32;
  417. /* issue the command and wait for completion */
  418. bnx2x_issue_dmae_with_comp(bp, &dmae);
  419. }
  420. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  421. u32 addr, u32 len)
  422. {
  423. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  424. int offset = 0;
  425. while (len > dmae_wr_max) {
  426. bnx2x_write_dmae(bp, phys_addr + offset,
  427. addr + offset, dmae_wr_max);
  428. offset += dmae_wr_max * 4;
  429. len -= dmae_wr_max;
  430. }
  431. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  432. }
  433. static int bnx2x_mc_assert(struct bnx2x *bp)
  434. {
  435. char last_idx;
  436. int i, rc = 0;
  437. u32 row0, row1, row2, row3;
  438. /* XSTORM */
  439. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  440. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  441. if (last_idx)
  442. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  443. /* print the asserts */
  444. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  445. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  446. XSTORM_ASSERT_LIST_OFFSET(i));
  447. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  448. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  449. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  450. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  451. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  452. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  453. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  454. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  455. i, row3, row2, row1, row0);
  456. rc++;
  457. } else {
  458. break;
  459. }
  460. }
  461. /* TSTORM */
  462. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  463. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  464. if (last_idx)
  465. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  466. /* print the asserts */
  467. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  468. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  469. TSTORM_ASSERT_LIST_OFFSET(i));
  470. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  471. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  472. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  473. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  474. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  475. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  476. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  477. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  478. i, row3, row2, row1, row0);
  479. rc++;
  480. } else {
  481. break;
  482. }
  483. }
  484. /* CSTORM */
  485. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  486. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  487. if (last_idx)
  488. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  489. /* print the asserts */
  490. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  491. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  492. CSTORM_ASSERT_LIST_OFFSET(i));
  493. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  494. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  495. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  496. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  497. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  498. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  499. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  500. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  501. i, row3, row2, row1, row0);
  502. rc++;
  503. } else {
  504. break;
  505. }
  506. }
  507. /* USTORM */
  508. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  509. USTORM_ASSERT_LIST_INDEX_OFFSET);
  510. if (last_idx)
  511. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  512. /* print the asserts */
  513. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  514. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  515. USTORM_ASSERT_LIST_OFFSET(i));
  516. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  517. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  518. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  519. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  520. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  521. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  522. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  523. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  524. i, row3, row2, row1, row0);
  525. rc++;
  526. } else {
  527. break;
  528. }
  529. }
  530. return rc;
  531. }
  532. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  533. {
  534. u32 addr, val;
  535. u32 mark, offset;
  536. __be32 data[9];
  537. int word;
  538. u32 trace_shmem_base;
  539. if (BP_NOMCP(bp)) {
  540. BNX2X_ERR("NO MCP - can not dump\n");
  541. return;
  542. }
  543. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  544. (bp->common.bc_ver & 0xff0000) >> 16,
  545. (bp->common.bc_ver & 0xff00) >> 8,
  546. (bp->common.bc_ver & 0xff));
  547. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  548. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  549. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  550. if (BP_PATH(bp) == 0)
  551. trace_shmem_base = bp->common.shmem_base;
  552. else
  553. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  554. addr = trace_shmem_base - 0x800;
  555. /* validate TRCB signature */
  556. mark = REG_RD(bp, addr);
  557. if (mark != MFW_TRACE_SIGNATURE) {
  558. BNX2X_ERR("Trace buffer signature is missing.");
  559. return ;
  560. }
  561. /* read cyclic buffer pointer */
  562. addr += 4;
  563. mark = REG_RD(bp, addr);
  564. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  565. + ((mark + 0x3) & ~0x3) - 0x08000000;
  566. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  567. printk("%s", lvl);
  568. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  569. for (word = 0; word < 8; word++)
  570. data[word] = htonl(REG_RD(bp, offset + 4*word));
  571. data[8] = 0x0;
  572. pr_cont("%s", (char *)data);
  573. }
  574. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  575. for (word = 0; word < 8; word++)
  576. data[word] = htonl(REG_RD(bp, offset + 4*word));
  577. data[8] = 0x0;
  578. pr_cont("%s", (char *)data);
  579. }
  580. printk("%s" "end of fw dump\n", lvl);
  581. }
  582. static void bnx2x_fw_dump(struct bnx2x *bp)
  583. {
  584. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  585. }
  586. void bnx2x_panic_dump(struct bnx2x *bp)
  587. {
  588. int i;
  589. u16 j;
  590. struct hc_sp_status_block_data sp_sb_data;
  591. int func = BP_FUNC(bp);
  592. #ifdef BNX2X_STOP_ON_ERROR
  593. u16 start = 0, end = 0;
  594. u8 cos;
  595. #endif
  596. bp->stats_state = STATS_STATE_DISABLED;
  597. bp->eth_stats.unrecoverable_error++;
  598. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  599. BNX2X_ERR("begin crash dump -----------------\n");
  600. /* Indices */
  601. /* Common */
  602. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  603. bp->def_idx, bp->def_att_idx, bp->attn_state,
  604. bp->spq_prod_idx, bp->stats_counter);
  605. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  606. bp->def_status_blk->atten_status_block.attn_bits,
  607. bp->def_status_blk->atten_status_block.attn_bits_ack,
  608. bp->def_status_blk->atten_status_block.status_block_id,
  609. bp->def_status_blk->atten_status_block.attn_bits_index);
  610. BNX2X_ERR(" def (");
  611. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  612. pr_cont("0x%x%s",
  613. bp->def_status_blk->sp_sb.index_values[i],
  614. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  615. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  616. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  617. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  618. i*sizeof(u32));
  619. pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
  620. sp_sb_data.igu_sb_id,
  621. sp_sb_data.igu_seg_id,
  622. sp_sb_data.p_func.pf_id,
  623. sp_sb_data.p_func.vnic_id,
  624. sp_sb_data.p_func.vf_id,
  625. sp_sb_data.p_func.vf_valid,
  626. sp_sb_data.state);
  627. for_each_eth_queue(bp, i) {
  628. struct bnx2x_fastpath *fp = &bp->fp[i];
  629. int loop;
  630. struct hc_status_block_data_e2 sb_data_e2;
  631. struct hc_status_block_data_e1x sb_data_e1x;
  632. struct hc_status_block_sm *hc_sm_p =
  633. CHIP_IS_E1x(bp) ?
  634. sb_data_e1x.common.state_machine :
  635. sb_data_e2.common.state_machine;
  636. struct hc_index_data *hc_index_p =
  637. CHIP_IS_E1x(bp) ?
  638. sb_data_e1x.index_data :
  639. sb_data_e2.index_data;
  640. u8 data_size, cos;
  641. u32 *sb_data_p;
  642. struct bnx2x_fp_txdata txdata;
  643. /* Rx */
  644. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  645. i, fp->rx_bd_prod, fp->rx_bd_cons,
  646. fp->rx_comp_prod,
  647. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  648. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  649. fp->rx_sge_prod, fp->last_max_sge,
  650. le16_to_cpu(fp->fp_hc_idx));
  651. /* Tx */
  652. for_each_cos_in_tx_queue(fp, cos)
  653. {
  654. txdata = fp->txdata[cos];
  655. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
  656. i, txdata.tx_pkt_prod,
  657. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  658. txdata.tx_bd_cons,
  659. le16_to_cpu(*txdata.tx_cons_sb));
  660. }
  661. loop = CHIP_IS_E1x(bp) ?
  662. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  663. /* host sb data */
  664. #ifdef BCM_CNIC
  665. if (IS_FCOE_FP(fp))
  666. continue;
  667. #endif
  668. BNX2X_ERR(" run indexes (");
  669. for (j = 0; j < HC_SB_MAX_SM; j++)
  670. pr_cont("0x%x%s",
  671. fp->sb_running_index[j],
  672. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  673. BNX2X_ERR(" indexes (");
  674. for (j = 0; j < loop; j++)
  675. pr_cont("0x%x%s",
  676. fp->sb_index_values[j],
  677. (j == loop - 1) ? ")" : " ");
  678. /* fw sb data */
  679. data_size = CHIP_IS_E1x(bp) ?
  680. sizeof(struct hc_status_block_data_e1x) :
  681. sizeof(struct hc_status_block_data_e2);
  682. data_size /= sizeof(u32);
  683. sb_data_p = CHIP_IS_E1x(bp) ?
  684. (u32 *)&sb_data_e1x :
  685. (u32 *)&sb_data_e2;
  686. /* copy sb data in here */
  687. for (j = 0; j < data_size; j++)
  688. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  689. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  690. j * sizeof(u32));
  691. if (!CHIP_IS_E1x(bp)) {
  692. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  693. sb_data_e2.common.p_func.pf_id,
  694. sb_data_e2.common.p_func.vf_id,
  695. sb_data_e2.common.p_func.vf_valid,
  696. sb_data_e2.common.p_func.vnic_id,
  697. sb_data_e2.common.same_igu_sb_1b,
  698. sb_data_e2.common.state);
  699. } else {
  700. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  701. sb_data_e1x.common.p_func.pf_id,
  702. sb_data_e1x.common.p_func.vf_id,
  703. sb_data_e1x.common.p_func.vf_valid,
  704. sb_data_e1x.common.p_func.vnic_id,
  705. sb_data_e1x.common.same_igu_sb_1b,
  706. sb_data_e1x.common.state);
  707. }
  708. /* SB_SMs data */
  709. for (j = 0; j < HC_SB_MAX_SM; j++) {
  710. pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
  711. j, hc_sm_p[j].__flags,
  712. hc_sm_p[j].igu_sb_id,
  713. hc_sm_p[j].igu_seg_id,
  714. hc_sm_p[j].time_to_expire,
  715. hc_sm_p[j].timer_value);
  716. }
  717. /* Indecies data */
  718. for (j = 0; j < loop; j++) {
  719. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  720. hc_index_p[j].flags,
  721. hc_index_p[j].timeout);
  722. }
  723. }
  724. #ifdef BNX2X_STOP_ON_ERROR
  725. /* Rings */
  726. /* Rx */
  727. for_each_rx_queue(bp, i) {
  728. struct bnx2x_fastpath *fp = &bp->fp[i];
  729. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  730. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  731. for (j = start; j != end; j = RX_BD(j + 1)) {
  732. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  733. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  734. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  735. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  736. }
  737. start = RX_SGE(fp->rx_sge_prod);
  738. end = RX_SGE(fp->last_max_sge);
  739. for (j = start; j != end; j = RX_SGE(j + 1)) {
  740. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  741. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  742. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  743. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  744. }
  745. start = RCQ_BD(fp->rx_comp_cons - 10);
  746. end = RCQ_BD(fp->rx_comp_cons + 503);
  747. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  748. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  749. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  750. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  751. }
  752. }
  753. /* Tx */
  754. for_each_tx_queue(bp, i) {
  755. struct bnx2x_fastpath *fp = &bp->fp[i];
  756. for_each_cos_in_tx_queue(fp, cos) {
  757. struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
  758. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  759. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  760. for (j = start; j != end; j = TX_BD(j + 1)) {
  761. struct sw_tx_bd *sw_bd =
  762. &txdata->tx_buf_ring[j];
  763. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  764. i, cos, j, sw_bd->skb,
  765. sw_bd->first_bd);
  766. }
  767. start = TX_BD(txdata->tx_bd_cons - 10);
  768. end = TX_BD(txdata->tx_bd_cons + 254);
  769. for (j = start; j != end; j = TX_BD(j + 1)) {
  770. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  771. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  772. i, cos, j, tx_bd[0], tx_bd[1],
  773. tx_bd[2], tx_bd[3]);
  774. }
  775. }
  776. }
  777. #endif
  778. bnx2x_fw_dump(bp);
  779. bnx2x_mc_assert(bp);
  780. BNX2X_ERR("end crash dump -----------------\n");
  781. }
  782. /*
  783. * FLR Support for E2
  784. *
  785. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  786. * initialization.
  787. */
  788. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  789. #define FLR_WAIT_INTERVAL 50 /* usec */
  790. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  791. struct pbf_pN_buf_regs {
  792. int pN;
  793. u32 init_crd;
  794. u32 crd;
  795. u32 crd_freed;
  796. };
  797. struct pbf_pN_cmd_regs {
  798. int pN;
  799. u32 lines_occup;
  800. u32 lines_freed;
  801. };
  802. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  803. struct pbf_pN_buf_regs *regs,
  804. u32 poll_count)
  805. {
  806. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  807. u32 cur_cnt = poll_count;
  808. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  809. crd = crd_start = REG_RD(bp, regs->crd);
  810. init_crd = REG_RD(bp, regs->init_crd);
  811. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  812. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  813. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  814. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  815. (init_crd - crd_start))) {
  816. if (cur_cnt--) {
  817. udelay(FLR_WAIT_INTERVAL);
  818. crd = REG_RD(bp, regs->crd);
  819. crd_freed = REG_RD(bp, regs->crd_freed);
  820. } else {
  821. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  822. regs->pN);
  823. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  824. regs->pN, crd);
  825. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  826. regs->pN, crd_freed);
  827. break;
  828. }
  829. }
  830. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  831. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  832. }
  833. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  834. struct pbf_pN_cmd_regs *regs,
  835. u32 poll_count)
  836. {
  837. u32 occup, to_free, freed, freed_start;
  838. u32 cur_cnt = poll_count;
  839. occup = to_free = REG_RD(bp, regs->lines_occup);
  840. freed = freed_start = REG_RD(bp, regs->lines_freed);
  841. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  842. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  843. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  844. if (cur_cnt--) {
  845. udelay(FLR_WAIT_INTERVAL);
  846. occup = REG_RD(bp, regs->lines_occup);
  847. freed = REG_RD(bp, regs->lines_freed);
  848. } else {
  849. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  850. regs->pN);
  851. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  852. regs->pN, occup);
  853. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  854. regs->pN, freed);
  855. break;
  856. }
  857. }
  858. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  859. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  860. }
  861. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  862. u32 expected, u32 poll_count)
  863. {
  864. u32 cur_cnt = poll_count;
  865. u32 val;
  866. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  867. udelay(FLR_WAIT_INTERVAL);
  868. return val;
  869. }
  870. static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  871. char *msg, u32 poll_cnt)
  872. {
  873. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  874. if (val != 0) {
  875. BNX2X_ERR("%s usage count=%d\n", msg, val);
  876. return 1;
  877. }
  878. return 0;
  879. }
  880. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  881. {
  882. /* adjust polling timeout */
  883. if (CHIP_REV_IS_EMUL(bp))
  884. return FLR_POLL_CNT * 2000;
  885. if (CHIP_REV_IS_FPGA(bp))
  886. return FLR_POLL_CNT * 120;
  887. return FLR_POLL_CNT;
  888. }
  889. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  890. {
  891. struct pbf_pN_cmd_regs cmd_regs[] = {
  892. {0, (CHIP_IS_E3B0(bp)) ?
  893. PBF_REG_TQ_OCCUPANCY_Q0 :
  894. PBF_REG_P0_TQ_OCCUPANCY,
  895. (CHIP_IS_E3B0(bp)) ?
  896. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  897. PBF_REG_P0_TQ_LINES_FREED_CNT},
  898. {1, (CHIP_IS_E3B0(bp)) ?
  899. PBF_REG_TQ_OCCUPANCY_Q1 :
  900. PBF_REG_P1_TQ_OCCUPANCY,
  901. (CHIP_IS_E3B0(bp)) ?
  902. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  903. PBF_REG_P1_TQ_LINES_FREED_CNT},
  904. {4, (CHIP_IS_E3B0(bp)) ?
  905. PBF_REG_TQ_OCCUPANCY_LB_Q :
  906. PBF_REG_P4_TQ_OCCUPANCY,
  907. (CHIP_IS_E3B0(bp)) ?
  908. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  909. PBF_REG_P4_TQ_LINES_FREED_CNT}
  910. };
  911. struct pbf_pN_buf_regs buf_regs[] = {
  912. {0, (CHIP_IS_E3B0(bp)) ?
  913. PBF_REG_INIT_CRD_Q0 :
  914. PBF_REG_P0_INIT_CRD ,
  915. (CHIP_IS_E3B0(bp)) ?
  916. PBF_REG_CREDIT_Q0 :
  917. PBF_REG_P0_CREDIT,
  918. (CHIP_IS_E3B0(bp)) ?
  919. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  920. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  921. {1, (CHIP_IS_E3B0(bp)) ?
  922. PBF_REG_INIT_CRD_Q1 :
  923. PBF_REG_P1_INIT_CRD,
  924. (CHIP_IS_E3B0(bp)) ?
  925. PBF_REG_CREDIT_Q1 :
  926. PBF_REG_P1_CREDIT,
  927. (CHIP_IS_E3B0(bp)) ?
  928. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  929. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  930. {4, (CHIP_IS_E3B0(bp)) ?
  931. PBF_REG_INIT_CRD_LB_Q :
  932. PBF_REG_P4_INIT_CRD,
  933. (CHIP_IS_E3B0(bp)) ?
  934. PBF_REG_CREDIT_LB_Q :
  935. PBF_REG_P4_CREDIT,
  936. (CHIP_IS_E3B0(bp)) ?
  937. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  938. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  939. };
  940. int i;
  941. /* Verify the command queues are flushed P0, P1, P4 */
  942. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  943. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  944. /* Verify the transmission buffers are flushed P0, P1, P4 */
  945. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  946. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  947. }
  948. #define OP_GEN_PARAM(param) \
  949. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  950. #define OP_GEN_TYPE(type) \
  951. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  952. #define OP_GEN_AGG_VECT(index) \
  953. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  954. static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  955. u32 poll_cnt)
  956. {
  957. struct sdm_op_gen op_gen = {0};
  958. u32 comp_addr = BAR_CSTRORM_INTMEM +
  959. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  960. int ret = 0;
  961. if (REG_RD(bp, comp_addr)) {
  962. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  963. return 1;
  964. }
  965. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  966. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  967. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  968. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  969. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  970. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  971. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  972. BNX2X_ERR("FW final cleanup did not succeed\n");
  973. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  974. (REG_RD(bp, comp_addr)));
  975. ret = 1;
  976. }
  977. /* Zero completion for nxt FLR */
  978. REG_WR(bp, comp_addr, 0);
  979. return ret;
  980. }
  981. static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  982. {
  983. int pos;
  984. u16 status;
  985. pos = pci_pcie_cap(dev);
  986. if (!pos)
  987. return false;
  988. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  989. return status & PCI_EXP_DEVSTA_TRPND;
  990. }
  991. /* PF FLR specific routines
  992. */
  993. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  994. {
  995. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  996. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  997. CFC_REG_NUM_LCIDS_INSIDE_PF,
  998. "CFC PF usage counter timed out",
  999. poll_cnt))
  1000. return 1;
  1001. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1002. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1003. DORQ_REG_PF_USAGE_CNT,
  1004. "DQ PF usage counter timed out",
  1005. poll_cnt))
  1006. return 1;
  1007. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1008. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1009. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1010. "QM PF usage counter timed out",
  1011. poll_cnt))
  1012. return 1;
  1013. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1014. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1015. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1016. "Timers VNIC usage counter timed out",
  1017. poll_cnt))
  1018. return 1;
  1019. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1020. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1021. "Timers NUM_SCANS usage counter timed out",
  1022. poll_cnt))
  1023. return 1;
  1024. /* Wait DMAE PF usage counter to zero */
  1025. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1026. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1027. "DMAE dommand register timed out",
  1028. poll_cnt))
  1029. return 1;
  1030. return 0;
  1031. }
  1032. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1033. {
  1034. u32 val;
  1035. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1036. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1037. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1038. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1039. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1040. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1041. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1042. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1043. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1044. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1045. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1046. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1047. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1048. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1049. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1050. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1051. val);
  1052. }
  1053. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1054. {
  1055. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1056. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1057. /* Re-enable PF target read access */
  1058. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1059. /* Poll HW usage counters */
  1060. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1061. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1062. return -EBUSY;
  1063. /* Zero the igu 'trailing edge' and 'leading edge' */
  1064. /* Send the FW cleanup command */
  1065. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1066. return -EBUSY;
  1067. /* ATC cleanup */
  1068. /* Verify TX hw is flushed */
  1069. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1070. /* Wait 100ms (not adjusted according to platform) */
  1071. msleep(100);
  1072. /* Verify no pending pci transactions */
  1073. if (bnx2x_is_pcie_pending(bp->pdev))
  1074. BNX2X_ERR("PCIE Transactions still pending\n");
  1075. /* Debug */
  1076. bnx2x_hw_enable_status(bp);
  1077. /*
  1078. * Master enable - Due to WB DMAE writes performed before this
  1079. * register is re-initialized as part of the regular function init
  1080. */
  1081. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1082. return 0;
  1083. }
  1084. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1085. {
  1086. int port = BP_PORT(bp);
  1087. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1088. u32 val = REG_RD(bp, addr);
  1089. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1090. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1091. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1092. if (msix) {
  1093. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1094. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1095. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1096. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1097. if (single_msix)
  1098. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1099. } else if (msi) {
  1100. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1101. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1102. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1103. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1104. } else {
  1105. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1106. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1107. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1108. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1109. if (!CHIP_IS_E1(bp)) {
  1110. DP(NETIF_MSG_IFUP,
  1111. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1112. REG_WR(bp, addr, val);
  1113. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1114. }
  1115. }
  1116. if (CHIP_IS_E1(bp))
  1117. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1118. DP(NETIF_MSG_IFUP,
  1119. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1120. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1121. REG_WR(bp, addr, val);
  1122. /*
  1123. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1124. */
  1125. mmiowb();
  1126. barrier();
  1127. if (!CHIP_IS_E1(bp)) {
  1128. /* init leading/trailing edge */
  1129. if (IS_MF(bp)) {
  1130. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1131. if (bp->port.pmf)
  1132. /* enable nig and gpio3 attention */
  1133. val |= 0x1100;
  1134. } else
  1135. val = 0xffff;
  1136. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1137. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1138. }
  1139. /* Make sure that interrupts are indeed enabled from here on */
  1140. mmiowb();
  1141. }
  1142. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1143. {
  1144. u32 val;
  1145. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1146. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1147. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1148. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1149. if (msix) {
  1150. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1151. IGU_PF_CONF_SINGLE_ISR_EN);
  1152. val |= (IGU_PF_CONF_FUNC_EN |
  1153. IGU_PF_CONF_MSI_MSIX_EN |
  1154. IGU_PF_CONF_ATTN_BIT_EN);
  1155. if (single_msix)
  1156. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1157. } else if (msi) {
  1158. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1159. val |= (IGU_PF_CONF_FUNC_EN |
  1160. IGU_PF_CONF_MSI_MSIX_EN |
  1161. IGU_PF_CONF_ATTN_BIT_EN |
  1162. IGU_PF_CONF_SINGLE_ISR_EN);
  1163. } else {
  1164. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1165. val |= (IGU_PF_CONF_FUNC_EN |
  1166. IGU_PF_CONF_INT_LINE_EN |
  1167. IGU_PF_CONF_ATTN_BIT_EN |
  1168. IGU_PF_CONF_SINGLE_ISR_EN);
  1169. }
  1170. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1171. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1172. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1173. if (val & IGU_PF_CONF_INT_LINE_EN)
  1174. pci_intx(bp->pdev, true);
  1175. barrier();
  1176. /* init leading/trailing edge */
  1177. if (IS_MF(bp)) {
  1178. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1179. if (bp->port.pmf)
  1180. /* enable nig and gpio3 attention */
  1181. val |= 0x1100;
  1182. } else
  1183. val = 0xffff;
  1184. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1185. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1186. /* Make sure that interrupts are indeed enabled from here on */
  1187. mmiowb();
  1188. }
  1189. void bnx2x_int_enable(struct bnx2x *bp)
  1190. {
  1191. if (bp->common.int_block == INT_BLOCK_HC)
  1192. bnx2x_hc_int_enable(bp);
  1193. else
  1194. bnx2x_igu_int_enable(bp);
  1195. }
  1196. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1197. {
  1198. int port = BP_PORT(bp);
  1199. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1200. u32 val = REG_RD(bp, addr);
  1201. /*
  1202. * in E1 we must use only PCI configuration space to disable
  1203. * MSI/MSIX capablility
  1204. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1205. */
  1206. if (CHIP_IS_E1(bp)) {
  1207. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1208. * Use mask register to prevent from HC sending interrupts
  1209. * after we exit the function
  1210. */
  1211. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1212. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1213. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1214. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1215. } else
  1216. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1217. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1218. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1219. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1220. DP(NETIF_MSG_IFDOWN,
  1221. "write %x to HC %d (addr 0x%x)\n",
  1222. val, port, addr);
  1223. /* flush all outstanding writes */
  1224. mmiowb();
  1225. REG_WR(bp, addr, val);
  1226. if (REG_RD(bp, addr) != val)
  1227. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1228. }
  1229. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1230. {
  1231. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1232. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1233. IGU_PF_CONF_INT_LINE_EN |
  1234. IGU_PF_CONF_ATTN_BIT_EN);
  1235. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1236. /* flush all outstanding writes */
  1237. mmiowb();
  1238. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1239. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1240. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1241. }
  1242. void bnx2x_int_disable(struct bnx2x *bp)
  1243. {
  1244. if (bp->common.int_block == INT_BLOCK_HC)
  1245. bnx2x_hc_int_disable(bp);
  1246. else
  1247. bnx2x_igu_int_disable(bp);
  1248. }
  1249. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1250. {
  1251. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1252. int i, offset;
  1253. if (disable_hw)
  1254. /* prevent the HW from sending interrupts */
  1255. bnx2x_int_disable(bp);
  1256. /* make sure all ISRs are done */
  1257. if (msix) {
  1258. synchronize_irq(bp->msix_table[0].vector);
  1259. offset = 1;
  1260. #ifdef BCM_CNIC
  1261. offset++;
  1262. #endif
  1263. for_each_eth_queue(bp, i)
  1264. synchronize_irq(bp->msix_table[offset++].vector);
  1265. } else
  1266. synchronize_irq(bp->pdev->irq);
  1267. /* make sure sp_task is not running */
  1268. cancel_delayed_work(&bp->sp_task);
  1269. cancel_delayed_work(&bp->period_task);
  1270. flush_workqueue(bnx2x_wq);
  1271. }
  1272. /* fast path */
  1273. /*
  1274. * General service functions
  1275. */
  1276. /* Return true if succeeded to acquire the lock */
  1277. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1278. {
  1279. u32 lock_status;
  1280. u32 resource_bit = (1 << resource);
  1281. int func = BP_FUNC(bp);
  1282. u32 hw_lock_control_reg;
  1283. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1284. "Trying to take a lock on resource %d\n", resource);
  1285. /* Validating that the resource is within range */
  1286. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1287. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1288. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1289. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1290. return false;
  1291. }
  1292. if (func <= 5)
  1293. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1294. else
  1295. hw_lock_control_reg =
  1296. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1297. /* Try to acquire the lock */
  1298. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1299. lock_status = REG_RD(bp, hw_lock_control_reg);
  1300. if (lock_status & resource_bit)
  1301. return true;
  1302. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1303. "Failed to get a lock on resource %d\n", resource);
  1304. return false;
  1305. }
  1306. /**
  1307. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1308. *
  1309. * @bp: driver handle
  1310. *
  1311. * Returns the recovery leader resource id according to the engine this function
  1312. * belongs to. Currently only only 2 engines is supported.
  1313. */
  1314. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1315. {
  1316. if (BP_PATH(bp))
  1317. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1318. else
  1319. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1320. }
  1321. /**
  1322. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1323. *
  1324. * @bp: driver handle
  1325. *
  1326. * Tries to aquire a leader lock for current engine.
  1327. */
  1328. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1329. {
  1330. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1331. }
  1332. #ifdef BCM_CNIC
  1333. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1334. #endif
  1335. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1336. {
  1337. struct bnx2x *bp = fp->bp;
  1338. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1339. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1340. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1341. struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
  1342. DP(BNX2X_MSG_SP,
  1343. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1344. fp->index, cid, command, bp->state,
  1345. rr_cqe->ramrod_cqe.ramrod_type);
  1346. switch (command) {
  1347. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1348. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1349. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1350. break;
  1351. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1352. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1353. drv_cmd = BNX2X_Q_CMD_SETUP;
  1354. break;
  1355. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1356. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1357. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1358. break;
  1359. case (RAMROD_CMD_ID_ETH_HALT):
  1360. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1361. drv_cmd = BNX2X_Q_CMD_HALT;
  1362. break;
  1363. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1364. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1365. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1366. break;
  1367. case (RAMROD_CMD_ID_ETH_EMPTY):
  1368. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1369. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1370. break;
  1371. default:
  1372. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1373. command, fp->index);
  1374. return;
  1375. }
  1376. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1377. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1378. /* q_obj->complete_cmd() failure means that this was
  1379. * an unexpected completion.
  1380. *
  1381. * In this case we don't want to increase the bp->spq_left
  1382. * because apparently we haven't sent this command the first
  1383. * place.
  1384. */
  1385. #ifdef BNX2X_STOP_ON_ERROR
  1386. bnx2x_panic();
  1387. #else
  1388. return;
  1389. #endif
  1390. smp_mb__before_atomic_inc();
  1391. atomic_inc(&bp->cq_spq_left);
  1392. /* push the change in bp->spq_left and towards the memory */
  1393. smp_mb__after_atomic_inc();
  1394. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1395. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1396. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1397. /* if Q update ramrod is completed for last Q in AFEX vif set
  1398. * flow, then ACK MCP at the end
  1399. *
  1400. * mark pending ACK to MCP bit.
  1401. * prevent case that both bits are cleared.
  1402. * At the end of load/unload driver checks that
  1403. * sp_state is cleaerd, and this order prevents
  1404. * races
  1405. */
  1406. smp_mb__before_clear_bit();
  1407. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1408. wmb();
  1409. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1410. smp_mb__after_clear_bit();
  1411. /* schedule workqueue to send ack to MCP */
  1412. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1413. }
  1414. return;
  1415. }
  1416. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1417. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1418. {
  1419. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1420. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1421. start);
  1422. }
  1423. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1424. {
  1425. struct bnx2x *bp = netdev_priv(dev_instance);
  1426. u16 status = bnx2x_ack_int(bp);
  1427. u16 mask;
  1428. int i;
  1429. u8 cos;
  1430. /* Return here if interrupt is shared and it's not for us */
  1431. if (unlikely(status == 0)) {
  1432. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1433. return IRQ_NONE;
  1434. }
  1435. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1436. #ifdef BNX2X_STOP_ON_ERROR
  1437. if (unlikely(bp->panic))
  1438. return IRQ_HANDLED;
  1439. #endif
  1440. for_each_eth_queue(bp, i) {
  1441. struct bnx2x_fastpath *fp = &bp->fp[i];
  1442. mask = 0x2 << (fp->index + CNIC_PRESENT);
  1443. if (status & mask) {
  1444. /* Handle Rx or Tx according to SB id */
  1445. prefetch(fp->rx_cons_sb);
  1446. for_each_cos_in_tx_queue(fp, cos)
  1447. prefetch(fp->txdata[cos].tx_cons_sb);
  1448. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1449. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1450. status &= ~mask;
  1451. }
  1452. }
  1453. #ifdef BCM_CNIC
  1454. mask = 0x2;
  1455. if (status & (mask | 0x1)) {
  1456. struct cnic_ops *c_ops = NULL;
  1457. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1458. rcu_read_lock();
  1459. c_ops = rcu_dereference(bp->cnic_ops);
  1460. if (c_ops)
  1461. c_ops->cnic_handler(bp->cnic_data, NULL);
  1462. rcu_read_unlock();
  1463. }
  1464. status &= ~mask;
  1465. }
  1466. #endif
  1467. if (unlikely(status & 0x1)) {
  1468. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1469. status &= ~0x1;
  1470. if (!status)
  1471. return IRQ_HANDLED;
  1472. }
  1473. if (unlikely(status))
  1474. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1475. status);
  1476. return IRQ_HANDLED;
  1477. }
  1478. /* Link */
  1479. /*
  1480. * General service functions
  1481. */
  1482. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1483. {
  1484. u32 lock_status;
  1485. u32 resource_bit = (1 << resource);
  1486. int func = BP_FUNC(bp);
  1487. u32 hw_lock_control_reg;
  1488. int cnt;
  1489. /* Validating that the resource is within range */
  1490. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1491. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1492. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1493. return -EINVAL;
  1494. }
  1495. if (func <= 5) {
  1496. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1497. } else {
  1498. hw_lock_control_reg =
  1499. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1500. }
  1501. /* Validating that the resource is not already taken */
  1502. lock_status = REG_RD(bp, hw_lock_control_reg);
  1503. if (lock_status & resource_bit) {
  1504. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1505. lock_status, resource_bit);
  1506. return -EEXIST;
  1507. }
  1508. /* Try for 5 second every 5ms */
  1509. for (cnt = 0; cnt < 1000; cnt++) {
  1510. /* Try to acquire the lock */
  1511. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1512. lock_status = REG_RD(bp, hw_lock_control_reg);
  1513. if (lock_status & resource_bit)
  1514. return 0;
  1515. msleep(5);
  1516. }
  1517. BNX2X_ERR("Timeout\n");
  1518. return -EAGAIN;
  1519. }
  1520. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1521. {
  1522. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1523. }
  1524. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1525. {
  1526. u32 lock_status;
  1527. u32 resource_bit = (1 << resource);
  1528. int func = BP_FUNC(bp);
  1529. u32 hw_lock_control_reg;
  1530. /* Validating that the resource is within range */
  1531. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1532. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1533. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1534. return -EINVAL;
  1535. }
  1536. if (func <= 5) {
  1537. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1538. } else {
  1539. hw_lock_control_reg =
  1540. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1541. }
  1542. /* Validating that the resource is currently taken */
  1543. lock_status = REG_RD(bp, hw_lock_control_reg);
  1544. if (!(lock_status & resource_bit)) {
  1545. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1546. lock_status, resource_bit);
  1547. return -EFAULT;
  1548. }
  1549. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1550. return 0;
  1551. }
  1552. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1553. {
  1554. /* The GPIO should be swapped if swap register is set and active */
  1555. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1556. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1557. int gpio_shift = gpio_num +
  1558. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1559. u32 gpio_mask = (1 << gpio_shift);
  1560. u32 gpio_reg;
  1561. int value;
  1562. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1563. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1564. return -EINVAL;
  1565. }
  1566. /* read GPIO value */
  1567. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1568. /* get the requested pin value */
  1569. if ((gpio_reg & gpio_mask) == gpio_mask)
  1570. value = 1;
  1571. else
  1572. value = 0;
  1573. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1574. return value;
  1575. }
  1576. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1577. {
  1578. /* The GPIO should be swapped if swap register is set and active */
  1579. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1580. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1581. int gpio_shift = gpio_num +
  1582. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1583. u32 gpio_mask = (1 << gpio_shift);
  1584. u32 gpio_reg;
  1585. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1586. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1587. return -EINVAL;
  1588. }
  1589. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1590. /* read GPIO and mask except the float bits */
  1591. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1592. switch (mode) {
  1593. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1594. DP(NETIF_MSG_LINK,
  1595. "Set GPIO %d (shift %d) -> output low\n",
  1596. gpio_num, gpio_shift);
  1597. /* clear FLOAT and set CLR */
  1598. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1599. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1600. break;
  1601. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1602. DP(NETIF_MSG_LINK,
  1603. "Set GPIO %d (shift %d) -> output high\n",
  1604. gpio_num, gpio_shift);
  1605. /* clear FLOAT and set SET */
  1606. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1607. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1608. break;
  1609. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1610. DP(NETIF_MSG_LINK,
  1611. "Set GPIO %d (shift %d) -> input\n",
  1612. gpio_num, gpio_shift);
  1613. /* set FLOAT */
  1614. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1615. break;
  1616. default:
  1617. break;
  1618. }
  1619. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1620. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1621. return 0;
  1622. }
  1623. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1624. {
  1625. u32 gpio_reg = 0;
  1626. int rc = 0;
  1627. /* Any port swapping should be handled by caller. */
  1628. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1629. /* read GPIO and mask except the float bits */
  1630. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1631. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1632. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1633. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1634. switch (mode) {
  1635. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1636. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1637. /* set CLR */
  1638. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1639. break;
  1640. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1641. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1642. /* set SET */
  1643. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1644. break;
  1645. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1646. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1647. /* set FLOAT */
  1648. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1649. break;
  1650. default:
  1651. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1652. rc = -EINVAL;
  1653. break;
  1654. }
  1655. if (rc == 0)
  1656. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1657. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1658. return rc;
  1659. }
  1660. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1661. {
  1662. /* The GPIO should be swapped if swap register is set and active */
  1663. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1664. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1665. int gpio_shift = gpio_num +
  1666. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1667. u32 gpio_mask = (1 << gpio_shift);
  1668. u32 gpio_reg;
  1669. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1670. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1671. return -EINVAL;
  1672. }
  1673. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1674. /* read GPIO int */
  1675. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1676. switch (mode) {
  1677. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1678. DP(NETIF_MSG_LINK,
  1679. "Clear GPIO INT %d (shift %d) -> output low\n",
  1680. gpio_num, gpio_shift);
  1681. /* clear SET and set CLR */
  1682. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1683. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1684. break;
  1685. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1686. DP(NETIF_MSG_LINK,
  1687. "Set GPIO INT %d (shift %d) -> output high\n",
  1688. gpio_num, gpio_shift);
  1689. /* clear CLR and set SET */
  1690. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1691. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1692. break;
  1693. default:
  1694. break;
  1695. }
  1696. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1697. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1698. return 0;
  1699. }
  1700. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1701. {
  1702. u32 spio_mask = (1 << spio_num);
  1703. u32 spio_reg;
  1704. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1705. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1706. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1707. return -EINVAL;
  1708. }
  1709. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1710. /* read SPIO and mask except the float bits */
  1711. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1712. switch (mode) {
  1713. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1714. DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
  1715. /* clear FLOAT and set CLR */
  1716. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1717. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1718. break;
  1719. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1720. DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
  1721. /* clear FLOAT and set SET */
  1722. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1723. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1724. break;
  1725. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1726. DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
  1727. /* set FLOAT */
  1728. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1729. break;
  1730. default:
  1731. break;
  1732. }
  1733. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1734. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1735. return 0;
  1736. }
  1737. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1738. {
  1739. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1740. switch (bp->link_vars.ieee_fc &
  1741. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1742. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1743. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1744. ADVERTISED_Pause);
  1745. break;
  1746. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1747. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1748. ADVERTISED_Pause);
  1749. break;
  1750. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1751. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1752. break;
  1753. default:
  1754. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1755. ADVERTISED_Pause);
  1756. break;
  1757. }
  1758. }
  1759. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1760. {
  1761. if (!BP_NOMCP(bp)) {
  1762. u8 rc;
  1763. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1764. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1765. /*
  1766. * Initialize link parameters structure variables
  1767. * It is recommended to turn off RX FC for jumbo frames
  1768. * for better performance
  1769. */
  1770. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1771. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1772. else
  1773. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1774. bnx2x_acquire_phy_lock(bp);
  1775. if (load_mode == LOAD_DIAG) {
  1776. struct link_params *lp = &bp->link_params;
  1777. lp->loopback_mode = LOOPBACK_XGXS;
  1778. /* do PHY loopback at 10G speed, if possible */
  1779. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1780. if (lp->speed_cap_mask[cfx_idx] &
  1781. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1782. lp->req_line_speed[cfx_idx] =
  1783. SPEED_10000;
  1784. else
  1785. lp->req_line_speed[cfx_idx] =
  1786. SPEED_1000;
  1787. }
  1788. }
  1789. if (load_mode == LOAD_LOOPBACK_EXT) {
  1790. struct link_params *lp = &bp->link_params;
  1791. lp->loopback_mode = LOOPBACK_EXT;
  1792. }
  1793. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1794. bnx2x_release_phy_lock(bp);
  1795. bnx2x_calc_fc_adv(bp);
  1796. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1797. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1798. bnx2x_link_report(bp);
  1799. } else
  1800. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1801. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1802. return rc;
  1803. }
  1804. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1805. return -EINVAL;
  1806. }
  1807. void bnx2x_link_set(struct bnx2x *bp)
  1808. {
  1809. if (!BP_NOMCP(bp)) {
  1810. bnx2x_acquire_phy_lock(bp);
  1811. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1812. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1813. bnx2x_release_phy_lock(bp);
  1814. bnx2x_calc_fc_adv(bp);
  1815. } else
  1816. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1817. }
  1818. static void bnx2x__link_reset(struct bnx2x *bp)
  1819. {
  1820. if (!BP_NOMCP(bp)) {
  1821. bnx2x_acquire_phy_lock(bp);
  1822. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1823. bnx2x_release_phy_lock(bp);
  1824. } else
  1825. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1826. }
  1827. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1828. {
  1829. u8 rc = 0;
  1830. if (!BP_NOMCP(bp)) {
  1831. bnx2x_acquire_phy_lock(bp);
  1832. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1833. is_serdes);
  1834. bnx2x_release_phy_lock(bp);
  1835. } else
  1836. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1837. return rc;
  1838. }
  1839. /* Calculates the sum of vn_min_rates.
  1840. It's needed for further normalizing of the min_rates.
  1841. Returns:
  1842. sum of vn_min_rates.
  1843. or
  1844. 0 - if all the min_rates are 0.
  1845. In the later case fainess algorithm should be deactivated.
  1846. If not all min_rates are zero then those that are zeroes will be set to 1.
  1847. */
  1848. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1849. struct cmng_init_input *input)
  1850. {
  1851. int all_zero = 1;
  1852. int vn;
  1853. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1854. u32 vn_cfg = bp->mf_config[vn];
  1855. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1856. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1857. /* Skip hidden vns */
  1858. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1859. vn_min_rate = 0;
  1860. /* If min rate is zero - set it to 1 */
  1861. else if (!vn_min_rate)
  1862. vn_min_rate = DEF_MIN_RATE;
  1863. else
  1864. all_zero = 0;
  1865. input->vnic_min_rate[vn] = vn_min_rate;
  1866. }
  1867. /* if ETS or all min rates are zeros - disable fairness */
  1868. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1869. input->flags.cmng_enables &=
  1870. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1871. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1872. } else if (all_zero) {
  1873. input->flags.cmng_enables &=
  1874. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1875. DP(NETIF_MSG_IFUP,
  1876. "All MIN values are zeroes fairness will be disabled\n");
  1877. } else
  1878. input->flags.cmng_enables |=
  1879. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1880. }
  1881. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  1882. struct cmng_init_input *input)
  1883. {
  1884. u16 vn_max_rate;
  1885. u32 vn_cfg = bp->mf_config[vn];
  1886. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1887. vn_max_rate = 0;
  1888. else {
  1889. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1890. if (IS_MF_SI(bp)) {
  1891. /* maxCfg in percents of linkspeed */
  1892. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1893. } else /* SD modes */
  1894. /* maxCfg is absolute in 100Mb units */
  1895. vn_max_rate = maxCfg * 100;
  1896. }
  1897. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  1898. input->vnic_max_rate[vn] = vn_max_rate;
  1899. }
  1900. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  1901. {
  1902. if (CHIP_REV_IS_SLOW(bp))
  1903. return CMNG_FNS_NONE;
  1904. if (IS_MF(bp))
  1905. return CMNG_FNS_MINMAX;
  1906. return CMNG_FNS_NONE;
  1907. }
  1908. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  1909. {
  1910. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  1911. if (BP_NOMCP(bp))
  1912. return; /* what should be the default bvalue in this case */
  1913. /* For 2 port configuration the absolute function number formula
  1914. * is:
  1915. * abs_func = 2 * vn + BP_PORT + BP_PATH
  1916. *
  1917. * and there are 4 functions per port
  1918. *
  1919. * For 4 port configuration it is
  1920. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  1921. *
  1922. * and there are 2 functions per port
  1923. */
  1924. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1925. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  1926. if (func >= E1H_FUNC_MAX)
  1927. break;
  1928. bp->mf_config[vn] =
  1929. MF_CFG_RD(bp, func_mf_config[func].config);
  1930. }
  1931. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  1932. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  1933. bp->flags |= MF_FUNC_DIS;
  1934. } else {
  1935. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  1936. bp->flags &= ~MF_FUNC_DIS;
  1937. }
  1938. }
  1939. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  1940. {
  1941. struct cmng_init_input input;
  1942. memset(&input, 0, sizeof(struct cmng_init_input));
  1943. input.port_rate = bp->link_vars.line_speed;
  1944. if (cmng_type == CMNG_FNS_MINMAX) {
  1945. int vn;
  1946. /* read mf conf from shmem */
  1947. if (read_cfg)
  1948. bnx2x_read_mf_cfg(bp);
  1949. /* vn_weight_sum and enable fairness if not 0 */
  1950. bnx2x_calc_vn_min(bp, &input);
  1951. /* calculate and set min-max rate for each vn */
  1952. if (bp->port.pmf)
  1953. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  1954. bnx2x_calc_vn_max(bp, vn, &input);
  1955. /* always enable rate shaping and fairness */
  1956. input.flags.cmng_enables |=
  1957. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  1958. bnx2x_init_cmng(&input, &bp->cmng);
  1959. return;
  1960. }
  1961. /* rate shaping and fairness are disabled */
  1962. DP(NETIF_MSG_IFUP,
  1963. "rate shaping and fairness are disabled\n");
  1964. }
  1965. static void storm_memset_cmng(struct bnx2x *bp,
  1966. struct cmng_init *cmng,
  1967. u8 port)
  1968. {
  1969. int vn;
  1970. size_t size = sizeof(struct cmng_struct_per_port);
  1971. u32 addr = BAR_XSTRORM_INTMEM +
  1972. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  1973. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  1974. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1975. int func = func_by_vn(bp, vn);
  1976. addr = BAR_XSTRORM_INTMEM +
  1977. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  1978. size = sizeof(struct rate_shaping_vars_per_vn);
  1979. __storm_memset_struct(bp, addr, size,
  1980. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  1981. addr = BAR_XSTRORM_INTMEM +
  1982. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  1983. size = sizeof(struct fairness_vars_per_vn);
  1984. __storm_memset_struct(bp, addr, size,
  1985. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  1986. }
  1987. }
  1988. /* This function is called upon link interrupt */
  1989. static void bnx2x_link_attn(struct bnx2x *bp)
  1990. {
  1991. /* Make sure that we are synced with the current statistics */
  1992. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1993. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  1994. if (bp->link_vars.link_up) {
  1995. /* dropless flow control */
  1996. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  1997. int port = BP_PORT(bp);
  1998. u32 pause_enabled = 0;
  1999. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2000. pause_enabled = 1;
  2001. REG_WR(bp, BAR_USTRORM_INTMEM +
  2002. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2003. pause_enabled);
  2004. }
  2005. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2006. struct host_port_stats *pstats;
  2007. pstats = bnx2x_sp(bp, port_stats);
  2008. /* reset old mac stats */
  2009. memset(&(pstats->mac_stx[0]), 0,
  2010. sizeof(struct mac_stx));
  2011. }
  2012. if (bp->state == BNX2X_STATE_OPEN)
  2013. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2014. }
  2015. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2016. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2017. if (cmng_fns != CMNG_FNS_NONE) {
  2018. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2019. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2020. } else
  2021. /* rate shaping and fairness are disabled */
  2022. DP(NETIF_MSG_IFUP,
  2023. "single function mode without fairness\n");
  2024. }
  2025. __bnx2x_link_report(bp);
  2026. if (IS_MF(bp))
  2027. bnx2x_link_sync_notify(bp);
  2028. }
  2029. void bnx2x__link_status_update(struct bnx2x *bp)
  2030. {
  2031. if (bp->state != BNX2X_STATE_OPEN)
  2032. return;
  2033. /* read updated dcb configuration */
  2034. bnx2x_dcbx_pmf_update(bp);
  2035. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2036. if (bp->link_vars.link_up)
  2037. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2038. else
  2039. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2040. /* indicate link status */
  2041. bnx2x_link_report(bp);
  2042. }
  2043. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2044. u16 vlan_val, u8 allowed_prio)
  2045. {
  2046. struct bnx2x_func_state_params func_params = {0};
  2047. struct bnx2x_func_afex_update_params *f_update_params =
  2048. &func_params.params.afex_update;
  2049. func_params.f_obj = &bp->func_obj;
  2050. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2051. /* no need to wait for RAMROD completion, so don't
  2052. * set RAMROD_COMP_WAIT flag
  2053. */
  2054. f_update_params->vif_id = vifid;
  2055. f_update_params->afex_default_vlan = vlan_val;
  2056. f_update_params->allowed_priorities = allowed_prio;
  2057. /* if ramrod can not be sent, response to MCP immediately */
  2058. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2059. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2060. return 0;
  2061. }
  2062. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2063. u16 vif_index, u8 func_bit_map)
  2064. {
  2065. struct bnx2x_func_state_params func_params = {0};
  2066. struct bnx2x_func_afex_viflists_params *update_params =
  2067. &func_params.params.afex_viflists;
  2068. int rc;
  2069. u32 drv_msg_code;
  2070. /* validate only LIST_SET and LIST_GET are received from switch */
  2071. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2072. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2073. cmd_type);
  2074. func_params.f_obj = &bp->func_obj;
  2075. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2076. /* set parameters according to cmd_type */
  2077. update_params->afex_vif_list_command = cmd_type;
  2078. update_params->vif_list_index = cpu_to_le16(vif_index);
  2079. update_params->func_bit_map =
  2080. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2081. update_params->func_to_clear = 0;
  2082. drv_msg_code =
  2083. (cmd_type == VIF_LIST_RULE_GET) ?
  2084. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2085. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2086. /* if ramrod can not be sent, respond to MCP immediately for
  2087. * SET and GET requests (other are not triggered from MCP)
  2088. */
  2089. rc = bnx2x_func_state_change(bp, &func_params);
  2090. if (rc < 0)
  2091. bnx2x_fw_command(bp, drv_msg_code, 0);
  2092. return 0;
  2093. }
  2094. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2095. {
  2096. struct afex_stats afex_stats;
  2097. u32 func = BP_ABS_FUNC(bp);
  2098. u32 mf_config;
  2099. u16 vlan_val;
  2100. u32 vlan_prio;
  2101. u16 vif_id;
  2102. u8 allowed_prio;
  2103. u8 vlan_mode;
  2104. u32 addr_to_write, vifid, addrs, stats_type, i;
  2105. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2106. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2107. DP(BNX2X_MSG_MCP,
  2108. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2109. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2110. }
  2111. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2112. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2113. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2114. DP(BNX2X_MSG_MCP,
  2115. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2116. vifid, addrs);
  2117. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2118. addrs);
  2119. }
  2120. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2121. addr_to_write = SHMEM2_RD(bp,
  2122. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2123. stats_type = SHMEM2_RD(bp,
  2124. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2125. DP(BNX2X_MSG_MCP,
  2126. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2127. addr_to_write);
  2128. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2129. /* write response to scratchpad, for MCP */
  2130. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2131. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2132. *(((u32 *)(&afex_stats))+i));
  2133. /* send ack message to MCP */
  2134. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2135. }
  2136. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2137. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2138. bp->mf_config[BP_VN(bp)] = mf_config;
  2139. DP(BNX2X_MSG_MCP,
  2140. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2141. mf_config);
  2142. /* if VIF_SET is "enabled" */
  2143. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2144. /* set rate limit directly to internal RAM */
  2145. struct cmng_init_input cmng_input;
  2146. struct rate_shaping_vars_per_vn m_rs_vn;
  2147. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2148. u32 addr = BAR_XSTRORM_INTMEM +
  2149. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2150. bp->mf_config[BP_VN(bp)] = mf_config;
  2151. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2152. m_rs_vn.vn_counter.rate =
  2153. cmng_input.vnic_max_rate[BP_VN(bp)];
  2154. m_rs_vn.vn_counter.quota =
  2155. (m_rs_vn.vn_counter.rate *
  2156. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2157. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2158. /* read relevant values from mf_cfg struct in shmem */
  2159. vif_id =
  2160. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2161. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2162. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2163. vlan_val =
  2164. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2165. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2166. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2167. vlan_prio = (mf_config &
  2168. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2169. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2170. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2171. vlan_mode =
  2172. (MF_CFG_RD(bp,
  2173. func_mf_config[func].afex_config) &
  2174. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2175. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2176. allowed_prio =
  2177. (MF_CFG_RD(bp,
  2178. func_mf_config[func].afex_config) &
  2179. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2180. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2181. /* send ramrod to FW, return in case of failure */
  2182. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2183. allowed_prio))
  2184. return;
  2185. bp->afex_def_vlan_tag = vlan_val;
  2186. bp->afex_vlan_mode = vlan_mode;
  2187. } else {
  2188. /* notify link down because BP->flags is disabled */
  2189. bnx2x_link_report(bp);
  2190. /* send INVALID VIF ramrod to FW */
  2191. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2192. /* Reset the default afex VLAN */
  2193. bp->afex_def_vlan_tag = -1;
  2194. }
  2195. }
  2196. }
  2197. static void bnx2x_pmf_update(struct bnx2x *bp)
  2198. {
  2199. int port = BP_PORT(bp);
  2200. u32 val;
  2201. bp->port.pmf = 1;
  2202. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2203. /*
  2204. * We need the mb() to ensure the ordering between the writing to
  2205. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2206. */
  2207. smp_mb();
  2208. /* queue a periodic task */
  2209. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2210. bnx2x_dcbx_pmf_update(bp);
  2211. /* enable nig attention */
  2212. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2213. if (bp->common.int_block == INT_BLOCK_HC) {
  2214. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2215. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2216. } else if (!CHIP_IS_E1x(bp)) {
  2217. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2218. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2219. }
  2220. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2221. }
  2222. /* end of Link */
  2223. /* slow path */
  2224. /*
  2225. * General service functions
  2226. */
  2227. /* send the MCP a request, block until there is a reply */
  2228. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2229. {
  2230. int mb_idx = BP_FW_MB_IDX(bp);
  2231. u32 seq;
  2232. u32 rc = 0;
  2233. u32 cnt = 1;
  2234. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2235. mutex_lock(&bp->fw_mb_mutex);
  2236. seq = ++bp->fw_seq;
  2237. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2238. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2239. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2240. (command | seq), param);
  2241. do {
  2242. /* let the FW do it's magic ... */
  2243. msleep(delay);
  2244. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2245. /* Give the FW up to 5 second (500*10ms) */
  2246. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2247. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2248. cnt*delay, rc, seq);
  2249. /* is this a reply to our command? */
  2250. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2251. rc &= FW_MSG_CODE_MASK;
  2252. else {
  2253. /* FW BUG! */
  2254. BNX2X_ERR("FW failed to respond!\n");
  2255. bnx2x_fw_dump(bp);
  2256. rc = 0;
  2257. }
  2258. mutex_unlock(&bp->fw_mb_mutex);
  2259. return rc;
  2260. }
  2261. static void storm_memset_func_cfg(struct bnx2x *bp,
  2262. struct tstorm_eth_function_common_config *tcfg,
  2263. u16 abs_fid)
  2264. {
  2265. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2266. u32 addr = BAR_TSTRORM_INTMEM +
  2267. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2268. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2269. }
  2270. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2271. {
  2272. if (CHIP_IS_E1x(bp)) {
  2273. struct tstorm_eth_function_common_config tcfg = {0};
  2274. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2275. }
  2276. /* Enable the function in the FW */
  2277. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2278. storm_memset_func_en(bp, p->func_id, 1);
  2279. /* spq */
  2280. if (p->func_flgs & FUNC_FLG_SPQ) {
  2281. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2282. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2283. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2284. }
  2285. }
  2286. /**
  2287. * bnx2x_get_tx_only_flags - Return common flags
  2288. *
  2289. * @bp device handle
  2290. * @fp queue handle
  2291. * @zero_stats TRUE if statistics zeroing is needed
  2292. *
  2293. * Return the flags that are common for the Tx-only and not normal connections.
  2294. */
  2295. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2296. struct bnx2x_fastpath *fp,
  2297. bool zero_stats)
  2298. {
  2299. unsigned long flags = 0;
  2300. /* PF driver will always initialize the Queue to an ACTIVE state */
  2301. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2302. /* tx only connections collect statistics (on the same index as the
  2303. * parent connection). The statistics are zeroed when the parent
  2304. * connection is initialized.
  2305. */
  2306. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2307. if (zero_stats)
  2308. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2309. return flags;
  2310. }
  2311. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2312. struct bnx2x_fastpath *fp,
  2313. bool leading)
  2314. {
  2315. unsigned long flags = 0;
  2316. /* calculate other queue flags */
  2317. if (IS_MF_SD(bp))
  2318. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2319. if (IS_FCOE_FP(fp)) {
  2320. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2321. /* For FCoE - force usage of default priority (for afex) */
  2322. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2323. }
  2324. if (!fp->disable_tpa) {
  2325. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2326. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2327. if (fp->mode == TPA_MODE_GRO)
  2328. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2329. }
  2330. if (leading) {
  2331. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2332. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2333. }
  2334. /* Always set HW VLAN stripping */
  2335. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2336. /* configure silent vlan removal */
  2337. if (IS_MF_AFEX(bp))
  2338. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2339. return flags | bnx2x_get_common_flags(bp, fp, true);
  2340. }
  2341. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2342. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2343. u8 cos)
  2344. {
  2345. gen_init->stat_id = bnx2x_stats_id(fp);
  2346. gen_init->spcl_id = fp->cl_id;
  2347. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2348. if (IS_FCOE_FP(fp))
  2349. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2350. else
  2351. gen_init->mtu = bp->dev->mtu;
  2352. gen_init->cos = cos;
  2353. }
  2354. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2355. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2356. struct bnx2x_rxq_setup_params *rxq_init)
  2357. {
  2358. u8 max_sge = 0;
  2359. u16 sge_sz = 0;
  2360. u16 tpa_agg_size = 0;
  2361. if (!fp->disable_tpa) {
  2362. pause->sge_th_lo = SGE_TH_LO(bp);
  2363. pause->sge_th_hi = SGE_TH_HI(bp);
  2364. /* validate SGE ring has enough to cross high threshold */
  2365. WARN_ON(bp->dropless_fc &&
  2366. pause->sge_th_hi + FW_PREFETCH_CNT >
  2367. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2368. tpa_agg_size = min_t(u32,
  2369. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2370. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2371. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2372. SGE_PAGE_SHIFT;
  2373. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2374. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2375. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2376. 0xffff);
  2377. }
  2378. /* pause - not for e1 */
  2379. if (!CHIP_IS_E1(bp)) {
  2380. pause->bd_th_lo = BD_TH_LO(bp);
  2381. pause->bd_th_hi = BD_TH_HI(bp);
  2382. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2383. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2384. /*
  2385. * validate that rings have enough entries to cross
  2386. * high thresholds
  2387. */
  2388. WARN_ON(bp->dropless_fc &&
  2389. pause->bd_th_hi + FW_PREFETCH_CNT >
  2390. bp->rx_ring_size);
  2391. WARN_ON(bp->dropless_fc &&
  2392. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2393. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2394. pause->pri_map = 1;
  2395. }
  2396. /* rxq setup */
  2397. rxq_init->dscr_map = fp->rx_desc_mapping;
  2398. rxq_init->sge_map = fp->rx_sge_mapping;
  2399. rxq_init->rcq_map = fp->rx_comp_mapping;
  2400. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2401. /* This should be a maximum number of data bytes that may be
  2402. * placed on the BD (not including paddings).
  2403. */
  2404. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2405. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2406. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2407. rxq_init->tpa_agg_sz = tpa_agg_size;
  2408. rxq_init->sge_buf_sz = sge_sz;
  2409. rxq_init->max_sges_pkt = max_sge;
  2410. rxq_init->rss_engine_id = BP_FUNC(bp);
  2411. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2412. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2413. *
  2414. * For PF Clients it should be the maximum avaliable number.
  2415. * VF driver(s) may want to define it to a smaller value.
  2416. */
  2417. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2418. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2419. rxq_init->fw_sb_id = fp->fw_sb_id;
  2420. if (IS_FCOE_FP(fp))
  2421. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2422. else
  2423. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2424. /* configure silent vlan removal
  2425. * if multi function mode is afex, then mask default vlan
  2426. */
  2427. if (IS_MF_AFEX(bp)) {
  2428. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2429. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2430. }
  2431. }
  2432. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2433. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2434. u8 cos)
  2435. {
  2436. txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
  2437. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2438. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2439. txq_init->fw_sb_id = fp->fw_sb_id;
  2440. /*
  2441. * set the tss leading client id for TX classfication ==
  2442. * leading RSS client id
  2443. */
  2444. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2445. if (IS_FCOE_FP(fp)) {
  2446. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2447. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2448. }
  2449. }
  2450. static void bnx2x_pf_init(struct bnx2x *bp)
  2451. {
  2452. struct bnx2x_func_init_params func_init = {0};
  2453. struct event_ring_data eq_data = { {0} };
  2454. u16 flags;
  2455. if (!CHIP_IS_E1x(bp)) {
  2456. /* reset IGU PF statistics: MSIX + ATTN */
  2457. /* PF */
  2458. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2459. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2460. (CHIP_MODE_IS_4_PORT(bp) ?
  2461. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2462. /* ATTN */
  2463. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2464. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2465. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2466. (CHIP_MODE_IS_4_PORT(bp) ?
  2467. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2468. }
  2469. /* function setup flags */
  2470. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2471. /* This flag is relevant for E1x only.
  2472. * E2 doesn't have a TPA configuration in a function level.
  2473. */
  2474. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2475. func_init.func_flgs = flags;
  2476. func_init.pf_id = BP_FUNC(bp);
  2477. func_init.func_id = BP_FUNC(bp);
  2478. func_init.spq_map = bp->spq_mapping;
  2479. func_init.spq_prod = bp->spq_prod_idx;
  2480. bnx2x_func_init(bp, &func_init);
  2481. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2482. /*
  2483. * Congestion management values depend on the link rate
  2484. * There is no active link so initial link rate is set to 10 Gbps.
  2485. * When the link comes up The congestion management values are
  2486. * re-calculated according to the actual link rate.
  2487. */
  2488. bp->link_vars.line_speed = SPEED_10000;
  2489. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2490. /* Only the PMF sets the HW */
  2491. if (bp->port.pmf)
  2492. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2493. /* init Event Queue */
  2494. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2495. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2496. eq_data.producer = bp->eq_prod;
  2497. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2498. eq_data.sb_id = DEF_SB_ID;
  2499. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2500. }
  2501. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2502. {
  2503. int port = BP_PORT(bp);
  2504. bnx2x_tx_disable(bp);
  2505. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2506. }
  2507. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2508. {
  2509. int port = BP_PORT(bp);
  2510. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2511. /* Tx queue should be only reenabled */
  2512. netif_tx_wake_all_queues(bp->dev);
  2513. /*
  2514. * Should not call netif_carrier_on since it will be called if the link
  2515. * is up when checking for link state
  2516. */
  2517. }
  2518. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2519. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2520. {
  2521. struct eth_stats_info *ether_stat =
  2522. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2523. /* leave last char as NULL */
  2524. memcpy(ether_stat->version, DRV_MODULE_VERSION,
  2525. ETH_STAT_INFO_VERSION_LEN - 1);
  2526. bp->fp[0].mac_obj.get_n_elements(bp, &bp->fp[0].mac_obj,
  2527. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2528. ether_stat->mac_local);
  2529. ether_stat->mtu_size = bp->dev->mtu;
  2530. if (bp->dev->features & NETIF_F_RXCSUM)
  2531. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2532. if (bp->dev->features & NETIF_F_TSO)
  2533. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2534. ether_stat->feature_flags |= bp->common.boot_mode;
  2535. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2536. ether_stat->txq_size = bp->tx_ring_size;
  2537. ether_stat->rxq_size = bp->rx_ring_size;
  2538. }
  2539. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2540. {
  2541. #ifdef BCM_CNIC
  2542. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2543. struct fcoe_stats_info *fcoe_stat =
  2544. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2545. memcpy(fcoe_stat->mac_local, bp->fip_mac, ETH_ALEN);
  2546. fcoe_stat->qos_priority =
  2547. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2548. /* insert FCoE stats from ramrod response */
  2549. if (!NO_FCOE(bp)) {
  2550. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2551. &bp->fw_stats_data->queue_stats[FCOE_IDX].
  2552. tstorm_queue_statistics;
  2553. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2554. &bp->fw_stats_data->queue_stats[FCOE_IDX].
  2555. xstorm_queue_statistics;
  2556. struct fcoe_statistics_params *fw_fcoe_stat =
  2557. &bp->fw_stats_data->fcoe;
  2558. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2559. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2560. ADD_64(fcoe_stat->rx_bytes_hi,
  2561. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2562. fcoe_stat->rx_bytes_lo,
  2563. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2564. ADD_64(fcoe_stat->rx_bytes_hi,
  2565. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2566. fcoe_stat->rx_bytes_lo,
  2567. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2568. ADD_64(fcoe_stat->rx_bytes_hi,
  2569. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2570. fcoe_stat->rx_bytes_lo,
  2571. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2572. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2573. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2574. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2575. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2576. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2577. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2578. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2579. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2580. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2581. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2582. ADD_64(fcoe_stat->tx_bytes_hi,
  2583. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2584. fcoe_stat->tx_bytes_lo,
  2585. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2586. ADD_64(fcoe_stat->tx_bytes_hi,
  2587. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2588. fcoe_stat->tx_bytes_lo,
  2589. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2590. ADD_64(fcoe_stat->tx_bytes_hi,
  2591. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2592. fcoe_stat->tx_bytes_lo,
  2593. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2594. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2595. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2596. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2597. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2598. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2599. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2600. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2601. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2602. }
  2603. /* ask L5 driver to add data to the struct */
  2604. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2605. #endif
  2606. }
  2607. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2608. {
  2609. #ifdef BCM_CNIC
  2610. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2611. struct iscsi_stats_info *iscsi_stat =
  2612. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2613. memcpy(iscsi_stat->mac_local, bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2614. iscsi_stat->qos_priority =
  2615. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2616. /* ask L5 driver to add data to the struct */
  2617. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2618. #endif
  2619. }
  2620. /* called due to MCP event (on pmf):
  2621. * reread new bandwidth configuration
  2622. * configure FW
  2623. * notify others function about the change
  2624. */
  2625. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2626. {
  2627. if (bp->link_vars.link_up) {
  2628. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2629. bnx2x_link_sync_notify(bp);
  2630. }
  2631. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2632. }
  2633. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2634. {
  2635. bnx2x_config_mf_bw(bp);
  2636. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2637. }
  2638. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2639. {
  2640. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2641. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2642. }
  2643. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2644. {
  2645. enum drv_info_opcode op_code;
  2646. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2647. /* if drv_info version supported by MFW doesn't match - send NACK */
  2648. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2649. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2650. return;
  2651. }
  2652. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2653. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2654. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2655. sizeof(union drv_info_to_mcp));
  2656. switch (op_code) {
  2657. case ETH_STATS_OPCODE:
  2658. bnx2x_drv_info_ether_stat(bp);
  2659. break;
  2660. case FCOE_STATS_OPCODE:
  2661. bnx2x_drv_info_fcoe_stat(bp);
  2662. break;
  2663. case ISCSI_STATS_OPCODE:
  2664. bnx2x_drv_info_iscsi_stat(bp);
  2665. break;
  2666. default:
  2667. /* if op code isn't supported - send NACK */
  2668. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2669. return;
  2670. }
  2671. /* if we got drv_info attn from MFW then these fields are defined in
  2672. * shmem2 for sure
  2673. */
  2674. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2675. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2676. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2677. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2678. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2679. }
  2680. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2681. {
  2682. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2683. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2684. /*
  2685. * This is the only place besides the function initialization
  2686. * where the bp->flags can change so it is done without any
  2687. * locks
  2688. */
  2689. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2690. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2691. bp->flags |= MF_FUNC_DIS;
  2692. bnx2x_e1h_disable(bp);
  2693. } else {
  2694. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2695. bp->flags &= ~MF_FUNC_DIS;
  2696. bnx2x_e1h_enable(bp);
  2697. }
  2698. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2699. }
  2700. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2701. bnx2x_config_mf_bw(bp);
  2702. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2703. }
  2704. /* Report results to MCP */
  2705. if (dcc_event)
  2706. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2707. else
  2708. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2709. }
  2710. /* must be called under the spq lock */
  2711. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2712. {
  2713. struct eth_spe *next_spe = bp->spq_prod_bd;
  2714. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2715. bp->spq_prod_bd = bp->spq;
  2716. bp->spq_prod_idx = 0;
  2717. DP(BNX2X_MSG_SP, "end of spq\n");
  2718. } else {
  2719. bp->spq_prod_bd++;
  2720. bp->spq_prod_idx++;
  2721. }
  2722. return next_spe;
  2723. }
  2724. /* must be called under the spq lock */
  2725. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2726. {
  2727. int func = BP_FUNC(bp);
  2728. /*
  2729. * Make sure that BD data is updated before writing the producer:
  2730. * BD data is written to the memory, the producer is read from the
  2731. * memory, thus we need a full memory barrier to ensure the ordering.
  2732. */
  2733. mb();
  2734. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2735. bp->spq_prod_idx);
  2736. mmiowb();
  2737. }
  2738. /**
  2739. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2740. *
  2741. * @cmd: command to check
  2742. * @cmd_type: command type
  2743. */
  2744. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2745. {
  2746. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2747. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2748. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2749. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2750. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2751. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2752. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2753. return true;
  2754. else
  2755. return false;
  2756. }
  2757. /**
  2758. * bnx2x_sp_post - place a single command on an SP ring
  2759. *
  2760. * @bp: driver handle
  2761. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2762. * @cid: SW CID the command is related to
  2763. * @data_hi: command private data address (high 32 bits)
  2764. * @data_lo: command private data address (low 32 bits)
  2765. * @cmd_type: command type (e.g. NONE, ETH)
  2766. *
  2767. * SP data is handled as if it's always an address pair, thus data fields are
  2768. * not swapped to little endian in upper functions. Instead this function swaps
  2769. * data as if it's two u32 fields.
  2770. */
  2771. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2772. u32 data_hi, u32 data_lo, int cmd_type)
  2773. {
  2774. struct eth_spe *spe;
  2775. u16 type;
  2776. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2777. #ifdef BNX2X_STOP_ON_ERROR
  2778. if (unlikely(bp->panic)) {
  2779. BNX2X_ERR("Can't post SP when there is panic\n");
  2780. return -EIO;
  2781. }
  2782. #endif
  2783. spin_lock_bh(&bp->spq_lock);
  2784. if (common) {
  2785. if (!atomic_read(&bp->eq_spq_left)) {
  2786. BNX2X_ERR("BUG! EQ ring full!\n");
  2787. spin_unlock_bh(&bp->spq_lock);
  2788. bnx2x_panic();
  2789. return -EBUSY;
  2790. }
  2791. } else if (!atomic_read(&bp->cq_spq_left)) {
  2792. BNX2X_ERR("BUG! SPQ ring full!\n");
  2793. spin_unlock_bh(&bp->spq_lock);
  2794. bnx2x_panic();
  2795. return -EBUSY;
  2796. }
  2797. spe = bnx2x_sp_get_next(bp);
  2798. /* CID needs port number to be encoded int it */
  2799. spe->hdr.conn_and_cmd_data =
  2800. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2801. HW_CID(bp, cid));
  2802. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2803. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2804. SPE_HDR_FUNCTION_ID);
  2805. spe->hdr.type = cpu_to_le16(type);
  2806. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2807. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2808. /*
  2809. * It's ok if the actual decrement is issued towards the memory
  2810. * somewhere between the spin_lock and spin_unlock. Thus no
  2811. * more explict memory barrier is needed.
  2812. */
  2813. if (common)
  2814. atomic_dec(&bp->eq_spq_left);
  2815. else
  2816. atomic_dec(&bp->cq_spq_left);
  2817. DP(BNX2X_MSG_SP,
  2818. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2819. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2820. (u32)(U64_LO(bp->spq_mapping) +
  2821. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2822. HW_CID(bp, cid), data_hi, data_lo, type,
  2823. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2824. bnx2x_sp_prod_update(bp);
  2825. spin_unlock_bh(&bp->spq_lock);
  2826. return 0;
  2827. }
  2828. /* acquire split MCP access lock register */
  2829. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2830. {
  2831. u32 j, val;
  2832. int rc = 0;
  2833. might_sleep();
  2834. for (j = 0; j < 1000; j++) {
  2835. val = (1UL << 31);
  2836. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2837. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2838. if (val & (1L << 31))
  2839. break;
  2840. msleep(5);
  2841. }
  2842. if (!(val & (1L << 31))) {
  2843. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2844. rc = -EBUSY;
  2845. }
  2846. return rc;
  2847. }
  2848. /* release split MCP access lock register */
  2849. static void bnx2x_release_alr(struct bnx2x *bp)
  2850. {
  2851. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2852. }
  2853. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2854. #define BNX2X_DEF_SB_IDX 0x0002
  2855. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2856. {
  2857. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2858. u16 rc = 0;
  2859. barrier(); /* status block is written to by the chip */
  2860. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2861. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2862. rc |= BNX2X_DEF_SB_ATT_IDX;
  2863. }
  2864. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2865. bp->def_idx = def_sb->sp_sb.running_index;
  2866. rc |= BNX2X_DEF_SB_IDX;
  2867. }
  2868. /* Do not reorder: indecies reading should complete before handling */
  2869. barrier();
  2870. return rc;
  2871. }
  2872. /*
  2873. * slow path service functions
  2874. */
  2875. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2876. {
  2877. int port = BP_PORT(bp);
  2878. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2879. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2880. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2881. NIG_REG_MASK_INTERRUPT_PORT0;
  2882. u32 aeu_mask;
  2883. u32 nig_mask = 0;
  2884. u32 reg_addr;
  2885. if (bp->attn_state & asserted)
  2886. BNX2X_ERR("IGU ERROR\n");
  2887. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2888. aeu_mask = REG_RD(bp, aeu_addr);
  2889. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2890. aeu_mask, asserted);
  2891. aeu_mask &= ~(asserted & 0x3ff);
  2892. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2893. REG_WR(bp, aeu_addr, aeu_mask);
  2894. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2895. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2896. bp->attn_state |= asserted;
  2897. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2898. if (asserted & ATTN_HARD_WIRED_MASK) {
  2899. if (asserted & ATTN_NIG_FOR_FUNC) {
  2900. bnx2x_acquire_phy_lock(bp);
  2901. /* save nig interrupt mask */
  2902. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2903. /* If nig_mask is not set, no need to call the update
  2904. * function.
  2905. */
  2906. if (nig_mask) {
  2907. REG_WR(bp, nig_int_mask_addr, 0);
  2908. bnx2x_link_attn(bp);
  2909. }
  2910. /* handle unicore attn? */
  2911. }
  2912. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2913. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2914. if (asserted & GPIO_2_FUNC)
  2915. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2916. if (asserted & GPIO_3_FUNC)
  2917. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2918. if (asserted & GPIO_4_FUNC)
  2919. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2920. if (port == 0) {
  2921. if (asserted & ATTN_GENERAL_ATTN_1) {
  2922. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2923. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2924. }
  2925. if (asserted & ATTN_GENERAL_ATTN_2) {
  2926. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2927. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2928. }
  2929. if (asserted & ATTN_GENERAL_ATTN_3) {
  2930. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2931. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2932. }
  2933. } else {
  2934. if (asserted & ATTN_GENERAL_ATTN_4) {
  2935. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2936. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2937. }
  2938. if (asserted & ATTN_GENERAL_ATTN_5) {
  2939. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2940. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2941. }
  2942. if (asserted & ATTN_GENERAL_ATTN_6) {
  2943. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2944. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2945. }
  2946. }
  2947. } /* if hardwired */
  2948. if (bp->common.int_block == INT_BLOCK_HC)
  2949. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2950. COMMAND_REG_ATTN_BITS_SET);
  2951. else
  2952. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2953. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2954. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2955. REG_WR(bp, reg_addr, asserted);
  2956. /* now set back the mask */
  2957. if (asserted & ATTN_NIG_FOR_FUNC) {
  2958. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2959. bnx2x_release_phy_lock(bp);
  2960. }
  2961. }
  2962. static void bnx2x_fan_failure(struct bnx2x *bp)
  2963. {
  2964. int port = BP_PORT(bp);
  2965. u32 ext_phy_config;
  2966. /* mark the failure */
  2967. ext_phy_config =
  2968. SHMEM_RD(bp,
  2969. dev_info.port_hw_config[port].external_phy_config);
  2970. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2971. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2972. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2973. ext_phy_config);
  2974. /* log the failure */
  2975. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  2976. "Please contact OEM Support for assistance\n");
  2977. /*
  2978. * Scheudle device reset (unload)
  2979. * This is due to some boards consuming sufficient power when driver is
  2980. * up to overheat if fan fails.
  2981. */
  2982. smp_mb__before_clear_bit();
  2983. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  2984. smp_mb__after_clear_bit();
  2985. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  2986. }
  2987. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  2988. {
  2989. int port = BP_PORT(bp);
  2990. int reg_offset;
  2991. u32 val;
  2992. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  2993. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  2994. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  2995. val = REG_RD(bp, reg_offset);
  2996. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  2997. REG_WR(bp, reg_offset, val);
  2998. BNX2X_ERR("SPIO5 hw attention\n");
  2999. /* Fan failure attention */
  3000. bnx2x_hw_reset_phy(&bp->link_params);
  3001. bnx2x_fan_failure(bp);
  3002. }
  3003. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3004. bnx2x_acquire_phy_lock(bp);
  3005. bnx2x_handle_module_detect_int(&bp->link_params);
  3006. bnx2x_release_phy_lock(bp);
  3007. }
  3008. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3009. val = REG_RD(bp, reg_offset);
  3010. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3011. REG_WR(bp, reg_offset, val);
  3012. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3013. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3014. bnx2x_panic();
  3015. }
  3016. }
  3017. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3018. {
  3019. u32 val;
  3020. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3021. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3022. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3023. /* DORQ discard attention */
  3024. if (val & 0x2)
  3025. BNX2X_ERR("FATAL error from DORQ\n");
  3026. }
  3027. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3028. int port = BP_PORT(bp);
  3029. int reg_offset;
  3030. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3031. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3032. val = REG_RD(bp, reg_offset);
  3033. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3034. REG_WR(bp, reg_offset, val);
  3035. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3036. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3037. bnx2x_panic();
  3038. }
  3039. }
  3040. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3041. {
  3042. u32 val;
  3043. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3044. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3045. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3046. /* CFC error attention */
  3047. if (val & 0x2)
  3048. BNX2X_ERR("FATAL error from CFC\n");
  3049. }
  3050. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3051. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3052. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3053. /* RQ_USDMDP_FIFO_OVERFLOW */
  3054. if (val & 0x18000)
  3055. BNX2X_ERR("FATAL error from PXP\n");
  3056. if (!CHIP_IS_E1x(bp)) {
  3057. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3058. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3059. }
  3060. }
  3061. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3062. int port = BP_PORT(bp);
  3063. int reg_offset;
  3064. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3065. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3066. val = REG_RD(bp, reg_offset);
  3067. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3068. REG_WR(bp, reg_offset, val);
  3069. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3070. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3071. bnx2x_panic();
  3072. }
  3073. }
  3074. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3075. {
  3076. u32 val;
  3077. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3078. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3079. int func = BP_FUNC(bp);
  3080. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3081. bnx2x_read_mf_cfg(bp);
  3082. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3083. func_mf_config[BP_ABS_FUNC(bp)].config);
  3084. val = SHMEM_RD(bp,
  3085. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3086. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3087. bnx2x_dcc_event(bp,
  3088. (val & DRV_STATUS_DCC_EVENT_MASK));
  3089. if (val & DRV_STATUS_SET_MF_BW)
  3090. bnx2x_set_mf_bw(bp);
  3091. if (val & DRV_STATUS_DRV_INFO_REQ)
  3092. bnx2x_handle_drv_info_req(bp);
  3093. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3094. bnx2x_pmf_update(bp);
  3095. if (bp->port.pmf &&
  3096. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3097. bp->dcbx_enabled > 0)
  3098. /* start dcbx state machine */
  3099. bnx2x_dcbx_set_params(bp,
  3100. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3101. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3102. bnx2x_handle_afex_cmd(bp,
  3103. val & DRV_STATUS_AFEX_EVENT_MASK);
  3104. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3105. bnx2x_handle_eee_event(bp);
  3106. if (bp->link_vars.periodic_flags &
  3107. PERIODIC_FLAGS_LINK_EVENT) {
  3108. /* sync with link */
  3109. bnx2x_acquire_phy_lock(bp);
  3110. bp->link_vars.periodic_flags &=
  3111. ~PERIODIC_FLAGS_LINK_EVENT;
  3112. bnx2x_release_phy_lock(bp);
  3113. if (IS_MF(bp))
  3114. bnx2x_link_sync_notify(bp);
  3115. bnx2x_link_report(bp);
  3116. }
  3117. /* Always call it here: bnx2x_link_report() will
  3118. * prevent the link indication duplication.
  3119. */
  3120. bnx2x__link_status_update(bp);
  3121. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3122. BNX2X_ERR("MC assert!\n");
  3123. bnx2x_mc_assert(bp);
  3124. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3125. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3126. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3127. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3128. bnx2x_panic();
  3129. } else if (attn & BNX2X_MCP_ASSERT) {
  3130. BNX2X_ERR("MCP assert!\n");
  3131. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3132. bnx2x_fw_dump(bp);
  3133. } else
  3134. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3135. }
  3136. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3137. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3138. if (attn & BNX2X_GRC_TIMEOUT) {
  3139. val = CHIP_IS_E1(bp) ? 0 :
  3140. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3141. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3142. }
  3143. if (attn & BNX2X_GRC_RSV) {
  3144. val = CHIP_IS_E1(bp) ? 0 :
  3145. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3146. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3147. }
  3148. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3149. }
  3150. }
  3151. /*
  3152. * Bits map:
  3153. * 0-7 - Engine0 load counter.
  3154. * 8-15 - Engine1 load counter.
  3155. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3156. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3157. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3158. * on the engine
  3159. * 19 - Engine1 ONE_IS_LOADED.
  3160. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3161. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3162. * just the one belonging to its engine).
  3163. *
  3164. */
  3165. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3166. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3167. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3168. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3169. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3170. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3171. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3172. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3173. /*
  3174. * Set the GLOBAL_RESET bit.
  3175. *
  3176. * Should be run under rtnl lock
  3177. */
  3178. void bnx2x_set_reset_global(struct bnx2x *bp)
  3179. {
  3180. u32 val;
  3181. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3182. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3183. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3184. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3185. }
  3186. /*
  3187. * Clear the GLOBAL_RESET bit.
  3188. *
  3189. * Should be run under rtnl lock
  3190. */
  3191. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3192. {
  3193. u32 val;
  3194. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3195. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3196. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3197. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3198. }
  3199. /*
  3200. * Checks the GLOBAL_RESET bit.
  3201. *
  3202. * should be run under rtnl lock
  3203. */
  3204. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3205. {
  3206. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3207. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3208. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3209. }
  3210. /*
  3211. * Clear RESET_IN_PROGRESS bit for the current engine.
  3212. *
  3213. * Should be run under rtnl lock
  3214. */
  3215. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3216. {
  3217. u32 val;
  3218. u32 bit = BP_PATH(bp) ?
  3219. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3220. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3221. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3222. /* Clear the bit */
  3223. val &= ~bit;
  3224. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3225. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3226. }
  3227. /*
  3228. * Set RESET_IN_PROGRESS for the current engine.
  3229. *
  3230. * should be run under rtnl lock
  3231. */
  3232. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3233. {
  3234. u32 val;
  3235. u32 bit = BP_PATH(bp) ?
  3236. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3237. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3238. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3239. /* Set the bit */
  3240. val |= bit;
  3241. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3242. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3243. }
  3244. /*
  3245. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3246. * should be run under rtnl lock
  3247. */
  3248. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3249. {
  3250. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3251. u32 bit = engine ?
  3252. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3253. /* return false if bit is set */
  3254. return (val & bit) ? false : true;
  3255. }
  3256. /*
  3257. * set pf load for the current pf.
  3258. *
  3259. * should be run under rtnl lock
  3260. */
  3261. void bnx2x_set_pf_load(struct bnx2x *bp)
  3262. {
  3263. u32 val1, val;
  3264. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3265. BNX2X_PATH0_LOAD_CNT_MASK;
  3266. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3267. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3268. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3269. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3270. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3271. /* get the current counter value */
  3272. val1 = (val & mask) >> shift;
  3273. /* set bit of that PF */
  3274. val1 |= (1 << bp->pf_num);
  3275. /* clear the old value */
  3276. val &= ~mask;
  3277. /* set the new one */
  3278. val |= ((val1 << shift) & mask);
  3279. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3280. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3281. }
  3282. /**
  3283. * bnx2x_clear_pf_load - clear pf load mark
  3284. *
  3285. * @bp: driver handle
  3286. *
  3287. * Should be run under rtnl lock.
  3288. * Decrements the load counter for the current engine. Returns
  3289. * whether other functions are still loaded
  3290. */
  3291. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3292. {
  3293. u32 val1, val;
  3294. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3295. BNX2X_PATH0_LOAD_CNT_MASK;
  3296. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3297. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3298. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3299. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3300. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3301. /* get the current counter value */
  3302. val1 = (val & mask) >> shift;
  3303. /* clear bit of that PF */
  3304. val1 &= ~(1 << bp->pf_num);
  3305. /* clear the old value */
  3306. val &= ~mask;
  3307. /* set the new one */
  3308. val |= ((val1 << shift) & mask);
  3309. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3310. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3311. return val1 != 0;
  3312. }
  3313. /*
  3314. * Read the load status for the current engine.
  3315. *
  3316. * should be run under rtnl lock
  3317. */
  3318. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3319. {
  3320. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3321. BNX2X_PATH0_LOAD_CNT_MASK);
  3322. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3323. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3324. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3325. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3326. val = (val & mask) >> shift;
  3327. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3328. engine, val);
  3329. return val != 0;
  3330. }
  3331. /*
  3332. * Reset the load status for the current engine.
  3333. */
  3334. static void bnx2x_clear_load_status(struct bnx2x *bp)
  3335. {
  3336. u32 val;
  3337. u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3338. BNX2X_PATH0_LOAD_CNT_MASK);
  3339. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3340. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3341. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
  3342. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3343. }
  3344. static void _print_next_block(int idx, const char *blk)
  3345. {
  3346. pr_cont("%s%s", idx ? ", " : "", blk);
  3347. }
  3348. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3349. bool print)
  3350. {
  3351. int i = 0;
  3352. u32 cur_bit = 0;
  3353. for (i = 0; sig; i++) {
  3354. cur_bit = ((u32)0x1 << i);
  3355. if (sig & cur_bit) {
  3356. switch (cur_bit) {
  3357. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3358. if (print)
  3359. _print_next_block(par_num++, "BRB");
  3360. break;
  3361. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3362. if (print)
  3363. _print_next_block(par_num++, "PARSER");
  3364. break;
  3365. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3366. if (print)
  3367. _print_next_block(par_num++, "TSDM");
  3368. break;
  3369. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3370. if (print)
  3371. _print_next_block(par_num++,
  3372. "SEARCHER");
  3373. break;
  3374. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3375. if (print)
  3376. _print_next_block(par_num++, "TCM");
  3377. break;
  3378. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3379. if (print)
  3380. _print_next_block(par_num++, "TSEMI");
  3381. break;
  3382. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3383. if (print)
  3384. _print_next_block(par_num++, "XPB");
  3385. break;
  3386. }
  3387. /* Clear the bit */
  3388. sig &= ~cur_bit;
  3389. }
  3390. }
  3391. return par_num;
  3392. }
  3393. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3394. bool *global, bool print)
  3395. {
  3396. int i = 0;
  3397. u32 cur_bit = 0;
  3398. for (i = 0; sig; i++) {
  3399. cur_bit = ((u32)0x1 << i);
  3400. if (sig & cur_bit) {
  3401. switch (cur_bit) {
  3402. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3403. if (print)
  3404. _print_next_block(par_num++, "PBF");
  3405. break;
  3406. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3407. if (print)
  3408. _print_next_block(par_num++, "QM");
  3409. break;
  3410. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3411. if (print)
  3412. _print_next_block(par_num++, "TM");
  3413. break;
  3414. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3415. if (print)
  3416. _print_next_block(par_num++, "XSDM");
  3417. break;
  3418. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3419. if (print)
  3420. _print_next_block(par_num++, "XCM");
  3421. break;
  3422. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3423. if (print)
  3424. _print_next_block(par_num++, "XSEMI");
  3425. break;
  3426. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3427. if (print)
  3428. _print_next_block(par_num++,
  3429. "DOORBELLQ");
  3430. break;
  3431. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3432. if (print)
  3433. _print_next_block(par_num++, "NIG");
  3434. break;
  3435. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3436. if (print)
  3437. _print_next_block(par_num++,
  3438. "VAUX PCI CORE");
  3439. *global = true;
  3440. break;
  3441. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3442. if (print)
  3443. _print_next_block(par_num++, "DEBUG");
  3444. break;
  3445. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3446. if (print)
  3447. _print_next_block(par_num++, "USDM");
  3448. break;
  3449. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3450. if (print)
  3451. _print_next_block(par_num++, "UCM");
  3452. break;
  3453. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3454. if (print)
  3455. _print_next_block(par_num++, "USEMI");
  3456. break;
  3457. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3458. if (print)
  3459. _print_next_block(par_num++, "UPB");
  3460. break;
  3461. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3462. if (print)
  3463. _print_next_block(par_num++, "CSDM");
  3464. break;
  3465. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3466. if (print)
  3467. _print_next_block(par_num++, "CCM");
  3468. break;
  3469. }
  3470. /* Clear the bit */
  3471. sig &= ~cur_bit;
  3472. }
  3473. }
  3474. return par_num;
  3475. }
  3476. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3477. bool print)
  3478. {
  3479. int i = 0;
  3480. u32 cur_bit = 0;
  3481. for (i = 0; sig; i++) {
  3482. cur_bit = ((u32)0x1 << i);
  3483. if (sig & cur_bit) {
  3484. switch (cur_bit) {
  3485. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3486. if (print)
  3487. _print_next_block(par_num++, "CSEMI");
  3488. break;
  3489. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3490. if (print)
  3491. _print_next_block(par_num++, "PXP");
  3492. break;
  3493. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3494. if (print)
  3495. _print_next_block(par_num++,
  3496. "PXPPCICLOCKCLIENT");
  3497. break;
  3498. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3499. if (print)
  3500. _print_next_block(par_num++, "CFC");
  3501. break;
  3502. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3503. if (print)
  3504. _print_next_block(par_num++, "CDU");
  3505. break;
  3506. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3507. if (print)
  3508. _print_next_block(par_num++, "DMAE");
  3509. break;
  3510. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3511. if (print)
  3512. _print_next_block(par_num++, "IGU");
  3513. break;
  3514. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3515. if (print)
  3516. _print_next_block(par_num++, "MISC");
  3517. break;
  3518. }
  3519. /* Clear the bit */
  3520. sig &= ~cur_bit;
  3521. }
  3522. }
  3523. return par_num;
  3524. }
  3525. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3526. bool *global, bool print)
  3527. {
  3528. int i = 0;
  3529. u32 cur_bit = 0;
  3530. for (i = 0; sig; i++) {
  3531. cur_bit = ((u32)0x1 << i);
  3532. if (sig & cur_bit) {
  3533. switch (cur_bit) {
  3534. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3535. if (print)
  3536. _print_next_block(par_num++, "MCP ROM");
  3537. *global = true;
  3538. break;
  3539. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3540. if (print)
  3541. _print_next_block(par_num++,
  3542. "MCP UMP RX");
  3543. *global = true;
  3544. break;
  3545. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3546. if (print)
  3547. _print_next_block(par_num++,
  3548. "MCP UMP TX");
  3549. *global = true;
  3550. break;
  3551. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3552. if (print)
  3553. _print_next_block(par_num++,
  3554. "MCP SCPAD");
  3555. *global = true;
  3556. break;
  3557. }
  3558. /* Clear the bit */
  3559. sig &= ~cur_bit;
  3560. }
  3561. }
  3562. return par_num;
  3563. }
  3564. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3565. bool print)
  3566. {
  3567. int i = 0;
  3568. u32 cur_bit = 0;
  3569. for (i = 0; sig; i++) {
  3570. cur_bit = ((u32)0x1 << i);
  3571. if (sig & cur_bit) {
  3572. switch (cur_bit) {
  3573. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3574. if (print)
  3575. _print_next_block(par_num++, "PGLUE_B");
  3576. break;
  3577. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3578. if (print)
  3579. _print_next_block(par_num++, "ATC");
  3580. break;
  3581. }
  3582. /* Clear the bit */
  3583. sig &= ~cur_bit;
  3584. }
  3585. }
  3586. return par_num;
  3587. }
  3588. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3589. u32 *sig)
  3590. {
  3591. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3592. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3593. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3594. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3595. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3596. int par_num = 0;
  3597. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3598. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3599. sig[0] & HW_PRTY_ASSERT_SET_0,
  3600. sig[1] & HW_PRTY_ASSERT_SET_1,
  3601. sig[2] & HW_PRTY_ASSERT_SET_2,
  3602. sig[3] & HW_PRTY_ASSERT_SET_3,
  3603. sig[4] & HW_PRTY_ASSERT_SET_4);
  3604. if (print)
  3605. netdev_err(bp->dev,
  3606. "Parity errors detected in blocks: ");
  3607. par_num = bnx2x_check_blocks_with_parity0(
  3608. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3609. par_num = bnx2x_check_blocks_with_parity1(
  3610. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3611. par_num = bnx2x_check_blocks_with_parity2(
  3612. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3613. par_num = bnx2x_check_blocks_with_parity3(
  3614. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3615. par_num = bnx2x_check_blocks_with_parity4(
  3616. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3617. if (print)
  3618. pr_cont("\n");
  3619. return true;
  3620. } else
  3621. return false;
  3622. }
  3623. /**
  3624. * bnx2x_chk_parity_attn - checks for parity attentions.
  3625. *
  3626. * @bp: driver handle
  3627. * @global: true if there was a global attention
  3628. * @print: show parity attention in syslog
  3629. */
  3630. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3631. {
  3632. struct attn_route attn = { {0} };
  3633. int port = BP_PORT(bp);
  3634. attn.sig[0] = REG_RD(bp,
  3635. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3636. port*4);
  3637. attn.sig[1] = REG_RD(bp,
  3638. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3639. port*4);
  3640. attn.sig[2] = REG_RD(bp,
  3641. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3642. port*4);
  3643. attn.sig[3] = REG_RD(bp,
  3644. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3645. port*4);
  3646. if (!CHIP_IS_E1x(bp))
  3647. attn.sig[4] = REG_RD(bp,
  3648. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3649. port*4);
  3650. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3651. }
  3652. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3653. {
  3654. u32 val;
  3655. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3656. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3657. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3658. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3659. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3660. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3661. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3662. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3663. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3664. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3665. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3666. if (val &
  3667. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3668. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3669. if (val &
  3670. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3671. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3672. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3673. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3674. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3675. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3676. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3677. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3678. }
  3679. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3680. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3681. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3682. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3683. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3684. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3685. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3686. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3687. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3688. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3689. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3690. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3691. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3692. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3693. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3694. }
  3695. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3696. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3697. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3698. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3699. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3700. }
  3701. }
  3702. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3703. {
  3704. struct attn_route attn, *group_mask;
  3705. int port = BP_PORT(bp);
  3706. int index;
  3707. u32 reg_addr;
  3708. u32 val;
  3709. u32 aeu_mask;
  3710. bool global = false;
  3711. /* need to take HW lock because MCP or other port might also
  3712. try to handle this event */
  3713. bnx2x_acquire_alr(bp);
  3714. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3715. #ifndef BNX2X_STOP_ON_ERROR
  3716. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3717. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3718. /* Disable HW interrupts */
  3719. bnx2x_int_disable(bp);
  3720. /* In case of parity errors don't handle attentions so that
  3721. * other function would "see" parity errors.
  3722. */
  3723. #else
  3724. bnx2x_panic();
  3725. #endif
  3726. bnx2x_release_alr(bp);
  3727. return;
  3728. }
  3729. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3730. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3731. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3732. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3733. if (!CHIP_IS_E1x(bp))
  3734. attn.sig[4] =
  3735. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3736. else
  3737. attn.sig[4] = 0;
  3738. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3739. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3740. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3741. if (deasserted & (1 << index)) {
  3742. group_mask = &bp->attn_group[index];
  3743. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3744. index,
  3745. group_mask->sig[0], group_mask->sig[1],
  3746. group_mask->sig[2], group_mask->sig[3],
  3747. group_mask->sig[4]);
  3748. bnx2x_attn_int_deasserted4(bp,
  3749. attn.sig[4] & group_mask->sig[4]);
  3750. bnx2x_attn_int_deasserted3(bp,
  3751. attn.sig[3] & group_mask->sig[3]);
  3752. bnx2x_attn_int_deasserted1(bp,
  3753. attn.sig[1] & group_mask->sig[1]);
  3754. bnx2x_attn_int_deasserted2(bp,
  3755. attn.sig[2] & group_mask->sig[2]);
  3756. bnx2x_attn_int_deasserted0(bp,
  3757. attn.sig[0] & group_mask->sig[0]);
  3758. }
  3759. }
  3760. bnx2x_release_alr(bp);
  3761. if (bp->common.int_block == INT_BLOCK_HC)
  3762. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3763. COMMAND_REG_ATTN_BITS_CLR);
  3764. else
  3765. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3766. val = ~deasserted;
  3767. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3768. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3769. REG_WR(bp, reg_addr, val);
  3770. if (~bp->attn_state & deasserted)
  3771. BNX2X_ERR("IGU ERROR\n");
  3772. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3773. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3774. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3775. aeu_mask = REG_RD(bp, reg_addr);
  3776. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3777. aeu_mask, deasserted);
  3778. aeu_mask |= (deasserted & 0x3ff);
  3779. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3780. REG_WR(bp, reg_addr, aeu_mask);
  3781. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3782. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3783. bp->attn_state &= ~deasserted;
  3784. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3785. }
  3786. static void bnx2x_attn_int(struct bnx2x *bp)
  3787. {
  3788. /* read local copy of bits */
  3789. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3790. attn_bits);
  3791. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3792. attn_bits_ack);
  3793. u32 attn_state = bp->attn_state;
  3794. /* look for changed bits */
  3795. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3796. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3797. DP(NETIF_MSG_HW,
  3798. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3799. attn_bits, attn_ack, asserted, deasserted);
  3800. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3801. BNX2X_ERR("BAD attention state\n");
  3802. /* handle bits that were raised */
  3803. if (asserted)
  3804. bnx2x_attn_int_asserted(bp, asserted);
  3805. if (deasserted)
  3806. bnx2x_attn_int_deasserted(bp, deasserted);
  3807. }
  3808. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3809. u16 index, u8 op, u8 update)
  3810. {
  3811. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3812. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3813. igu_addr);
  3814. }
  3815. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3816. {
  3817. /* No memory barriers */
  3818. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3819. mmiowb(); /* keep prod updates ordered */
  3820. }
  3821. #ifdef BCM_CNIC
  3822. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3823. union event_ring_elem *elem)
  3824. {
  3825. u8 err = elem->message.error;
  3826. if (!bp->cnic_eth_dev.starting_cid ||
  3827. (cid < bp->cnic_eth_dev.starting_cid &&
  3828. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3829. return 1;
  3830. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3831. if (unlikely(err)) {
  3832. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3833. cid);
  3834. bnx2x_panic_dump(bp);
  3835. }
  3836. bnx2x_cnic_cfc_comp(bp, cid, err);
  3837. return 0;
  3838. }
  3839. #endif
  3840. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3841. {
  3842. struct bnx2x_mcast_ramrod_params rparam;
  3843. int rc;
  3844. memset(&rparam, 0, sizeof(rparam));
  3845. rparam.mcast_obj = &bp->mcast_obj;
  3846. netif_addr_lock_bh(bp->dev);
  3847. /* Clear pending state for the last command */
  3848. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3849. /* If there are pending mcast commands - send them */
  3850. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3851. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3852. if (rc < 0)
  3853. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3854. rc);
  3855. }
  3856. netif_addr_unlock_bh(bp->dev);
  3857. }
  3858. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3859. union event_ring_elem *elem)
  3860. {
  3861. unsigned long ramrod_flags = 0;
  3862. int rc = 0;
  3863. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3864. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3865. /* Always push next commands out, don't wait here */
  3866. __set_bit(RAMROD_CONT, &ramrod_flags);
  3867. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3868. case BNX2X_FILTER_MAC_PENDING:
  3869. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3870. #ifdef BCM_CNIC
  3871. if (cid == BNX2X_ISCSI_ETH_CID)
  3872. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3873. else
  3874. #endif
  3875. vlan_mac_obj = &bp->fp[cid].mac_obj;
  3876. break;
  3877. case BNX2X_FILTER_MCAST_PENDING:
  3878. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3879. /* This is only relevant for 57710 where multicast MACs are
  3880. * configured as unicast MACs using the same ramrod.
  3881. */
  3882. bnx2x_handle_mcast_eqe(bp);
  3883. return;
  3884. default:
  3885. BNX2X_ERR("Unsupported classification command: %d\n",
  3886. elem->message.data.eth_event.echo);
  3887. return;
  3888. }
  3889. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3890. if (rc < 0)
  3891. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3892. else if (rc > 0)
  3893. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3894. }
  3895. #ifdef BCM_CNIC
  3896. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3897. #endif
  3898. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3899. {
  3900. netif_addr_lock_bh(bp->dev);
  3901. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3902. /* Send rx_mode command again if was requested */
  3903. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3904. bnx2x_set_storm_rx_mode(bp);
  3905. #ifdef BCM_CNIC
  3906. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3907. &bp->sp_state))
  3908. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3909. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3910. &bp->sp_state))
  3911. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3912. #endif
  3913. netif_addr_unlock_bh(bp->dev);
  3914. }
  3915. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  3916. union event_ring_elem *elem)
  3917. {
  3918. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  3919. DP(BNX2X_MSG_SP,
  3920. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  3921. elem->message.data.vif_list_event.func_bit_map);
  3922. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  3923. elem->message.data.vif_list_event.func_bit_map);
  3924. } else if (elem->message.data.vif_list_event.echo ==
  3925. VIF_LIST_RULE_SET) {
  3926. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  3927. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  3928. }
  3929. }
  3930. /* called with rtnl_lock */
  3931. static void bnx2x_after_function_update(struct bnx2x *bp)
  3932. {
  3933. int q, rc;
  3934. struct bnx2x_fastpath *fp;
  3935. struct bnx2x_queue_state_params queue_params = {NULL};
  3936. struct bnx2x_queue_update_params *q_update_params =
  3937. &queue_params.params.update;
  3938. /* Send Q update command with afex vlan removal values for all Qs */
  3939. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  3940. /* set silent vlan removal values according to vlan mode */
  3941. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3942. &q_update_params->update_flags);
  3943. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  3944. &q_update_params->update_flags);
  3945. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3946. /* in access mode mark mask and value are 0 to strip all vlans */
  3947. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  3948. q_update_params->silent_removal_value = 0;
  3949. q_update_params->silent_removal_mask = 0;
  3950. } else {
  3951. q_update_params->silent_removal_value =
  3952. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  3953. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  3954. }
  3955. for_each_eth_queue(bp, q) {
  3956. /* Set the appropriate Queue object */
  3957. fp = &bp->fp[q];
  3958. queue_params.q_obj = &fp->q_obj;
  3959. /* send the ramrod */
  3960. rc = bnx2x_queue_state_change(bp, &queue_params);
  3961. if (rc < 0)
  3962. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3963. q);
  3964. }
  3965. #ifdef BCM_CNIC
  3966. if (!NO_FCOE(bp)) {
  3967. fp = &bp->fp[FCOE_IDX];
  3968. queue_params.q_obj = &fp->q_obj;
  3969. /* clear pending completion bit */
  3970. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3971. /* mark latest Q bit */
  3972. smp_mb__before_clear_bit();
  3973. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  3974. smp_mb__after_clear_bit();
  3975. /* send Q update ramrod for FCoE Q */
  3976. rc = bnx2x_queue_state_change(bp, &queue_params);
  3977. if (rc < 0)
  3978. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3979. q);
  3980. } else {
  3981. /* If no FCoE ring - ACK MCP now */
  3982. bnx2x_link_report(bp);
  3983. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  3984. }
  3985. #else
  3986. /* If no FCoE ring - ACK MCP now */
  3987. bnx2x_link_report(bp);
  3988. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  3989. #endif /* BCM_CNIC */
  3990. }
  3991. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  3992. struct bnx2x *bp, u32 cid)
  3993. {
  3994. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  3995. #ifdef BCM_CNIC
  3996. if (cid == BNX2X_FCOE_ETH_CID)
  3997. return &bnx2x_fcoe(bp, q_obj);
  3998. else
  3999. #endif
  4000. return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
  4001. }
  4002. static void bnx2x_eq_int(struct bnx2x *bp)
  4003. {
  4004. u16 hw_cons, sw_cons, sw_prod;
  4005. union event_ring_elem *elem;
  4006. u32 cid;
  4007. u8 opcode;
  4008. int spqe_cnt = 0;
  4009. struct bnx2x_queue_sp_obj *q_obj;
  4010. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4011. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4012. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4013. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4014. * when we get the the next-page we nned to adjust so the loop
  4015. * condition below will be met. The next element is the size of a
  4016. * regular element and hence incrementing by 1
  4017. */
  4018. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4019. hw_cons++;
  4020. /* This function may never run in parallel with itself for a
  4021. * specific bp, thus there is no need in "paired" read memory
  4022. * barrier here.
  4023. */
  4024. sw_cons = bp->eq_cons;
  4025. sw_prod = bp->eq_prod;
  4026. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4027. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4028. for (; sw_cons != hw_cons;
  4029. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4030. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4031. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4032. opcode = elem->message.opcode;
  4033. /* handle eq element */
  4034. switch (opcode) {
  4035. case EVENT_RING_OPCODE_STAT_QUERY:
  4036. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4037. "got statistics comp event %d\n",
  4038. bp->stats_comp++);
  4039. /* nothing to do with stats comp */
  4040. goto next_spqe;
  4041. case EVENT_RING_OPCODE_CFC_DEL:
  4042. /* handle according to cid range */
  4043. /*
  4044. * we may want to verify here that the bp state is
  4045. * HALTING
  4046. */
  4047. DP(BNX2X_MSG_SP,
  4048. "got delete ramrod for MULTI[%d]\n", cid);
  4049. #ifdef BCM_CNIC
  4050. if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4051. goto next_spqe;
  4052. #endif
  4053. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4054. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4055. break;
  4056. goto next_spqe;
  4057. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4058. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4059. if (f_obj->complete_cmd(bp, f_obj,
  4060. BNX2X_F_CMD_TX_STOP))
  4061. break;
  4062. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4063. goto next_spqe;
  4064. case EVENT_RING_OPCODE_START_TRAFFIC:
  4065. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4066. if (f_obj->complete_cmd(bp, f_obj,
  4067. BNX2X_F_CMD_TX_START))
  4068. break;
  4069. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4070. goto next_spqe;
  4071. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4072. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4073. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4074. f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_AFEX_UPDATE);
  4075. /* We will perform the Queues update from sp_rtnl task
  4076. * as all Queue SP operations should run under
  4077. * rtnl_lock.
  4078. */
  4079. smp_mb__before_clear_bit();
  4080. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4081. &bp->sp_rtnl_state);
  4082. smp_mb__after_clear_bit();
  4083. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4084. goto next_spqe;
  4085. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4086. f_obj->complete_cmd(bp, f_obj,
  4087. BNX2X_F_CMD_AFEX_VIFLISTS);
  4088. bnx2x_after_afex_vif_lists(bp, elem);
  4089. goto next_spqe;
  4090. case EVENT_RING_OPCODE_FUNCTION_START:
  4091. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4092. "got FUNC_START ramrod\n");
  4093. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4094. break;
  4095. goto next_spqe;
  4096. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4097. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4098. "got FUNC_STOP ramrod\n");
  4099. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4100. break;
  4101. goto next_spqe;
  4102. }
  4103. switch (opcode | bp->state) {
  4104. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4105. BNX2X_STATE_OPEN):
  4106. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4107. BNX2X_STATE_OPENING_WAIT4_PORT):
  4108. cid = elem->message.data.eth_event.echo &
  4109. BNX2X_SWCID_MASK;
  4110. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4111. cid);
  4112. rss_raw->clear_pending(rss_raw);
  4113. break;
  4114. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4115. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4116. case (EVENT_RING_OPCODE_SET_MAC |
  4117. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4118. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4119. BNX2X_STATE_OPEN):
  4120. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4121. BNX2X_STATE_DIAG):
  4122. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4123. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4124. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4125. bnx2x_handle_classification_eqe(bp, elem);
  4126. break;
  4127. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4128. BNX2X_STATE_OPEN):
  4129. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4130. BNX2X_STATE_DIAG):
  4131. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4132. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4133. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4134. bnx2x_handle_mcast_eqe(bp);
  4135. break;
  4136. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4137. BNX2X_STATE_OPEN):
  4138. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4139. BNX2X_STATE_DIAG):
  4140. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4141. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4142. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4143. bnx2x_handle_rx_mode_eqe(bp);
  4144. break;
  4145. default:
  4146. /* unknown event log error and continue */
  4147. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4148. elem->message.opcode, bp->state);
  4149. }
  4150. next_spqe:
  4151. spqe_cnt++;
  4152. } /* for */
  4153. smp_mb__before_atomic_inc();
  4154. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4155. bp->eq_cons = sw_cons;
  4156. bp->eq_prod = sw_prod;
  4157. /* Make sure that above mem writes were issued towards the memory */
  4158. smp_wmb();
  4159. /* update producer */
  4160. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4161. }
  4162. static void bnx2x_sp_task(struct work_struct *work)
  4163. {
  4164. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4165. u16 status;
  4166. status = bnx2x_update_dsb_idx(bp);
  4167. /* if (status == 0) */
  4168. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  4169. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  4170. /* HW attentions */
  4171. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4172. bnx2x_attn_int(bp);
  4173. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4174. }
  4175. /* SP events: STAT_QUERY and others */
  4176. if (status & BNX2X_DEF_SB_IDX) {
  4177. #ifdef BCM_CNIC
  4178. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4179. if ((!NO_FCOE(bp)) &&
  4180. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4181. /*
  4182. * Prevent local bottom-halves from running as
  4183. * we are going to change the local NAPI list.
  4184. */
  4185. local_bh_disable();
  4186. napi_schedule(&bnx2x_fcoe(bp, napi));
  4187. local_bh_enable();
  4188. }
  4189. #endif
  4190. /* Handle EQ completions */
  4191. bnx2x_eq_int(bp);
  4192. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4193. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4194. status &= ~BNX2X_DEF_SB_IDX;
  4195. }
  4196. if (unlikely(status))
  4197. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  4198. status);
  4199. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4200. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4201. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4202. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4203. &bp->sp_state)) {
  4204. bnx2x_link_report(bp);
  4205. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4206. }
  4207. }
  4208. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4209. {
  4210. struct net_device *dev = dev_instance;
  4211. struct bnx2x *bp = netdev_priv(dev);
  4212. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4213. IGU_INT_DISABLE, 0);
  4214. #ifdef BNX2X_STOP_ON_ERROR
  4215. if (unlikely(bp->panic))
  4216. return IRQ_HANDLED;
  4217. #endif
  4218. #ifdef BCM_CNIC
  4219. {
  4220. struct cnic_ops *c_ops;
  4221. rcu_read_lock();
  4222. c_ops = rcu_dereference(bp->cnic_ops);
  4223. if (c_ops)
  4224. c_ops->cnic_handler(bp->cnic_data, NULL);
  4225. rcu_read_unlock();
  4226. }
  4227. #endif
  4228. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  4229. return IRQ_HANDLED;
  4230. }
  4231. /* end of slow path */
  4232. void bnx2x_drv_pulse(struct bnx2x *bp)
  4233. {
  4234. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4235. bp->fw_drv_pulse_wr_seq);
  4236. }
  4237. static void bnx2x_timer(unsigned long data)
  4238. {
  4239. struct bnx2x *bp = (struct bnx2x *) data;
  4240. if (!netif_running(bp->dev))
  4241. return;
  4242. if (!BP_NOMCP(bp)) {
  4243. int mb_idx = BP_FW_MB_IDX(bp);
  4244. u32 drv_pulse;
  4245. u32 mcp_pulse;
  4246. ++bp->fw_drv_pulse_wr_seq;
  4247. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4248. /* TBD - add SYSTEM_TIME */
  4249. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4250. bnx2x_drv_pulse(bp);
  4251. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4252. MCP_PULSE_SEQ_MASK);
  4253. /* The delta between driver pulse and mcp response
  4254. * should be 1 (before mcp response) or 0 (after mcp response)
  4255. */
  4256. if ((drv_pulse != mcp_pulse) &&
  4257. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4258. /* someone lost a heartbeat... */
  4259. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4260. drv_pulse, mcp_pulse);
  4261. }
  4262. }
  4263. if (bp->state == BNX2X_STATE_OPEN)
  4264. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4265. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4266. }
  4267. /* end of Statistics */
  4268. /* nic init */
  4269. /*
  4270. * nic init service functions
  4271. */
  4272. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4273. {
  4274. u32 i;
  4275. if (!(len%4) && !(addr%4))
  4276. for (i = 0; i < len; i += 4)
  4277. REG_WR(bp, addr + i, fill);
  4278. else
  4279. for (i = 0; i < len; i++)
  4280. REG_WR8(bp, addr + i, fill);
  4281. }
  4282. /* helper: writes FP SP data to FW - data_size in dwords */
  4283. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4284. int fw_sb_id,
  4285. u32 *sb_data_p,
  4286. u32 data_size)
  4287. {
  4288. int index;
  4289. for (index = 0; index < data_size; index++)
  4290. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4291. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4292. sizeof(u32)*index,
  4293. *(sb_data_p + index));
  4294. }
  4295. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4296. {
  4297. u32 *sb_data_p;
  4298. u32 data_size = 0;
  4299. struct hc_status_block_data_e2 sb_data_e2;
  4300. struct hc_status_block_data_e1x sb_data_e1x;
  4301. /* disable the function first */
  4302. if (!CHIP_IS_E1x(bp)) {
  4303. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4304. sb_data_e2.common.state = SB_DISABLED;
  4305. sb_data_e2.common.p_func.vf_valid = false;
  4306. sb_data_p = (u32 *)&sb_data_e2;
  4307. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4308. } else {
  4309. memset(&sb_data_e1x, 0,
  4310. sizeof(struct hc_status_block_data_e1x));
  4311. sb_data_e1x.common.state = SB_DISABLED;
  4312. sb_data_e1x.common.p_func.vf_valid = false;
  4313. sb_data_p = (u32 *)&sb_data_e1x;
  4314. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4315. }
  4316. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4317. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4318. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4319. CSTORM_STATUS_BLOCK_SIZE);
  4320. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4321. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4322. CSTORM_SYNC_BLOCK_SIZE);
  4323. }
  4324. /* helper: writes SP SB data to FW */
  4325. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4326. struct hc_sp_status_block_data *sp_sb_data)
  4327. {
  4328. int func = BP_FUNC(bp);
  4329. int i;
  4330. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4331. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4332. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4333. i*sizeof(u32),
  4334. *((u32 *)sp_sb_data + i));
  4335. }
  4336. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4337. {
  4338. int func = BP_FUNC(bp);
  4339. struct hc_sp_status_block_data sp_sb_data;
  4340. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4341. sp_sb_data.state = SB_DISABLED;
  4342. sp_sb_data.p_func.vf_valid = false;
  4343. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4344. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4345. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4346. CSTORM_SP_STATUS_BLOCK_SIZE);
  4347. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4348. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4349. CSTORM_SP_SYNC_BLOCK_SIZE);
  4350. }
  4351. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4352. int igu_sb_id, int igu_seg_id)
  4353. {
  4354. hc_sm->igu_sb_id = igu_sb_id;
  4355. hc_sm->igu_seg_id = igu_seg_id;
  4356. hc_sm->timer_value = 0xFF;
  4357. hc_sm->time_to_expire = 0xFFFFFFFF;
  4358. }
  4359. /* allocates state machine ids. */
  4360. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4361. {
  4362. /* zero out state machine indices */
  4363. /* rx indices */
  4364. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4365. /* tx indices */
  4366. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4367. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4368. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4369. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4370. /* map indices */
  4371. /* rx indices */
  4372. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4373. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4374. /* tx indices */
  4375. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4376. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4377. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4378. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4379. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4380. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4381. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4382. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4383. }
  4384. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4385. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4386. {
  4387. int igu_seg_id;
  4388. struct hc_status_block_data_e2 sb_data_e2;
  4389. struct hc_status_block_data_e1x sb_data_e1x;
  4390. struct hc_status_block_sm *hc_sm_p;
  4391. int data_size;
  4392. u32 *sb_data_p;
  4393. if (CHIP_INT_MODE_IS_BC(bp))
  4394. igu_seg_id = HC_SEG_ACCESS_NORM;
  4395. else
  4396. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4397. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4398. if (!CHIP_IS_E1x(bp)) {
  4399. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4400. sb_data_e2.common.state = SB_ENABLED;
  4401. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4402. sb_data_e2.common.p_func.vf_id = vfid;
  4403. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4404. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4405. sb_data_e2.common.same_igu_sb_1b = true;
  4406. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4407. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4408. hc_sm_p = sb_data_e2.common.state_machine;
  4409. sb_data_p = (u32 *)&sb_data_e2;
  4410. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4411. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4412. } else {
  4413. memset(&sb_data_e1x, 0,
  4414. sizeof(struct hc_status_block_data_e1x));
  4415. sb_data_e1x.common.state = SB_ENABLED;
  4416. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4417. sb_data_e1x.common.p_func.vf_id = 0xff;
  4418. sb_data_e1x.common.p_func.vf_valid = false;
  4419. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4420. sb_data_e1x.common.same_igu_sb_1b = true;
  4421. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4422. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4423. hc_sm_p = sb_data_e1x.common.state_machine;
  4424. sb_data_p = (u32 *)&sb_data_e1x;
  4425. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4426. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4427. }
  4428. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4429. igu_sb_id, igu_seg_id);
  4430. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4431. igu_sb_id, igu_seg_id);
  4432. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4433. /* write indecies to HW */
  4434. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4435. }
  4436. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4437. u16 tx_usec, u16 rx_usec)
  4438. {
  4439. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4440. false, rx_usec);
  4441. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4442. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4443. tx_usec);
  4444. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4445. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4446. tx_usec);
  4447. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4448. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4449. tx_usec);
  4450. }
  4451. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4452. {
  4453. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4454. dma_addr_t mapping = bp->def_status_blk_mapping;
  4455. int igu_sp_sb_index;
  4456. int igu_seg_id;
  4457. int port = BP_PORT(bp);
  4458. int func = BP_FUNC(bp);
  4459. int reg_offset, reg_offset_en5;
  4460. u64 section;
  4461. int index;
  4462. struct hc_sp_status_block_data sp_sb_data;
  4463. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4464. if (CHIP_INT_MODE_IS_BC(bp)) {
  4465. igu_sp_sb_index = DEF_SB_IGU_ID;
  4466. igu_seg_id = HC_SEG_ACCESS_DEF;
  4467. } else {
  4468. igu_sp_sb_index = bp->igu_dsb_id;
  4469. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4470. }
  4471. /* ATTN */
  4472. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4473. atten_status_block);
  4474. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4475. bp->attn_state = 0;
  4476. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4477. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4478. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4479. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4480. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4481. int sindex;
  4482. /* take care of sig[0]..sig[4] */
  4483. for (sindex = 0; sindex < 4; sindex++)
  4484. bp->attn_group[index].sig[sindex] =
  4485. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4486. if (!CHIP_IS_E1x(bp))
  4487. /*
  4488. * enable5 is separate from the rest of the registers,
  4489. * and therefore the address skip is 4
  4490. * and not 16 between the different groups
  4491. */
  4492. bp->attn_group[index].sig[4] = REG_RD(bp,
  4493. reg_offset_en5 + 0x4*index);
  4494. else
  4495. bp->attn_group[index].sig[4] = 0;
  4496. }
  4497. if (bp->common.int_block == INT_BLOCK_HC) {
  4498. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4499. HC_REG_ATTN_MSG0_ADDR_L);
  4500. REG_WR(bp, reg_offset, U64_LO(section));
  4501. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4502. } else if (!CHIP_IS_E1x(bp)) {
  4503. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4504. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4505. }
  4506. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4507. sp_sb);
  4508. bnx2x_zero_sp_sb(bp);
  4509. sp_sb_data.state = SB_ENABLED;
  4510. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4511. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4512. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4513. sp_sb_data.igu_seg_id = igu_seg_id;
  4514. sp_sb_data.p_func.pf_id = func;
  4515. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4516. sp_sb_data.p_func.vf_id = 0xff;
  4517. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4518. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4519. }
  4520. void bnx2x_update_coalesce(struct bnx2x *bp)
  4521. {
  4522. int i;
  4523. for_each_eth_queue(bp, i)
  4524. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4525. bp->tx_ticks, bp->rx_ticks);
  4526. }
  4527. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4528. {
  4529. spin_lock_init(&bp->spq_lock);
  4530. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4531. bp->spq_prod_idx = 0;
  4532. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4533. bp->spq_prod_bd = bp->spq;
  4534. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4535. }
  4536. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4537. {
  4538. int i;
  4539. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4540. union event_ring_elem *elem =
  4541. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4542. elem->next_page.addr.hi =
  4543. cpu_to_le32(U64_HI(bp->eq_mapping +
  4544. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4545. elem->next_page.addr.lo =
  4546. cpu_to_le32(U64_LO(bp->eq_mapping +
  4547. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4548. }
  4549. bp->eq_cons = 0;
  4550. bp->eq_prod = NUM_EQ_DESC;
  4551. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4552. /* we want a warning message before it gets rought... */
  4553. atomic_set(&bp->eq_spq_left,
  4554. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4555. }
  4556. /* called with netif_addr_lock_bh() */
  4557. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4558. unsigned long rx_mode_flags,
  4559. unsigned long rx_accept_flags,
  4560. unsigned long tx_accept_flags,
  4561. unsigned long ramrod_flags)
  4562. {
  4563. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4564. int rc;
  4565. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4566. /* Prepare ramrod parameters */
  4567. ramrod_param.cid = 0;
  4568. ramrod_param.cl_id = cl_id;
  4569. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4570. ramrod_param.func_id = BP_FUNC(bp);
  4571. ramrod_param.pstate = &bp->sp_state;
  4572. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4573. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4574. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4575. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4576. ramrod_param.ramrod_flags = ramrod_flags;
  4577. ramrod_param.rx_mode_flags = rx_mode_flags;
  4578. ramrod_param.rx_accept_flags = rx_accept_flags;
  4579. ramrod_param.tx_accept_flags = tx_accept_flags;
  4580. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4581. if (rc < 0) {
  4582. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4583. return;
  4584. }
  4585. }
  4586. /* called with netif_addr_lock_bh() */
  4587. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4588. {
  4589. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4590. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4591. #ifdef BCM_CNIC
  4592. if (!NO_FCOE(bp))
  4593. /* Configure rx_mode of FCoE Queue */
  4594. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4595. #endif
  4596. switch (bp->rx_mode) {
  4597. case BNX2X_RX_MODE_NONE:
  4598. /*
  4599. * 'drop all' supersedes any accept flags that may have been
  4600. * passed to the function.
  4601. */
  4602. break;
  4603. case BNX2X_RX_MODE_NORMAL:
  4604. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4605. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4606. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4607. /* internal switching mode */
  4608. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4609. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4610. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4611. break;
  4612. case BNX2X_RX_MODE_ALLMULTI:
  4613. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4614. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4615. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4616. /* internal switching mode */
  4617. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4618. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4619. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4620. break;
  4621. case BNX2X_RX_MODE_PROMISC:
  4622. /* According to deffinition of SI mode, iface in promisc mode
  4623. * should receive matched and unmatched (in resolution of port)
  4624. * unicast packets.
  4625. */
  4626. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4627. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4628. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4629. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4630. /* internal switching mode */
  4631. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4632. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4633. if (IS_MF_SI(bp))
  4634. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4635. else
  4636. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4637. break;
  4638. default:
  4639. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4640. return;
  4641. }
  4642. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4643. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4644. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4645. }
  4646. __set_bit(RAMROD_RX, &ramrod_flags);
  4647. __set_bit(RAMROD_TX, &ramrod_flags);
  4648. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4649. tx_accept_flags, ramrod_flags);
  4650. }
  4651. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4652. {
  4653. int i;
  4654. if (IS_MF_SI(bp))
  4655. /*
  4656. * In switch independent mode, the TSTORM needs to accept
  4657. * packets that failed classification, since approximate match
  4658. * mac addresses aren't written to NIG LLH
  4659. */
  4660. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4661. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4662. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4663. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4664. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4665. /* Zero this manually as its initialization is
  4666. currently missing in the initTool */
  4667. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4668. REG_WR(bp, BAR_USTRORM_INTMEM +
  4669. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4670. if (!CHIP_IS_E1x(bp)) {
  4671. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4672. CHIP_INT_MODE_IS_BC(bp) ?
  4673. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4674. }
  4675. }
  4676. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4677. {
  4678. switch (load_code) {
  4679. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4680. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4681. bnx2x_init_internal_common(bp);
  4682. /* no break */
  4683. case FW_MSG_CODE_DRV_LOAD_PORT:
  4684. /* nothing to do */
  4685. /* no break */
  4686. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4687. /* internal memory per function is
  4688. initialized inside bnx2x_pf_init */
  4689. break;
  4690. default:
  4691. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4692. break;
  4693. }
  4694. }
  4695. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4696. {
  4697. return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
  4698. }
  4699. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4700. {
  4701. return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
  4702. }
  4703. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4704. {
  4705. if (CHIP_IS_E1x(fp->bp))
  4706. return BP_L_ID(fp->bp) + fp->index;
  4707. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4708. return bnx2x_fp_igu_sb_id(fp);
  4709. }
  4710. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4711. {
  4712. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4713. u8 cos;
  4714. unsigned long q_type = 0;
  4715. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4716. fp->rx_queue = fp_idx;
  4717. fp->cid = fp_idx;
  4718. fp->cl_id = bnx2x_fp_cl_id(fp);
  4719. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4720. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4721. /* qZone id equals to FW (per path) client id */
  4722. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4723. /* init shortcut */
  4724. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4725. /* Setup SB indicies */
  4726. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4727. /* Configure Queue State object */
  4728. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4729. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4730. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4731. /* init tx data */
  4732. for_each_cos_in_tx_queue(fp, cos) {
  4733. bnx2x_init_txdata(bp, &fp->txdata[cos],
  4734. CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
  4735. FP_COS_TO_TXQ(fp, cos),
  4736. BNX2X_TX_SB_INDEX_BASE + cos);
  4737. cids[cos] = fp->txdata[cos].cid;
  4738. }
  4739. bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
  4740. BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4741. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4742. /**
  4743. * Configure classification DBs: Always enable Tx switching
  4744. */
  4745. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4746. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4747. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4748. fp->igu_sb_id);
  4749. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4750. fp->fw_sb_id, fp->igu_sb_id);
  4751. bnx2x_update_fpsb_idx(fp);
  4752. }
  4753. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4754. {
  4755. int i;
  4756. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4757. struct eth_tx_next_bd *tx_next_bd =
  4758. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4759. tx_next_bd->addr_hi =
  4760. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4761. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4762. tx_next_bd->addr_lo =
  4763. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4764. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4765. }
  4766. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4767. txdata->tx_db.data.zero_fill1 = 0;
  4768. txdata->tx_db.data.prod = 0;
  4769. txdata->tx_pkt_prod = 0;
  4770. txdata->tx_pkt_cons = 0;
  4771. txdata->tx_bd_prod = 0;
  4772. txdata->tx_bd_cons = 0;
  4773. txdata->tx_pkt = 0;
  4774. }
  4775. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4776. {
  4777. int i;
  4778. u8 cos;
  4779. for_each_tx_queue(bp, i)
  4780. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4781. bnx2x_init_tx_ring_one(&bp->fp[i].txdata[cos]);
  4782. }
  4783. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4784. {
  4785. int i;
  4786. for_each_eth_queue(bp, i)
  4787. bnx2x_init_eth_fp(bp, i);
  4788. #ifdef BCM_CNIC
  4789. if (!NO_FCOE(bp))
  4790. bnx2x_init_fcoe_fp(bp);
  4791. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4792. BNX2X_VF_ID_INVALID, false,
  4793. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4794. #endif
  4795. /* Initialize MOD_ABS interrupts */
  4796. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4797. bp->common.shmem_base, bp->common.shmem2_base,
  4798. BP_PORT(bp));
  4799. /* ensure status block indices were read */
  4800. rmb();
  4801. bnx2x_init_def_sb(bp);
  4802. bnx2x_update_dsb_idx(bp);
  4803. bnx2x_init_rx_rings(bp);
  4804. bnx2x_init_tx_rings(bp);
  4805. bnx2x_init_sp_ring(bp);
  4806. bnx2x_init_eq_ring(bp);
  4807. bnx2x_init_internal(bp, load_code);
  4808. bnx2x_pf_init(bp);
  4809. bnx2x_stats_init(bp);
  4810. /* flush all before enabling interrupts */
  4811. mb();
  4812. mmiowb();
  4813. bnx2x_int_enable(bp);
  4814. /* Check for SPIO5 */
  4815. bnx2x_attn_int_deasserted0(bp,
  4816. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4817. AEU_INPUTS_ATTN_BITS_SPIO5);
  4818. }
  4819. /* end of nic init */
  4820. /*
  4821. * gzip service functions
  4822. */
  4823. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4824. {
  4825. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4826. &bp->gunzip_mapping, GFP_KERNEL);
  4827. if (bp->gunzip_buf == NULL)
  4828. goto gunzip_nomem1;
  4829. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4830. if (bp->strm == NULL)
  4831. goto gunzip_nomem2;
  4832. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4833. if (bp->strm->workspace == NULL)
  4834. goto gunzip_nomem3;
  4835. return 0;
  4836. gunzip_nomem3:
  4837. kfree(bp->strm);
  4838. bp->strm = NULL;
  4839. gunzip_nomem2:
  4840. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4841. bp->gunzip_mapping);
  4842. bp->gunzip_buf = NULL;
  4843. gunzip_nomem1:
  4844. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4845. return -ENOMEM;
  4846. }
  4847. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4848. {
  4849. if (bp->strm) {
  4850. vfree(bp->strm->workspace);
  4851. kfree(bp->strm);
  4852. bp->strm = NULL;
  4853. }
  4854. if (bp->gunzip_buf) {
  4855. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4856. bp->gunzip_mapping);
  4857. bp->gunzip_buf = NULL;
  4858. }
  4859. }
  4860. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4861. {
  4862. int n, rc;
  4863. /* check gzip header */
  4864. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4865. BNX2X_ERR("Bad gzip header\n");
  4866. return -EINVAL;
  4867. }
  4868. n = 10;
  4869. #define FNAME 0x8
  4870. if (zbuf[3] & FNAME)
  4871. while ((zbuf[n++] != 0) && (n < len));
  4872. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4873. bp->strm->avail_in = len - n;
  4874. bp->strm->next_out = bp->gunzip_buf;
  4875. bp->strm->avail_out = FW_BUF_SIZE;
  4876. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4877. if (rc != Z_OK)
  4878. return rc;
  4879. rc = zlib_inflate(bp->strm, Z_FINISH);
  4880. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4881. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4882. bp->strm->msg);
  4883. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4884. if (bp->gunzip_outlen & 0x3)
  4885. netdev_err(bp->dev,
  4886. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4887. bp->gunzip_outlen);
  4888. bp->gunzip_outlen >>= 2;
  4889. zlib_inflateEnd(bp->strm);
  4890. if (rc == Z_STREAM_END)
  4891. return 0;
  4892. return rc;
  4893. }
  4894. /* nic load/unload */
  4895. /*
  4896. * General service functions
  4897. */
  4898. /* send a NIG loopback debug packet */
  4899. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4900. {
  4901. u32 wb_write[3];
  4902. /* Ethernet source and destination addresses */
  4903. wb_write[0] = 0x55555555;
  4904. wb_write[1] = 0x55555555;
  4905. wb_write[2] = 0x20; /* SOP */
  4906. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4907. /* NON-IP protocol */
  4908. wb_write[0] = 0x09000000;
  4909. wb_write[1] = 0x55555555;
  4910. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4911. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4912. }
  4913. /* some of the internal memories
  4914. * are not directly readable from the driver
  4915. * to test them we send debug packets
  4916. */
  4917. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4918. {
  4919. int factor;
  4920. int count, i;
  4921. u32 val = 0;
  4922. if (CHIP_REV_IS_FPGA(bp))
  4923. factor = 120;
  4924. else if (CHIP_REV_IS_EMUL(bp))
  4925. factor = 200;
  4926. else
  4927. factor = 1;
  4928. /* Disable inputs of parser neighbor blocks */
  4929. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4930. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4931. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4932. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4933. /* Write 0 to parser credits for CFC search request */
  4934. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4935. /* send Ethernet packet */
  4936. bnx2x_lb_pckt(bp);
  4937. /* TODO do i reset NIG statistic? */
  4938. /* Wait until NIG register shows 1 packet of size 0x10 */
  4939. count = 1000 * factor;
  4940. while (count) {
  4941. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4942. val = *bnx2x_sp(bp, wb_data[0]);
  4943. if (val == 0x10)
  4944. break;
  4945. msleep(10);
  4946. count--;
  4947. }
  4948. if (val != 0x10) {
  4949. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4950. return -1;
  4951. }
  4952. /* Wait until PRS register shows 1 packet */
  4953. count = 1000 * factor;
  4954. while (count) {
  4955. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4956. if (val == 1)
  4957. break;
  4958. msleep(10);
  4959. count--;
  4960. }
  4961. if (val != 0x1) {
  4962. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4963. return -2;
  4964. }
  4965. /* Reset and init BRB, PRS */
  4966. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4967. msleep(50);
  4968. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4969. msleep(50);
  4970. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4971. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4972. DP(NETIF_MSG_HW, "part2\n");
  4973. /* Disable inputs of parser neighbor blocks */
  4974. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4975. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4976. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4977. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4978. /* Write 0 to parser credits for CFC search request */
  4979. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4980. /* send 10 Ethernet packets */
  4981. for (i = 0; i < 10; i++)
  4982. bnx2x_lb_pckt(bp);
  4983. /* Wait until NIG register shows 10 + 1
  4984. packets of size 11*0x10 = 0xb0 */
  4985. count = 1000 * factor;
  4986. while (count) {
  4987. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4988. val = *bnx2x_sp(bp, wb_data[0]);
  4989. if (val == 0xb0)
  4990. break;
  4991. msleep(10);
  4992. count--;
  4993. }
  4994. if (val != 0xb0) {
  4995. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4996. return -3;
  4997. }
  4998. /* Wait until PRS register shows 2 packets */
  4999. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5000. if (val != 2)
  5001. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5002. /* Write 1 to parser credits for CFC search request */
  5003. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5004. /* Wait until PRS register shows 3 packets */
  5005. msleep(10 * factor);
  5006. /* Wait until NIG register shows 1 packet of size 0x10 */
  5007. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5008. if (val != 3)
  5009. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5010. /* clear NIG EOP FIFO */
  5011. for (i = 0; i < 11; i++)
  5012. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5013. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5014. if (val != 1) {
  5015. BNX2X_ERR("clear of NIG failed\n");
  5016. return -4;
  5017. }
  5018. /* Reset and init BRB, PRS, NIG */
  5019. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5020. msleep(50);
  5021. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5022. msleep(50);
  5023. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5024. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5025. #ifndef BCM_CNIC
  5026. /* set NIC mode */
  5027. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5028. #endif
  5029. /* Enable inputs of parser neighbor blocks */
  5030. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5031. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5032. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5033. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5034. DP(NETIF_MSG_HW, "done\n");
  5035. return 0; /* OK */
  5036. }
  5037. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5038. {
  5039. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5040. if (!CHIP_IS_E1x(bp))
  5041. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5042. else
  5043. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5044. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5045. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5046. /*
  5047. * mask read length error interrupts in brb for parser
  5048. * (parsing unit and 'checksum and crc' unit)
  5049. * these errors are legal (PU reads fixed length and CAC can cause
  5050. * read length error on truncated packets)
  5051. */
  5052. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5053. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5054. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5055. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5056. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5057. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5058. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5059. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5060. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5061. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5062. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5063. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5064. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5065. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5066. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5067. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5068. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5069. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5070. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5071. if (CHIP_REV_IS_FPGA(bp))
  5072. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  5073. else if (!CHIP_IS_E1x(bp))
  5074. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  5075. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  5076. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  5077. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  5078. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  5079. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  5080. else
  5081. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  5082. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5083. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5084. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5085. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5086. if (!CHIP_IS_E1x(bp))
  5087. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5088. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5089. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5090. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5091. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5092. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5093. }
  5094. static void bnx2x_reset_common(struct bnx2x *bp)
  5095. {
  5096. u32 val = 0x1400;
  5097. /* reset_common */
  5098. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5099. 0xd3ffff7f);
  5100. if (CHIP_IS_E3(bp)) {
  5101. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5102. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5103. }
  5104. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5105. }
  5106. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5107. {
  5108. bp->dmae_ready = 0;
  5109. spin_lock_init(&bp->dmae_lock);
  5110. }
  5111. static void bnx2x_init_pxp(struct bnx2x *bp)
  5112. {
  5113. u16 devctl;
  5114. int r_order, w_order;
  5115. pci_read_config_word(bp->pdev,
  5116. pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
  5117. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5118. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5119. if (bp->mrrs == -1)
  5120. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5121. else {
  5122. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5123. r_order = bp->mrrs;
  5124. }
  5125. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5126. }
  5127. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5128. {
  5129. int is_required;
  5130. u32 val;
  5131. int port;
  5132. if (BP_NOMCP(bp))
  5133. return;
  5134. is_required = 0;
  5135. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5136. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5137. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5138. is_required = 1;
  5139. /*
  5140. * The fan failure mechanism is usually related to the PHY type since
  5141. * the power consumption of the board is affected by the PHY. Currently,
  5142. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5143. */
  5144. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5145. for (port = PORT_0; port < PORT_MAX; port++) {
  5146. is_required |=
  5147. bnx2x_fan_failure_det_req(
  5148. bp,
  5149. bp->common.shmem_base,
  5150. bp->common.shmem2_base,
  5151. port);
  5152. }
  5153. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5154. if (is_required == 0)
  5155. return;
  5156. /* Fan failure is indicated by SPIO 5 */
  5157. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  5158. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  5159. /* set to active low mode */
  5160. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5161. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  5162. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  5163. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5164. /* enable interrupt to signal the IGU */
  5165. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5166. val |= (1 << MISC_REGISTERS_SPIO_5);
  5167. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5168. }
  5169. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  5170. {
  5171. u32 offset = 0;
  5172. if (CHIP_IS_E1(bp))
  5173. return;
  5174. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  5175. return;
  5176. switch (BP_ABS_FUNC(bp)) {
  5177. case 0:
  5178. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  5179. break;
  5180. case 1:
  5181. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  5182. break;
  5183. case 2:
  5184. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  5185. break;
  5186. case 3:
  5187. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  5188. break;
  5189. case 4:
  5190. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  5191. break;
  5192. case 5:
  5193. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  5194. break;
  5195. case 6:
  5196. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  5197. break;
  5198. case 7:
  5199. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  5200. break;
  5201. default:
  5202. return;
  5203. }
  5204. REG_WR(bp, offset, pretend_func_num);
  5205. REG_RD(bp, offset);
  5206. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  5207. }
  5208. void bnx2x_pf_disable(struct bnx2x *bp)
  5209. {
  5210. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5211. val &= ~IGU_PF_CONF_FUNC_EN;
  5212. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5213. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5214. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5215. }
  5216. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5217. {
  5218. u32 shmem_base[2], shmem2_base[2];
  5219. shmem_base[0] = bp->common.shmem_base;
  5220. shmem2_base[0] = bp->common.shmem2_base;
  5221. if (!CHIP_IS_E1x(bp)) {
  5222. shmem_base[1] =
  5223. SHMEM2_RD(bp, other_shmem_base_addr);
  5224. shmem2_base[1] =
  5225. SHMEM2_RD(bp, other_shmem2_base_addr);
  5226. }
  5227. bnx2x_acquire_phy_lock(bp);
  5228. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5229. bp->common.chip_id);
  5230. bnx2x_release_phy_lock(bp);
  5231. }
  5232. /**
  5233. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5234. *
  5235. * @bp: driver handle
  5236. */
  5237. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5238. {
  5239. u32 val;
  5240. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5241. /*
  5242. * take the UNDI lock to protect undi_unload flow from accessing
  5243. * registers while we're resetting the chip
  5244. */
  5245. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5246. bnx2x_reset_common(bp);
  5247. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5248. val = 0xfffc;
  5249. if (CHIP_IS_E3(bp)) {
  5250. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5251. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5252. }
  5253. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5254. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5255. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5256. if (!CHIP_IS_E1x(bp)) {
  5257. u8 abs_func_id;
  5258. /**
  5259. * 4-port mode or 2-port mode we need to turn of master-enable
  5260. * for everyone, after that, turn it back on for self.
  5261. * so, we disregard multi-function or not, and always disable
  5262. * for all functions on the given path, this means 0,2,4,6 for
  5263. * path 0 and 1,3,5,7 for path 1
  5264. */
  5265. for (abs_func_id = BP_PATH(bp);
  5266. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5267. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5268. REG_WR(bp,
  5269. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5270. 1);
  5271. continue;
  5272. }
  5273. bnx2x_pretend_func(bp, abs_func_id);
  5274. /* clear pf enable */
  5275. bnx2x_pf_disable(bp);
  5276. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5277. }
  5278. }
  5279. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5280. if (CHIP_IS_E1(bp)) {
  5281. /* enable HW interrupt from PXP on USDM overflow
  5282. bit 16 on INT_MASK_0 */
  5283. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5284. }
  5285. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5286. bnx2x_init_pxp(bp);
  5287. #ifdef __BIG_ENDIAN
  5288. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5289. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5290. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5291. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5292. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5293. /* make sure this value is 0 */
  5294. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5295. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5296. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5297. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5298. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5299. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5300. #endif
  5301. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5302. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5303. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5304. /* let the HW do it's magic ... */
  5305. msleep(100);
  5306. /* finish PXP init */
  5307. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5308. if (val != 1) {
  5309. BNX2X_ERR("PXP2 CFG failed\n");
  5310. return -EBUSY;
  5311. }
  5312. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5313. if (val != 1) {
  5314. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5315. return -EBUSY;
  5316. }
  5317. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5318. * have entries with value "0" and valid bit on.
  5319. * This needs to be done by the first PF that is loaded in a path
  5320. * (i.e. common phase)
  5321. */
  5322. if (!CHIP_IS_E1x(bp)) {
  5323. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5324. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5325. * This occurs when a different function (func2,3) is being marked
  5326. * as "scan-off". Real-life scenario for example: if a driver is being
  5327. * load-unloaded while func6,7 are down. This will cause the timer to access
  5328. * the ilt, translate to a logical address and send a request to read/write.
  5329. * Since the ilt for the function that is down is not valid, this will cause
  5330. * a translation error which is unrecoverable.
  5331. * The Workaround is intended to make sure that when this happens nothing fatal
  5332. * will occur. The workaround:
  5333. * 1. First PF driver which loads on a path will:
  5334. * a. After taking the chip out of reset, by using pretend,
  5335. * it will write "0" to the following registers of
  5336. * the other vnics.
  5337. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5338. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5339. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5340. * And for itself it will write '1' to
  5341. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5342. * dmae-operations (writing to pram for example.)
  5343. * note: can be done for only function 6,7 but cleaner this
  5344. * way.
  5345. * b. Write zero+valid to the entire ILT.
  5346. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5347. * VNIC3 (of that port). The range allocated will be the
  5348. * entire ILT. This is needed to prevent ILT range error.
  5349. * 2. Any PF driver load flow:
  5350. * a. ILT update with the physical addresses of the allocated
  5351. * logical pages.
  5352. * b. Wait 20msec. - note that this timeout is needed to make
  5353. * sure there are no requests in one of the PXP internal
  5354. * queues with "old" ILT addresses.
  5355. * c. PF enable in the PGLC.
  5356. * d. Clear the was_error of the PF in the PGLC. (could have
  5357. * occured while driver was down)
  5358. * e. PF enable in the CFC (WEAK + STRONG)
  5359. * f. Timers scan enable
  5360. * 3. PF driver unload flow:
  5361. * a. Clear the Timers scan_en.
  5362. * b. Polling for scan_on=0 for that PF.
  5363. * c. Clear the PF enable bit in the PXP.
  5364. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5365. * e. Write zero+valid to all ILT entries (The valid bit must
  5366. * stay set)
  5367. * f. If this is VNIC 3 of a port then also init
  5368. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5369. * to the last enrty in the ILT.
  5370. *
  5371. * Notes:
  5372. * Currently the PF error in the PGLC is non recoverable.
  5373. * In the future the there will be a recovery routine for this error.
  5374. * Currently attention is masked.
  5375. * Having an MCP lock on the load/unload process does not guarantee that
  5376. * there is no Timer disable during Func6/7 enable. This is because the
  5377. * Timers scan is currently being cleared by the MCP on FLR.
  5378. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5379. * there is error before clearing it. But the flow above is simpler and
  5380. * more general.
  5381. * All ILT entries are written by zero+valid and not just PF6/7
  5382. * ILT entries since in the future the ILT entries allocation for
  5383. * PF-s might be dynamic.
  5384. */
  5385. struct ilt_client_info ilt_cli;
  5386. struct bnx2x_ilt ilt;
  5387. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5388. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5389. /* initialize dummy TM client */
  5390. ilt_cli.start = 0;
  5391. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5392. ilt_cli.client_num = ILT_CLIENT_TM;
  5393. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5394. * Step 2: set the timers first/last ilt entry to point
  5395. * to the entire range to prevent ILT range error for 3rd/4th
  5396. * vnic (this code assumes existance of the vnic)
  5397. *
  5398. * both steps performed by call to bnx2x_ilt_client_init_op()
  5399. * with dummy TM client
  5400. *
  5401. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5402. * and his brother are split registers
  5403. */
  5404. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5405. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5406. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5407. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5408. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5409. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5410. }
  5411. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5412. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5413. if (!CHIP_IS_E1x(bp)) {
  5414. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5415. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5416. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5417. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5418. /* let the HW do it's magic ... */
  5419. do {
  5420. msleep(200);
  5421. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5422. } while (factor-- && (val != 1));
  5423. if (val != 1) {
  5424. BNX2X_ERR("ATC_INIT failed\n");
  5425. return -EBUSY;
  5426. }
  5427. }
  5428. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5429. /* clean the DMAE memory */
  5430. bp->dmae_ready = 1;
  5431. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5432. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5433. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5434. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5435. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5436. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5437. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5438. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5439. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5440. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5441. /* QM queues pointers table */
  5442. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5443. /* soft reset pulse */
  5444. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5445. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5446. #ifdef BCM_CNIC
  5447. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5448. #endif
  5449. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5450. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5451. if (!CHIP_REV_IS_SLOW(bp))
  5452. /* enable hw interrupt from doorbell Q */
  5453. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5454. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5455. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5456. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5457. if (!CHIP_IS_E1(bp))
  5458. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5459. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5460. if (IS_MF_AFEX(bp)) {
  5461. /* configure that VNTag and VLAN headers must be
  5462. * received in afex mode
  5463. */
  5464. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5465. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5466. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5467. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5468. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5469. } else {
  5470. /* Bit-map indicating which L2 hdrs may appear
  5471. * after the basic Ethernet header
  5472. */
  5473. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5474. bp->path_has_ovlan ? 7 : 6);
  5475. }
  5476. }
  5477. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5478. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5479. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5480. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5481. if (!CHIP_IS_E1x(bp)) {
  5482. /* reset VFC memories */
  5483. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5484. VFC_MEMORIES_RST_REG_CAM_RST |
  5485. VFC_MEMORIES_RST_REG_RAM_RST);
  5486. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5487. VFC_MEMORIES_RST_REG_CAM_RST |
  5488. VFC_MEMORIES_RST_REG_RAM_RST);
  5489. msleep(20);
  5490. }
  5491. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5492. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5493. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5494. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5495. /* sync semi rtc */
  5496. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5497. 0x80000000);
  5498. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5499. 0x80000000);
  5500. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5501. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5502. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5503. if (!CHIP_IS_E1x(bp)) {
  5504. if (IS_MF_AFEX(bp)) {
  5505. /* configure that VNTag and VLAN headers must be
  5506. * sent in afex mode
  5507. */
  5508. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5509. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5510. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5511. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5512. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5513. } else {
  5514. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5515. bp->path_has_ovlan ? 7 : 6);
  5516. }
  5517. }
  5518. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5519. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5520. #ifdef BCM_CNIC
  5521. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5522. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5523. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5524. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5525. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5526. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5527. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5528. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5529. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5530. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5531. #endif
  5532. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5533. if (sizeof(union cdu_context) != 1024)
  5534. /* we currently assume that a context is 1024 bytes */
  5535. dev_alert(&bp->pdev->dev,
  5536. "please adjust the size of cdu_context(%ld)\n",
  5537. (long)sizeof(union cdu_context));
  5538. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5539. val = (4 << 24) + (0 << 12) + 1024;
  5540. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5541. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5542. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5543. /* enable context validation interrupt from CFC */
  5544. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5545. /* set the thresholds to prevent CFC/CDU race */
  5546. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5547. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5548. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5549. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5550. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5551. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5552. /* Reset PCIE errors for debug */
  5553. REG_WR(bp, 0x2814, 0xffffffff);
  5554. REG_WR(bp, 0x3820, 0xffffffff);
  5555. if (!CHIP_IS_E1x(bp)) {
  5556. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5557. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5558. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5559. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5560. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5561. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5562. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5563. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5564. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5565. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5566. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5567. }
  5568. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5569. if (!CHIP_IS_E1(bp)) {
  5570. /* in E3 this done in per-port section */
  5571. if (!CHIP_IS_E3(bp))
  5572. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5573. }
  5574. if (CHIP_IS_E1H(bp))
  5575. /* not applicable for E2 (and above ...) */
  5576. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5577. if (CHIP_REV_IS_SLOW(bp))
  5578. msleep(200);
  5579. /* finish CFC init */
  5580. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5581. if (val != 1) {
  5582. BNX2X_ERR("CFC LL_INIT failed\n");
  5583. return -EBUSY;
  5584. }
  5585. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5586. if (val != 1) {
  5587. BNX2X_ERR("CFC AC_INIT failed\n");
  5588. return -EBUSY;
  5589. }
  5590. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5591. if (val != 1) {
  5592. BNX2X_ERR("CFC CAM_INIT failed\n");
  5593. return -EBUSY;
  5594. }
  5595. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5596. if (CHIP_IS_E1(bp)) {
  5597. /* read NIG statistic
  5598. to see if this is our first up since powerup */
  5599. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5600. val = *bnx2x_sp(bp, wb_data[0]);
  5601. /* do internal memory self test */
  5602. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5603. BNX2X_ERR("internal mem self test failed\n");
  5604. return -EBUSY;
  5605. }
  5606. }
  5607. bnx2x_setup_fan_failure_detection(bp);
  5608. /* clear PXP2 attentions */
  5609. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5610. bnx2x_enable_blocks_attention(bp);
  5611. bnx2x_enable_blocks_parity(bp);
  5612. if (!BP_NOMCP(bp)) {
  5613. if (CHIP_IS_E1x(bp))
  5614. bnx2x__common_init_phy(bp);
  5615. } else
  5616. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5617. return 0;
  5618. }
  5619. /**
  5620. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5621. *
  5622. * @bp: driver handle
  5623. */
  5624. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5625. {
  5626. int rc = bnx2x_init_hw_common(bp);
  5627. if (rc)
  5628. return rc;
  5629. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5630. if (!BP_NOMCP(bp))
  5631. bnx2x__common_init_phy(bp);
  5632. return 0;
  5633. }
  5634. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5635. {
  5636. int port = BP_PORT(bp);
  5637. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5638. u32 low, high;
  5639. u32 val;
  5640. bnx2x__link_reset(bp);
  5641. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5642. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5643. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5644. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5645. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5646. /* Timers bug workaround: disables the pf_master bit in pglue at
  5647. * common phase, we need to enable it here before any dmae access are
  5648. * attempted. Therefore we manually added the enable-master to the
  5649. * port phase (it also happens in the function phase)
  5650. */
  5651. if (!CHIP_IS_E1x(bp))
  5652. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5653. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5654. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5655. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5656. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5657. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5658. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5659. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5660. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5661. /* QM cid (connection) count */
  5662. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5663. #ifdef BCM_CNIC
  5664. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5665. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5666. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5667. #endif
  5668. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5669. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5670. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5671. if (IS_MF(bp))
  5672. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5673. else if (bp->dev->mtu > 4096) {
  5674. if (bp->flags & ONE_PORT_FLAG)
  5675. low = 160;
  5676. else {
  5677. val = bp->dev->mtu;
  5678. /* (24*1024 + val*4)/256 */
  5679. low = 96 + (val/64) +
  5680. ((val % 64) ? 1 : 0);
  5681. }
  5682. } else
  5683. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5684. high = low + 56; /* 14*1024/256 */
  5685. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5686. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5687. }
  5688. if (CHIP_MODE_IS_4_PORT(bp))
  5689. REG_WR(bp, (BP_PORT(bp) ?
  5690. BRB1_REG_MAC_GUARANTIED_1 :
  5691. BRB1_REG_MAC_GUARANTIED_0), 40);
  5692. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5693. if (CHIP_IS_E3B0(bp)) {
  5694. if (IS_MF_AFEX(bp)) {
  5695. /* configure headers for AFEX mode */
  5696. REG_WR(bp, BP_PORT(bp) ?
  5697. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5698. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5699. REG_WR(bp, BP_PORT(bp) ?
  5700. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5701. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5702. REG_WR(bp, BP_PORT(bp) ?
  5703. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5704. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5705. } else {
  5706. /* Ovlan exists only if we are in multi-function +
  5707. * switch-dependent mode, in switch-independent there
  5708. * is no ovlan headers
  5709. */
  5710. REG_WR(bp, BP_PORT(bp) ?
  5711. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5712. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5713. (bp->path_has_ovlan ? 7 : 6));
  5714. }
  5715. }
  5716. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5717. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5718. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5719. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5720. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5721. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5722. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5723. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5724. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5725. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5726. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5727. if (CHIP_IS_E1x(bp)) {
  5728. /* configure PBF to work without PAUSE mtu 9000 */
  5729. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5730. /* update threshold */
  5731. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5732. /* update init credit */
  5733. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5734. /* probe changes */
  5735. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5736. udelay(50);
  5737. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5738. }
  5739. #ifdef BCM_CNIC
  5740. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5741. #endif
  5742. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5743. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5744. if (CHIP_IS_E1(bp)) {
  5745. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5746. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5747. }
  5748. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5749. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5750. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5751. /* init aeu_mask_attn_func_0/1:
  5752. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5753. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5754. * bits 4-7 are used for "per vn group attention" */
  5755. val = IS_MF(bp) ? 0xF7 : 0x7;
  5756. /* Enable DCBX attention for all but E1 */
  5757. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5758. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5759. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5760. if (!CHIP_IS_E1x(bp)) {
  5761. /* Bit-map indicating which L2 hdrs may appear after the
  5762. * basic Ethernet header
  5763. */
  5764. if (IS_MF_AFEX(bp))
  5765. REG_WR(bp, BP_PORT(bp) ?
  5766. NIG_REG_P1_HDRS_AFTER_BASIC :
  5767. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5768. else
  5769. REG_WR(bp, BP_PORT(bp) ?
  5770. NIG_REG_P1_HDRS_AFTER_BASIC :
  5771. NIG_REG_P0_HDRS_AFTER_BASIC,
  5772. IS_MF_SD(bp) ? 7 : 6);
  5773. if (CHIP_IS_E3(bp))
  5774. REG_WR(bp, BP_PORT(bp) ?
  5775. NIG_REG_LLH1_MF_MODE :
  5776. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5777. }
  5778. if (!CHIP_IS_E3(bp))
  5779. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5780. if (!CHIP_IS_E1(bp)) {
  5781. /* 0x2 disable mf_ov, 0x1 enable */
  5782. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5783. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5784. if (!CHIP_IS_E1x(bp)) {
  5785. val = 0;
  5786. switch (bp->mf_mode) {
  5787. case MULTI_FUNCTION_SD:
  5788. val = 1;
  5789. break;
  5790. case MULTI_FUNCTION_SI:
  5791. case MULTI_FUNCTION_AFEX:
  5792. val = 2;
  5793. break;
  5794. }
  5795. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5796. NIG_REG_LLH0_CLS_TYPE), val);
  5797. }
  5798. {
  5799. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5800. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5801. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5802. }
  5803. }
  5804. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5805. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5806. if (val & (1 << MISC_REGISTERS_SPIO_5)) {
  5807. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5808. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5809. val = REG_RD(bp, reg_addr);
  5810. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5811. REG_WR(bp, reg_addr, val);
  5812. }
  5813. return 0;
  5814. }
  5815. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5816. {
  5817. int reg;
  5818. u32 wb_write[2];
  5819. if (CHIP_IS_E1(bp))
  5820. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5821. else
  5822. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5823. wb_write[0] = ONCHIP_ADDR1(addr);
  5824. wb_write[1] = ONCHIP_ADDR2(addr);
  5825. REG_WR_DMAE(bp, reg, wb_write, 2);
  5826. }
  5827. static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
  5828. u8 idu_sb_id, bool is_Pf)
  5829. {
  5830. u32 data, ctl, cnt = 100;
  5831. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5832. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  5833. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  5834. u32 sb_bit = 1 << (idu_sb_id%32);
  5835. u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  5836. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  5837. /* Not supported in BC mode */
  5838. if (CHIP_INT_MODE_IS_BC(bp))
  5839. return;
  5840. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  5841. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  5842. IGU_REGULAR_CLEANUP_SET |
  5843. IGU_REGULAR_BCLEANUP;
  5844. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  5845. func_encode << IGU_CTRL_REG_FID_SHIFT |
  5846. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  5847. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5848. data, igu_addr_data);
  5849. REG_WR(bp, igu_addr_data, data);
  5850. mmiowb();
  5851. barrier();
  5852. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5853. ctl, igu_addr_ctl);
  5854. REG_WR(bp, igu_addr_ctl, ctl);
  5855. mmiowb();
  5856. barrier();
  5857. /* wait for clean up to finish */
  5858. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  5859. msleep(20);
  5860. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  5861. DP(NETIF_MSG_HW,
  5862. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  5863. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  5864. }
  5865. }
  5866. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5867. {
  5868. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5869. }
  5870. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5871. {
  5872. u32 i, base = FUNC_ILT_BASE(func);
  5873. for (i = base; i < base + ILT_PER_FUNC; i++)
  5874. bnx2x_ilt_wr(bp, i, 0);
  5875. }
  5876. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5877. {
  5878. int port = BP_PORT(bp);
  5879. int func = BP_FUNC(bp);
  5880. int init_phase = PHASE_PF0 + func;
  5881. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5882. u16 cdu_ilt_start;
  5883. u32 addr, val;
  5884. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5885. int i, main_mem_width, rc;
  5886. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  5887. /* FLR cleanup - hmmm */
  5888. if (!CHIP_IS_E1x(bp)) {
  5889. rc = bnx2x_pf_flr_clnup(bp);
  5890. if (rc)
  5891. return rc;
  5892. }
  5893. /* set MSI reconfigure capability */
  5894. if (bp->common.int_block == INT_BLOCK_HC) {
  5895. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5896. val = REG_RD(bp, addr);
  5897. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5898. REG_WR(bp, addr, val);
  5899. }
  5900. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5901. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5902. ilt = BP_ILT(bp);
  5903. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  5904. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  5905. ilt->lines[cdu_ilt_start + i].page =
  5906. bp->context.vcxt + (ILT_PAGE_CIDS * i);
  5907. ilt->lines[cdu_ilt_start + i].page_mapping =
  5908. bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
  5909. /* cdu ilt pages are allocated manually so there's no need to
  5910. set the size */
  5911. }
  5912. bnx2x_ilt_init_op(bp, INITOP_SET);
  5913. #ifdef BCM_CNIC
  5914. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5915. /* T1 hash bits value determines the T1 number of entries */
  5916. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5917. #endif
  5918. #ifndef BCM_CNIC
  5919. /* set NIC mode */
  5920. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5921. #endif /* BCM_CNIC */
  5922. if (!CHIP_IS_E1x(bp)) {
  5923. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  5924. /* Turn on a single ISR mode in IGU if driver is going to use
  5925. * INT#x or MSI
  5926. */
  5927. if (!(bp->flags & USING_MSIX_FLAG))
  5928. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  5929. /*
  5930. * Timers workaround bug: function init part.
  5931. * Need to wait 20msec after initializing ILT,
  5932. * needed to make sure there are no requests in
  5933. * one of the PXP internal queues with "old" ILT addresses
  5934. */
  5935. msleep(20);
  5936. /*
  5937. * Master enable - Due to WB DMAE writes performed before this
  5938. * register is re-initialized as part of the regular function
  5939. * init
  5940. */
  5941. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5942. /* Enable the function in IGU */
  5943. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  5944. }
  5945. bp->dmae_ready = 1;
  5946. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5947. if (!CHIP_IS_E1x(bp))
  5948. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  5949. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5950. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5951. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5952. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5953. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5954. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5955. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5956. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5957. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5958. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5959. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5960. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5961. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5962. if (!CHIP_IS_E1x(bp))
  5963. REG_WR(bp, QM_REG_PF_EN, 1);
  5964. if (!CHIP_IS_E1x(bp)) {
  5965. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5966. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5967. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5968. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5969. }
  5970. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5971. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5972. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5973. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5974. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5975. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5976. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5977. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5978. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5979. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5980. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5981. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5982. if (!CHIP_IS_E1x(bp))
  5983. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  5984. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5985. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5986. if (!CHIP_IS_E1x(bp))
  5987. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  5988. if (IS_MF(bp)) {
  5989. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  5990. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  5991. }
  5992. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5993. /* HC init per function */
  5994. if (bp->common.int_block == INT_BLOCK_HC) {
  5995. if (CHIP_IS_E1H(bp)) {
  5996. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5997. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5998. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5999. }
  6000. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6001. } else {
  6002. int num_segs, sb_idx, prod_offset;
  6003. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6004. if (!CHIP_IS_E1x(bp)) {
  6005. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6006. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6007. }
  6008. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6009. if (!CHIP_IS_E1x(bp)) {
  6010. int dsb_idx = 0;
  6011. /**
  6012. * Producer memory:
  6013. * E2 mode: address 0-135 match to the mapping memory;
  6014. * 136 - PF0 default prod; 137 - PF1 default prod;
  6015. * 138 - PF2 default prod; 139 - PF3 default prod;
  6016. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6017. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6018. * 144-147 reserved.
  6019. *
  6020. * E1.5 mode - In backward compatible mode;
  6021. * for non default SB; each even line in the memory
  6022. * holds the U producer and each odd line hold
  6023. * the C producer. The first 128 producers are for
  6024. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6025. * producers are for the DSB for each PF.
  6026. * Each PF has five segments: (the order inside each
  6027. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6028. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6029. * 144-147 attn prods;
  6030. */
  6031. /* non-default-status-blocks */
  6032. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6033. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6034. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6035. prod_offset = (bp->igu_base_sb + sb_idx) *
  6036. num_segs;
  6037. for (i = 0; i < num_segs; i++) {
  6038. addr = IGU_REG_PROD_CONS_MEMORY +
  6039. (prod_offset + i) * 4;
  6040. REG_WR(bp, addr, 0);
  6041. }
  6042. /* send consumer update with value 0 */
  6043. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6044. USTORM_ID, 0, IGU_INT_NOP, 1);
  6045. bnx2x_igu_clear_sb(bp,
  6046. bp->igu_base_sb + sb_idx);
  6047. }
  6048. /* default-status-blocks */
  6049. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6050. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6051. if (CHIP_MODE_IS_4_PORT(bp))
  6052. dsb_idx = BP_FUNC(bp);
  6053. else
  6054. dsb_idx = BP_VN(bp);
  6055. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6056. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6057. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6058. /*
  6059. * igu prods come in chunks of E1HVN_MAX (4) -
  6060. * does not matters what is the current chip mode
  6061. */
  6062. for (i = 0; i < (num_segs * E1HVN_MAX);
  6063. i += E1HVN_MAX) {
  6064. addr = IGU_REG_PROD_CONS_MEMORY +
  6065. (prod_offset + i)*4;
  6066. REG_WR(bp, addr, 0);
  6067. }
  6068. /* send consumer update with 0 */
  6069. if (CHIP_INT_MODE_IS_BC(bp)) {
  6070. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6071. USTORM_ID, 0, IGU_INT_NOP, 1);
  6072. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6073. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6074. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6075. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6076. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6077. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6078. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6079. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6080. } else {
  6081. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6082. USTORM_ID, 0, IGU_INT_NOP, 1);
  6083. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6084. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6085. }
  6086. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6087. /* !!! these should become driver const once
  6088. rf-tool supports split-68 const */
  6089. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6090. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6091. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6092. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6093. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6094. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6095. }
  6096. }
  6097. /* Reset PCIE errors for debug */
  6098. REG_WR(bp, 0x2114, 0xffffffff);
  6099. REG_WR(bp, 0x2120, 0xffffffff);
  6100. if (CHIP_IS_E1x(bp)) {
  6101. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6102. main_mem_base = HC_REG_MAIN_MEMORY +
  6103. BP_PORT(bp) * (main_mem_size * 4);
  6104. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6105. main_mem_width = 8;
  6106. val = REG_RD(bp, main_mem_prty_clr);
  6107. if (val)
  6108. DP(NETIF_MSG_HW,
  6109. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6110. val);
  6111. /* Clear "false" parity errors in MSI-X table */
  6112. for (i = main_mem_base;
  6113. i < main_mem_base + main_mem_size * 4;
  6114. i += main_mem_width) {
  6115. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6116. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6117. i, main_mem_width / 4);
  6118. }
  6119. /* Clear HC parity attention */
  6120. REG_RD(bp, main_mem_prty_clr);
  6121. }
  6122. #ifdef BNX2X_STOP_ON_ERROR
  6123. /* Enable STORMs SP logging */
  6124. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6125. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6126. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6127. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6128. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6129. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6130. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6131. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6132. #endif
  6133. bnx2x_phy_probe(&bp->link_params);
  6134. return 0;
  6135. }
  6136. void bnx2x_free_mem(struct bnx2x *bp)
  6137. {
  6138. /* fastpath */
  6139. bnx2x_free_fp_mem(bp);
  6140. /* end of fastpath */
  6141. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6142. sizeof(struct host_sp_status_block));
  6143. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6144. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6145. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6146. sizeof(struct bnx2x_slowpath));
  6147. BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
  6148. bp->context.size);
  6149. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6150. BNX2X_FREE(bp->ilt->lines);
  6151. #ifdef BCM_CNIC
  6152. if (!CHIP_IS_E1x(bp))
  6153. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6154. sizeof(struct host_hc_status_block_e2));
  6155. else
  6156. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6157. sizeof(struct host_hc_status_block_e1x));
  6158. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6159. #endif
  6160. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6161. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6162. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6163. }
  6164. static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  6165. {
  6166. int num_groups;
  6167. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  6168. /* number of queues for statistics is number of eth queues + FCoE */
  6169. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  6170. /* Total number of FW statistics requests =
  6171. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  6172. * num of queues
  6173. */
  6174. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  6175. /* Request is built from stats_query_header and an array of
  6176. * stats_query_cmd_group each of which contains
  6177. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  6178. * configured in the stats_query_header.
  6179. */
  6180. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  6181. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  6182. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  6183. num_groups * sizeof(struct stats_query_cmd_group);
  6184. /* Data for statistics requests + stats_conter
  6185. *
  6186. * stats_counter holds per-STORM counters that are incremented
  6187. * when STORM has finished with the current request.
  6188. *
  6189. * memory for FCoE offloaded statistics are counted anyway,
  6190. * even if they will not be sent.
  6191. */
  6192. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  6193. sizeof(struct per_pf_stats) +
  6194. sizeof(struct fcoe_statistics_params) +
  6195. sizeof(struct per_queue_stats) * num_queue_stats +
  6196. sizeof(struct stats_counter);
  6197. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  6198. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6199. /* Set shortcuts */
  6200. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  6201. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  6202. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  6203. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  6204. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  6205. bp->fw_stats_req_sz;
  6206. return 0;
  6207. alloc_mem_err:
  6208. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6209. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6210. BNX2X_ERR("Can't allocate memory\n");
  6211. return -ENOMEM;
  6212. }
  6213. int bnx2x_alloc_mem(struct bnx2x *bp)
  6214. {
  6215. #ifdef BCM_CNIC
  6216. if (!CHIP_IS_E1x(bp))
  6217. /* size = the status block + ramrod buffers */
  6218. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6219. sizeof(struct host_hc_status_block_e2));
  6220. else
  6221. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
  6222. sizeof(struct host_hc_status_block_e1x));
  6223. /* allocate searcher T2 table */
  6224. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6225. #endif
  6226. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6227. sizeof(struct host_sp_status_block));
  6228. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6229. sizeof(struct bnx2x_slowpath));
  6230. #ifdef BCM_CNIC
  6231. /* write address to which L5 should insert its values */
  6232. bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
  6233. #endif
  6234. /* Allocated memory for FW statistics */
  6235. if (bnx2x_alloc_fw_stats_mem(bp))
  6236. goto alloc_mem_err;
  6237. bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6238. BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
  6239. bp->context.size);
  6240. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6241. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6242. goto alloc_mem_err;
  6243. /* Slow path ring */
  6244. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6245. /* EQ */
  6246. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6247. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6248. /* fastpath */
  6249. /* need to be done at the end, since it's self adjusting to amount
  6250. * of memory available for RSS queues
  6251. */
  6252. if (bnx2x_alloc_fp_mem(bp))
  6253. goto alloc_mem_err;
  6254. return 0;
  6255. alloc_mem_err:
  6256. bnx2x_free_mem(bp);
  6257. BNX2X_ERR("Can't allocate memory\n");
  6258. return -ENOMEM;
  6259. }
  6260. /*
  6261. * Init service functions
  6262. */
  6263. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6264. struct bnx2x_vlan_mac_obj *obj, bool set,
  6265. int mac_type, unsigned long *ramrod_flags)
  6266. {
  6267. int rc;
  6268. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6269. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6270. /* Fill general parameters */
  6271. ramrod_param.vlan_mac_obj = obj;
  6272. ramrod_param.ramrod_flags = *ramrod_flags;
  6273. /* Fill a user request section if needed */
  6274. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6275. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6276. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6277. /* Set the command: ADD or DEL */
  6278. if (set)
  6279. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6280. else
  6281. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6282. }
  6283. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6284. if (rc < 0)
  6285. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6286. return rc;
  6287. }
  6288. int bnx2x_del_all_macs(struct bnx2x *bp,
  6289. struct bnx2x_vlan_mac_obj *mac_obj,
  6290. int mac_type, bool wait_for_comp)
  6291. {
  6292. int rc;
  6293. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6294. /* Wait for completion of requested */
  6295. if (wait_for_comp)
  6296. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6297. /* Set the mac type of addresses we want to clear */
  6298. __set_bit(mac_type, &vlan_mac_flags);
  6299. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6300. if (rc < 0)
  6301. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6302. return rc;
  6303. }
  6304. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6305. {
  6306. unsigned long ramrod_flags = 0;
  6307. #ifdef BCM_CNIC
  6308. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6309. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6310. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6311. "Ignoring Zero MAC for STORAGE SD mode\n");
  6312. return 0;
  6313. }
  6314. #endif
  6315. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6316. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6317. /* Eth MAC is set on RSS leading client (fp[0]) */
  6318. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
  6319. BNX2X_ETH_MAC, &ramrod_flags);
  6320. }
  6321. int bnx2x_setup_leading(struct bnx2x *bp)
  6322. {
  6323. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6324. }
  6325. /**
  6326. * bnx2x_set_int_mode - configure interrupt mode
  6327. *
  6328. * @bp: driver handle
  6329. *
  6330. * In case of MSI-X it will also try to enable MSI-X.
  6331. */
  6332. static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
  6333. {
  6334. switch (int_mode) {
  6335. case INT_MODE_MSI:
  6336. bnx2x_enable_msi(bp);
  6337. /* falling through... */
  6338. case INT_MODE_INTx:
  6339. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6340. BNX2X_DEV_INFO("set number of queues to 1\n");
  6341. break;
  6342. default:
  6343. /* Set number of queues for MSI-X mode */
  6344. bnx2x_set_num_queues(bp);
  6345. BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
  6346. /* if we can't use MSI-X we only need one fp,
  6347. * so try to enable MSI-X with the requested number of fp's
  6348. * and fallback to MSI or legacy INTx with one fp
  6349. */
  6350. if (bnx2x_enable_msix(bp) ||
  6351. bp->flags & USING_SINGLE_MSIX_FLAG) {
  6352. /* failed to enable multiple MSI-X */
  6353. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6354. bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
  6355. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6356. /* Try to enable MSI */
  6357. if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
  6358. !(bp->flags & DISABLE_MSI_FLAG))
  6359. bnx2x_enable_msi(bp);
  6360. }
  6361. break;
  6362. }
  6363. }
  6364. /* must be called prioir to any HW initializations */
  6365. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6366. {
  6367. return L2_ILT_LINES(bp);
  6368. }
  6369. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6370. {
  6371. struct ilt_client_info *ilt_client;
  6372. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6373. u16 line = 0;
  6374. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6375. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6376. /* CDU */
  6377. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6378. ilt_client->client_num = ILT_CLIENT_CDU;
  6379. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6380. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6381. ilt_client->start = line;
  6382. line += bnx2x_cid_ilt_lines(bp);
  6383. #ifdef BCM_CNIC
  6384. line += CNIC_ILT_LINES;
  6385. #endif
  6386. ilt_client->end = line - 1;
  6387. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6388. ilt_client->start,
  6389. ilt_client->end,
  6390. ilt_client->page_size,
  6391. ilt_client->flags,
  6392. ilog2(ilt_client->page_size >> 12));
  6393. /* QM */
  6394. if (QM_INIT(bp->qm_cid_count)) {
  6395. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6396. ilt_client->client_num = ILT_CLIENT_QM;
  6397. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6398. ilt_client->flags = 0;
  6399. ilt_client->start = line;
  6400. /* 4 bytes for each cid */
  6401. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6402. QM_ILT_PAGE_SZ);
  6403. ilt_client->end = line - 1;
  6404. DP(NETIF_MSG_IFUP,
  6405. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6406. ilt_client->start,
  6407. ilt_client->end,
  6408. ilt_client->page_size,
  6409. ilt_client->flags,
  6410. ilog2(ilt_client->page_size >> 12));
  6411. }
  6412. /* SRC */
  6413. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6414. #ifdef BCM_CNIC
  6415. ilt_client->client_num = ILT_CLIENT_SRC;
  6416. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6417. ilt_client->flags = 0;
  6418. ilt_client->start = line;
  6419. line += SRC_ILT_LINES;
  6420. ilt_client->end = line - 1;
  6421. DP(NETIF_MSG_IFUP,
  6422. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6423. ilt_client->start,
  6424. ilt_client->end,
  6425. ilt_client->page_size,
  6426. ilt_client->flags,
  6427. ilog2(ilt_client->page_size >> 12));
  6428. #else
  6429. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6430. #endif
  6431. /* TM */
  6432. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6433. #ifdef BCM_CNIC
  6434. ilt_client->client_num = ILT_CLIENT_TM;
  6435. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6436. ilt_client->flags = 0;
  6437. ilt_client->start = line;
  6438. line += TM_ILT_LINES;
  6439. ilt_client->end = line - 1;
  6440. DP(NETIF_MSG_IFUP,
  6441. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6442. ilt_client->start,
  6443. ilt_client->end,
  6444. ilt_client->page_size,
  6445. ilt_client->flags,
  6446. ilog2(ilt_client->page_size >> 12));
  6447. #else
  6448. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6449. #endif
  6450. BUG_ON(line > ILT_MAX_LINES);
  6451. }
  6452. /**
  6453. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6454. *
  6455. * @bp: driver handle
  6456. * @fp: pointer to fastpath
  6457. * @init_params: pointer to parameters structure
  6458. *
  6459. * parameters configured:
  6460. * - HC configuration
  6461. * - Queue's CDU context
  6462. */
  6463. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6464. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6465. {
  6466. u8 cos;
  6467. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6468. if (!IS_FCOE_FP(fp)) {
  6469. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6470. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6471. /* If HC is supporterd, enable host coalescing in the transition
  6472. * to INIT state.
  6473. */
  6474. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6475. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6476. /* HC rate */
  6477. init_params->rx.hc_rate = bp->rx_ticks ?
  6478. (1000000 / bp->rx_ticks) : 0;
  6479. init_params->tx.hc_rate = bp->tx_ticks ?
  6480. (1000000 / bp->tx_ticks) : 0;
  6481. /* FW SB ID */
  6482. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6483. fp->fw_sb_id;
  6484. /*
  6485. * CQ index among the SB indices: FCoE clients uses the default
  6486. * SB, therefore it's different.
  6487. */
  6488. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6489. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6490. }
  6491. /* set maximum number of COSs supported by this queue */
  6492. init_params->max_cos = fp->max_cos;
  6493. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6494. fp->index, init_params->max_cos);
  6495. /* set the context pointers queue object */
  6496. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
  6497. init_params->cxts[cos] =
  6498. &bp->context.vcxt[fp->txdata[cos].cid].eth;
  6499. }
  6500. int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6501. struct bnx2x_queue_state_params *q_params,
  6502. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6503. int tx_index, bool leading)
  6504. {
  6505. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6506. /* Set the command */
  6507. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6508. /* Set tx-only QUEUE flags: don't zero statistics */
  6509. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6510. /* choose the index of the cid to send the slow path on */
  6511. tx_only_params->cid_index = tx_index;
  6512. /* Set general TX_ONLY_SETUP parameters */
  6513. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6514. /* Set Tx TX_ONLY_SETUP parameters */
  6515. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6516. DP(NETIF_MSG_IFUP,
  6517. "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n",
  6518. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6519. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6520. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6521. /* send the ramrod */
  6522. return bnx2x_queue_state_change(bp, q_params);
  6523. }
  6524. /**
  6525. * bnx2x_setup_queue - setup queue
  6526. *
  6527. * @bp: driver handle
  6528. * @fp: pointer to fastpath
  6529. * @leading: is leading
  6530. *
  6531. * This function performs 2 steps in a Queue state machine
  6532. * actually: 1) RESET->INIT 2) INIT->SETUP
  6533. */
  6534. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6535. bool leading)
  6536. {
  6537. struct bnx2x_queue_state_params q_params = {NULL};
  6538. struct bnx2x_queue_setup_params *setup_params =
  6539. &q_params.params.setup;
  6540. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6541. &q_params.params.tx_only;
  6542. int rc;
  6543. u8 tx_index;
  6544. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6545. /* reset IGU state skip FCoE L2 queue */
  6546. if (!IS_FCOE_FP(fp))
  6547. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6548. IGU_INT_ENABLE, 0);
  6549. q_params.q_obj = &fp->q_obj;
  6550. /* We want to wait for completion in this context */
  6551. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6552. /* Prepare the INIT parameters */
  6553. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6554. /* Set the command */
  6555. q_params.cmd = BNX2X_Q_CMD_INIT;
  6556. /* Change the state to INIT */
  6557. rc = bnx2x_queue_state_change(bp, &q_params);
  6558. if (rc) {
  6559. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6560. return rc;
  6561. }
  6562. DP(NETIF_MSG_IFUP, "init complete\n");
  6563. /* Now move the Queue to the SETUP state... */
  6564. memset(setup_params, 0, sizeof(*setup_params));
  6565. /* Set QUEUE flags */
  6566. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6567. /* Set general SETUP parameters */
  6568. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6569. FIRST_TX_COS_INDEX);
  6570. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6571. &setup_params->rxq_params);
  6572. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6573. FIRST_TX_COS_INDEX);
  6574. /* Set the command */
  6575. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6576. /* Change the state to SETUP */
  6577. rc = bnx2x_queue_state_change(bp, &q_params);
  6578. if (rc) {
  6579. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6580. return rc;
  6581. }
  6582. /* loop through the relevant tx-only indices */
  6583. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6584. tx_index < fp->max_cos;
  6585. tx_index++) {
  6586. /* prepare and send tx-only ramrod*/
  6587. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6588. tx_only_params, tx_index, leading);
  6589. if (rc) {
  6590. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6591. fp->index, tx_index);
  6592. return rc;
  6593. }
  6594. }
  6595. return rc;
  6596. }
  6597. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6598. {
  6599. struct bnx2x_fastpath *fp = &bp->fp[index];
  6600. struct bnx2x_fp_txdata *txdata;
  6601. struct bnx2x_queue_state_params q_params = {NULL};
  6602. int rc, tx_index;
  6603. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6604. q_params.q_obj = &fp->q_obj;
  6605. /* We want to wait for completion in this context */
  6606. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6607. /* close tx-only connections */
  6608. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6609. tx_index < fp->max_cos;
  6610. tx_index++){
  6611. /* ascertain this is a normal queue*/
  6612. txdata = &fp->txdata[tx_index];
  6613. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6614. txdata->txq_index);
  6615. /* send halt terminate on tx-only connection */
  6616. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6617. memset(&q_params.params.terminate, 0,
  6618. sizeof(q_params.params.terminate));
  6619. q_params.params.terminate.cid_index = tx_index;
  6620. rc = bnx2x_queue_state_change(bp, &q_params);
  6621. if (rc)
  6622. return rc;
  6623. /* send halt terminate on tx-only connection */
  6624. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6625. memset(&q_params.params.cfc_del, 0,
  6626. sizeof(q_params.params.cfc_del));
  6627. q_params.params.cfc_del.cid_index = tx_index;
  6628. rc = bnx2x_queue_state_change(bp, &q_params);
  6629. if (rc)
  6630. return rc;
  6631. }
  6632. /* Stop the primary connection: */
  6633. /* ...halt the connection */
  6634. q_params.cmd = BNX2X_Q_CMD_HALT;
  6635. rc = bnx2x_queue_state_change(bp, &q_params);
  6636. if (rc)
  6637. return rc;
  6638. /* ...terminate the connection */
  6639. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6640. memset(&q_params.params.terminate, 0,
  6641. sizeof(q_params.params.terminate));
  6642. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6643. rc = bnx2x_queue_state_change(bp, &q_params);
  6644. if (rc)
  6645. return rc;
  6646. /* ...delete cfc entry */
  6647. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6648. memset(&q_params.params.cfc_del, 0,
  6649. sizeof(q_params.params.cfc_del));
  6650. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6651. return bnx2x_queue_state_change(bp, &q_params);
  6652. }
  6653. static void bnx2x_reset_func(struct bnx2x *bp)
  6654. {
  6655. int port = BP_PORT(bp);
  6656. int func = BP_FUNC(bp);
  6657. int i;
  6658. /* Disable the function in the FW */
  6659. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6660. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6661. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6662. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6663. /* FP SBs */
  6664. for_each_eth_queue(bp, i) {
  6665. struct bnx2x_fastpath *fp = &bp->fp[i];
  6666. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6667. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6668. SB_DISABLED);
  6669. }
  6670. #ifdef BCM_CNIC
  6671. /* CNIC SB */
  6672. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6673. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
  6674. SB_DISABLED);
  6675. #endif
  6676. /* SP SB */
  6677. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6678. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6679. SB_DISABLED);
  6680. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6681. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6682. 0);
  6683. /* Configure IGU */
  6684. if (bp->common.int_block == INT_BLOCK_HC) {
  6685. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6686. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6687. } else {
  6688. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6689. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6690. }
  6691. #ifdef BCM_CNIC
  6692. /* Disable Timer scan */
  6693. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6694. /*
  6695. * Wait for at least 10ms and up to 2 second for the timers scan to
  6696. * complete
  6697. */
  6698. for (i = 0; i < 200; i++) {
  6699. msleep(10);
  6700. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6701. break;
  6702. }
  6703. #endif
  6704. /* Clear ILT */
  6705. bnx2x_clear_func_ilt(bp, func);
  6706. /* Timers workaround bug for E2: if this is vnic-3,
  6707. * we need to set the entire ilt range for this timers.
  6708. */
  6709. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6710. struct ilt_client_info ilt_cli;
  6711. /* use dummy TM client */
  6712. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6713. ilt_cli.start = 0;
  6714. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6715. ilt_cli.client_num = ILT_CLIENT_TM;
  6716. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6717. }
  6718. /* this assumes that reset_port() called before reset_func()*/
  6719. if (!CHIP_IS_E1x(bp))
  6720. bnx2x_pf_disable(bp);
  6721. bp->dmae_ready = 0;
  6722. }
  6723. static void bnx2x_reset_port(struct bnx2x *bp)
  6724. {
  6725. int port = BP_PORT(bp);
  6726. u32 val;
  6727. /* Reset physical Link */
  6728. bnx2x__link_reset(bp);
  6729. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6730. /* Do not rcv packets to BRB */
  6731. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6732. /* Do not direct rcv packets that are not for MCP to the BRB */
  6733. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6734. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6735. /* Configure AEU */
  6736. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6737. msleep(100);
  6738. /* Check for BRB port occupancy */
  6739. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6740. if (val)
  6741. DP(NETIF_MSG_IFDOWN,
  6742. "BRB1 is not empty %d blocks are occupied\n", val);
  6743. /* TODO: Close Doorbell port? */
  6744. }
  6745. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6746. {
  6747. struct bnx2x_func_state_params func_params = {NULL};
  6748. /* Prepare parameters for function state transitions */
  6749. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6750. func_params.f_obj = &bp->func_obj;
  6751. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6752. func_params.params.hw_init.load_phase = load_code;
  6753. return bnx2x_func_state_change(bp, &func_params);
  6754. }
  6755. static int bnx2x_func_stop(struct bnx2x *bp)
  6756. {
  6757. struct bnx2x_func_state_params func_params = {NULL};
  6758. int rc;
  6759. /* Prepare parameters for function state transitions */
  6760. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6761. func_params.f_obj = &bp->func_obj;
  6762. func_params.cmd = BNX2X_F_CMD_STOP;
  6763. /*
  6764. * Try to stop the function the 'good way'. If fails (in case
  6765. * of a parity error during bnx2x_chip_cleanup()) and we are
  6766. * not in a debug mode, perform a state transaction in order to
  6767. * enable further HW_RESET transaction.
  6768. */
  6769. rc = bnx2x_func_state_change(bp, &func_params);
  6770. if (rc) {
  6771. #ifdef BNX2X_STOP_ON_ERROR
  6772. return rc;
  6773. #else
  6774. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6775. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6776. return bnx2x_func_state_change(bp, &func_params);
  6777. #endif
  6778. }
  6779. return 0;
  6780. }
  6781. /**
  6782. * bnx2x_send_unload_req - request unload mode from the MCP.
  6783. *
  6784. * @bp: driver handle
  6785. * @unload_mode: requested function's unload mode
  6786. *
  6787. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6788. */
  6789. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6790. {
  6791. u32 reset_code = 0;
  6792. int port = BP_PORT(bp);
  6793. /* Select the UNLOAD request mode */
  6794. if (unload_mode == UNLOAD_NORMAL)
  6795. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6796. else if (bp->flags & NO_WOL_FLAG)
  6797. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6798. else if (bp->wol) {
  6799. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6800. u8 *mac_addr = bp->dev->dev_addr;
  6801. u32 val;
  6802. u16 pmc;
  6803. /* The mac address is written to entries 1-4 to
  6804. * preserve entry 0 which is used by the PMF
  6805. */
  6806. u8 entry = (BP_VN(bp) + 1)*8;
  6807. val = (mac_addr[0] << 8) | mac_addr[1];
  6808. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6809. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6810. (mac_addr[4] << 8) | mac_addr[5];
  6811. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6812. /* Enable the PME and clear the status */
  6813. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6814. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6815. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6816. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6817. } else
  6818. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6819. /* Send the request to the MCP */
  6820. if (!BP_NOMCP(bp))
  6821. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6822. else {
  6823. int path = BP_PATH(bp);
  6824. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  6825. path, load_count[path][0], load_count[path][1],
  6826. load_count[path][2]);
  6827. load_count[path][0]--;
  6828. load_count[path][1 + port]--;
  6829. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  6830. path, load_count[path][0], load_count[path][1],
  6831. load_count[path][2]);
  6832. if (load_count[path][0] == 0)
  6833. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6834. else if (load_count[path][1 + port] == 0)
  6835. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6836. else
  6837. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6838. }
  6839. return reset_code;
  6840. }
  6841. /**
  6842. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6843. *
  6844. * @bp: driver handle
  6845. */
  6846. void bnx2x_send_unload_done(struct bnx2x *bp)
  6847. {
  6848. /* Report UNLOAD_DONE to MCP */
  6849. if (!BP_NOMCP(bp))
  6850. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6851. }
  6852. static int bnx2x_func_wait_started(struct bnx2x *bp)
  6853. {
  6854. int tout = 50;
  6855. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  6856. if (!bp->port.pmf)
  6857. return 0;
  6858. /*
  6859. * (assumption: No Attention from MCP at this stage)
  6860. * PMF probably in the middle of TXdisable/enable transaction
  6861. * 1. Sync IRS for default SB
  6862. * 2. Sync SP queue - this guarantes us that attention handling started
  6863. * 3. Wait, that TXdisable/enable transaction completes
  6864. *
  6865. * 1+2 guranty that if DCBx attention was scheduled it already changed
  6866. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  6867. * received complettion for the transaction the state is TX_STOPPED.
  6868. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  6869. * transaction.
  6870. */
  6871. /* make sure default SB ISR is done */
  6872. if (msix)
  6873. synchronize_irq(bp->msix_table[0].vector);
  6874. else
  6875. synchronize_irq(bp->pdev->irq);
  6876. flush_workqueue(bnx2x_wq);
  6877. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6878. BNX2X_F_STATE_STARTED && tout--)
  6879. msleep(20);
  6880. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6881. BNX2X_F_STATE_STARTED) {
  6882. #ifdef BNX2X_STOP_ON_ERROR
  6883. BNX2X_ERR("Wrong function state\n");
  6884. return -EBUSY;
  6885. #else
  6886. /*
  6887. * Failed to complete the transaction in a "good way"
  6888. * Force both transactions with CLR bit
  6889. */
  6890. struct bnx2x_func_state_params func_params = {NULL};
  6891. DP(NETIF_MSG_IFDOWN,
  6892. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  6893. func_params.f_obj = &bp->func_obj;
  6894. __set_bit(RAMROD_DRV_CLR_ONLY,
  6895. &func_params.ramrod_flags);
  6896. /* STARTED-->TX_ST0PPED */
  6897. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  6898. bnx2x_func_state_change(bp, &func_params);
  6899. /* TX_ST0PPED-->STARTED */
  6900. func_params.cmd = BNX2X_F_CMD_TX_START;
  6901. return bnx2x_func_state_change(bp, &func_params);
  6902. #endif
  6903. }
  6904. return 0;
  6905. }
  6906. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
  6907. {
  6908. int port = BP_PORT(bp);
  6909. int i, rc = 0;
  6910. u8 cos;
  6911. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  6912. u32 reset_code;
  6913. /* Wait until tx fastpath tasks complete */
  6914. for_each_tx_queue(bp, i) {
  6915. struct bnx2x_fastpath *fp = &bp->fp[i];
  6916. for_each_cos_in_tx_queue(fp, cos)
  6917. rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
  6918. #ifdef BNX2X_STOP_ON_ERROR
  6919. if (rc)
  6920. return;
  6921. #endif
  6922. }
  6923. /* Give HW time to discard old tx messages */
  6924. usleep_range(1000, 1000);
  6925. /* Clean all ETH MACs */
  6926. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
  6927. if (rc < 0)
  6928. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  6929. /* Clean up UC list */
  6930. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
  6931. true);
  6932. if (rc < 0)
  6933. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  6934. rc);
  6935. /* Disable LLH */
  6936. if (!CHIP_IS_E1(bp))
  6937. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6938. /* Set "drop all" (stop Rx).
  6939. * We need to take a netif_addr_lock() here in order to prevent
  6940. * a race between the completion code and this code.
  6941. */
  6942. netif_addr_lock_bh(bp->dev);
  6943. /* Schedule the rx_mode command */
  6944. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  6945. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  6946. else
  6947. bnx2x_set_storm_rx_mode(bp);
  6948. /* Cleanup multicast configuration */
  6949. rparam.mcast_obj = &bp->mcast_obj;
  6950. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  6951. if (rc < 0)
  6952. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  6953. netif_addr_unlock_bh(bp->dev);
  6954. /*
  6955. * Send the UNLOAD_REQUEST to the MCP. This will return if
  6956. * this function should perform FUNC, PORT or COMMON HW
  6957. * reset.
  6958. */
  6959. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  6960. /*
  6961. * (assumption: No Attention from MCP at this stage)
  6962. * PMF probably in the middle of TXdisable/enable transaction
  6963. */
  6964. rc = bnx2x_func_wait_started(bp);
  6965. if (rc) {
  6966. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  6967. #ifdef BNX2X_STOP_ON_ERROR
  6968. return;
  6969. #endif
  6970. }
  6971. /* Close multi and leading connections
  6972. * Completions for ramrods are collected in a synchronous way
  6973. */
  6974. for_each_queue(bp, i)
  6975. if (bnx2x_stop_queue(bp, i))
  6976. #ifdef BNX2X_STOP_ON_ERROR
  6977. return;
  6978. #else
  6979. goto unload_error;
  6980. #endif
  6981. /* If SP settings didn't get completed so far - something
  6982. * very wrong has happen.
  6983. */
  6984. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  6985. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  6986. #ifndef BNX2X_STOP_ON_ERROR
  6987. unload_error:
  6988. #endif
  6989. rc = bnx2x_func_stop(bp);
  6990. if (rc) {
  6991. BNX2X_ERR("Function stop failed!\n");
  6992. #ifdef BNX2X_STOP_ON_ERROR
  6993. return;
  6994. #endif
  6995. }
  6996. /* Disable HW interrupts, NAPI */
  6997. bnx2x_netif_stop(bp, 1);
  6998. /* Release IRQs */
  6999. bnx2x_free_irq(bp);
  7000. /* Reset the chip */
  7001. rc = bnx2x_reset_hw(bp, reset_code);
  7002. if (rc)
  7003. BNX2X_ERR("HW_RESET failed\n");
  7004. /* Report UNLOAD_DONE to MCP */
  7005. bnx2x_send_unload_done(bp);
  7006. }
  7007. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7008. {
  7009. u32 val;
  7010. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7011. if (CHIP_IS_E1(bp)) {
  7012. int port = BP_PORT(bp);
  7013. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7014. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7015. val = REG_RD(bp, addr);
  7016. val &= ~(0x300);
  7017. REG_WR(bp, addr, val);
  7018. } else {
  7019. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7020. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7021. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7022. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7023. }
  7024. }
  7025. /* Close gates #2, #3 and #4: */
  7026. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7027. {
  7028. u32 val;
  7029. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7030. if (!CHIP_IS_E1(bp)) {
  7031. /* #4 */
  7032. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7033. /* #2 */
  7034. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7035. }
  7036. /* #3 */
  7037. if (CHIP_IS_E1x(bp)) {
  7038. /* Prevent interrupts from HC on both ports */
  7039. val = REG_RD(bp, HC_REG_CONFIG_1);
  7040. REG_WR(bp, HC_REG_CONFIG_1,
  7041. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7042. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7043. val = REG_RD(bp, HC_REG_CONFIG_0);
  7044. REG_WR(bp, HC_REG_CONFIG_0,
  7045. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7046. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7047. } else {
  7048. /* Prevent incomming interrupts in IGU */
  7049. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7050. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7051. (!close) ?
  7052. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7053. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7054. }
  7055. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7056. close ? "closing" : "opening");
  7057. mmiowb();
  7058. }
  7059. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7060. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7061. {
  7062. /* Do some magic... */
  7063. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7064. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7065. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7066. }
  7067. /**
  7068. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7069. *
  7070. * @bp: driver handle
  7071. * @magic_val: old value of the `magic' bit.
  7072. */
  7073. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7074. {
  7075. /* Restore the `magic' bit value... */
  7076. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7077. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7078. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7079. }
  7080. /**
  7081. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7082. *
  7083. * @bp: driver handle
  7084. * @magic_val: old value of 'magic' bit.
  7085. *
  7086. * Takes care of CLP configurations.
  7087. */
  7088. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7089. {
  7090. u32 shmem;
  7091. u32 validity_offset;
  7092. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7093. /* Set `magic' bit in order to save MF config */
  7094. if (!CHIP_IS_E1(bp))
  7095. bnx2x_clp_reset_prep(bp, magic_val);
  7096. /* Get shmem offset */
  7097. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7098. validity_offset = offsetof(struct shmem_region, validity_map[0]);
  7099. /* Clear validity map flags */
  7100. if (shmem > 0)
  7101. REG_WR(bp, shmem + validity_offset, 0);
  7102. }
  7103. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7104. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7105. /**
  7106. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7107. *
  7108. * @bp: driver handle
  7109. */
  7110. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7111. {
  7112. /* special handling for emulation and FPGA,
  7113. wait 10 times longer */
  7114. if (CHIP_REV_IS_SLOW(bp))
  7115. msleep(MCP_ONE_TIMEOUT*10);
  7116. else
  7117. msleep(MCP_ONE_TIMEOUT);
  7118. }
  7119. /*
  7120. * initializes bp->common.shmem_base and waits for validity signature to appear
  7121. */
  7122. static int bnx2x_init_shmem(struct bnx2x *bp)
  7123. {
  7124. int cnt = 0;
  7125. u32 val = 0;
  7126. do {
  7127. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7128. if (bp->common.shmem_base) {
  7129. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7130. if (val & SHR_MEM_VALIDITY_MB)
  7131. return 0;
  7132. }
  7133. bnx2x_mcp_wait_one(bp);
  7134. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7135. BNX2X_ERR("BAD MCP validity signature\n");
  7136. return -ENODEV;
  7137. }
  7138. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7139. {
  7140. int rc = bnx2x_init_shmem(bp);
  7141. /* Restore the `magic' bit value */
  7142. if (!CHIP_IS_E1(bp))
  7143. bnx2x_clp_reset_done(bp, magic_val);
  7144. return rc;
  7145. }
  7146. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7147. {
  7148. if (!CHIP_IS_E1(bp)) {
  7149. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7150. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7151. mmiowb();
  7152. }
  7153. }
  7154. /*
  7155. * Reset the whole chip except for:
  7156. * - PCIE core
  7157. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7158. * one reset bit)
  7159. * - IGU
  7160. * - MISC (including AEU)
  7161. * - GRC
  7162. * - RBCN, RBCP
  7163. */
  7164. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7165. {
  7166. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7167. u32 global_bits2, stay_reset2;
  7168. /*
  7169. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7170. * (per chip) blocks.
  7171. */
  7172. global_bits2 =
  7173. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7174. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7175. /* Don't reset the following blocks */
  7176. not_reset_mask1 =
  7177. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7178. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7179. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7180. not_reset_mask2 =
  7181. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7182. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7183. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7184. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7185. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7186. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7187. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7188. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7189. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7190. MISC_REGISTERS_RESET_REG_2_PGLC;
  7191. /*
  7192. * Keep the following blocks in reset:
  7193. * - all xxMACs are handled by the bnx2x_link code.
  7194. */
  7195. stay_reset2 =
  7196. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7197. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7198. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7199. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7200. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7201. MISC_REGISTERS_RESET_REG_2_UMAC1 |
  7202. MISC_REGISTERS_RESET_REG_2_XMAC |
  7203. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7204. /* Full reset masks according to the chip */
  7205. reset_mask1 = 0xffffffff;
  7206. if (CHIP_IS_E1(bp))
  7207. reset_mask2 = 0xffff;
  7208. else if (CHIP_IS_E1H(bp))
  7209. reset_mask2 = 0x1ffff;
  7210. else if (CHIP_IS_E2(bp))
  7211. reset_mask2 = 0xfffff;
  7212. else /* CHIP_IS_E3 */
  7213. reset_mask2 = 0x3ffffff;
  7214. /* Don't reset global blocks unless we need to */
  7215. if (!global)
  7216. reset_mask2 &= ~global_bits2;
  7217. /*
  7218. * In case of attention in the QM, we need to reset PXP
  7219. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7220. * because otherwise QM reset would release 'close the gates' shortly
  7221. * before resetting the PXP, then the PSWRQ would send a write
  7222. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7223. * read the payload data from PSWWR, but PSWWR would not
  7224. * respond. The write queue in PGLUE would stuck, dmae commands
  7225. * would not return. Therefore it's important to reset the second
  7226. * reset register (containing the
  7227. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7228. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7229. * bit).
  7230. */
  7231. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7232. reset_mask2 & (~not_reset_mask2));
  7233. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7234. reset_mask1 & (~not_reset_mask1));
  7235. barrier();
  7236. mmiowb();
  7237. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7238. reset_mask2 & (~stay_reset2));
  7239. barrier();
  7240. mmiowb();
  7241. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7242. mmiowb();
  7243. }
  7244. /**
  7245. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7246. * It should get cleared in no more than 1s.
  7247. *
  7248. * @bp: driver handle
  7249. *
  7250. * It should get cleared in no more than 1s. Returns 0 if
  7251. * pending writes bit gets cleared.
  7252. */
  7253. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7254. {
  7255. u32 cnt = 1000;
  7256. u32 pend_bits = 0;
  7257. do {
  7258. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7259. if (pend_bits == 0)
  7260. break;
  7261. usleep_range(1000, 1000);
  7262. } while (cnt-- > 0);
  7263. if (cnt <= 0) {
  7264. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7265. pend_bits);
  7266. return -EBUSY;
  7267. }
  7268. return 0;
  7269. }
  7270. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7271. {
  7272. int cnt = 1000;
  7273. u32 val = 0;
  7274. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7275. /* Empty the Tetris buffer, wait for 1s */
  7276. do {
  7277. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7278. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7279. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7280. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7281. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7282. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7283. ((port_is_idle_0 & 0x1) == 0x1) &&
  7284. ((port_is_idle_1 & 0x1) == 0x1) &&
  7285. (pgl_exp_rom2 == 0xffffffff))
  7286. break;
  7287. usleep_range(1000, 1000);
  7288. } while (cnt-- > 0);
  7289. if (cnt <= 0) {
  7290. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7291. BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
  7292. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7293. pgl_exp_rom2);
  7294. return -EAGAIN;
  7295. }
  7296. barrier();
  7297. /* Close gates #2, #3 and #4 */
  7298. bnx2x_set_234_gates(bp, true);
  7299. /* Poll for IGU VQs for 57712 and newer chips */
  7300. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7301. return -EAGAIN;
  7302. /* TBD: Indicate that "process kill" is in progress to MCP */
  7303. /* Clear "unprepared" bit */
  7304. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7305. barrier();
  7306. /* Make sure all is written to the chip before the reset */
  7307. mmiowb();
  7308. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7309. * PSWHST, GRC and PSWRD Tetris buffer.
  7310. */
  7311. usleep_range(1000, 1000);
  7312. /* Prepare to chip reset: */
  7313. /* MCP */
  7314. if (global)
  7315. bnx2x_reset_mcp_prep(bp, &val);
  7316. /* PXP */
  7317. bnx2x_pxp_prep(bp);
  7318. barrier();
  7319. /* reset the chip */
  7320. bnx2x_process_kill_chip_reset(bp, global);
  7321. barrier();
  7322. /* Recover after reset: */
  7323. /* MCP */
  7324. if (global && bnx2x_reset_mcp_comp(bp, val))
  7325. return -EAGAIN;
  7326. /* TBD: Add resetting the NO_MCP mode DB here */
  7327. /* PXP */
  7328. bnx2x_pxp_prep(bp);
  7329. /* Open the gates #2, #3 and #4 */
  7330. bnx2x_set_234_gates(bp, false);
  7331. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7332. * reset state, re-enable attentions. */
  7333. return 0;
  7334. }
  7335. int bnx2x_leader_reset(struct bnx2x *bp)
  7336. {
  7337. int rc = 0;
  7338. bool global = bnx2x_reset_is_global(bp);
  7339. u32 load_code;
  7340. /* if not going to reset MCP - load "fake" driver to reset HW while
  7341. * driver is owner of the HW
  7342. */
  7343. if (!global && !BP_NOMCP(bp)) {
  7344. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
  7345. if (!load_code) {
  7346. BNX2X_ERR("MCP response failure, aborting\n");
  7347. rc = -EAGAIN;
  7348. goto exit_leader_reset;
  7349. }
  7350. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7351. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7352. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7353. rc = -EAGAIN;
  7354. goto exit_leader_reset2;
  7355. }
  7356. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7357. if (!load_code) {
  7358. BNX2X_ERR("MCP response failure, aborting\n");
  7359. rc = -EAGAIN;
  7360. goto exit_leader_reset2;
  7361. }
  7362. }
  7363. /* Try to recover after the failure */
  7364. if (bnx2x_process_kill(bp, global)) {
  7365. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7366. BP_PATH(bp));
  7367. rc = -EAGAIN;
  7368. goto exit_leader_reset2;
  7369. }
  7370. /*
  7371. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7372. * state.
  7373. */
  7374. bnx2x_set_reset_done(bp);
  7375. if (global)
  7376. bnx2x_clear_reset_global(bp);
  7377. exit_leader_reset2:
  7378. /* unload "fake driver" if it was loaded */
  7379. if (!global && !BP_NOMCP(bp)) {
  7380. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7381. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7382. }
  7383. exit_leader_reset:
  7384. bp->is_leader = 0;
  7385. bnx2x_release_leader_lock(bp);
  7386. smp_mb();
  7387. return rc;
  7388. }
  7389. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7390. {
  7391. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7392. /* Disconnect this device */
  7393. netif_device_detach(bp->dev);
  7394. /*
  7395. * Block ifup for all function on this engine until "process kill"
  7396. * or power cycle.
  7397. */
  7398. bnx2x_set_reset_in_progress(bp);
  7399. /* Shut down the power */
  7400. bnx2x_set_power_state(bp, PCI_D3hot);
  7401. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7402. smp_mb();
  7403. }
  7404. /*
  7405. * Assumption: runs under rtnl lock. This together with the fact
  7406. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7407. * will never be called when netif_running(bp->dev) is false.
  7408. */
  7409. static void bnx2x_parity_recover(struct bnx2x *bp)
  7410. {
  7411. bool global = false;
  7412. u32 error_recovered, error_unrecovered;
  7413. bool is_parity;
  7414. DP(NETIF_MSG_HW, "Handling parity\n");
  7415. while (1) {
  7416. switch (bp->recovery_state) {
  7417. case BNX2X_RECOVERY_INIT:
  7418. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7419. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7420. WARN_ON(!is_parity);
  7421. /* Try to get a LEADER_LOCK HW lock */
  7422. if (bnx2x_trylock_leader_lock(bp)) {
  7423. bnx2x_set_reset_in_progress(bp);
  7424. /*
  7425. * Check if there is a global attention and if
  7426. * there was a global attention, set the global
  7427. * reset bit.
  7428. */
  7429. if (global)
  7430. bnx2x_set_reset_global(bp);
  7431. bp->is_leader = 1;
  7432. }
  7433. /* Stop the driver */
  7434. /* If interface has been removed - break */
  7435. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
  7436. return;
  7437. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7438. /* Ensure "is_leader", MCP command sequence and
  7439. * "recovery_state" update values are seen on other
  7440. * CPUs.
  7441. */
  7442. smp_mb();
  7443. break;
  7444. case BNX2X_RECOVERY_WAIT:
  7445. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7446. if (bp->is_leader) {
  7447. int other_engine = BP_PATH(bp) ? 0 : 1;
  7448. bool other_load_status =
  7449. bnx2x_get_load_status(bp, other_engine);
  7450. bool load_status =
  7451. bnx2x_get_load_status(bp, BP_PATH(bp));
  7452. global = bnx2x_reset_is_global(bp);
  7453. /*
  7454. * In case of a parity in a global block, let
  7455. * the first leader that performs a
  7456. * leader_reset() reset the global blocks in
  7457. * order to clear global attentions. Otherwise
  7458. * the the gates will remain closed for that
  7459. * engine.
  7460. */
  7461. if (load_status ||
  7462. (global && other_load_status)) {
  7463. /* Wait until all other functions get
  7464. * down.
  7465. */
  7466. schedule_delayed_work(&bp->sp_rtnl_task,
  7467. HZ/10);
  7468. return;
  7469. } else {
  7470. /* If all other functions got down -
  7471. * try to bring the chip back to
  7472. * normal. In any case it's an exit
  7473. * point for a leader.
  7474. */
  7475. if (bnx2x_leader_reset(bp)) {
  7476. bnx2x_recovery_failed(bp);
  7477. return;
  7478. }
  7479. /* If we are here, means that the
  7480. * leader has succeeded and doesn't
  7481. * want to be a leader any more. Try
  7482. * to continue as a none-leader.
  7483. */
  7484. break;
  7485. }
  7486. } else { /* non-leader */
  7487. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7488. /* Try to get a LEADER_LOCK HW lock as
  7489. * long as a former leader may have
  7490. * been unloaded by the user or
  7491. * released a leadership by another
  7492. * reason.
  7493. */
  7494. if (bnx2x_trylock_leader_lock(bp)) {
  7495. /* I'm a leader now! Restart a
  7496. * switch case.
  7497. */
  7498. bp->is_leader = 1;
  7499. break;
  7500. }
  7501. schedule_delayed_work(&bp->sp_rtnl_task,
  7502. HZ/10);
  7503. return;
  7504. } else {
  7505. /*
  7506. * If there was a global attention, wait
  7507. * for it to be cleared.
  7508. */
  7509. if (bnx2x_reset_is_global(bp)) {
  7510. schedule_delayed_work(
  7511. &bp->sp_rtnl_task,
  7512. HZ/10);
  7513. return;
  7514. }
  7515. error_recovered =
  7516. bp->eth_stats.recoverable_error;
  7517. error_unrecovered =
  7518. bp->eth_stats.unrecoverable_error;
  7519. bp->recovery_state =
  7520. BNX2X_RECOVERY_NIC_LOADING;
  7521. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7522. error_unrecovered++;
  7523. netdev_err(bp->dev,
  7524. "Recovery failed. Power cycle needed\n");
  7525. /* Disconnect this device */
  7526. netif_device_detach(bp->dev);
  7527. /* Shut down the power */
  7528. bnx2x_set_power_state(
  7529. bp, PCI_D3hot);
  7530. smp_mb();
  7531. } else {
  7532. bp->recovery_state =
  7533. BNX2X_RECOVERY_DONE;
  7534. error_recovered++;
  7535. smp_mb();
  7536. }
  7537. bp->eth_stats.recoverable_error =
  7538. error_recovered;
  7539. bp->eth_stats.unrecoverable_error =
  7540. error_unrecovered;
  7541. return;
  7542. }
  7543. }
  7544. default:
  7545. return;
  7546. }
  7547. }
  7548. }
  7549. static int bnx2x_close(struct net_device *dev);
  7550. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7551. * scheduled on a general queue in order to prevent a dead lock.
  7552. */
  7553. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7554. {
  7555. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7556. rtnl_lock();
  7557. if (!netif_running(bp->dev))
  7558. goto sp_rtnl_exit;
  7559. /* if stop on error is defined no recovery flows should be executed */
  7560. #ifdef BNX2X_STOP_ON_ERROR
  7561. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7562. "you will need to reboot when done\n");
  7563. goto sp_rtnl_not_reset;
  7564. #endif
  7565. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7566. /*
  7567. * Clear all pending SP commands as we are going to reset the
  7568. * function anyway.
  7569. */
  7570. bp->sp_rtnl_state = 0;
  7571. smp_mb();
  7572. bnx2x_parity_recover(bp);
  7573. goto sp_rtnl_exit;
  7574. }
  7575. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7576. /*
  7577. * Clear all pending SP commands as we are going to reset the
  7578. * function anyway.
  7579. */
  7580. bp->sp_rtnl_state = 0;
  7581. smp_mb();
  7582. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7583. bnx2x_nic_load(bp, LOAD_NORMAL);
  7584. goto sp_rtnl_exit;
  7585. }
  7586. #ifdef BNX2X_STOP_ON_ERROR
  7587. sp_rtnl_not_reset:
  7588. #endif
  7589. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7590. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7591. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7592. bnx2x_after_function_update(bp);
  7593. /*
  7594. * in case of fan failure we need to reset id if the "stop on error"
  7595. * debug flag is set, since we trying to prevent permanent overheating
  7596. * damage
  7597. */
  7598. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7599. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7600. netif_device_detach(bp->dev);
  7601. bnx2x_close(bp->dev);
  7602. }
  7603. sp_rtnl_exit:
  7604. rtnl_unlock();
  7605. }
  7606. /* end of nic load/unload */
  7607. static void bnx2x_period_task(struct work_struct *work)
  7608. {
  7609. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7610. if (!netif_running(bp->dev))
  7611. goto period_task_exit;
  7612. if (CHIP_REV_IS_SLOW(bp)) {
  7613. BNX2X_ERR("period task called on emulation, ignoring\n");
  7614. goto period_task_exit;
  7615. }
  7616. bnx2x_acquire_phy_lock(bp);
  7617. /*
  7618. * The barrier is needed to ensure the ordering between the writing to
  7619. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7620. * the reading here.
  7621. */
  7622. smp_mb();
  7623. if (bp->port.pmf) {
  7624. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7625. /* Re-queue task in 1 sec */
  7626. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7627. }
  7628. bnx2x_release_phy_lock(bp);
  7629. period_task_exit:
  7630. return;
  7631. }
  7632. /*
  7633. * Init service functions
  7634. */
  7635. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7636. {
  7637. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7638. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7639. return base + (BP_ABS_FUNC(bp)) * stride;
  7640. }
  7641. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7642. {
  7643. u32 reg = bnx2x_get_pretend_reg(bp);
  7644. /* Flush all outstanding writes */
  7645. mmiowb();
  7646. /* Pretend to be function 0 */
  7647. REG_WR(bp, reg, 0);
  7648. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7649. /* From now we are in the "like-E1" mode */
  7650. bnx2x_int_disable(bp);
  7651. /* Flush all outstanding writes */
  7652. mmiowb();
  7653. /* Restore the original function */
  7654. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7655. REG_RD(bp, reg);
  7656. }
  7657. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7658. {
  7659. if (CHIP_IS_E1(bp))
  7660. bnx2x_int_disable(bp);
  7661. else
  7662. bnx2x_undi_int_disable_e1h(bp);
  7663. }
  7664. static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
  7665. {
  7666. u32 val, base_addr, offset, mask, reset_reg;
  7667. bool mac_stopped = false;
  7668. u8 port = BP_PORT(bp);
  7669. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7670. if (!CHIP_IS_E3(bp)) {
  7671. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7672. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7673. if ((mask & reset_reg) && val) {
  7674. u32 wb_data[2];
  7675. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7676. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7677. : NIG_REG_INGRESS_BMAC0_MEM;
  7678. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7679. : BIGMAC_REGISTER_BMAC_CONTROL;
  7680. /*
  7681. * use rd/wr since we cannot use dmae. This is safe
  7682. * since MCP won't access the bus due to the request
  7683. * to unload, and no function on the path can be
  7684. * loaded at this time.
  7685. */
  7686. wb_data[0] = REG_RD(bp, base_addr + offset);
  7687. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  7688. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  7689. REG_WR(bp, base_addr + offset, wb_data[0]);
  7690. REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
  7691. }
  7692. BNX2X_DEV_INFO("Disable emac Rx\n");
  7693. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
  7694. mac_stopped = true;
  7695. } else {
  7696. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  7697. BNX2X_DEV_INFO("Disable xmac Rx\n");
  7698. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  7699. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  7700. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7701. val & ~(1 << 1));
  7702. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7703. val | (1 << 1));
  7704. REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
  7705. mac_stopped = true;
  7706. }
  7707. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  7708. if (mask & reset_reg) {
  7709. BNX2X_DEV_INFO("Disable umac Rx\n");
  7710. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  7711. REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
  7712. mac_stopped = true;
  7713. }
  7714. }
  7715. if (mac_stopped)
  7716. msleep(20);
  7717. }
  7718. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  7719. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  7720. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  7721. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  7722. static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
  7723. u8 inc)
  7724. {
  7725. u16 rcq, bd;
  7726. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  7727. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  7728. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  7729. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  7730. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  7731. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  7732. port, bd, rcq);
  7733. }
  7734. static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
  7735. {
  7736. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7737. if (!rc) {
  7738. BNX2X_ERR("MCP response failure, aborting\n");
  7739. return -EBUSY;
  7740. }
  7741. return 0;
  7742. }
  7743. static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
  7744. {
  7745. struct bnx2x_prev_path_list *tmp_list;
  7746. int rc = false;
  7747. if (down_trylock(&bnx2x_prev_sem))
  7748. return false;
  7749. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  7750. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7751. bp->pdev->bus->number == tmp_list->bus &&
  7752. BP_PATH(bp) == tmp_list->path) {
  7753. rc = true;
  7754. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  7755. BP_PATH(bp));
  7756. break;
  7757. }
  7758. }
  7759. up(&bnx2x_prev_sem);
  7760. return rc;
  7761. }
  7762. static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
  7763. {
  7764. struct bnx2x_prev_path_list *tmp_list;
  7765. int rc;
  7766. tmp_list = (struct bnx2x_prev_path_list *)
  7767. kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  7768. if (!tmp_list) {
  7769. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  7770. return -ENOMEM;
  7771. }
  7772. tmp_list->bus = bp->pdev->bus->number;
  7773. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  7774. tmp_list->path = BP_PATH(bp);
  7775. rc = down_interruptible(&bnx2x_prev_sem);
  7776. if (rc) {
  7777. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  7778. kfree(tmp_list);
  7779. } else {
  7780. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  7781. BP_PATH(bp));
  7782. list_add(&tmp_list->list, &bnx2x_prev_list);
  7783. up(&bnx2x_prev_sem);
  7784. }
  7785. return rc;
  7786. }
  7787. static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
  7788. {
  7789. int pos;
  7790. u32 cap;
  7791. struct pci_dev *dev = bp->pdev;
  7792. pos = pci_pcie_cap(dev);
  7793. if (!pos)
  7794. return false;
  7795. pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap);
  7796. if (!(cap & PCI_EXP_DEVCAP_FLR))
  7797. return false;
  7798. return true;
  7799. }
  7800. static int __devinit bnx2x_do_flr(struct bnx2x *bp)
  7801. {
  7802. int i, pos;
  7803. u16 status;
  7804. struct pci_dev *dev = bp->pdev;
  7805. /* probe the capability first */
  7806. if (bnx2x_can_flr(bp))
  7807. return -ENOTTY;
  7808. pos = pci_pcie_cap(dev);
  7809. if (!pos)
  7810. return -ENOTTY;
  7811. /* Wait for Transaction Pending bit clean */
  7812. for (i = 0; i < 4; i++) {
  7813. if (i)
  7814. msleep((1 << (i - 1)) * 100);
  7815. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  7816. if (!(status & PCI_EXP_DEVSTA_TRPND))
  7817. goto clear;
  7818. }
  7819. dev_err(&dev->dev,
  7820. "transaction is not cleared; proceeding with reset anyway\n");
  7821. clear:
  7822. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  7823. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  7824. bp->common.bc_ver);
  7825. return -EINVAL;
  7826. }
  7827. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  7828. return 0;
  7829. }
  7830. static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  7831. {
  7832. int rc;
  7833. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  7834. /* Test if previous unload process was already finished for this path */
  7835. if (bnx2x_prev_is_path_marked(bp))
  7836. return bnx2x_prev_mcp_done(bp);
  7837. /* If function has FLR capabilities, and existing FW version matches
  7838. * the one required, then FLR will be sufficient to clean any residue
  7839. * left by previous driver
  7840. */
  7841. if (bnx2x_test_firmware_version(bp, false) && bnx2x_can_flr(bp))
  7842. return bnx2x_do_flr(bp);
  7843. /* Close the MCP request, return failure*/
  7844. rc = bnx2x_prev_mcp_done(bp);
  7845. if (!rc)
  7846. rc = BNX2X_PREV_WAIT_NEEDED;
  7847. return rc;
  7848. }
  7849. static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
  7850. {
  7851. u32 reset_reg, tmp_reg = 0, rc;
  7852. /* It is possible a previous function received 'common' answer,
  7853. * but hasn't loaded yet, therefore creating a scenario of
  7854. * multiple functions receiving 'common' on the same path.
  7855. */
  7856. BNX2X_DEV_INFO("Common unload Flow\n");
  7857. if (bnx2x_prev_is_path_marked(bp))
  7858. return bnx2x_prev_mcp_done(bp);
  7859. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7860. /* Reset should be performed after BRB is emptied */
  7861. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  7862. u32 timer_count = 1000;
  7863. bool prev_undi = false;
  7864. /* Close the MAC Rx to prevent BRB from filling up */
  7865. bnx2x_prev_unload_close_mac(bp);
  7866. /* Check if the UNDI driver was previously loaded
  7867. * UNDI driver initializes CID offset for normal bell to 0x7
  7868. */
  7869. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7870. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  7871. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  7872. if (tmp_reg == 0x7) {
  7873. BNX2X_DEV_INFO("UNDI previously loaded\n");
  7874. prev_undi = true;
  7875. /* clear the UNDI indication */
  7876. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  7877. }
  7878. }
  7879. /* wait until BRB is empty */
  7880. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7881. while (timer_count) {
  7882. u32 prev_brb = tmp_reg;
  7883. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7884. if (!tmp_reg)
  7885. break;
  7886. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  7887. /* reset timer as long as BRB actually gets emptied */
  7888. if (prev_brb > tmp_reg)
  7889. timer_count = 1000;
  7890. else
  7891. timer_count--;
  7892. /* If UNDI resides in memory, manually increment it */
  7893. if (prev_undi)
  7894. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  7895. udelay(10);
  7896. }
  7897. if (!timer_count)
  7898. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  7899. }
  7900. /* No packets are in the pipeline, path is ready for reset */
  7901. bnx2x_reset_common(bp);
  7902. rc = bnx2x_prev_mark_path(bp);
  7903. if (rc) {
  7904. bnx2x_prev_mcp_done(bp);
  7905. return rc;
  7906. }
  7907. return bnx2x_prev_mcp_done(bp);
  7908. }
  7909. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  7910. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  7911. * the addresses of the transaction, resulting in was-error bit set in the pci
  7912. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  7913. * to clear the interrupt which detected this from the pglueb and the was done
  7914. * bit
  7915. */
  7916. static void __devinit bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  7917. {
  7918. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  7919. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  7920. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  7921. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << BP_FUNC(bp));
  7922. }
  7923. }
  7924. static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
  7925. {
  7926. int time_counter = 10;
  7927. u32 rc, fw, hw_lock_reg, hw_lock_val;
  7928. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  7929. /* clear hw from errors which may have resulted from an interrupted
  7930. * dmae transaction.
  7931. */
  7932. bnx2x_prev_interrupted_dmae(bp);
  7933. /* Release previously held locks */
  7934. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  7935. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  7936. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  7937. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  7938. if (hw_lock_val) {
  7939. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  7940. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  7941. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  7942. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  7943. }
  7944. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  7945. REG_WR(bp, hw_lock_reg, 0xffffffff);
  7946. } else
  7947. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  7948. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  7949. BNX2X_DEV_INFO("Release previously held alr\n");
  7950. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  7951. }
  7952. do {
  7953. /* Lock MCP using an unload request */
  7954. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  7955. if (!fw) {
  7956. BNX2X_ERR("MCP response failure, aborting\n");
  7957. rc = -EBUSY;
  7958. break;
  7959. }
  7960. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  7961. rc = bnx2x_prev_unload_common(bp);
  7962. break;
  7963. }
  7964. /* non-common reply from MCP night require looping */
  7965. rc = bnx2x_prev_unload_uncommon(bp);
  7966. if (rc != BNX2X_PREV_WAIT_NEEDED)
  7967. break;
  7968. msleep(20);
  7969. } while (--time_counter);
  7970. if (!time_counter || rc) {
  7971. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  7972. rc = -EBUSY;
  7973. }
  7974. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  7975. return rc;
  7976. }
  7977. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  7978. {
  7979. u32 val, val2, val3, val4, id, boot_mode;
  7980. u16 pmc;
  7981. /* Get the chip revision id and number. */
  7982. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  7983. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  7984. id = ((val & 0xffff) << 16);
  7985. val = REG_RD(bp, MISC_REG_CHIP_REV);
  7986. id |= ((val & 0xf) << 12);
  7987. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  7988. id |= ((val & 0xff) << 4);
  7989. val = REG_RD(bp, MISC_REG_BOND_ID);
  7990. id |= (val & 0xf);
  7991. bp->common.chip_id = id;
  7992. /* force 57811 according to MISC register */
  7993. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  7994. if (CHIP_IS_57810(bp))
  7995. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  7996. (bp->common.chip_id & 0x0000FFFF);
  7997. else if (CHIP_IS_57810_MF(bp))
  7998. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  7999. (bp->common.chip_id & 0x0000FFFF);
  8000. bp->common.chip_id |= 0x1;
  8001. }
  8002. /* Set doorbell size */
  8003. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8004. if (!CHIP_IS_E1x(bp)) {
  8005. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8006. if ((val & 1) == 0)
  8007. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8008. else
  8009. val = (val >> 1) & 1;
  8010. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8011. "2_PORT_MODE");
  8012. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8013. CHIP_2_PORT_MODE;
  8014. if (CHIP_MODE_IS_4_PORT(bp))
  8015. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8016. else
  8017. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8018. } else {
  8019. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8020. bp->pfid = bp->pf_num; /* 0..7 */
  8021. }
  8022. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8023. bp->link_params.chip_id = bp->common.chip_id;
  8024. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8025. val = (REG_RD(bp, 0x2874) & 0x55);
  8026. if ((bp->common.chip_id & 0x1) ||
  8027. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8028. bp->flags |= ONE_PORT_FLAG;
  8029. BNX2X_DEV_INFO("single port device\n");
  8030. }
  8031. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8032. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8033. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8034. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8035. bp->common.flash_size, bp->common.flash_size);
  8036. bnx2x_init_shmem(bp);
  8037. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8038. MISC_REG_GENERIC_CR_1 :
  8039. MISC_REG_GENERIC_CR_0));
  8040. bp->link_params.shmem_base = bp->common.shmem_base;
  8041. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8042. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8043. bp->common.shmem_base, bp->common.shmem2_base);
  8044. if (!bp->common.shmem_base) {
  8045. BNX2X_DEV_INFO("MCP not active\n");
  8046. bp->flags |= NO_MCP_FLAG;
  8047. return;
  8048. }
  8049. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8050. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8051. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8052. SHARED_HW_CFG_LED_MODE_MASK) >>
  8053. SHARED_HW_CFG_LED_MODE_SHIFT);
  8054. bp->link_params.feature_config_flags = 0;
  8055. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8056. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8057. bp->link_params.feature_config_flags |=
  8058. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8059. else
  8060. bp->link_params.feature_config_flags &=
  8061. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8062. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8063. bp->common.bc_ver = val;
  8064. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8065. if (val < BNX2X_BC_VER) {
  8066. /* for now only warn
  8067. * later we might need to enforce this */
  8068. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8069. BNX2X_BC_VER, val);
  8070. }
  8071. bp->link_params.feature_config_flags |=
  8072. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8073. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8074. bp->link_params.feature_config_flags |=
  8075. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8076. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8077. bp->link_params.feature_config_flags |=
  8078. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8079. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8080. bp->link_params.feature_config_flags |=
  8081. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8082. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8083. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8084. BC_SUPPORTS_PFC_STATS : 0;
  8085. boot_mode = SHMEM_RD(bp,
  8086. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8087. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8088. switch (boot_mode) {
  8089. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8090. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8091. break;
  8092. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8093. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8094. break;
  8095. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8096. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8097. break;
  8098. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8099. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8100. break;
  8101. }
  8102. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8103. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8104. BNX2X_DEV_INFO("%sWoL capable\n",
  8105. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8106. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8107. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8108. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8109. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8110. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8111. val, val2, val3, val4);
  8112. }
  8113. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8114. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8115. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8116. {
  8117. int pfid = BP_FUNC(bp);
  8118. int igu_sb_id;
  8119. u32 val;
  8120. u8 fid, igu_sb_cnt = 0;
  8121. bp->igu_base_sb = 0xff;
  8122. if (CHIP_INT_MODE_IS_BC(bp)) {
  8123. int vn = BP_VN(bp);
  8124. igu_sb_cnt = bp->igu_sb_cnt;
  8125. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8126. FP_SB_MAX_E1x;
  8127. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8128. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8129. return;
  8130. }
  8131. /* IGU in normal mode - read CAM */
  8132. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8133. igu_sb_id++) {
  8134. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8135. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8136. continue;
  8137. fid = IGU_FID(val);
  8138. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8139. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8140. continue;
  8141. if (IGU_VEC(val) == 0)
  8142. /* default status block */
  8143. bp->igu_dsb_id = igu_sb_id;
  8144. else {
  8145. if (bp->igu_base_sb == 0xff)
  8146. bp->igu_base_sb = igu_sb_id;
  8147. igu_sb_cnt++;
  8148. }
  8149. }
  8150. }
  8151. #ifdef CONFIG_PCI_MSI
  8152. /*
  8153. * It's expected that number of CAM entries for this functions is equal
  8154. * to the number evaluated based on the MSI-X table size. We want a
  8155. * harsh warning if these values are different!
  8156. */
  8157. WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
  8158. #endif
  8159. if (igu_sb_cnt == 0)
  8160. BNX2X_ERR("CAM configuration error\n");
  8161. }
  8162. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  8163. u32 switch_cfg)
  8164. {
  8165. int cfg_size = 0, idx, port = BP_PORT(bp);
  8166. /* Aggregation of supported attributes of all external phys */
  8167. bp->port.supported[0] = 0;
  8168. bp->port.supported[1] = 0;
  8169. switch (bp->link_params.num_phys) {
  8170. case 1:
  8171. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8172. cfg_size = 1;
  8173. break;
  8174. case 2:
  8175. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8176. cfg_size = 1;
  8177. break;
  8178. case 3:
  8179. if (bp->link_params.multi_phy_config &
  8180. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8181. bp->port.supported[1] =
  8182. bp->link_params.phy[EXT_PHY1].supported;
  8183. bp->port.supported[0] =
  8184. bp->link_params.phy[EXT_PHY2].supported;
  8185. } else {
  8186. bp->port.supported[0] =
  8187. bp->link_params.phy[EXT_PHY1].supported;
  8188. bp->port.supported[1] =
  8189. bp->link_params.phy[EXT_PHY2].supported;
  8190. }
  8191. cfg_size = 2;
  8192. break;
  8193. }
  8194. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8195. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8196. SHMEM_RD(bp,
  8197. dev_info.port_hw_config[port].external_phy_config),
  8198. SHMEM_RD(bp,
  8199. dev_info.port_hw_config[port].external_phy_config2));
  8200. return;
  8201. }
  8202. if (CHIP_IS_E3(bp))
  8203. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8204. else {
  8205. switch (switch_cfg) {
  8206. case SWITCH_CFG_1G:
  8207. bp->port.phy_addr = REG_RD(
  8208. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8209. break;
  8210. case SWITCH_CFG_10G:
  8211. bp->port.phy_addr = REG_RD(
  8212. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8213. break;
  8214. default:
  8215. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8216. bp->port.link_config[0]);
  8217. return;
  8218. }
  8219. }
  8220. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8221. /* mask what we support according to speed_cap_mask per configuration */
  8222. for (idx = 0; idx < cfg_size; idx++) {
  8223. if (!(bp->link_params.speed_cap_mask[idx] &
  8224. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8225. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8226. if (!(bp->link_params.speed_cap_mask[idx] &
  8227. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8228. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8229. if (!(bp->link_params.speed_cap_mask[idx] &
  8230. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8231. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8232. if (!(bp->link_params.speed_cap_mask[idx] &
  8233. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8234. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8235. if (!(bp->link_params.speed_cap_mask[idx] &
  8236. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8237. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8238. SUPPORTED_1000baseT_Full);
  8239. if (!(bp->link_params.speed_cap_mask[idx] &
  8240. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8241. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8242. if (!(bp->link_params.speed_cap_mask[idx] &
  8243. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8244. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8245. }
  8246. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8247. bp->port.supported[1]);
  8248. }
  8249. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  8250. {
  8251. u32 link_config, idx, cfg_size = 0;
  8252. bp->port.advertising[0] = 0;
  8253. bp->port.advertising[1] = 0;
  8254. switch (bp->link_params.num_phys) {
  8255. case 1:
  8256. case 2:
  8257. cfg_size = 1;
  8258. break;
  8259. case 3:
  8260. cfg_size = 2;
  8261. break;
  8262. }
  8263. for (idx = 0; idx < cfg_size; idx++) {
  8264. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8265. link_config = bp->port.link_config[idx];
  8266. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8267. case PORT_FEATURE_LINK_SPEED_AUTO:
  8268. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8269. bp->link_params.req_line_speed[idx] =
  8270. SPEED_AUTO_NEG;
  8271. bp->port.advertising[idx] |=
  8272. bp->port.supported[idx];
  8273. if (bp->link_params.phy[EXT_PHY1].type ==
  8274. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8275. bp->port.advertising[idx] |=
  8276. (SUPPORTED_100baseT_Half |
  8277. SUPPORTED_100baseT_Full);
  8278. } else {
  8279. /* force 10G, no AN */
  8280. bp->link_params.req_line_speed[idx] =
  8281. SPEED_10000;
  8282. bp->port.advertising[idx] |=
  8283. (ADVERTISED_10000baseT_Full |
  8284. ADVERTISED_FIBRE);
  8285. continue;
  8286. }
  8287. break;
  8288. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8289. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8290. bp->link_params.req_line_speed[idx] =
  8291. SPEED_10;
  8292. bp->port.advertising[idx] |=
  8293. (ADVERTISED_10baseT_Full |
  8294. ADVERTISED_TP);
  8295. } else {
  8296. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8297. link_config,
  8298. bp->link_params.speed_cap_mask[idx]);
  8299. return;
  8300. }
  8301. break;
  8302. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8303. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8304. bp->link_params.req_line_speed[idx] =
  8305. SPEED_10;
  8306. bp->link_params.req_duplex[idx] =
  8307. DUPLEX_HALF;
  8308. bp->port.advertising[idx] |=
  8309. (ADVERTISED_10baseT_Half |
  8310. ADVERTISED_TP);
  8311. } else {
  8312. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8313. link_config,
  8314. bp->link_params.speed_cap_mask[idx]);
  8315. return;
  8316. }
  8317. break;
  8318. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8319. if (bp->port.supported[idx] &
  8320. SUPPORTED_100baseT_Full) {
  8321. bp->link_params.req_line_speed[idx] =
  8322. SPEED_100;
  8323. bp->port.advertising[idx] |=
  8324. (ADVERTISED_100baseT_Full |
  8325. ADVERTISED_TP);
  8326. } else {
  8327. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8328. link_config,
  8329. bp->link_params.speed_cap_mask[idx]);
  8330. return;
  8331. }
  8332. break;
  8333. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8334. if (bp->port.supported[idx] &
  8335. SUPPORTED_100baseT_Half) {
  8336. bp->link_params.req_line_speed[idx] =
  8337. SPEED_100;
  8338. bp->link_params.req_duplex[idx] =
  8339. DUPLEX_HALF;
  8340. bp->port.advertising[idx] |=
  8341. (ADVERTISED_100baseT_Half |
  8342. ADVERTISED_TP);
  8343. } else {
  8344. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8345. link_config,
  8346. bp->link_params.speed_cap_mask[idx]);
  8347. return;
  8348. }
  8349. break;
  8350. case PORT_FEATURE_LINK_SPEED_1G:
  8351. if (bp->port.supported[idx] &
  8352. SUPPORTED_1000baseT_Full) {
  8353. bp->link_params.req_line_speed[idx] =
  8354. SPEED_1000;
  8355. bp->port.advertising[idx] |=
  8356. (ADVERTISED_1000baseT_Full |
  8357. ADVERTISED_TP);
  8358. } else {
  8359. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8360. link_config,
  8361. bp->link_params.speed_cap_mask[idx]);
  8362. return;
  8363. }
  8364. break;
  8365. case PORT_FEATURE_LINK_SPEED_2_5G:
  8366. if (bp->port.supported[idx] &
  8367. SUPPORTED_2500baseX_Full) {
  8368. bp->link_params.req_line_speed[idx] =
  8369. SPEED_2500;
  8370. bp->port.advertising[idx] |=
  8371. (ADVERTISED_2500baseX_Full |
  8372. ADVERTISED_TP);
  8373. } else {
  8374. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8375. link_config,
  8376. bp->link_params.speed_cap_mask[idx]);
  8377. return;
  8378. }
  8379. break;
  8380. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8381. if (bp->port.supported[idx] &
  8382. SUPPORTED_10000baseT_Full) {
  8383. bp->link_params.req_line_speed[idx] =
  8384. SPEED_10000;
  8385. bp->port.advertising[idx] |=
  8386. (ADVERTISED_10000baseT_Full |
  8387. ADVERTISED_FIBRE);
  8388. } else {
  8389. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8390. link_config,
  8391. bp->link_params.speed_cap_mask[idx]);
  8392. return;
  8393. }
  8394. break;
  8395. case PORT_FEATURE_LINK_SPEED_20G:
  8396. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8397. break;
  8398. default:
  8399. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8400. link_config);
  8401. bp->link_params.req_line_speed[idx] =
  8402. SPEED_AUTO_NEG;
  8403. bp->port.advertising[idx] =
  8404. bp->port.supported[idx];
  8405. break;
  8406. }
  8407. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8408. PORT_FEATURE_FLOW_CONTROL_MASK);
  8409. if ((bp->link_params.req_flow_ctrl[idx] ==
  8410. BNX2X_FLOW_CTRL_AUTO) &&
  8411. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  8412. bp->link_params.req_flow_ctrl[idx] =
  8413. BNX2X_FLOW_CTRL_NONE;
  8414. }
  8415. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8416. bp->link_params.req_line_speed[idx],
  8417. bp->link_params.req_duplex[idx],
  8418. bp->link_params.req_flow_ctrl[idx],
  8419. bp->port.advertising[idx]);
  8420. }
  8421. }
  8422. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8423. {
  8424. mac_hi = cpu_to_be16(mac_hi);
  8425. mac_lo = cpu_to_be32(mac_lo);
  8426. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8427. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8428. }
  8429. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8430. {
  8431. int port = BP_PORT(bp);
  8432. u32 config;
  8433. u32 ext_phy_type, ext_phy_config, eee_mode;
  8434. bp->link_params.bp = bp;
  8435. bp->link_params.port = port;
  8436. bp->link_params.lane_config =
  8437. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8438. bp->link_params.speed_cap_mask[0] =
  8439. SHMEM_RD(bp,
  8440. dev_info.port_hw_config[port].speed_capability_mask);
  8441. bp->link_params.speed_cap_mask[1] =
  8442. SHMEM_RD(bp,
  8443. dev_info.port_hw_config[port].speed_capability_mask2);
  8444. bp->port.link_config[0] =
  8445. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8446. bp->port.link_config[1] =
  8447. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8448. bp->link_params.multi_phy_config =
  8449. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8450. /* If the device is capable of WoL, set the default state according
  8451. * to the HW
  8452. */
  8453. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8454. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8455. (config & PORT_FEATURE_WOL_ENABLED));
  8456. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8457. bp->link_params.lane_config,
  8458. bp->link_params.speed_cap_mask[0],
  8459. bp->port.link_config[0]);
  8460. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8461. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8462. bnx2x_phy_probe(&bp->link_params);
  8463. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8464. bnx2x_link_settings_requested(bp);
  8465. /*
  8466. * If connected directly, work with the internal PHY, otherwise, work
  8467. * with the external PHY
  8468. */
  8469. ext_phy_config =
  8470. SHMEM_RD(bp,
  8471. dev_info.port_hw_config[port].external_phy_config);
  8472. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8473. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8474. bp->mdio.prtad = bp->port.phy_addr;
  8475. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8476. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8477. bp->mdio.prtad =
  8478. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8479. /*
  8480. * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
  8481. * In MF mode, it is set to cover self test cases
  8482. */
  8483. if (IS_MF(bp))
  8484. bp->port.need_hw_lock = 1;
  8485. else
  8486. bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
  8487. bp->common.shmem_base,
  8488. bp->common.shmem2_base);
  8489. /* Configure link feature according to nvram value */
  8490. eee_mode = (((SHMEM_RD(bp, dev_info.
  8491. port_feature_config[port].eee_power_mode)) &
  8492. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8493. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8494. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8495. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8496. EEE_MODE_ENABLE_LPI |
  8497. EEE_MODE_OUTPUT_TIME;
  8498. } else {
  8499. bp->link_params.eee_mode = 0;
  8500. }
  8501. }
  8502. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8503. {
  8504. u32 no_flags = NO_ISCSI_FLAG;
  8505. #ifdef BCM_CNIC
  8506. int port = BP_PORT(bp);
  8507. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8508. drv_lic_key[port].max_iscsi_conn);
  8509. /* Get the number of maximum allowed iSCSI connections */
  8510. bp->cnic_eth_dev.max_iscsi_conn =
  8511. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8512. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8513. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8514. bp->cnic_eth_dev.max_iscsi_conn);
  8515. /*
  8516. * If maximum allowed number of connections is zero -
  8517. * disable the feature.
  8518. */
  8519. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8520. bp->flags |= no_flags;
  8521. #else
  8522. bp->flags |= no_flags;
  8523. #endif
  8524. }
  8525. #ifdef BCM_CNIC
  8526. static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8527. {
  8528. /* Port info */
  8529. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8530. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8531. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8532. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8533. /* Node info */
  8534. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8535. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8536. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8537. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8538. }
  8539. #endif
  8540. static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
  8541. {
  8542. #ifdef BCM_CNIC
  8543. int port = BP_PORT(bp);
  8544. int func = BP_ABS_FUNC(bp);
  8545. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8546. drv_lic_key[port].max_fcoe_conn);
  8547. /* Get the number of maximum allowed FCoE connections */
  8548. bp->cnic_eth_dev.max_fcoe_conn =
  8549. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8550. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8551. /* Read the WWN: */
  8552. if (!IS_MF(bp)) {
  8553. /* Port info */
  8554. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8555. SHMEM_RD(bp,
  8556. dev_info.port_hw_config[port].
  8557. fcoe_wwn_port_name_upper);
  8558. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8559. SHMEM_RD(bp,
  8560. dev_info.port_hw_config[port].
  8561. fcoe_wwn_port_name_lower);
  8562. /* Node info */
  8563. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8564. SHMEM_RD(bp,
  8565. dev_info.port_hw_config[port].
  8566. fcoe_wwn_node_name_upper);
  8567. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8568. SHMEM_RD(bp,
  8569. dev_info.port_hw_config[port].
  8570. fcoe_wwn_node_name_lower);
  8571. } else if (!IS_MF_SD(bp)) {
  8572. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8573. /*
  8574. * Read the WWN info only if the FCoE feature is enabled for
  8575. * this function.
  8576. */
  8577. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
  8578. bnx2x_get_ext_wwn_info(bp, func);
  8579. } else if (IS_MF_FCOE_SD(bp))
  8580. bnx2x_get_ext_wwn_info(bp, func);
  8581. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8582. /*
  8583. * If maximum allowed number of connections is zero -
  8584. * disable the feature.
  8585. */
  8586. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8587. bp->flags |= NO_FCOE_FLAG;
  8588. #else
  8589. bp->flags |= NO_FCOE_FLAG;
  8590. #endif
  8591. }
  8592. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  8593. {
  8594. /*
  8595. * iSCSI may be dynamically disabled but reading
  8596. * info here we will decrease memory usage by driver
  8597. * if the feature is disabled for good
  8598. */
  8599. bnx2x_get_iscsi_info(bp);
  8600. bnx2x_get_fcoe_info(bp);
  8601. }
  8602. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8603. {
  8604. u32 val, val2;
  8605. int func = BP_ABS_FUNC(bp);
  8606. int port = BP_PORT(bp);
  8607. #ifdef BCM_CNIC
  8608. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8609. u8 *fip_mac = bp->fip_mac;
  8610. #endif
  8611. /* Zero primary MAC configuration */
  8612. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8613. if (BP_NOMCP(bp)) {
  8614. BNX2X_ERROR("warning: random MAC workaround active\n");
  8615. eth_hw_addr_random(bp->dev);
  8616. } else if (IS_MF(bp)) {
  8617. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8618. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8619. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8620. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8621. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8622. #ifdef BCM_CNIC
  8623. /*
  8624. * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8625. * FCoE MAC then the appropriate feature should be disabled.
  8626. *
  8627. * In non SD mode features configuration comes from
  8628. * struct func_ext_config.
  8629. */
  8630. if (!IS_MF_SD(bp)) {
  8631. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8632. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8633. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8634. iscsi_mac_addr_upper);
  8635. val = MF_CFG_RD(bp, func_ext_config[func].
  8636. iscsi_mac_addr_lower);
  8637. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8638. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8639. iscsi_mac);
  8640. } else
  8641. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8642. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8643. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8644. fcoe_mac_addr_upper);
  8645. val = MF_CFG_RD(bp, func_ext_config[func].
  8646. fcoe_mac_addr_lower);
  8647. bnx2x_set_mac_buf(fip_mac, val, val2);
  8648. BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
  8649. fip_mac);
  8650. } else
  8651. bp->flags |= NO_FCOE_FLAG;
  8652. bp->mf_ext_config = cfg;
  8653. } else { /* SD MODE */
  8654. if (IS_MF_STORAGE_SD(bp)) {
  8655. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8656. /* use primary mac as iscsi mac */
  8657. memcpy(iscsi_mac, bp->dev->dev_addr,
  8658. ETH_ALEN);
  8659. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8660. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8661. iscsi_mac);
  8662. } else { /* FCoE */
  8663. memcpy(fip_mac, bp->dev->dev_addr,
  8664. ETH_ALEN);
  8665. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8666. BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
  8667. fip_mac);
  8668. }
  8669. /* Zero primary MAC configuration */
  8670. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8671. }
  8672. }
  8673. if (IS_MF_FCOE_AFEX(bp))
  8674. /* use FIP MAC as primary MAC */
  8675. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  8676. #endif
  8677. } else {
  8678. /* in SF read MACs from port configuration */
  8679. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8680. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8681. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8682. #ifdef BCM_CNIC
  8683. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8684. iscsi_mac_upper);
  8685. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8686. iscsi_mac_lower);
  8687. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8688. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8689. fcoe_fip_mac_upper);
  8690. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8691. fcoe_fip_mac_lower);
  8692. bnx2x_set_mac_buf(fip_mac, val, val2);
  8693. #endif
  8694. }
  8695. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8696. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8697. #ifdef BCM_CNIC
  8698. /* Disable iSCSI if MAC configuration is
  8699. * invalid.
  8700. */
  8701. if (!is_valid_ether_addr(iscsi_mac)) {
  8702. bp->flags |= NO_ISCSI_FLAG;
  8703. memset(iscsi_mac, 0, ETH_ALEN);
  8704. }
  8705. /* Disable FCoE if MAC configuration is
  8706. * invalid.
  8707. */
  8708. if (!is_valid_ether_addr(fip_mac)) {
  8709. bp->flags |= NO_FCOE_FLAG;
  8710. memset(bp->fip_mac, 0, ETH_ALEN);
  8711. }
  8712. #endif
  8713. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8714. dev_err(&bp->pdev->dev,
  8715. "bad Ethernet MAC address configuration: %pM\n"
  8716. "change it manually before bringing up the appropriate network interface\n",
  8717. bp->dev->dev_addr);
  8718. }
  8719. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  8720. {
  8721. int /*abs*/func = BP_ABS_FUNC(bp);
  8722. int vn;
  8723. u32 val = 0;
  8724. int rc = 0;
  8725. bnx2x_get_common_hwinfo(bp);
  8726. /*
  8727. * initialize IGU parameters
  8728. */
  8729. if (CHIP_IS_E1x(bp)) {
  8730. bp->common.int_block = INT_BLOCK_HC;
  8731. bp->igu_dsb_id = DEF_SB_IGU_ID;
  8732. bp->igu_base_sb = 0;
  8733. } else {
  8734. bp->common.int_block = INT_BLOCK_IGU;
  8735. /* do not allow device reset during IGU info preocessing */
  8736. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8737. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  8738. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8739. int tout = 5000;
  8740. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  8741. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  8742. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  8743. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  8744. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8745. tout--;
  8746. usleep_range(1000, 1000);
  8747. }
  8748. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8749. dev_err(&bp->pdev->dev,
  8750. "FORCING Normal Mode failed!!!\n");
  8751. return -EPERM;
  8752. }
  8753. }
  8754. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8755. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  8756. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  8757. } else
  8758. BNX2X_DEV_INFO("IGU Normal Mode\n");
  8759. bnx2x_get_igu_cam_info(bp);
  8760. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8761. }
  8762. /*
  8763. * set base FW non-default (fast path) status block id, this value is
  8764. * used to initialize the fw_sb_id saved on the fp/queue structure to
  8765. * determine the id used by the FW.
  8766. */
  8767. if (CHIP_IS_E1x(bp))
  8768. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  8769. else /*
  8770. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  8771. * the same queue are indicated on the same IGU SB). So we prefer
  8772. * FW and IGU SBs to be the same value.
  8773. */
  8774. bp->base_fw_ndsb = bp->igu_base_sb;
  8775. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  8776. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  8777. bp->igu_sb_cnt, bp->base_fw_ndsb);
  8778. /*
  8779. * Initialize MF configuration
  8780. */
  8781. bp->mf_ov = 0;
  8782. bp->mf_mode = 0;
  8783. vn = BP_VN(bp);
  8784. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  8785. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  8786. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  8787. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  8788. if (SHMEM2_HAS(bp, mf_cfg_addr))
  8789. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  8790. else
  8791. bp->common.mf_cfg_base = bp->common.shmem_base +
  8792. offsetof(struct shmem_region, func_mb) +
  8793. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  8794. /*
  8795. * get mf configuration:
  8796. * 1. existence of MF configuration
  8797. * 2. MAC address must be legal (check only upper bytes)
  8798. * for Switch-Independent mode;
  8799. * OVLAN must be legal for Switch-Dependent mode
  8800. * 3. SF_MODE configures specific MF mode
  8801. */
  8802. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8803. /* get mf configuration */
  8804. val = SHMEM_RD(bp,
  8805. dev_info.shared_feature_config.config);
  8806. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  8807. switch (val) {
  8808. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  8809. val = MF_CFG_RD(bp, func_mf_config[func].
  8810. mac_upper);
  8811. /* check for legal mac (upper bytes)*/
  8812. if (val != 0xffff) {
  8813. bp->mf_mode = MULTI_FUNCTION_SI;
  8814. bp->mf_config[vn] = MF_CFG_RD(bp,
  8815. func_mf_config[func].config);
  8816. } else
  8817. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  8818. break;
  8819. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  8820. if ((!CHIP_IS_E1x(bp)) &&
  8821. (MF_CFG_RD(bp, func_mf_config[func].
  8822. mac_upper) != 0xffff) &&
  8823. (SHMEM2_HAS(bp,
  8824. afex_driver_support))) {
  8825. bp->mf_mode = MULTI_FUNCTION_AFEX;
  8826. bp->mf_config[vn] = MF_CFG_RD(bp,
  8827. func_mf_config[func].config);
  8828. } else {
  8829. BNX2X_DEV_INFO("can not configure afex mode\n");
  8830. }
  8831. break;
  8832. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  8833. /* get OV configuration */
  8834. val = MF_CFG_RD(bp,
  8835. func_mf_config[FUNC_0].e1hov_tag);
  8836. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  8837. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8838. bp->mf_mode = MULTI_FUNCTION_SD;
  8839. bp->mf_config[vn] = MF_CFG_RD(bp,
  8840. func_mf_config[func].config);
  8841. } else
  8842. BNX2X_DEV_INFO("illegal OV for SD\n");
  8843. break;
  8844. default:
  8845. /* Unknown configuration: reset mf_config */
  8846. bp->mf_config[vn] = 0;
  8847. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  8848. }
  8849. }
  8850. BNX2X_DEV_INFO("%s function mode\n",
  8851. IS_MF(bp) ? "multi" : "single");
  8852. switch (bp->mf_mode) {
  8853. case MULTI_FUNCTION_SD:
  8854. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  8855. FUNC_MF_CFG_E1HOV_TAG_MASK;
  8856. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8857. bp->mf_ov = val;
  8858. bp->path_has_ovlan = true;
  8859. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  8860. func, bp->mf_ov, bp->mf_ov);
  8861. } else {
  8862. dev_err(&bp->pdev->dev,
  8863. "No valid MF OV for func %d, aborting\n",
  8864. func);
  8865. return -EPERM;
  8866. }
  8867. break;
  8868. case MULTI_FUNCTION_AFEX:
  8869. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  8870. break;
  8871. case MULTI_FUNCTION_SI:
  8872. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  8873. func);
  8874. break;
  8875. default:
  8876. if (vn) {
  8877. dev_err(&bp->pdev->dev,
  8878. "VN %d is in a single function mode, aborting\n",
  8879. vn);
  8880. return -EPERM;
  8881. }
  8882. break;
  8883. }
  8884. /* check if other port on the path needs ovlan:
  8885. * Since MF configuration is shared between ports
  8886. * Possible mixed modes are only
  8887. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  8888. */
  8889. if (CHIP_MODE_IS_4_PORT(bp) &&
  8890. !bp->path_has_ovlan &&
  8891. !IS_MF(bp) &&
  8892. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8893. u8 other_port = !BP_PORT(bp);
  8894. u8 other_func = BP_PATH(bp) + 2*other_port;
  8895. val = MF_CFG_RD(bp,
  8896. func_mf_config[other_func].e1hov_tag);
  8897. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  8898. bp->path_has_ovlan = true;
  8899. }
  8900. }
  8901. /* adjust igu_sb_cnt to MF for E1x */
  8902. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  8903. bp->igu_sb_cnt /= E1HVN_MAX;
  8904. /* port info */
  8905. bnx2x_get_port_hwinfo(bp);
  8906. /* Get MAC addresses */
  8907. bnx2x_get_mac_hwinfo(bp);
  8908. bnx2x_get_cnic_info(bp);
  8909. return rc;
  8910. }
  8911. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  8912. {
  8913. int cnt, i, block_end, rodi;
  8914. char vpd_start[BNX2X_VPD_LEN+1];
  8915. char str_id_reg[VENDOR_ID_LEN+1];
  8916. char str_id_cap[VENDOR_ID_LEN+1];
  8917. char *vpd_data;
  8918. char *vpd_extended_data = NULL;
  8919. u8 len;
  8920. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  8921. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  8922. if (cnt < BNX2X_VPD_LEN)
  8923. goto out_not_found;
  8924. /* VPD RO tag should be first tag after identifier string, hence
  8925. * we should be able to find it in first BNX2X_VPD_LEN chars
  8926. */
  8927. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  8928. PCI_VPD_LRDT_RO_DATA);
  8929. if (i < 0)
  8930. goto out_not_found;
  8931. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  8932. pci_vpd_lrdt_size(&vpd_start[i]);
  8933. i += PCI_VPD_LRDT_TAG_SIZE;
  8934. if (block_end > BNX2X_VPD_LEN) {
  8935. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  8936. if (vpd_extended_data == NULL)
  8937. goto out_not_found;
  8938. /* read rest of vpd image into vpd_extended_data */
  8939. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  8940. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  8941. block_end - BNX2X_VPD_LEN,
  8942. vpd_extended_data + BNX2X_VPD_LEN);
  8943. if (cnt < (block_end - BNX2X_VPD_LEN))
  8944. goto out_not_found;
  8945. vpd_data = vpd_extended_data;
  8946. } else
  8947. vpd_data = vpd_start;
  8948. /* now vpd_data holds full vpd content in both cases */
  8949. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8950. PCI_VPD_RO_KEYWORD_MFR_ID);
  8951. if (rodi < 0)
  8952. goto out_not_found;
  8953. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8954. if (len != VENDOR_ID_LEN)
  8955. goto out_not_found;
  8956. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8957. /* vendor specific info */
  8958. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  8959. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  8960. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  8961. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  8962. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8963. PCI_VPD_RO_KEYWORD_VENDOR0);
  8964. if (rodi >= 0) {
  8965. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8966. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8967. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  8968. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  8969. bp->fw_ver[len] = ' ';
  8970. }
  8971. }
  8972. kfree(vpd_extended_data);
  8973. return;
  8974. }
  8975. out_not_found:
  8976. kfree(vpd_extended_data);
  8977. return;
  8978. }
  8979. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  8980. {
  8981. u32 flags = 0;
  8982. if (CHIP_REV_IS_FPGA(bp))
  8983. SET_FLAGS(flags, MODE_FPGA);
  8984. else if (CHIP_REV_IS_EMUL(bp))
  8985. SET_FLAGS(flags, MODE_EMUL);
  8986. else
  8987. SET_FLAGS(flags, MODE_ASIC);
  8988. if (CHIP_MODE_IS_4_PORT(bp))
  8989. SET_FLAGS(flags, MODE_PORT4);
  8990. else
  8991. SET_FLAGS(flags, MODE_PORT2);
  8992. if (CHIP_IS_E2(bp))
  8993. SET_FLAGS(flags, MODE_E2);
  8994. else if (CHIP_IS_E3(bp)) {
  8995. SET_FLAGS(flags, MODE_E3);
  8996. if (CHIP_REV(bp) == CHIP_REV_Ax)
  8997. SET_FLAGS(flags, MODE_E3_A0);
  8998. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  8999. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9000. }
  9001. if (IS_MF(bp)) {
  9002. SET_FLAGS(flags, MODE_MF);
  9003. switch (bp->mf_mode) {
  9004. case MULTI_FUNCTION_SD:
  9005. SET_FLAGS(flags, MODE_MF_SD);
  9006. break;
  9007. case MULTI_FUNCTION_SI:
  9008. SET_FLAGS(flags, MODE_MF_SI);
  9009. break;
  9010. case MULTI_FUNCTION_AFEX:
  9011. SET_FLAGS(flags, MODE_MF_AFEX);
  9012. break;
  9013. }
  9014. } else
  9015. SET_FLAGS(flags, MODE_SF);
  9016. #if defined(__LITTLE_ENDIAN)
  9017. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9018. #else /*(__BIG_ENDIAN)*/
  9019. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9020. #endif
  9021. INIT_MODE_FLAGS(bp) = flags;
  9022. }
  9023. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  9024. {
  9025. int func;
  9026. int rc;
  9027. mutex_init(&bp->port.phy_mutex);
  9028. mutex_init(&bp->fw_mb_mutex);
  9029. spin_lock_init(&bp->stats_lock);
  9030. #ifdef BCM_CNIC
  9031. mutex_init(&bp->cnic_mutex);
  9032. #endif
  9033. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9034. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9035. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9036. rc = bnx2x_get_hwinfo(bp);
  9037. if (rc)
  9038. return rc;
  9039. bnx2x_set_modes_bitmap(bp);
  9040. rc = bnx2x_alloc_mem_bp(bp);
  9041. if (rc)
  9042. return rc;
  9043. bnx2x_read_fwinfo(bp);
  9044. func = BP_FUNC(bp);
  9045. /* need to reset chip if undi was active */
  9046. if (!BP_NOMCP(bp)) {
  9047. /* init fw_seq */
  9048. bp->fw_seq =
  9049. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9050. DRV_MSG_SEQ_NUMBER_MASK;
  9051. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9052. bnx2x_prev_unload(bp);
  9053. }
  9054. if (CHIP_REV_IS_FPGA(bp))
  9055. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9056. if (BP_NOMCP(bp) && (func == 0))
  9057. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9058. bp->disable_tpa = disable_tpa;
  9059. #ifdef BCM_CNIC
  9060. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9061. #endif
  9062. /* Set TPA flags */
  9063. if (bp->disable_tpa) {
  9064. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9065. bp->dev->features &= ~NETIF_F_LRO;
  9066. } else {
  9067. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9068. bp->dev->features |= NETIF_F_LRO;
  9069. }
  9070. if (CHIP_IS_E1(bp))
  9071. bp->dropless_fc = 0;
  9072. else
  9073. bp->dropless_fc = dropless_fc;
  9074. bp->mrrs = mrrs;
  9075. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9076. /* make sure that the numbers are in the right granularity */
  9077. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9078. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9079. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9080. init_timer(&bp->timer);
  9081. bp->timer.expires = jiffies + bp->current_interval;
  9082. bp->timer.data = (unsigned long) bp;
  9083. bp->timer.function = bnx2x_timer;
  9084. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9085. bnx2x_dcbx_init_params(bp);
  9086. #ifdef BCM_CNIC
  9087. if (CHIP_IS_E1x(bp))
  9088. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9089. else
  9090. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9091. #endif
  9092. /* multiple tx priority */
  9093. if (CHIP_IS_E1x(bp))
  9094. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9095. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9096. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9097. if (CHIP_IS_E3B0(bp))
  9098. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9099. return rc;
  9100. }
  9101. /****************************************************************************
  9102. * General service functions
  9103. ****************************************************************************/
  9104. /*
  9105. * net_device service functions
  9106. */
  9107. /* called with rtnl_lock */
  9108. static int bnx2x_open(struct net_device *dev)
  9109. {
  9110. struct bnx2x *bp = netdev_priv(dev);
  9111. bool global = false;
  9112. int other_engine = BP_PATH(bp) ? 0 : 1;
  9113. bool other_load_status, load_status;
  9114. bp->stats_init = true;
  9115. netif_carrier_off(dev);
  9116. bnx2x_set_power_state(bp, PCI_D0);
  9117. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9118. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9119. /*
  9120. * If parity had happen during the unload, then attentions
  9121. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9122. * want the first function loaded on the current engine to
  9123. * complete the recovery.
  9124. */
  9125. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9126. bnx2x_chk_parity_attn(bp, &global, true))
  9127. do {
  9128. /*
  9129. * If there are attentions and they are in a global
  9130. * blocks, set the GLOBAL_RESET bit regardless whether
  9131. * it will be this function that will complete the
  9132. * recovery or not.
  9133. */
  9134. if (global)
  9135. bnx2x_set_reset_global(bp);
  9136. /*
  9137. * Only the first function on the current engine should
  9138. * try to recover in open. In case of attentions in
  9139. * global blocks only the first in the chip should try
  9140. * to recover.
  9141. */
  9142. if ((!load_status &&
  9143. (!global || !other_load_status)) &&
  9144. bnx2x_trylock_leader_lock(bp) &&
  9145. !bnx2x_leader_reset(bp)) {
  9146. netdev_info(bp->dev, "Recovered in open\n");
  9147. break;
  9148. }
  9149. /* recovery has failed... */
  9150. bnx2x_set_power_state(bp, PCI_D3hot);
  9151. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9152. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9153. "If you still see this message after a few retries then power cycle is required.\n");
  9154. return -EAGAIN;
  9155. } while (0);
  9156. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9157. return bnx2x_nic_load(bp, LOAD_OPEN);
  9158. }
  9159. /* called with rtnl_lock */
  9160. static int bnx2x_close(struct net_device *dev)
  9161. {
  9162. struct bnx2x *bp = netdev_priv(dev);
  9163. /* Unload the driver, release IRQs */
  9164. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  9165. /* Power off */
  9166. bnx2x_set_power_state(bp, PCI_D3hot);
  9167. return 0;
  9168. }
  9169. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9170. struct bnx2x_mcast_ramrod_params *p)
  9171. {
  9172. int mc_count = netdev_mc_count(bp->dev);
  9173. struct bnx2x_mcast_list_elem *mc_mac =
  9174. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9175. struct netdev_hw_addr *ha;
  9176. if (!mc_mac)
  9177. return -ENOMEM;
  9178. INIT_LIST_HEAD(&p->mcast_list);
  9179. netdev_for_each_mc_addr(ha, bp->dev) {
  9180. mc_mac->mac = bnx2x_mc_addr(ha);
  9181. list_add_tail(&mc_mac->link, &p->mcast_list);
  9182. mc_mac++;
  9183. }
  9184. p->mcast_list_len = mc_count;
  9185. return 0;
  9186. }
  9187. static void bnx2x_free_mcast_macs_list(
  9188. struct bnx2x_mcast_ramrod_params *p)
  9189. {
  9190. struct bnx2x_mcast_list_elem *mc_mac =
  9191. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9192. link);
  9193. WARN_ON(!mc_mac);
  9194. kfree(mc_mac);
  9195. }
  9196. /**
  9197. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9198. *
  9199. * @bp: driver handle
  9200. *
  9201. * We will use zero (0) as a MAC type for these MACs.
  9202. */
  9203. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9204. {
  9205. int rc;
  9206. struct net_device *dev = bp->dev;
  9207. struct netdev_hw_addr *ha;
  9208. struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
  9209. unsigned long ramrod_flags = 0;
  9210. /* First schedule a cleanup up of old configuration */
  9211. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9212. if (rc < 0) {
  9213. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9214. return rc;
  9215. }
  9216. netdev_for_each_uc_addr(ha, dev) {
  9217. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9218. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9219. if (rc < 0) {
  9220. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9221. rc);
  9222. return rc;
  9223. }
  9224. }
  9225. /* Execute the pending commands */
  9226. __set_bit(RAMROD_CONT, &ramrod_flags);
  9227. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9228. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9229. }
  9230. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9231. {
  9232. struct net_device *dev = bp->dev;
  9233. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9234. int rc = 0;
  9235. rparam.mcast_obj = &bp->mcast_obj;
  9236. /* first, clear all configured multicast MACs */
  9237. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9238. if (rc < 0) {
  9239. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9240. return rc;
  9241. }
  9242. /* then, configure a new MACs list */
  9243. if (netdev_mc_count(dev)) {
  9244. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9245. if (rc) {
  9246. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9247. rc);
  9248. return rc;
  9249. }
  9250. /* Now add the new MACs */
  9251. rc = bnx2x_config_mcast(bp, &rparam,
  9252. BNX2X_MCAST_CMD_ADD);
  9253. if (rc < 0)
  9254. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9255. rc);
  9256. bnx2x_free_mcast_macs_list(&rparam);
  9257. }
  9258. return rc;
  9259. }
  9260. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9261. void bnx2x_set_rx_mode(struct net_device *dev)
  9262. {
  9263. struct bnx2x *bp = netdev_priv(dev);
  9264. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9265. if (bp->state != BNX2X_STATE_OPEN) {
  9266. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9267. return;
  9268. }
  9269. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9270. if (dev->flags & IFF_PROMISC)
  9271. rx_mode = BNX2X_RX_MODE_PROMISC;
  9272. else if ((dev->flags & IFF_ALLMULTI) ||
  9273. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9274. CHIP_IS_E1(bp)))
  9275. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9276. else {
  9277. /* some multicasts */
  9278. if (bnx2x_set_mc_list(bp) < 0)
  9279. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9280. if (bnx2x_set_uc_list(bp) < 0)
  9281. rx_mode = BNX2X_RX_MODE_PROMISC;
  9282. }
  9283. bp->rx_mode = rx_mode;
  9284. #ifdef BCM_CNIC
  9285. /* handle ISCSI SD mode */
  9286. if (IS_MF_ISCSI_SD(bp))
  9287. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9288. #endif
  9289. /* Schedule the rx_mode command */
  9290. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9291. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9292. return;
  9293. }
  9294. bnx2x_set_storm_rx_mode(bp);
  9295. }
  9296. /* called with rtnl_lock */
  9297. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9298. int devad, u16 addr)
  9299. {
  9300. struct bnx2x *bp = netdev_priv(netdev);
  9301. u16 value;
  9302. int rc;
  9303. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9304. prtad, devad, addr);
  9305. /* The HW expects different devad if CL22 is used */
  9306. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9307. bnx2x_acquire_phy_lock(bp);
  9308. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9309. bnx2x_release_phy_lock(bp);
  9310. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9311. if (!rc)
  9312. rc = value;
  9313. return rc;
  9314. }
  9315. /* called with rtnl_lock */
  9316. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9317. u16 addr, u16 value)
  9318. {
  9319. struct bnx2x *bp = netdev_priv(netdev);
  9320. int rc;
  9321. DP(NETIF_MSG_LINK,
  9322. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9323. prtad, devad, addr, value);
  9324. /* The HW expects different devad if CL22 is used */
  9325. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9326. bnx2x_acquire_phy_lock(bp);
  9327. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9328. bnx2x_release_phy_lock(bp);
  9329. return rc;
  9330. }
  9331. /* called with rtnl_lock */
  9332. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9333. {
  9334. struct bnx2x *bp = netdev_priv(dev);
  9335. struct mii_ioctl_data *mdio = if_mii(ifr);
  9336. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9337. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9338. if (!netif_running(dev))
  9339. return -EAGAIN;
  9340. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9341. }
  9342. #ifdef CONFIG_NET_POLL_CONTROLLER
  9343. static void poll_bnx2x(struct net_device *dev)
  9344. {
  9345. struct bnx2x *bp = netdev_priv(dev);
  9346. disable_irq(bp->pdev->irq);
  9347. bnx2x_interrupt(bp->pdev->irq, dev);
  9348. enable_irq(bp->pdev->irq);
  9349. }
  9350. #endif
  9351. static int bnx2x_validate_addr(struct net_device *dev)
  9352. {
  9353. struct bnx2x *bp = netdev_priv(dev);
  9354. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9355. BNX2X_ERR("Non-valid Ethernet address\n");
  9356. return -EADDRNOTAVAIL;
  9357. }
  9358. return 0;
  9359. }
  9360. static const struct net_device_ops bnx2x_netdev_ops = {
  9361. .ndo_open = bnx2x_open,
  9362. .ndo_stop = bnx2x_close,
  9363. .ndo_start_xmit = bnx2x_start_xmit,
  9364. .ndo_select_queue = bnx2x_select_queue,
  9365. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9366. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9367. .ndo_validate_addr = bnx2x_validate_addr,
  9368. .ndo_do_ioctl = bnx2x_ioctl,
  9369. .ndo_change_mtu = bnx2x_change_mtu,
  9370. .ndo_fix_features = bnx2x_fix_features,
  9371. .ndo_set_features = bnx2x_set_features,
  9372. .ndo_tx_timeout = bnx2x_tx_timeout,
  9373. #ifdef CONFIG_NET_POLL_CONTROLLER
  9374. .ndo_poll_controller = poll_bnx2x,
  9375. #endif
  9376. .ndo_setup_tc = bnx2x_setup_tc,
  9377. #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
  9378. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9379. #endif
  9380. };
  9381. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9382. {
  9383. struct device *dev = &bp->pdev->dev;
  9384. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9385. bp->flags |= USING_DAC_FLAG;
  9386. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9387. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9388. return -EIO;
  9389. }
  9390. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9391. dev_err(dev, "System does not support DMA, aborting\n");
  9392. return -EIO;
  9393. }
  9394. return 0;
  9395. }
  9396. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  9397. struct net_device *dev,
  9398. unsigned long board_type)
  9399. {
  9400. struct bnx2x *bp;
  9401. int rc;
  9402. u32 pci_cfg_dword;
  9403. bool chip_is_e1x = (board_type == BCM57710 ||
  9404. board_type == BCM57711 ||
  9405. board_type == BCM57711E);
  9406. SET_NETDEV_DEV(dev, &pdev->dev);
  9407. bp = netdev_priv(dev);
  9408. bp->dev = dev;
  9409. bp->pdev = pdev;
  9410. bp->flags = 0;
  9411. rc = pci_enable_device(pdev);
  9412. if (rc) {
  9413. dev_err(&bp->pdev->dev,
  9414. "Cannot enable PCI device, aborting\n");
  9415. goto err_out;
  9416. }
  9417. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9418. dev_err(&bp->pdev->dev,
  9419. "Cannot find PCI device base address, aborting\n");
  9420. rc = -ENODEV;
  9421. goto err_out_disable;
  9422. }
  9423. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9424. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  9425. " base address, aborting\n");
  9426. rc = -ENODEV;
  9427. goto err_out_disable;
  9428. }
  9429. if (atomic_read(&pdev->enable_cnt) == 1) {
  9430. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9431. if (rc) {
  9432. dev_err(&bp->pdev->dev,
  9433. "Cannot obtain PCI resources, aborting\n");
  9434. goto err_out_disable;
  9435. }
  9436. pci_set_master(pdev);
  9437. pci_save_state(pdev);
  9438. }
  9439. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9440. if (bp->pm_cap == 0) {
  9441. dev_err(&bp->pdev->dev,
  9442. "Cannot find power management capability, aborting\n");
  9443. rc = -EIO;
  9444. goto err_out_release;
  9445. }
  9446. if (!pci_is_pcie(pdev)) {
  9447. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9448. rc = -EIO;
  9449. goto err_out_release;
  9450. }
  9451. rc = bnx2x_set_coherency_mask(bp);
  9452. if (rc)
  9453. goto err_out_release;
  9454. dev->mem_start = pci_resource_start(pdev, 0);
  9455. dev->base_addr = dev->mem_start;
  9456. dev->mem_end = pci_resource_end(pdev, 0);
  9457. dev->irq = pdev->irq;
  9458. bp->regview = pci_ioremap_bar(pdev, 0);
  9459. if (!bp->regview) {
  9460. dev_err(&bp->pdev->dev,
  9461. "Cannot map register space, aborting\n");
  9462. rc = -ENOMEM;
  9463. goto err_out_release;
  9464. }
  9465. /* In E1/E1H use pci device function given by kernel.
  9466. * In E2/E3 read physical function from ME register since these chips
  9467. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9468. * (depending on hypervisor).
  9469. */
  9470. if (chip_is_e1x)
  9471. bp->pf_num = PCI_FUNC(pdev->devfn);
  9472. else {/* chip is E2/3*/
  9473. pci_read_config_dword(bp->pdev,
  9474. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9475. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9476. ME_REG_ABS_PF_NUM_SHIFT);
  9477. }
  9478. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9479. bnx2x_set_power_state(bp, PCI_D0);
  9480. /* clean indirect addresses */
  9481. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9482. PCICFG_VENDOR_ID_OFFSET);
  9483. /*
  9484. * Clean the following indirect addresses for all functions since it
  9485. * is not used by the driver.
  9486. */
  9487. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9488. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9489. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9490. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9491. if (chip_is_e1x) {
  9492. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9493. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9494. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9495. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9496. }
  9497. /*
  9498. * Enable internal target-read (in case we are probed after PF FLR).
  9499. * Must be done prior to any BAR read access. Only for 57712 and up
  9500. */
  9501. if (!chip_is_e1x)
  9502. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9503. /* Reset the load counter */
  9504. bnx2x_clear_load_status(bp);
  9505. dev->watchdog_timeo = TX_TIMEOUT;
  9506. dev->netdev_ops = &bnx2x_netdev_ops;
  9507. bnx2x_set_ethtool_ops(dev);
  9508. dev->priv_flags |= IFF_UNICAST_FLT;
  9509. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9510. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9511. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9512. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9513. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9514. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9515. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9516. if (bp->flags & USING_DAC_FLAG)
  9517. dev->features |= NETIF_F_HIGHDMA;
  9518. /* Add Loopback capability to the device */
  9519. dev->hw_features |= NETIF_F_LOOPBACK;
  9520. #ifdef BCM_DCBNL
  9521. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9522. #endif
  9523. /* get_port_hwinfo() will set prtad and mmds properly */
  9524. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9525. bp->mdio.mmds = 0;
  9526. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9527. bp->mdio.dev = dev;
  9528. bp->mdio.mdio_read = bnx2x_mdio_read;
  9529. bp->mdio.mdio_write = bnx2x_mdio_write;
  9530. return 0;
  9531. err_out_release:
  9532. if (atomic_read(&pdev->enable_cnt) == 1)
  9533. pci_release_regions(pdev);
  9534. err_out_disable:
  9535. pci_disable_device(pdev);
  9536. pci_set_drvdata(pdev, NULL);
  9537. err_out:
  9538. return rc;
  9539. }
  9540. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  9541. int *width, int *speed)
  9542. {
  9543. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9544. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9545. /* return value of 1=2.5GHz 2=5GHz */
  9546. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9547. }
  9548. static int bnx2x_check_firmware(struct bnx2x *bp)
  9549. {
  9550. const struct firmware *firmware = bp->firmware;
  9551. struct bnx2x_fw_file_hdr *fw_hdr;
  9552. struct bnx2x_fw_file_section *sections;
  9553. u32 offset, len, num_ops;
  9554. u16 *ops_offsets;
  9555. int i;
  9556. const u8 *fw_ver;
  9557. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9558. BNX2X_ERR("Wrong FW size\n");
  9559. return -EINVAL;
  9560. }
  9561. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9562. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9563. /* Make sure none of the offsets and sizes make us read beyond
  9564. * the end of the firmware data */
  9565. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9566. offset = be32_to_cpu(sections[i].offset);
  9567. len = be32_to_cpu(sections[i].len);
  9568. if (offset + len > firmware->size) {
  9569. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9570. return -EINVAL;
  9571. }
  9572. }
  9573. /* Likewise for the init_ops offsets */
  9574. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9575. ops_offsets = (u16 *)(firmware->data + offset);
  9576. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9577. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9578. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9579. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  9580. return -EINVAL;
  9581. }
  9582. }
  9583. /* Check FW version */
  9584. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9585. fw_ver = firmware->data + offset;
  9586. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9587. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9588. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9589. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9590. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  9591. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  9592. BCM_5710_FW_MAJOR_VERSION,
  9593. BCM_5710_FW_MINOR_VERSION,
  9594. BCM_5710_FW_REVISION_VERSION,
  9595. BCM_5710_FW_ENGINEERING_VERSION);
  9596. return -EINVAL;
  9597. }
  9598. return 0;
  9599. }
  9600. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9601. {
  9602. const __be32 *source = (const __be32 *)_source;
  9603. u32 *target = (u32 *)_target;
  9604. u32 i;
  9605. for (i = 0; i < n/4; i++)
  9606. target[i] = be32_to_cpu(source[i]);
  9607. }
  9608. /*
  9609. Ops array is stored in the following format:
  9610. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9611. */
  9612. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9613. {
  9614. const __be32 *source = (const __be32 *)_source;
  9615. struct raw_op *target = (struct raw_op *)_target;
  9616. u32 i, j, tmp;
  9617. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9618. tmp = be32_to_cpu(source[j]);
  9619. target[i].op = (tmp >> 24) & 0xff;
  9620. target[i].offset = tmp & 0xffffff;
  9621. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9622. }
  9623. }
  9624. /**
  9625. * IRO array is stored in the following format:
  9626. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9627. */
  9628. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9629. {
  9630. const __be32 *source = (const __be32 *)_source;
  9631. struct iro *target = (struct iro *)_target;
  9632. u32 i, j, tmp;
  9633. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9634. target[i].base = be32_to_cpu(source[j]);
  9635. j++;
  9636. tmp = be32_to_cpu(source[j]);
  9637. target[i].m1 = (tmp >> 16) & 0xffff;
  9638. target[i].m2 = tmp & 0xffff;
  9639. j++;
  9640. tmp = be32_to_cpu(source[j]);
  9641. target[i].m3 = (tmp >> 16) & 0xffff;
  9642. target[i].size = tmp & 0xffff;
  9643. j++;
  9644. }
  9645. }
  9646. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9647. {
  9648. const __be16 *source = (const __be16 *)_source;
  9649. u16 *target = (u16 *)_target;
  9650. u32 i;
  9651. for (i = 0; i < n/2; i++)
  9652. target[i] = be16_to_cpu(source[i]);
  9653. }
  9654. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9655. do { \
  9656. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9657. bp->arr = kmalloc(len, GFP_KERNEL); \
  9658. if (!bp->arr) \
  9659. goto lbl; \
  9660. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9661. (u8 *)bp->arr, len); \
  9662. } while (0)
  9663. static int bnx2x_init_firmware(struct bnx2x *bp)
  9664. {
  9665. const char *fw_file_name;
  9666. struct bnx2x_fw_file_hdr *fw_hdr;
  9667. int rc;
  9668. if (bp->firmware)
  9669. return 0;
  9670. if (CHIP_IS_E1(bp))
  9671. fw_file_name = FW_FILE_NAME_E1;
  9672. else if (CHIP_IS_E1H(bp))
  9673. fw_file_name = FW_FILE_NAME_E1H;
  9674. else if (!CHIP_IS_E1x(bp))
  9675. fw_file_name = FW_FILE_NAME_E2;
  9676. else {
  9677. BNX2X_ERR("Unsupported chip revision\n");
  9678. return -EINVAL;
  9679. }
  9680. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9681. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9682. if (rc) {
  9683. BNX2X_ERR("Can't load firmware file %s\n",
  9684. fw_file_name);
  9685. goto request_firmware_exit;
  9686. }
  9687. rc = bnx2x_check_firmware(bp);
  9688. if (rc) {
  9689. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9690. goto request_firmware_exit;
  9691. }
  9692. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  9693. /* Initialize the pointers to the init arrays */
  9694. /* Blob */
  9695. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  9696. /* Opcodes */
  9697. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  9698. /* Offsets */
  9699. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  9700. be16_to_cpu_n);
  9701. /* STORMs firmware */
  9702. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9703. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  9704. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  9705. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  9706. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9707. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  9708. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  9709. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  9710. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9711. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  9712. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  9713. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  9714. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9715. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  9716. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  9717. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  9718. /* IRO */
  9719. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  9720. return 0;
  9721. iro_alloc_err:
  9722. kfree(bp->init_ops_offsets);
  9723. init_offsets_alloc_err:
  9724. kfree(bp->init_ops);
  9725. init_ops_alloc_err:
  9726. kfree(bp->init_data);
  9727. request_firmware_exit:
  9728. release_firmware(bp->firmware);
  9729. bp->firmware = NULL;
  9730. return rc;
  9731. }
  9732. static void bnx2x_release_firmware(struct bnx2x *bp)
  9733. {
  9734. kfree(bp->init_ops_offsets);
  9735. kfree(bp->init_ops);
  9736. kfree(bp->init_data);
  9737. release_firmware(bp->firmware);
  9738. bp->firmware = NULL;
  9739. }
  9740. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  9741. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  9742. .init_hw_cmn = bnx2x_init_hw_common,
  9743. .init_hw_port = bnx2x_init_hw_port,
  9744. .init_hw_func = bnx2x_init_hw_func,
  9745. .reset_hw_cmn = bnx2x_reset_common,
  9746. .reset_hw_port = bnx2x_reset_port,
  9747. .reset_hw_func = bnx2x_reset_func,
  9748. .gunzip_init = bnx2x_gunzip_init,
  9749. .gunzip_end = bnx2x_gunzip_end,
  9750. .init_fw = bnx2x_init_firmware,
  9751. .release_fw = bnx2x_release_firmware,
  9752. };
  9753. void bnx2x__init_func_obj(struct bnx2x *bp)
  9754. {
  9755. /* Prepare DMAE related driver resources */
  9756. bnx2x_setup_dmae(bp);
  9757. bnx2x_init_func_obj(bp, &bp->func_obj,
  9758. bnx2x_sp(bp, func_rdata),
  9759. bnx2x_sp_mapping(bp, func_rdata),
  9760. bnx2x_sp(bp, func_afex_rdata),
  9761. bnx2x_sp_mapping(bp, func_afex_rdata),
  9762. &bnx2x_func_sp_drv);
  9763. }
  9764. /* must be called after sriov-enable */
  9765. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  9766. {
  9767. int cid_count = BNX2X_L2_CID_COUNT(bp);
  9768. #ifdef BCM_CNIC
  9769. cid_count += CNIC_CID_MAX;
  9770. #endif
  9771. return roundup(cid_count, QM_CID_ROUND);
  9772. }
  9773. /**
  9774. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  9775. *
  9776. * @dev: pci device
  9777. *
  9778. */
  9779. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
  9780. {
  9781. int pos;
  9782. u16 control;
  9783. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  9784. /*
  9785. * If MSI-X is not supported - return number of SBs needed to support
  9786. * one fast path queue: one FP queue + SB for CNIC
  9787. */
  9788. if (!pos)
  9789. return 1 + CNIC_PRESENT;
  9790. /*
  9791. * The value in the PCI configuration space is the index of the last
  9792. * entry, namely one less than the actual size of the table, which is
  9793. * exactly what we want to return from this function: number of all SBs
  9794. * without the default SB.
  9795. */
  9796. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  9797. return control & PCI_MSIX_FLAGS_QSIZE;
  9798. }
  9799. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  9800. const struct pci_device_id *ent)
  9801. {
  9802. struct net_device *dev = NULL;
  9803. struct bnx2x *bp;
  9804. int pcie_width, pcie_speed;
  9805. int rc, max_non_def_sbs;
  9806. int rx_count, tx_count, rss_count;
  9807. /*
  9808. * An estimated maximum supported CoS number according to the chip
  9809. * version.
  9810. * We will try to roughly estimate the maximum number of CoSes this chip
  9811. * may support in order to minimize the memory allocated for Tx
  9812. * netdev_queue's. This number will be accurately calculated during the
  9813. * initialization of bp->max_cos based on the chip versions AND chip
  9814. * revision in the bnx2x_init_bp().
  9815. */
  9816. u8 max_cos_est = 0;
  9817. switch (ent->driver_data) {
  9818. case BCM57710:
  9819. case BCM57711:
  9820. case BCM57711E:
  9821. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  9822. break;
  9823. case BCM57712:
  9824. case BCM57712_MF:
  9825. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  9826. break;
  9827. case BCM57800:
  9828. case BCM57800_MF:
  9829. case BCM57810:
  9830. case BCM57810_MF:
  9831. case BCM57840:
  9832. case BCM57840_MF:
  9833. case BCM57811:
  9834. case BCM57811_MF:
  9835. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  9836. break;
  9837. default:
  9838. pr_err("Unknown board_type (%ld), aborting\n",
  9839. ent->driver_data);
  9840. return -ENODEV;
  9841. }
  9842. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
  9843. /* !!! FIXME !!!
  9844. * Do not allow the maximum SB count to grow above 16
  9845. * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
  9846. * We will use the FP_SB_MAX_E1x macro for this matter.
  9847. */
  9848. max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
  9849. WARN_ON(!max_non_def_sbs);
  9850. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  9851. rss_count = max_non_def_sbs - CNIC_PRESENT;
  9852. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  9853. rx_count = rss_count + FCOE_PRESENT;
  9854. /*
  9855. * Maximum number of netdev Tx queues:
  9856. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  9857. */
  9858. tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
  9859. /* dev zeroed in init_etherdev */
  9860. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  9861. if (!dev)
  9862. return -ENOMEM;
  9863. bp = netdev_priv(dev);
  9864. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  9865. tx_count, rx_count);
  9866. bp->igu_sb_cnt = max_non_def_sbs;
  9867. bp->msg_enable = debug;
  9868. pci_set_drvdata(pdev, dev);
  9869. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  9870. if (rc < 0) {
  9871. free_netdev(dev);
  9872. return rc;
  9873. }
  9874. BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
  9875. rc = bnx2x_init_bp(bp);
  9876. if (rc)
  9877. goto init_one_exit;
  9878. /*
  9879. * Map doorbels here as we need the real value of bp->max_cos which
  9880. * is initialized in bnx2x_init_bp().
  9881. */
  9882. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  9883. min_t(u64, BNX2X_DB_SIZE(bp),
  9884. pci_resource_len(pdev, 2)));
  9885. if (!bp->doorbells) {
  9886. dev_err(&bp->pdev->dev,
  9887. "Cannot map doorbell space, aborting\n");
  9888. rc = -ENOMEM;
  9889. goto init_one_exit;
  9890. }
  9891. /* calc qm_cid_count */
  9892. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  9893. #ifdef BCM_CNIC
  9894. /* disable FCOE L2 queue for E1x */
  9895. if (CHIP_IS_E1x(bp))
  9896. bp->flags |= NO_FCOE_FLAG;
  9897. #endif
  9898. /* Configure interrupt mode: try to enable MSI-X/MSI if
  9899. * needed, set bp->num_queues appropriately.
  9900. */
  9901. bnx2x_set_int_mode(bp);
  9902. /* Add all NAPI objects */
  9903. bnx2x_add_all_napi(bp);
  9904. rc = register_netdev(dev);
  9905. if (rc) {
  9906. dev_err(&pdev->dev, "Cannot register net device\n");
  9907. goto init_one_exit;
  9908. }
  9909. #ifdef BCM_CNIC
  9910. if (!NO_FCOE(bp)) {
  9911. /* Add storage MAC address */
  9912. rtnl_lock();
  9913. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9914. rtnl_unlock();
  9915. }
  9916. #endif
  9917. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  9918. BNX2X_DEV_INFO(
  9919. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  9920. board_info[ent->driver_data].name,
  9921. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  9922. pcie_width,
  9923. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  9924. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  9925. "5GHz (Gen2)" : "2.5GHz",
  9926. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  9927. return 0;
  9928. init_one_exit:
  9929. if (bp->regview)
  9930. iounmap(bp->regview);
  9931. if (bp->doorbells)
  9932. iounmap(bp->doorbells);
  9933. free_netdev(dev);
  9934. if (atomic_read(&pdev->enable_cnt) == 1)
  9935. pci_release_regions(pdev);
  9936. pci_disable_device(pdev);
  9937. pci_set_drvdata(pdev, NULL);
  9938. return rc;
  9939. }
  9940. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  9941. {
  9942. struct net_device *dev = pci_get_drvdata(pdev);
  9943. struct bnx2x *bp;
  9944. if (!dev) {
  9945. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  9946. return;
  9947. }
  9948. bp = netdev_priv(dev);
  9949. #ifdef BCM_CNIC
  9950. /* Delete storage MAC address */
  9951. if (!NO_FCOE(bp)) {
  9952. rtnl_lock();
  9953. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9954. rtnl_unlock();
  9955. }
  9956. #endif
  9957. #ifdef BCM_DCBNL
  9958. /* Delete app tlvs from dcbnl */
  9959. bnx2x_dcbnl_update_applist(bp, true);
  9960. #endif
  9961. unregister_netdev(dev);
  9962. /* Delete all NAPI objects */
  9963. bnx2x_del_all_napi(bp);
  9964. /* Power on: we can't let PCI layer write to us while we are in D3 */
  9965. bnx2x_set_power_state(bp, PCI_D0);
  9966. /* Disable MSI/MSI-X */
  9967. bnx2x_disable_msi(bp);
  9968. /* Power off */
  9969. bnx2x_set_power_state(bp, PCI_D3hot);
  9970. /* Make sure RESET task is not scheduled before continuing */
  9971. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  9972. if (bp->regview)
  9973. iounmap(bp->regview);
  9974. if (bp->doorbells)
  9975. iounmap(bp->doorbells);
  9976. bnx2x_release_firmware(bp);
  9977. bnx2x_free_mem_bp(bp);
  9978. free_netdev(dev);
  9979. if (atomic_read(&pdev->enable_cnt) == 1)
  9980. pci_release_regions(pdev);
  9981. pci_disable_device(pdev);
  9982. pci_set_drvdata(pdev, NULL);
  9983. }
  9984. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  9985. {
  9986. int i;
  9987. bp->state = BNX2X_STATE_ERROR;
  9988. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9989. #ifdef BCM_CNIC
  9990. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  9991. #endif
  9992. /* Stop Tx */
  9993. bnx2x_tx_disable(bp);
  9994. bnx2x_netif_stop(bp, 0);
  9995. del_timer_sync(&bp->timer);
  9996. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  9997. /* Release IRQs */
  9998. bnx2x_free_irq(bp);
  9999. /* Free SKBs, SGEs, TPA pool and driver internals */
  10000. bnx2x_free_skbs(bp);
  10001. for_each_rx_queue(bp, i)
  10002. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10003. bnx2x_free_mem(bp);
  10004. bp->state = BNX2X_STATE_CLOSED;
  10005. netif_carrier_off(bp->dev);
  10006. return 0;
  10007. }
  10008. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10009. {
  10010. u32 val;
  10011. mutex_init(&bp->port.phy_mutex);
  10012. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10013. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10014. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10015. BNX2X_ERR("BAD MCP validity signature\n");
  10016. }
  10017. /**
  10018. * bnx2x_io_error_detected - called when PCI error is detected
  10019. * @pdev: Pointer to PCI device
  10020. * @state: The current pci connection state
  10021. *
  10022. * This function is called after a PCI bus error affecting
  10023. * this device has been detected.
  10024. */
  10025. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10026. pci_channel_state_t state)
  10027. {
  10028. struct net_device *dev = pci_get_drvdata(pdev);
  10029. struct bnx2x *bp = netdev_priv(dev);
  10030. rtnl_lock();
  10031. netif_device_detach(dev);
  10032. if (state == pci_channel_io_perm_failure) {
  10033. rtnl_unlock();
  10034. return PCI_ERS_RESULT_DISCONNECT;
  10035. }
  10036. if (netif_running(dev))
  10037. bnx2x_eeh_nic_unload(bp);
  10038. pci_disable_device(pdev);
  10039. rtnl_unlock();
  10040. /* Request a slot reset */
  10041. return PCI_ERS_RESULT_NEED_RESET;
  10042. }
  10043. /**
  10044. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10045. * @pdev: Pointer to PCI device
  10046. *
  10047. * Restart the card from scratch, as if from a cold-boot.
  10048. */
  10049. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10050. {
  10051. struct net_device *dev = pci_get_drvdata(pdev);
  10052. struct bnx2x *bp = netdev_priv(dev);
  10053. rtnl_lock();
  10054. if (pci_enable_device(pdev)) {
  10055. dev_err(&pdev->dev,
  10056. "Cannot re-enable PCI device after reset\n");
  10057. rtnl_unlock();
  10058. return PCI_ERS_RESULT_DISCONNECT;
  10059. }
  10060. pci_set_master(pdev);
  10061. pci_restore_state(pdev);
  10062. if (netif_running(dev))
  10063. bnx2x_set_power_state(bp, PCI_D0);
  10064. rtnl_unlock();
  10065. return PCI_ERS_RESULT_RECOVERED;
  10066. }
  10067. /**
  10068. * bnx2x_io_resume - called when traffic can start flowing again
  10069. * @pdev: Pointer to PCI device
  10070. *
  10071. * This callback is called when the error recovery driver tells us that
  10072. * its OK to resume normal operation.
  10073. */
  10074. static void bnx2x_io_resume(struct pci_dev *pdev)
  10075. {
  10076. struct net_device *dev = pci_get_drvdata(pdev);
  10077. struct bnx2x *bp = netdev_priv(dev);
  10078. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10079. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10080. return;
  10081. }
  10082. rtnl_lock();
  10083. bnx2x_eeh_recover(bp);
  10084. if (netif_running(dev))
  10085. bnx2x_nic_load(bp, LOAD_NORMAL);
  10086. netif_device_attach(dev);
  10087. rtnl_unlock();
  10088. }
  10089. static struct pci_error_handlers bnx2x_err_handler = {
  10090. .error_detected = bnx2x_io_error_detected,
  10091. .slot_reset = bnx2x_io_slot_reset,
  10092. .resume = bnx2x_io_resume,
  10093. };
  10094. static struct pci_driver bnx2x_pci_driver = {
  10095. .name = DRV_MODULE_NAME,
  10096. .id_table = bnx2x_pci_tbl,
  10097. .probe = bnx2x_init_one,
  10098. .remove = __devexit_p(bnx2x_remove_one),
  10099. .suspend = bnx2x_suspend,
  10100. .resume = bnx2x_resume,
  10101. .err_handler = &bnx2x_err_handler,
  10102. };
  10103. static int __init bnx2x_init(void)
  10104. {
  10105. int ret;
  10106. pr_info("%s", version);
  10107. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10108. if (bnx2x_wq == NULL) {
  10109. pr_err("Cannot create workqueue\n");
  10110. return -ENOMEM;
  10111. }
  10112. ret = pci_register_driver(&bnx2x_pci_driver);
  10113. if (ret) {
  10114. pr_err("Cannot register driver\n");
  10115. destroy_workqueue(bnx2x_wq);
  10116. }
  10117. return ret;
  10118. }
  10119. static void __exit bnx2x_cleanup(void)
  10120. {
  10121. struct list_head *pos, *q;
  10122. pci_unregister_driver(&bnx2x_pci_driver);
  10123. destroy_workqueue(bnx2x_wq);
  10124. /* Free globablly allocated resources */
  10125. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10126. struct bnx2x_prev_path_list *tmp =
  10127. list_entry(pos, struct bnx2x_prev_path_list, list);
  10128. list_del(pos);
  10129. kfree(tmp);
  10130. }
  10131. }
  10132. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10133. {
  10134. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10135. }
  10136. module_init(bnx2x_init);
  10137. module_exit(bnx2x_cleanup);
  10138. #ifdef BCM_CNIC
  10139. /**
  10140. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10141. *
  10142. * @bp: driver handle
  10143. * @set: set or clear the CAM entry
  10144. *
  10145. * This function will wait until the ramdord completion returns.
  10146. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10147. */
  10148. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10149. {
  10150. unsigned long ramrod_flags = 0;
  10151. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10152. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10153. &bp->iscsi_l2_mac_obj, true,
  10154. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10155. }
  10156. /* count denotes the number of new completions we have seen */
  10157. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10158. {
  10159. struct eth_spe *spe;
  10160. #ifdef BNX2X_STOP_ON_ERROR
  10161. if (unlikely(bp->panic))
  10162. return;
  10163. #endif
  10164. spin_lock_bh(&bp->spq_lock);
  10165. BUG_ON(bp->cnic_spq_pending < count);
  10166. bp->cnic_spq_pending -= count;
  10167. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10168. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10169. & SPE_HDR_CONN_TYPE) >>
  10170. SPE_HDR_CONN_TYPE_SHIFT;
  10171. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10172. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10173. /* Set validation for iSCSI L2 client before sending SETUP
  10174. * ramrod
  10175. */
  10176. if (type == ETH_CONNECTION_TYPE) {
  10177. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
  10178. bnx2x_set_ctx_validation(bp, &bp->context.
  10179. vcxt[BNX2X_ISCSI_ETH_CID].eth,
  10180. BNX2X_ISCSI_ETH_CID);
  10181. }
  10182. /*
  10183. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10184. * and in the air. We also check that number of outstanding
  10185. * COMMON ramrods is not more than the EQ and SPQ can
  10186. * accommodate.
  10187. */
  10188. if (type == ETH_CONNECTION_TYPE) {
  10189. if (!atomic_read(&bp->cq_spq_left))
  10190. break;
  10191. else
  10192. atomic_dec(&bp->cq_spq_left);
  10193. } else if (type == NONE_CONNECTION_TYPE) {
  10194. if (!atomic_read(&bp->eq_spq_left))
  10195. break;
  10196. else
  10197. atomic_dec(&bp->eq_spq_left);
  10198. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10199. (type == FCOE_CONNECTION_TYPE)) {
  10200. if (bp->cnic_spq_pending >=
  10201. bp->cnic_eth_dev.max_kwqe_pending)
  10202. break;
  10203. else
  10204. bp->cnic_spq_pending++;
  10205. } else {
  10206. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10207. bnx2x_panic();
  10208. break;
  10209. }
  10210. spe = bnx2x_sp_get_next(bp);
  10211. *spe = *bp->cnic_kwq_cons;
  10212. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10213. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10214. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10215. bp->cnic_kwq_cons = bp->cnic_kwq;
  10216. else
  10217. bp->cnic_kwq_cons++;
  10218. }
  10219. bnx2x_sp_prod_update(bp);
  10220. spin_unlock_bh(&bp->spq_lock);
  10221. }
  10222. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10223. struct kwqe_16 *kwqes[], u32 count)
  10224. {
  10225. struct bnx2x *bp = netdev_priv(dev);
  10226. int i;
  10227. #ifdef BNX2X_STOP_ON_ERROR
  10228. if (unlikely(bp->panic)) {
  10229. BNX2X_ERR("Can't post to SP queue while panic\n");
  10230. return -EIO;
  10231. }
  10232. #endif
  10233. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10234. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10235. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10236. return -EAGAIN;
  10237. }
  10238. spin_lock_bh(&bp->spq_lock);
  10239. for (i = 0; i < count; i++) {
  10240. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10241. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10242. break;
  10243. *bp->cnic_kwq_prod = *spe;
  10244. bp->cnic_kwq_pending++;
  10245. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10246. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10247. spe->data.update_data_addr.hi,
  10248. spe->data.update_data_addr.lo,
  10249. bp->cnic_kwq_pending);
  10250. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10251. bp->cnic_kwq_prod = bp->cnic_kwq;
  10252. else
  10253. bp->cnic_kwq_prod++;
  10254. }
  10255. spin_unlock_bh(&bp->spq_lock);
  10256. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10257. bnx2x_cnic_sp_post(bp, 0);
  10258. return i;
  10259. }
  10260. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10261. {
  10262. struct cnic_ops *c_ops;
  10263. int rc = 0;
  10264. mutex_lock(&bp->cnic_mutex);
  10265. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10266. lockdep_is_held(&bp->cnic_mutex));
  10267. if (c_ops)
  10268. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10269. mutex_unlock(&bp->cnic_mutex);
  10270. return rc;
  10271. }
  10272. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10273. {
  10274. struct cnic_ops *c_ops;
  10275. int rc = 0;
  10276. rcu_read_lock();
  10277. c_ops = rcu_dereference(bp->cnic_ops);
  10278. if (c_ops)
  10279. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10280. rcu_read_unlock();
  10281. return rc;
  10282. }
  10283. /*
  10284. * for commands that have no data
  10285. */
  10286. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10287. {
  10288. struct cnic_ctl_info ctl = {0};
  10289. ctl.cmd = cmd;
  10290. return bnx2x_cnic_ctl_send(bp, &ctl);
  10291. }
  10292. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10293. {
  10294. struct cnic_ctl_info ctl = {0};
  10295. /* first we tell CNIC and only then we count this as a completion */
  10296. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10297. ctl.data.comp.cid = cid;
  10298. ctl.data.comp.error = err;
  10299. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10300. bnx2x_cnic_sp_post(bp, 0);
  10301. }
  10302. /* Called with netif_addr_lock_bh() taken.
  10303. * Sets an rx_mode config for an iSCSI ETH client.
  10304. * Doesn't block.
  10305. * Completion should be checked outside.
  10306. */
  10307. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10308. {
  10309. unsigned long accept_flags = 0, ramrod_flags = 0;
  10310. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10311. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10312. if (start) {
  10313. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10314. * because it's the only way for UIO Queue to accept
  10315. * multicasts (in non-promiscuous mode only one Queue per
  10316. * function will receive multicast packets (leading in our
  10317. * case).
  10318. */
  10319. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10320. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10321. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10322. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10323. /* Clear STOP_PENDING bit if START is requested */
  10324. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10325. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10326. } else
  10327. /* Clear START_PENDING bit if STOP is requested */
  10328. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10329. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10330. set_bit(sched_state, &bp->sp_state);
  10331. else {
  10332. __set_bit(RAMROD_RX, &ramrod_flags);
  10333. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10334. ramrod_flags);
  10335. }
  10336. }
  10337. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10338. {
  10339. struct bnx2x *bp = netdev_priv(dev);
  10340. int rc = 0;
  10341. switch (ctl->cmd) {
  10342. case DRV_CTL_CTXTBL_WR_CMD: {
  10343. u32 index = ctl->data.io.offset;
  10344. dma_addr_t addr = ctl->data.io.dma_addr;
  10345. bnx2x_ilt_wr(bp, index, addr);
  10346. break;
  10347. }
  10348. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10349. int count = ctl->data.credit.credit_count;
  10350. bnx2x_cnic_sp_post(bp, count);
  10351. break;
  10352. }
  10353. /* rtnl_lock is held. */
  10354. case DRV_CTL_START_L2_CMD: {
  10355. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10356. unsigned long sp_bits = 0;
  10357. /* Configure the iSCSI classification object */
  10358. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10359. cp->iscsi_l2_client_id,
  10360. cp->iscsi_l2_cid, BP_FUNC(bp),
  10361. bnx2x_sp(bp, mac_rdata),
  10362. bnx2x_sp_mapping(bp, mac_rdata),
  10363. BNX2X_FILTER_MAC_PENDING,
  10364. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10365. &bp->macs_pool);
  10366. /* Set iSCSI MAC address */
  10367. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10368. if (rc)
  10369. break;
  10370. mmiowb();
  10371. barrier();
  10372. /* Start accepting on iSCSI L2 ring */
  10373. netif_addr_lock_bh(dev);
  10374. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10375. netif_addr_unlock_bh(dev);
  10376. /* bits to wait on */
  10377. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10378. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10379. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10380. BNX2X_ERR("rx_mode completion timed out!\n");
  10381. break;
  10382. }
  10383. /* rtnl_lock is held. */
  10384. case DRV_CTL_STOP_L2_CMD: {
  10385. unsigned long sp_bits = 0;
  10386. /* Stop accepting on iSCSI L2 ring */
  10387. netif_addr_lock_bh(dev);
  10388. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10389. netif_addr_unlock_bh(dev);
  10390. /* bits to wait on */
  10391. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10392. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10393. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10394. BNX2X_ERR("rx_mode completion timed out!\n");
  10395. mmiowb();
  10396. barrier();
  10397. /* Unset iSCSI L2 MAC */
  10398. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10399. BNX2X_ISCSI_ETH_MAC, true);
  10400. break;
  10401. }
  10402. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10403. int count = ctl->data.credit.credit_count;
  10404. smp_mb__before_atomic_inc();
  10405. atomic_add(count, &bp->cq_spq_left);
  10406. smp_mb__after_atomic_inc();
  10407. break;
  10408. }
  10409. case DRV_CTL_ULP_REGISTER_CMD: {
  10410. int ulp_type = ctl->data.ulp_type;
  10411. if (CHIP_IS_E3(bp)) {
  10412. int idx = BP_FW_MB_IDX(bp);
  10413. u32 cap;
  10414. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10415. if (ulp_type == CNIC_ULP_ISCSI)
  10416. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10417. else if (ulp_type == CNIC_ULP_FCOE)
  10418. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10419. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10420. }
  10421. break;
  10422. }
  10423. case DRV_CTL_ULP_UNREGISTER_CMD: {
  10424. int ulp_type = ctl->data.ulp_type;
  10425. if (CHIP_IS_E3(bp)) {
  10426. int idx = BP_FW_MB_IDX(bp);
  10427. u32 cap;
  10428. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10429. if (ulp_type == CNIC_ULP_ISCSI)
  10430. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10431. else if (ulp_type == CNIC_ULP_FCOE)
  10432. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10433. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10434. }
  10435. break;
  10436. }
  10437. default:
  10438. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10439. rc = -EINVAL;
  10440. }
  10441. return rc;
  10442. }
  10443. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10444. {
  10445. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10446. if (bp->flags & USING_MSIX_FLAG) {
  10447. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10448. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10449. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10450. } else {
  10451. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10452. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10453. }
  10454. if (!CHIP_IS_E1x(bp))
  10455. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  10456. else
  10457. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  10458. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  10459. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  10460. cp->irq_arr[1].status_blk = bp->def_status_blk;
  10461. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  10462. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  10463. cp->num_irq = 2;
  10464. }
  10465. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  10466. void *data)
  10467. {
  10468. struct bnx2x *bp = netdev_priv(dev);
  10469. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10470. if (ops == NULL) {
  10471. BNX2X_ERR("NULL ops received\n");
  10472. return -EINVAL;
  10473. }
  10474. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  10475. if (!bp->cnic_kwq)
  10476. return -ENOMEM;
  10477. bp->cnic_kwq_cons = bp->cnic_kwq;
  10478. bp->cnic_kwq_prod = bp->cnic_kwq;
  10479. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  10480. bp->cnic_spq_pending = 0;
  10481. bp->cnic_kwq_pending = 0;
  10482. bp->cnic_data = data;
  10483. cp->num_irq = 0;
  10484. cp->drv_state |= CNIC_DRV_STATE_REGD;
  10485. cp->iro_arr = bp->iro_arr;
  10486. bnx2x_setup_cnic_irq_info(bp);
  10487. rcu_assign_pointer(bp->cnic_ops, ops);
  10488. return 0;
  10489. }
  10490. static int bnx2x_unregister_cnic(struct net_device *dev)
  10491. {
  10492. struct bnx2x *bp = netdev_priv(dev);
  10493. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10494. mutex_lock(&bp->cnic_mutex);
  10495. cp->drv_state = 0;
  10496. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  10497. mutex_unlock(&bp->cnic_mutex);
  10498. synchronize_rcu();
  10499. kfree(bp->cnic_kwq);
  10500. bp->cnic_kwq = NULL;
  10501. return 0;
  10502. }
  10503. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  10504. {
  10505. struct bnx2x *bp = netdev_priv(dev);
  10506. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10507. /* If both iSCSI and FCoE are disabled - return NULL in
  10508. * order to indicate CNIC that it should not try to work
  10509. * with this device.
  10510. */
  10511. if (NO_ISCSI(bp) && NO_FCOE(bp))
  10512. return NULL;
  10513. cp->drv_owner = THIS_MODULE;
  10514. cp->chip_id = CHIP_ID(bp);
  10515. cp->pdev = bp->pdev;
  10516. cp->io_base = bp->regview;
  10517. cp->io_base2 = bp->doorbells;
  10518. cp->max_kwqe_pending = 8;
  10519. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  10520. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10521. bnx2x_cid_ilt_lines(bp);
  10522. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10523. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10524. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10525. cp->drv_ctl = bnx2x_drv_ctl;
  10526. cp->drv_register_cnic = bnx2x_register_cnic;
  10527. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10528. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
  10529. cp->iscsi_l2_client_id =
  10530. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10531. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
  10532. if (NO_ISCSI_OOO(bp))
  10533. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10534. if (NO_ISCSI(bp))
  10535. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  10536. if (NO_FCOE(bp))
  10537. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  10538. BNX2X_DEV_INFO(
  10539. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  10540. cp->ctx_blk_size,
  10541. cp->ctx_tbl_offset,
  10542. cp->ctx_tbl_len,
  10543. cp->starting_cid);
  10544. return cp;
  10545. }
  10546. EXPORT_SYMBOL(bnx2x_cnic_probe);
  10547. #endif /* BCM_CNIC */