bnx2x_main.c 308 KB

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