bnx2x_main.c 319 KB

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