bnx2x_main.c 308 KB

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