bnx2x_main.c 319 KB

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