bnx2x_main.c 343 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_dcb.h"
  60. #include "bnx2x_sp.h"
  61. #include <linux/firmware.h>
  62. #include "bnx2x_fw_file_hdr.h"
  63. /* FW files */
  64. #define FW_FILE_VERSION \
  65. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  66. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  68. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  69. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  70. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  72. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  73. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] __devinitdata =
  76. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  77. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  78. MODULE_AUTHOR("Eliezer Tamir");
  79. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  80. "BCM57710/57711/57711E/"
  81. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  82. "57840/57840_MF Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_MODULE_VERSION);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues,
  91. " Set number of queues (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. #define INT_MODE_INTx 1
  96. #define INT_MODE_MSI 2
  97. int int_mode;
  98. module_param(int_mode, int, 0);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, 0);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, 0);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, 0);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. struct workqueue_struct *bnx2x_wq;
  111. enum bnx2x_board_type {
  112. BCM57710 = 0,
  113. BCM57711,
  114. BCM57711E,
  115. BCM57712,
  116. BCM57712_MF,
  117. BCM57800,
  118. BCM57800_MF,
  119. BCM57810,
  120. BCM57810_MF,
  121. BCM57840_O,
  122. BCM57840_4_10,
  123. BCM57840_2_20,
  124. BCM57840_MFO,
  125. BCM57840_MF,
  126. BCM57811,
  127. BCM57811_MF
  128. };
  129. /* indexed by board_type, above */
  130. static struct {
  131. char *name;
  132. } board_info[] __devinitdata = {
  133. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  134. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  135. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  136. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  137. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  138. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  139. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  140. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  141. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  142. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  143. { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  144. { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  145. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  146. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  147. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
  148. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
  149. };
  150. #ifndef PCI_DEVICE_ID_NX2_57710
  151. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  152. #endif
  153. #ifndef PCI_DEVICE_ID_NX2_57711
  154. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  155. #endif
  156. #ifndef PCI_DEVICE_ID_NX2_57711E
  157. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  158. #endif
  159. #ifndef PCI_DEVICE_ID_NX2_57712
  160. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  161. #endif
  162. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  163. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  164. #endif
  165. #ifndef PCI_DEVICE_ID_NX2_57800
  166. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  167. #endif
  168. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  169. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57810
  172. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  175. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57840_O
  178. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  181. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  184. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  187. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  190. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57811
  193. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  196. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  197. #endif
  198. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  199. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  200. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  201. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  202. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  203. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  204. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  205. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  206. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  207. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  208. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  209. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  210. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  211. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  212. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  213. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  214. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  215. { 0 }
  216. };
  217. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  218. /* Global resources for unloading a previously loaded device */
  219. #define BNX2X_PREV_WAIT_NEEDED 1
  220. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  221. static LIST_HEAD(bnx2x_prev_list);
  222. /****************************************************************************
  223. * General service functions
  224. ****************************************************************************/
  225. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  226. u32 addr, dma_addr_t mapping)
  227. {
  228. REG_WR(bp, addr, U64_LO(mapping));
  229. REG_WR(bp, addr + 4, U64_HI(mapping));
  230. }
  231. static void storm_memset_spq_addr(struct bnx2x *bp,
  232. dma_addr_t mapping, u16 abs_fid)
  233. {
  234. u32 addr = XSEM_REG_FAST_MEMORY +
  235. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  236. __storm_memset_dma_mapping(bp, addr, mapping);
  237. }
  238. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  239. u16 pf_id)
  240. {
  241. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  242. pf_id);
  243. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  244. pf_id);
  245. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  246. pf_id);
  247. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  248. pf_id);
  249. }
  250. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  251. u8 enable)
  252. {
  253. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  254. enable);
  255. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  256. enable);
  257. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  258. enable);
  259. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  260. enable);
  261. }
  262. static void storm_memset_eq_data(struct bnx2x *bp,
  263. struct event_ring_data *eq_data,
  264. u16 pfid)
  265. {
  266. size_t size = sizeof(struct event_ring_data);
  267. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  268. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  269. }
  270. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  271. u16 pfid)
  272. {
  273. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  274. REG_WR16(bp, addr, eq_prod);
  275. }
  276. /* used only at init
  277. * locking is done by mcp
  278. */
  279. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  280. {
  281. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  282. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  283. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  284. PCICFG_VENDOR_ID_OFFSET);
  285. }
  286. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  287. {
  288. u32 val;
  289. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  290. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  291. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  292. PCICFG_VENDOR_ID_OFFSET);
  293. return val;
  294. }
  295. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  296. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  297. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  298. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  299. #define DMAE_DP_DST_NONE "dst_addr [none]"
  300. /* copy command into DMAE command memory and set DMAE command go */
  301. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  302. {
  303. u32 cmd_offset;
  304. int i;
  305. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  306. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  307. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  308. }
  309. REG_WR(bp, dmae_reg_go_c[idx], 1);
  310. }
  311. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  312. {
  313. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  314. DMAE_CMD_C_ENABLE);
  315. }
  316. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  317. {
  318. return opcode & ~DMAE_CMD_SRC_RESET;
  319. }
  320. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  321. bool with_comp, u8 comp_type)
  322. {
  323. u32 opcode = 0;
  324. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  325. (dst_type << DMAE_COMMAND_DST_SHIFT));
  326. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  327. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  328. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  329. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  330. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  331. #ifdef __BIG_ENDIAN
  332. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  333. #else
  334. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  335. #endif
  336. if (with_comp)
  337. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  338. return opcode;
  339. }
  340. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  341. struct dmae_command *dmae,
  342. u8 src_type, u8 dst_type)
  343. {
  344. memset(dmae, 0, sizeof(struct dmae_command));
  345. /* set the opcode */
  346. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  347. true, DMAE_COMP_PCI);
  348. /* fill in the completion parameters */
  349. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  350. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  351. dmae->comp_val = DMAE_COMP_VAL;
  352. }
  353. /* issue a dmae command over the init-channel and wailt for completion */
  354. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  355. struct dmae_command *dmae)
  356. {
  357. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  358. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  359. int rc = 0;
  360. /*
  361. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  362. * as long as this code is called both from syscall context and
  363. * from ndo_set_rx_mode() flow that may be called from BH.
  364. */
  365. spin_lock_bh(&bp->dmae_lock);
  366. /* reset completion */
  367. *wb_comp = 0;
  368. /* post the command on the channel used for initializations */
  369. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  370. /* wait for completion */
  371. udelay(5);
  372. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  373. if (!cnt ||
  374. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  375. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  376. BNX2X_ERR("DMAE timeout!\n");
  377. rc = DMAE_TIMEOUT;
  378. goto unlock;
  379. }
  380. cnt--;
  381. udelay(50);
  382. }
  383. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  384. BNX2X_ERR("DMAE PCI error!\n");
  385. rc = DMAE_PCI_ERROR;
  386. }
  387. unlock:
  388. spin_unlock_bh(&bp->dmae_lock);
  389. return rc;
  390. }
  391. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  392. u32 len32)
  393. {
  394. struct dmae_command dmae;
  395. if (!bp->dmae_ready) {
  396. u32 *data = bnx2x_sp(bp, wb_data[0]);
  397. if (CHIP_IS_E1(bp))
  398. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  399. else
  400. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  401. return;
  402. }
  403. /* set opcode and fixed command fields */
  404. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  405. /* fill in addresses and len */
  406. dmae.src_addr_lo = U64_LO(dma_addr);
  407. dmae.src_addr_hi = U64_HI(dma_addr);
  408. dmae.dst_addr_lo = dst_addr >> 2;
  409. dmae.dst_addr_hi = 0;
  410. dmae.len = len32;
  411. /* issue the command and wait for completion */
  412. bnx2x_issue_dmae_with_comp(bp, &dmae);
  413. }
  414. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  415. {
  416. struct dmae_command dmae;
  417. if (!bp->dmae_ready) {
  418. u32 *data = bnx2x_sp(bp, wb_data[0]);
  419. int i;
  420. if (CHIP_IS_E1(bp))
  421. for (i = 0; i < len32; i++)
  422. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  423. else
  424. for (i = 0; i < len32; i++)
  425. data[i] = REG_RD(bp, src_addr + i*4);
  426. return;
  427. }
  428. /* set opcode and fixed command fields */
  429. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  430. /* fill in addresses and len */
  431. dmae.src_addr_lo = src_addr >> 2;
  432. dmae.src_addr_hi = 0;
  433. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  434. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  435. dmae.len = len32;
  436. /* issue the command and wait for completion */
  437. bnx2x_issue_dmae_with_comp(bp, &dmae);
  438. }
  439. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  440. u32 addr, u32 len)
  441. {
  442. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  443. int offset = 0;
  444. while (len > dmae_wr_max) {
  445. bnx2x_write_dmae(bp, phys_addr + offset,
  446. addr + offset, dmae_wr_max);
  447. offset += dmae_wr_max * 4;
  448. len -= dmae_wr_max;
  449. }
  450. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  451. }
  452. static int bnx2x_mc_assert(struct bnx2x *bp)
  453. {
  454. char last_idx;
  455. int i, rc = 0;
  456. u32 row0, row1, row2, row3;
  457. /* XSTORM */
  458. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  459. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  460. if (last_idx)
  461. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  462. /* print the asserts */
  463. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  464. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  465. XSTORM_ASSERT_LIST_OFFSET(i));
  466. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  467. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  468. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  469. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  470. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  471. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  472. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  473. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  474. i, row3, row2, row1, row0);
  475. rc++;
  476. } else {
  477. break;
  478. }
  479. }
  480. /* TSTORM */
  481. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  482. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  483. if (last_idx)
  484. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  485. /* print the asserts */
  486. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  487. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  488. TSTORM_ASSERT_LIST_OFFSET(i));
  489. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  490. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  491. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  492. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  493. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  494. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  495. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  496. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  497. i, row3, row2, row1, row0);
  498. rc++;
  499. } else {
  500. break;
  501. }
  502. }
  503. /* CSTORM */
  504. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  505. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  506. if (last_idx)
  507. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  508. /* print the asserts */
  509. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  510. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  511. CSTORM_ASSERT_LIST_OFFSET(i));
  512. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  513. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  514. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  515. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  516. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  517. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  518. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  519. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  520. i, row3, row2, row1, row0);
  521. rc++;
  522. } else {
  523. break;
  524. }
  525. }
  526. /* USTORM */
  527. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  528. USTORM_ASSERT_LIST_INDEX_OFFSET);
  529. if (last_idx)
  530. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  531. /* print the asserts */
  532. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  533. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  534. USTORM_ASSERT_LIST_OFFSET(i));
  535. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  536. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  537. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  538. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  539. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  540. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  541. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  542. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  543. i, row3, row2, row1, row0);
  544. rc++;
  545. } else {
  546. break;
  547. }
  548. }
  549. return rc;
  550. }
  551. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  552. {
  553. u32 addr, val;
  554. u32 mark, offset;
  555. __be32 data[9];
  556. int word;
  557. u32 trace_shmem_base;
  558. if (BP_NOMCP(bp)) {
  559. BNX2X_ERR("NO MCP - can not dump\n");
  560. return;
  561. }
  562. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  563. (bp->common.bc_ver & 0xff0000) >> 16,
  564. (bp->common.bc_ver & 0xff00) >> 8,
  565. (bp->common.bc_ver & 0xff));
  566. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  567. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  568. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  569. if (BP_PATH(bp) == 0)
  570. trace_shmem_base = bp->common.shmem_base;
  571. else
  572. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  573. addr = trace_shmem_base - 0x800;
  574. /* validate TRCB signature */
  575. mark = REG_RD(bp, addr);
  576. if (mark != MFW_TRACE_SIGNATURE) {
  577. BNX2X_ERR("Trace buffer signature is missing.");
  578. return ;
  579. }
  580. /* read cyclic buffer pointer */
  581. addr += 4;
  582. mark = REG_RD(bp, addr);
  583. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  584. + ((mark + 0x3) & ~0x3) - 0x08000000;
  585. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  586. printk("%s", lvl);
  587. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  588. for (word = 0; word < 8; word++)
  589. data[word] = htonl(REG_RD(bp, offset + 4*word));
  590. data[8] = 0x0;
  591. pr_cont("%s", (char *)data);
  592. }
  593. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  594. for (word = 0; word < 8; word++)
  595. data[word] = htonl(REG_RD(bp, offset + 4*word));
  596. data[8] = 0x0;
  597. pr_cont("%s", (char *)data);
  598. }
  599. printk("%s" "end of fw dump\n", lvl);
  600. }
  601. static void bnx2x_fw_dump(struct bnx2x *bp)
  602. {
  603. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  604. }
  605. void bnx2x_panic_dump(struct bnx2x *bp)
  606. {
  607. int i;
  608. u16 j;
  609. struct hc_sp_status_block_data sp_sb_data;
  610. int func = BP_FUNC(bp);
  611. #ifdef BNX2X_STOP_ON_ERROR
  612. u16 start = 0, end = 0;
  613. u8 cos;
  614. #endif
  615. bp->stats_state = STATS_STATE_DISABLED;
  616. bp->eth_stats.unrecoverable_error++;
  617. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  618. BNX2X_ERR("begin crash dump -----------------\n");
  619. /* Indices */
  620. /* Common */
  621. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  622. bp->def_idx, bp->def_att_idx, bp->attn_state,
  623. bp->spq_prod_idx, bp->stats_counter);
  624. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  625. bp->def_status_blk->atten_status_block.attn_bits,
  626. bp->def_status_blk->atten_status_block.attn_bits_ack,
  627. bp->def_status_blk->atten_status_block.status_block_id,
  628. bp->def_status_blk->atten_status_block.attn_bits_index);
  629. BNX2X_ERR(" def (");
  630. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  631. pr_cont("0x%x%s",
  632. bp->def_status_blk->sp_sb.index_values[i],
  633. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  634. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  635. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  636. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  637. i*sizeof(u32));
  638. 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",
  639. sp_sb_data.igu_sb_id,
  640. sp_sb_data.igu_seg_id,
  641. sp_sb_data.p_func.pf_id,
  642. sp_sb_data.p_func.vnic_id,
  643. sp_sb_data.p_func.vf_id,
  644. sp_sb_data.p_func.vf_valid,
  645. sp_sb_data.state);
  646. for_each_eth_queue(bp, i) {
  647. struct bnx2x_fastpath *fp = &bp->fp[i];
  648. int loop;
  649. struct hc_status_block_data_e2 sb_data_e2;
  650. struct hc_status_block_data_e1x sb_data_e1x;
  651. struct hc_status_block_sm *hc_sm_p =
  652. CHIP_IS_E1x(bp) ?
  653. sb_data_e1x.common.state_machine :
  654. sb_data_e2.common.state_machine;
  655. struct hc_index_data *hc_index_p =
  656. CHIP_IS_E1x(bp) ?
  657. sb_data_e1x.index_data :
  658. sb_data_e2.index_data;
  659. u8 data_size, cos;
  660. u32 *sb_data_p;
  661. struct bnx2x_fp_txdata txdata;
  662. /* Rx */
  663. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  664. i, fp->rx_bd_prod, fp->rx_bd_cons,
  665. fp->rx_comp_prod,
  666. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  667. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  668. fp->rx_sge_prod, fp->last_max_sge,
  669. le16_to_cpu(fp->fp_hc_idx));
  670. /* Tx */
  671. for_each_cos_in_tx_queue(fp, cos)
  672. {
  673. txdata = *fp->txdata_ptr[cos];
  674. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
  675. i, txdata.tx_pkt_prod,
  676. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  677. txdata.tx_bd_cons,
  678. le16_to_cpu(*txdata.tx_cons_sb));
  679. }
  680. loop = CHIP_IS_E1x(bp) ?
  681. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  682. /* host sb data */
  683. #ifdef BCM_CNIC
  684. if (IS_FCOE_FP(fp))
  685. continue;
  686. #endif
  687. BNX2X_ERR(" run indexes (");
  688. for (j = 0; j < HC_SB_MAX_SM; j++)
  689. pr_cont("0x%x%s",
  690. fp->sb_running_index[j],
  691. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  692. BNX2X_ERR(" indexes (");
  693. for (j = 0; j < loop; j++)
  694. pr_cont("0x%x%s",
  695. fp->sb_index_values[j],
  696. (j == loop - 1) ? ")" : " ");
  697. /* fw sb data */
  698. data_size = CHIP_IS_E1x(bp) ?
  699. sizeof(struct hc_status_block_data_e1x) :
  700. sizeof(struct hc_status_block_data_e2);
  701. data_size /= sizeof(u32);
  702. sb_data_p = CHIP_IS_E1x(bp) ?
  703. (u32 *)&sb_data_e1x :
  704. (u32 *)&sb_data_e2;
  705. /* copy sb data in here */
  706. for (j = 0; j < data_size; j++)
  707. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  708. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  709. j * sizeof(u32));
  710. if (!CHIP_IS_E1x(bp)) {
  711. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  712. sb_data_e2.common.p_func.pf_id,
  713. sb_data_e2.common.p_func.vf_id,
  714. sb_data_e2.common.p_func.vf_valid,
  715. sb_data_e2.common.p_func.vnic_id,
  716. sb_data_e2.common.same_igu_sb_1b,
  717. sb_data_e2.common.state);
  718. } else {
  719. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  720. sb_data_e1x.common.p_func.pf_id,
  721. sb_data_e1x.common.p_func.vf_id,
  722. sb_data_e1x.common.p_func.vf_valid,
  723. sb_data_e1x.common.p_func.vnic_id,
  724. sb_data_e1x.common.same_igu_sb_1b,
  725. sb_data_e1x.common.state);
  726. }
  727. /* SB_SMs data */
  728. for (j = 0; j < HC_SB_MAX_SM; j++) {
  729. pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
  730. j, hc_sm_p[j].__flags,
  731. hc_sm_p[j].igu_sb_id,
  732. hc_sm_p[j].igu_seg_id,
  733. hc_sm_p[j].time_to_expire,
  734. hc_sm_p[j].timer_value);
  735. }
  736. /* Indecies data */
  737. for (j = 0; j < loop; j++) {
  738. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  739. hc_index_p[j].flags,
  740. hc_index_p[j].timeout);
  741. }
  742. }
  743. #ifdef BNX2X_STOP_ON_ERROR
  744. /* Rings */
  745. /* Rx */
  746. for_each_rx_queue(bp, i) {
  747. struct bnx2x_fastpath *fp = &bp->fp[i];
  748. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  749. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  750. for (j = start; j != end; j = RX_BD(j + 1)) {
  751. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  752. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  753. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  754. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  755. }
  756. start = RX_SGE(fp->rx_sge_prod);
  757. end = RX_SGE(fp->last_max_sge);
  758. for (j = start; j != end; j = RX_SGE(j + 1)) {
  759. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  760. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  761. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  762. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  763. }
  764. start = RCQ_BD(fp->rx_comp_cons - 10);
  765. end = RCQ_BD(fp->rx_comp_cons + 503);
  766. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  767. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  768. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  769. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  770. }
  771. }
  772. /* Tx */
  773. for_each_tx_queue(bp, i) {
  774. struct bnx2x_fastpath *fp = &bp->fp[i];
  775. for_each_cos_in_tx_queue(fp, cos) {
  776. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  777. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  778. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  779. for (j = start; j != end; j = TX_BD(j + 1)) {
  780. struct sw_tx_bd *sw_bd =
  781. &txdata->tx_buf_ring[j];
  782. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  783. i, cos, j, sw_bd->skb,
  784. sw_bd->first_bd);
  785. }
  786. start = TX_BD(txdata->tx_bd_cons - 10);
  787. end = TX_BD(txdata->tx_bd_cons + 254);
  788. for (j = start; j != end; j = TX_BD(j + 1)) {
  789. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  790. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  791. i, cos, j, tx_bd[0], tx_bd[1],
  792. tx_bd[2], tx_bd[3]);
  793. }
  794. }
  795. }
  796. #endif
  797. bnx2x_fw_dump(bp);
  798. bnx2x_mc_assert(bp);
  799. BNX2X_ERR("end crash dump -----------------\n");
  800. }
  801. /*
  802. * FLR Support for E2
  803. *
  804. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  805. * initialization.
  806. */
  807. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  808. #define FLR_WAIT_INTERVAL 50 /* usec */
  809. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  810. struct pbf_pN_buf_regs {
  811. int pN;
  812. u32 init_crd;
  813. u32 crd;
  814. u32 crd_freed;
  815. };
  816. struct pbf_pN_cmd_regs {
  817. int pN;
  818. u32 lines_occup;
  819. u32 lines_freed;
  820. };
  821. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  822. struct pbf_pN_buf_regs *regs,
  823. u32 poll_count)
  824. {
  825. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  826. u32 cur_cnt = poll_count;
  827. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  828. crd = crd_start = REG_RD(bp, regs->crd);
  829. init_crd = REG_RD(bp, regs->init_crd);
  830. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  831. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  832. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  833. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  834. (init_crd - crd_start))) {
  835. if (cur_cnt--) {
  836. udelay(FLR_WAIT_INTERVAL);
  837. crd = REG_RD(bp, regs->crd);
  838. crd_freed = REG_RD(bp, regs->crd_freed);
  839. } else {
  840. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  841. regs->pN);
  842. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  843. regs->pN, crd);
  844. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  845. regs->pN, crd_freed);
  846. break;
  847. }
  848. }
  849. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  850. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  851. }
  852. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  853. struct pbf_pN_cmd_regs *regs,
  854. u32 poll_count)
  855. {
  856. u32 occup, to_free, freed, freed_start;
  857. u32 cur_cnt = poll_count;
  858. occup = to_free = REG_RD(bp, regs->lines_occup);
  859. freed = freed_start = REG_RD(bp, regs->lines_freed);
  860. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  861. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  862. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  863. if (cur_cnt--) {
  864. udelay(FLR_WAIT_INTERVAL);
  865. occup = REG_RD(bp, regs->lines_occup);
  866. freed = REG_RD(bp, regs->lines_freed);
  867. } else {
  868. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  869. regs->pN);
  870. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  871. regs->pN, occup);
  872. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  873. regs->pN, freed);
  874. break;
  875. }
  876. }
  877. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  878. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  879. }
  880. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  881. u32 expected, u32 poll_count)
  882. {
  883. u32 cur_cnt = poll_count;
  884. u32 val;
  885. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  886. udelay(FLR_WAIT_INTERVAL);
  887. return val;
  888. }
  889. static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  890. char *msg, u32 poll_cnt)
  891. {
  892. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  893. if (val != 0) {
  894. BNX2X_ERR("%s usage count=%d\n", msg, val);
  895. return 1;
  896. }
  897. return 0;
  898. }
  899. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  900. {
  901. /* adjust polling timeout */
  902. if (CHIP_REV_IS_EMUL(bp))
  903. return FLR_POLL_CNT * 2000;
  904. if (CHIP_REV_IS_FPGA(bp))
  905. return FLR_POLL_CNT * 120;
  906. return FLR_POLL_CNT;
  907. }
  908. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  909. {
  910. struct pbf_pN_cmd_regs cmd_regs[] = {
  911. {0, (CHIP_IS_E3B0(bp)) ?
  912. PBF_REG_TQ_OCCUPANCY_Q0 :
  913. PBF_REG_P0_TQ_OCCUPANCY,
  914. (CHIP_IS_E3B0(bp)) ?
  915. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  916. PBF_REG_P0_TQ_LINES_FREED_CNT},
  917. {1, (CHIP_IS_E3B0(bp)) ?
  918. PBF_REG_TQ_OCCUPANCY_Q1 :
  919. PBF_REG_P1_TQ_OCCUPANCY,
  920. (CHIP_IS_E3B0(bp)) ?
  921. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  922. PBF_REG_P1_TQ_LINES_FREED_CNT},
  923. {4, (CHIP_IS_E3B0(bp)) ?
  924. PBF_REG_TQ_OCCUPANCY_LB_Q :
  925. PBF_REG_P4_TQ_OCCUPANCY,
  926. (CHIP_IS_E3B0(bp)) ?
  927. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  928. PBF_REG_P4_TQ_LINES_FREED_CNT}
  929. };
  930. struct pbf_pN_buf_regs buf_regs[] = {
  931. {0, (CHIP_IS_E3B0(bp)) ?
  932. PBF_REG_INIT_CRD_Q0 :
  933. PBF_REG_P0_INIT_CRD ,
  934. (CHIP_IS_E3B0(bp)) ?
  935. PBF_REG_CREDIT_Q0 :
  936. PBF_REG_P0_CREDIT,
  937. (CHIP_IS_E3B0(bp)) ?
  938. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  939. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  940. {1, (CHIP_IS_E3B0(bp)) ?
  941. PBF_REG_INIT_CRD_Q1 :
  942. PBF_REG_P1_INIT_CRD,
  943. (CHIP_IS_E3B0(bp)) ?
  944. PBF_REG_CREDIT_Q1 :
  945. PBF_REG_P1_CREDIT,
  946. (CHIP_IS_E3B0(bp)) ?
  947. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  948. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  949. {4, (CHIP_IS_E3B0(bp)) ?
  950. PBF_REG_INIT_CRD_LB_Q :
  951. PBF_REG_P4_INIT_CRD,
  952. (CHIP_IS_E3B0(bp)) ?
  953. PBF_REG_CREDIT_LB_Q :
  954. PBF_REG_P4_CREDIT,
  955. (CHIP_IS_E3B0(bp)) ?
  956. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  957. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  958. };
  959. int i;
  960. /* Verify the command queues are flushed P0, P1, P4 */
  961. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  962. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  963. /* Verify the transmission buffers are flushed P0, P1, P4 */
  964. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  965. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  966. }
  967. #define OP_GEN_PARAM(param) \
  968. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  969. #define OP_GEN_TYPE(type) \
  970. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  971. #define OP_GEN_AGG_VECT(index) \
  972. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  973. static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  974. u32 poll_cnt)
  975. {
  976. struct sdm_op_gen op_gen = {0};
  977. u32 comp_addr = BAR_CSTRORM_INTMEM +
  978. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  979. int ret = 0;
  980. if (REG_RD(bp, comp_addr)) {
  981. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  982. return 1;
  983. }
  984. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  985. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  986. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  987. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  988. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  989. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  990. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  991. BNX2X_ERR("FW final cleanup did not succeed\n");
  992. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  993. (REG_RD(bp, comp_addr)));
  994. ret = 1;
  995. }
  996. /* Zero completion for nxt FLR */
  997. REG_WR(bp, comp_addr, 0);
  998. return ret;
  999. }
  1000. static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1001. {
  1002. int pos;
  1003. u16 status;
  1004. pos = pci_pcie_cap(dev);
  1005. if (!pos)
  1006. return false;
  1007. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  1008. return status & PCI_EXP_DEVSTA_TRPND;
  1009. }
  1010. /* PF FLR specific routines
  1011. */
  1012. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1013. {
  1014. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1015. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1016. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1017. "CFC PF usage counter timed out",
  1018. poll_cnt))
  1019. return 1;
  1020. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1021. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1022. DORQ_REG_PF_USAGE_CNT,
  1023. "DQ PF usage counter timed out",
  1024. poll_cnt))
  1025. return 1;
  1026. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1027. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1028. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1029. "QM PF usage counter timed out",
  1030. poll_cnt))
  1031. return 1;
  1032. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1033. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1034. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1035. "Timers VNIC usage counter timed out",
  1036. poll_cnt))
  1037. return 1;
  1038. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1039. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1040. "Timers NUM_SCANS usage counter timed out",
  1041. poll_cnt))
  1042. return 1;
  1043. /* Wait DMAE PF usage counter to zero */
  1044. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1045. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1046. "DMAE dommand register timed out",
  1047. poll_cnt))
  1048. return 1;
  1049. return 0;
  1050. }
  1051. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1052. {
  1053. u32 val;
  1054. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1055. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1056. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1057. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1058. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1059. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1060. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1061. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1062. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1063. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1064. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1065. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1066. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1067. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1068. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1069. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1070. val);
  1071. }
  1072. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1073. {
  1074. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1075. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1076. /* Re-enable PF target read access */
  1077. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1078. /* Poll HW usage counters */
  1079. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1080. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1081. return -EBUSY;
  1082. /* Zero the igu 'trailing edge' and 'leading edge' */
  1083. /* Send the FW cleanup command */
  1084. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1085. return -EBUSY;
  1086. /* ATC cleanup */
  1087. /* Verify TX hw is flushed */
  1088. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1089. /* Wait 100ms (not adjusted according to platform) */
  1090. msleep(100);
  1091. /* Verify no pending pci transactions */
  1092. if (bnx2x_is_pcie_pending(bp->pdev))
  1093. BNX2X_ERR("PCIE Transactions still pending\n");
  1094. /* Debug */
  1095. bnx2x_hw_enable_status(bp);
  1096. /*
  1097. * Master enable - Due to WB DMAE writes performed before this
  1098. * register is re-initialized as part of the regular function init
  1099. */
  1100. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1101. return 0;
  1102. }
  1103. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1104. {
  1105. int port = BP_PORT(bp);
  1106. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1107. u32 val = REG_RD(bp, addr);
  1108. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1109. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1110. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1111. if (msix) {
  1112. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1113. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1114. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1115. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1116. if (single_msix)
  1117. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1118. } else if (msi) {
  1119. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1120. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1121. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1122. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1123. } else {
  1124. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1125. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1126. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1127. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1128. if (!CHIP_IS_E1(bp)) {
  1129. DP(NETIF_MSG_IFUP,
  1130. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1131. REG_WR(bp, addr, val);
  1132. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1133. }
  1134. }
  1135. if (CHIP_IS_E1(bp))
  1136. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1137. DP(NETIF_MSG_IFUP,
  1138. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1139. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1140. REG_WR(bp, addr, val);
  1141. /*
  1142. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1143. */
  1144. mmiowb();
  1145. barrier();
  1146. if (!CHIP_IS_E1(bp)) {
  1147. /* init leading/trailing edge */
  1148. if (IS_MF(bp)) {
  1149. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1150. if (bp->port.pmf)
  1151. /* enable nig and gpio3 attention */
  1152. val |= 0x1100;
  1153. } else
  1154. val = 0xffff;
  1155. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1156. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1157. }
  1158. /* Make sure that interrupts are indeed enabled from here on */
  1159. mmiowb();
  1160. }
  1161. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1162. {
  1163. u32 val;
  1164. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1165. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1166. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1167. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1168. if (msix) {
  1169. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1170. IGU_PF_CONF_SINGLE_ISR_EN);
  1171. val |= (IGU_PF_CONF_FUNC_EN |
  1172. IGU_PF_CONF_MSI_MSIX_EN |
  1173. IGU_PF_CONF_ATTN_BIT_EN);
  1174. if (single_msix)
  1175. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1176. } else if (msi) {
  1177. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1178. val |= (IGU_PF_CONF_FUNC_EN |
  1179. IGU_PF_CONF_MSI_MSIX_EN |
  1180. IGU_PF_CONF_ATTN_BIT_EN |
  1181. IGU_PF_CONF_SINGLE_ISR_EN);
  1182. } else {
  1183. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1184. val |= (IGU_PF_CONF_FUNC_EN |
  1185. IGU_PF_CONF_INT_LINE_EN |
  1186. IGU_PF_CONF_ATTN_BIT_EN |
  1187. IGU_PF_CONF_SINGLE_ISR_EN);
  1188. }
  1189. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1190. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1191. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1192. if (val & IGU_PF_CONF_INT_LINE_EN)
  1193. pci_intx(bp->pdev, true);
  1194. barrier();
  1195. /* init leading/trailing edge */
  1196. if (IS_MF(bp)) {
  1197. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1198. if (bp->port.pmf)
  1199. /* enable nig and gpio3 attention */
  1200. val |= 0x1100;
  1201. } else
  1202. val = 0xffff;
  1203. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1204. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1205. /* Make sure that interrupts are indeed enabled from here on */
  1206. mmiowb();
  1207. }
  1208. void bnx2x_int_enable(struct bnx2x *bp)
  1209. {
  1210. if (bp->common.int_block == INT_BLOCK_HC)
  1211. bnx2x_hc_int_enable(bp);
  1212. else
  1213. bnx2x_igu_int_enable(bp);
  1214. }
  1215. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1216. {
  1217. int port = BP_PORT(bp);
  1218. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1219. u32 val = REG_RD(bp, addr);
  1220. /*
  1221. * in E1 we must use only PCI configuration space to disable
  1222. * MSI/MSIX capablility
  1223. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1224. */
  1225. if (CHIP_IS_E1(bp)) {
  1226. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1227. * Use mask register to prevent from HC sending interrupts
  1228. * after we exit the function
  1229. */
  1230. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1231. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1232. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1233. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1234. } else
  1235. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1236. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1237. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1238. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1239. DP(NETIF_MSG_IFDOWN,
  1240. "write %x to HC %d (addr 0x%x)\n",
  1241. val, port, addr);
  1242. /* flush all outstanding writes */
  1243. mmiowb();
  1244. REG_WR(bp, addr, val);
  1245. if (REG_RD(bp, addr) != val)
  1246. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1247. }
  1248. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1249. {
  1250. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1251. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1252. IGU_PF_CONF_INT_LINE_EN |
  1253. IGU_PF_CONF_ATTN_BIT_EN);
  1254. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1255. /* flush all outstanding writes */
  1256. mmiowb();
  1257. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1258. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1259. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1260. }
  1261. void bnx2x_int_disable(struct bnx2x *bp)
  1262. {
  1263. if (bp->common.int_block == INT_BLOCK_HC)
  1264. bnx2x_hc_int_disable(bp);
  1265. else
  1266. bnx2x_igu_int_disable(bp);
  1267. }
  1268. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1269. {
  1270. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1271. int i, offset;
  1272. if (disable_hw)
  1273. /* prevent the HW from sending interrupts */
  1274. bnx2x_int_disable(bp);
  1275. /* make sure all ISRs are done */
  1276. if (msix) {
  1277. synchronize_irq(bp->msix_table[0].vector);
  1278. offset = 1;
  1279. #ifdef BCM_CNIC
  1280. offset++;
  1281. #endif
  1282. for_each_eth_queue(bp, i)
  1283. synchronize_irq(bp->msix_table[offset++].vector);
  1284. } else
  1285. synchronize_irq(bp->pdev->irq);
  1286. /* make sure sp_task is not running */
  1287. cancel_delayed_work(&bp->sp_task);
  1288. cancel_delayed_work(&bp->period_task);
  1289. flush_workqueue(bnx2x_wq);
  1290. }
  1291. /* fast path */
  1292. /*
  1293. * General service functions
  1294. */
  1295. /* Return true if succeeded to acquire the lock */
  1296. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1297. {
  1298. u32 lock_status;
  1299. u32 resource_bit = (1 << resource);
  1300. int func = BP_FUNC(bp);
  1301. u32 hw_lock_control_reg;
  1302. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1303. "Trying to take a lock on resource %d\n", resource);
  1304. /* Validating that the resource is within range */
  1305. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1306. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1307. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1308. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1309. return false;
  1310. }
  1311. if (func <= 5)
  1312. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1313. else
  1314. hw_lock_control_reg =
  1315. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1316. /* Try to acquire the lock */
  1317. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1318. lock_status = REG_RD(bp, hw_lock_control_reg);
  1319. if (lock_status & resource_bit)
  1320. return true;
  1321. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1322. "Failed to get a lock on resource %d\n", resource);
  1323. return false;
  1324. }
  1325. /**
  1326. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1327. *
  1328. * @bp: driver handle
  1329. *
  1330. * Returns the recovery leader resource id according to the engine this function
  1331. * belongs to. Currently only only 2 engines is supported.
  1332. */
  1333. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1334. {
  1335. if (BP_PATH(bp))
  1336. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1337. else
  1338. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1339. }
  1340. /**
  1341. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1342. *
  1343. * @bp: driver handle
  1344. *
  1345. * Tries to aquire a leader lock for current engine.
  1346. */
  1347. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1348. {
  1349. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1350. }
  1351. #ifdef BCM_CNIC
  1352. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1353. #endif
  1354. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1355. {
  1356. struct bnx2x *bp = fp->bp;
  1357. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1358. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1359. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1360. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1361. DP(BNX2X_MSG_SP,
  1362. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1363. fp->index, cid, command, bp->state,
  1364. rr_cqe->ramrod_cqe.ramrod_type);
  1365. switch (command) {
  1366. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1367. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1368. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1369. break;
  1370. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1371. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1372. drv_cmd = BNX2X_Q_CMD_SETUP;
  1373. break;
  1374. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1375. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1376. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1377. break;
  1378. case (RAMROD_CMD_ID_ETH_HALT):
  1379. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1380. drv_cmd = BNX2X_Q_CMD_HALT;
  1381. break;
  1382. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1383. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1384. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1385. break;
  1386. case (RAMROD_CMD_ID_ETH_EMPTY):
  1387. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1388. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1389. break;
  1390. default:
  1391. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1392. command, fp->index);
  1393. return;
  1394. }
  1395. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1396. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1397. /* q_obj->complete_cmd() failure means that this was
  1398. * an unexpected completion.
  1399. *
  1400. * In this case we don't want to increase the bp->spq_left
  1401. * because apparently we haven't sent this command the first
  1402. * place.
  1403. */
  1404. #ifdef BNX2X_STOP_ON_ERROR
  1405. bnx2x_panic();
  1406. #else
  1407. return;
  1408. #endif
  1409. smp_mb__before_atomic_inc();
  1410. atomic_inc(&bp->cq_spq_left);
  1411. /* push the change in bp->spq_left and towards the memory */
  1412. smp_mb__after_atomic_inc();
  1413. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1414. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1415. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1416. /* if Q update ramrod is completed for last Q in AFEX vif set
  1417. * flow, then ACK MCP at the end
  1418. *
  1419. * mark pending ACK to MCP bit.
  1420. * prevent case that both bits are cleared.
  1421. * At the end of load/unload driver checks that
  1422. * sp_state is cleaerd, and this order prevents
  1423. * races
  1424. */
  1425. smp_mb__before_clear_bit();
  1426. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1427. wmb();
  1428. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1429. smp_mb__after_clear_bit();
  1430. /* schedule workqueue to send ack to MCP */
  1431. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1432. }
  1433. return;
  1434. }
  1435. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1436. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1437. {
  1438. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1439. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1440. start);
  1441. }
  1442. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1443. {
  1444. struct bnx2x *bp = netdev_priv(dev_instance);
  1445. u16 status = bnx2x_ack_int(bp);
  1446. u16 mask;
  1447. int i;
  1448. u8 cos;
  1449. /* Return here if interrupt is shared and it's not for us */
  1450. if (unlikely(status == 0)) {
  1451. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1452. return IRQ_NONE;
  1453. }
  1454. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1455. #ifdef BNX2X_STOP_ON_ERROR
  1456. if (unlikely(bp->panic))
  1457. return IRQ_HANDLED;
  1458. #endif
  1459. for_each_eth_queue(bp, i) {
  1460. struct bnx2x_fastpath *fp = &bp->fp[i];
  1461. mask = 0x2 << (fp->index + CNIC_PRESENT);
  1462. if (status & mask) {
  1463. /* Handle Rx or Tx according to SB id */
  1464. prefetch(fp->rx_cons_sb);
  1465. for_each_cos_in_tx_queue(fp, cos)
  1466. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1467. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1468. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1469. status &= ~mask;
  1470. }
  1471. }
  1472. #ifdef BCM_CNIC
  1473. mask = 0x2;
  1474. if (status & (mask | 0x1)) {
  1475. struct cnic_ops *c_ops = NULL;
  1476. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1477. rcu_read_lock();
  1478. c_ops = rcu_dereference(bp->cnic_ops);
  1479. if (c_ops)
  1480. c_ops->cnic_handler(bp->cnic_data, NULL);
  1481. rcu_read_unlock();
  1482. }
  1483. status &= ~mask;
  1484. }
  1485. #endif
  1486. if (unlikely(status & 0x1)) {
  1487. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1488. status &= ~0x1;
  1489. if (!status)
  1490. return IRQ_HANDLED;
  1491. }
  1492. if (unlikely(status))
  1493. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1494. status);
  1495. return IRQ_HANDLED;
  1496. }
  1497. /* Link */
  1498. /*
  1499. * General service functions
  1500. */
  1501. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1502. {
  1503. u32 lock_status;
  1504. u32 resource_bit = (1 << resource);
  1505. int func = BP_FUNC(bp);
  1506. u32 hw_lock_control_reg;
  1507. int cnt;
  1508. /* Validating that the resource is within range */
  1509. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1510. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1511. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1512. return -EINVAL;
  1513. }
  1514. if (func <= 5) {
  1515. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1516. } else {
  1517. hw_lock_control_reg =
  1518. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1519. }
  1520. /* Validating that the resource is not already taken */
  1521. lock_status = REG_RD(bp, hw_lock_control_reg);
  1522. if (lock_status & resource_bit) {
  1523. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1524. lock_status, resource_bit);
  1525. return -EEXIST;
  1526. }
  1527. /* Try for 5 second every 5ms */
  1528. for (cnt = 0; cnt < 1000; cnt++) {
  1529. /* Try to acquire the lock */
  1530. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1531. lock_status = REG_RD(bp, hw_lock_control_reg);
  1532. if (lock_status & resource_bit)
  1533. return 0;
  1534. msleep(5);
  1535. }
  1536. BNX2X_ERR("Timeout\n");
  1537. return -EAGAIN;
  1538. }
  1539. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1540. {
  1541. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1542. }
  1543. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1544. {
  1545. u32 lock_status;
  1546. u32 resource_bit = (1 << resource);
  1547. int func = BP_FUNC(bp);
  1548. u32 hw_lock_control_reg;
  1549. /* Validating that the resource is within range */
  1550. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1551. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1552. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1553. return -EINVAL;
  1554. }
  1555. if (func <= 5) {
  1556. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1557. } else {
  1558. hw_lock_control_reg =
  1559. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1560. }
  1561. /* Validating that the resource is currently taken */
  1562. lock_status = REG_RD(bp, hw_lock_control_reg);
  1563. if (!(lock_status & resource_bit)) {
  1564. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1565. lock_status, resource_bit);
  1566. return -EFAULT;
  1567. }
  1568. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1569. return 0;
  1570. }
  1571. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1572. {
  1573. /* The GPIO should be swapped if swap register is set and active */
  1574. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1575. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1576. int gpio_shift = gpio_num +
  1577. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1578. u32 gpio_mask = (1 << gpio_shift);
  1579. u32 gpio_reg;
  1580. int value;
  1581. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1582. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1583. return -EINVAL;
  1584. }
  1585. /* read GPIO value */
  1586. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1587. /* get the requested pin value */
  1588. if ((gpio_reg & gpio_mask) == gpio_mask)
  1589. value = 1;
  1590. else
  1591. value = 0;
  1592. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1593. return value;
  1594. }
  1595. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1596. {
  1597. /* The GPIO should be swapped if swap register is set and active */
  1598. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1599. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1600. int gpio_shift = gpio_num +
  1601. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1602. u32 gpio_mask = (1 << gpio_shift);
  1603. u32 gpio_reg;
  1604. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1605. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1606. return -EINVAL;
  1607. }
  1608. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1609. /* read GPIO and mask except the float bits */
  1610. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1611. switch (mode) {
  1612. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1613. DP(NETIF_MSG_LINK,
  1614. "Set GPIO %d (shift %d) -> output low\n",
  1615. gpio_num, gpio_shift);
  1616. /* clear FLOAT and set CLR */
  1617. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1618. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1619. break;
  1620. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1621. DP(NETIF_MSG_LINK,
  1622. "Set GPIO %d (shift %d) -> output high\n",
  1623. gpio_num, gpio_shift);
  1624. /* clear FLOAT and set SET */
  1625. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1626. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1627. break;
  1628. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1629. DP(NETIF_MSG_LINK,
  1630. "Set GPIO %d (shift %d) -> input\n",
  1631. gpio_num, gpio_shift);
  1632. /* set FLOAT */
  1633. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1634. break;
  1635. default:
  1636. break;
  1637. }
  1638. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1639. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1640. return 0;
  1641. }
  1642. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1643. {
  1644. u32 gpio_reg = 0;
  1645. int rc = 0;
  1646. /* Any port swapping should be handled by caller. */
  1647. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1648. /* read GPIO and mask except the float bits */
  1649. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1650. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1651. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1652. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1653. switch (mode) {
  1654. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1655. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1656. /* set CLR */
  1657. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1658. break;
  1659. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1660. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1661. /* set SET */
  1662. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1663. break;
  1664. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1665. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1666. /* set FLOAT */
  1667. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1668. break;
  1669. default:
  1670. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1671. rc = -EINVAL;
  1672. break;
  1673. }
  1674. if (rc == 0)
  1675. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1676. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1677. return rc;
  1678. }
  1679. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1680. {
  1681. /* The GPIO should be swapped if swap register is set and active */
  1682. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1683. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1684. int gpio_shift = gpio_num +
  1685. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1686. u32 gpio_mask = (1 << gpio_shift);
  1687. u32 gpio_reg;
  1688. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1689. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1690. return -EINVAL;
  1691. }
  1692. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1693. /* read GPIO int */
  1694. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1695. switch (mode) {
  1696. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1697. DP(NETIF_MSG_LINK,
  1698. "Clear GPIO INT %d (shift %d) -> output low\n",
  1699. gpio_num, gpio_shift);
  1700. /* clear SET and set CLR */
  1701. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1702. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1703. break;
  1704. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1705. DP(NETIF_MSG_LINK,
  1706. "Set GPIO INT %d (shift %d) -> output high\n",
  1707. gpio_num, gpio_shift);
  1708. /* clear CLR and set SET */
  1709. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1710. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1711. break;
  1712. default:
  1713. break;
  1714. }
  1715. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1716. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1717. return 0;
  1718. }
  1719. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1720. {
  1721. u32 spio_mask = (1 << spio_num);
  1722. u32 spio_reg;
  1723. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1724. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1725. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1726. return -EINVAL;
  1727. }
  1728. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1729. /* read SPIO and mask except the float bits */
  1730. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1731. switch (mode) {
  1732. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1733. DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
  1734. /* clear FLOAT and set CLR */
  1735. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1736. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1737. break;
  1738. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1739. DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
  1740. /* clear FLOAT and set SET */
  1741. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1742. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1743. break;
  1744. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1745. DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
  1746. /* set FLOAT */
  1747. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1748. break;
  1749. default:
  1750. break;
  1751. }
  1752. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1753. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1754. return 0;
  1755. }
  1756. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1757. {
  1758. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1759. switch (bp->link_vars.ieee_fc &
  1760. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1761. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1762. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1763. ADVERTISED_Pause);
  1764. break;
  1765. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1766. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1767. ADVERTISED_Pause);
  1768. break;
  1769. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1770. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1771. break;
  1772. default:
  1773. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1774. ADVERTISED_Pause);
  1775. break;
  1776. }
  1777. }
  1778. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1779. {
  1780. if (!BP_NOMCP(bp)) {
  1781. u8 rc;
  1782. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1783. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1784. /*
  1785. * Initialize link parameters structure variables
  1786. * It is recommended to turn off RX FC for jumbo frames
  1787. * for better performance
  1788. */
  1789. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1790. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1791. else
  1792. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1793. bnx2x_acquire_phy_lock(bp);
  1794. if (load_mode == LOAD_DIAG) {
  1795. struct link_params *lp = &bp->link_params;
  1796. lp->loopback_mode = LOOPBACK_XGXS;
  1797. /* do PHY loopback at 10G speed, if possible */
  1798. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1799. if (lp->speed_cap_mask[cfx_idx] &
  1800. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1801. lp->req_line_speed[cfx_idx] =
  1802. SPEED_10000;
  1803. else
  1804. lp->req_line_speed[cfx_idx] =
  1805. SPEED_1000;
  1806. }
  1807. }
  1808. if (load_mode == LOAD_LOOPBACK_EXT) {
  1809. struct link_params *lp = &bp->link_params;
  1810. lp->loopback_mode = LOOPBACK_EXT;
  1811. }
  1812. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1813. bnx2x_release_phy_lock(bp);
  1814. bnx2x_calc_fc_adv(bp);
  1815. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1816. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1817. bnx2x_link_report(bp);
  1818. } else
  1819. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1820. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1821. return rc;
  1822. }
  1823. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1824. return -EINVAL;
  1825. }
  1826. void bnx2x_link_set(struct bnx2x *bp)
  1827. {
  1828. if (!BP_NOMCP(bp)) {
  1829. bnx2x_acquire_phy_lock(bp);
  1830. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1831. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1832. bnx2x_release_phy_lock(bp);
  1833. bnx2x_calc_fc_adv(bp);
  1834. } else
  1835. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1836. }
  1837. static void bnx2x__link_reset(struct bnx2x *bp)
  1838. {
  1839. if (!BP_NOMCP(bp)) {
  1840. bnx2x_acquire_phy_lock(bp);
  1841. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1842. bnx2x_release_phy_lock(bp);
  1843. } else
  1844. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1845. }
  1846. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1847. {
  1848. u8 rc = 0;
  1849. if (!BP_NOMCP(bp)) {
  1850. bnx2x_acquire_phy_lock(bp);
  1851. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1852. is_serdes);
  1853. bnx2x_release_phy_lock(bp);
  1854. } else
  1855. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1856. return rc;
  1857. }
  1858. /* Calculates the sum of vn_min_rates.
  1859. It's needed for further normalizing of the min_rates.
  1860. Returns:
  1861. sum of vn_min_rates.
  1862. or
  1863. 0 - if all the min_rates are 0.
  1864. In the later case fainess algorithm should be deactivated.
  1865. If not all min_rates are zero then those that are zeroes will be set to 1.
  1866. */
  1867. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1868. struct cmng_init_input *input)
  1869. {
  1870. int all_zero = 1;
  1871. int vn;
  1872. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1873. u32 vn_cfg = bp->mf_config[vn];
  1874. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1875. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1876. /* Skip hidden vns */
  1877. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1878. vn_min_rate = 0;
  1879. /* If min rate is zero - set it to 1 */
  1880. else if (!vn_min_rate)
  1881. vn_min_rate = DEF_MIN_RATE;
  1882. else
  1883. all_zero = 0;
  1884. input->vnic_min_rate[vn] = vn_min_rate;
  1885. }
  1886. /* if ETS or all min rates are zeros - disable fairness */
  1887. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1888. input->flags.cmng_enables &=
  1889. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1890. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1891. } else if (all_zero) {
  1892. input->flags.cmng_enables &=
  1893. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1894. DP(NETIF_MSG_IFUP,
  1895. "All MIN values are zeroes fairness will be disabled\n");
  1896. } else
  1897. input->flags.cmng_enables |=
  1898. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1899. }
  1900. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  1901. struct cmng_init_input *input)
  1902. {
  1903. u16 vn_max_rate;
  1904. u32 vn_cfg = bp->mf_config[vn];
  1905. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1906. vn_max_rate = 0;
  1907. else {
  1908. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1909. if (IS_MF_SI(bp)) {
  1910. /* maxCfg in percents of linkspeed */
  1911. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1912. } else /* SD modes */
  1913. /* maxCfg is absolute in 100Mb units */
  1914. vn_max_rate = maxCfg * 100;
  1915. }
  1916. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  1917. input->vnic_max_rate[vn] = vn_max_rate;
  1918. }
  1919. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  1920. {
  1921. if (CHIP_REV_IS_SLOW(bp))
  1922. return CMNG_FNS_NONE;
  1923. if (IS_MF(bp))
  1924. return CMNG_FNS_MINMAX;
  1925. return CMNG_FNS_NONE;
  1926. }
  1927. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  1928. {
  1929. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  1930. if (BP_NOMCP(bp))
  1931. return; /* what should be the default bvalue in this case */
  1932. /* For 2 port configuration the absolute function number formula
  1933. * is:
  1934. * abs_func = 2 * vn + BP_PORT + BP_PATH
  1935. *
  1936. * and there are 4 functions per port
  1937. *
  1938. * For 4 port configuration it is
  1939. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  1940. *
  1941. * and there are 2 functions per port
  1942. */
  1943. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1944. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  1945. if (func >= E1H_FUNC_MAX)
  1946. break;
  1947. bp->mf_config[vn] =
  1948. MF_CFG_RD(bp, func_mf_config[func].config);
  1949. }
  1950. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  1951. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  1952. bp->flags |= MF_FUNC_DIS;
  1953. } else {
  1954. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  1955. bp->flags &= ~MF_FUNC_DIS;
  1956. }
  1957. }
  1958. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  1959. {
  1960. struct cmng_init_input input;
  1961. memset(&input, 0, sizeof(struct cmng_init_input));
  1962. input.port_rate = bp->link_vars.line_speed;
  1963. if (cmng_type == CMNG_FNS_MINMAX) {
  1964. int vn;
  1965. /* read mf conf from shmem */
  1966. if (read_cfg)
  1967. bnx2x_read_mf_cfg(bp);
  1968. /* vn_weight_sum and enable fairness if not 0 */
  1969. bnx2x_calc_vn_min(bp, &input);
  1970. /* calculate and set min-max rate for each vn */
  1971. if (bp->port.pmf)
  1972. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  1973. bnx2x_calc_vn_max(bp, vn, &input);
  1974. /* always enable rate shaping and fairness */
  1975. input.flags.cmng_enables |=
  1976. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  1977. bnx2x_init_cmng(&input, &bp->cmng);
  1978. return;
  1979. }
  1980. /* rate shaping and fairness are disabled */
  1981. DP(NETIF_MSG_IFUP,
  1982. "rate shaping and fairness are disabled\n");
  1983. }
  1984. static void storm_memset_cmng(struct bnx2x *bp,
  1985. struct cmng_init *cmng,
  1986. u8 port)
  1987. {
  1988. int vn;
  1989. size_t size = sizeof(struct cmng_struct_per_port);
  1990. u32 addr = BAR_XSTRORM_INTMEM +
  1991. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  1992. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  1993. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1994. int func = func_by_vn(bp, vn);
  1995. addr = BAR_XSTRORM_INTMEM +
  1996. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  1997. size = sizeof(struct rate_shaping_vars_per_vn);
  1998. __storm_memset_struct(bp, addr, size,
  1999. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2000. addr = BAR_XSTRORM_INTMEM +
  2001. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2002. size = sizeof(struct fairness_vars_per_vn);
  2003. __storm_memset_struct(bp, addr, size,
  2004. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2005. }
  2006. }
  2007. /* This function is called upon link interrupt */
  2008. static void bnx2x_link_attn(struct bnx2x *bp)
  2009. {
  2010. /* Make sure that we are synced with the current statistics */
  2011. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2012. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2013. if (bp->link_vars.link_up) {
  2014. /* dropless flow control */
  2015. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2016. int port = BP_PORT(bp);
  2017. u32 pause_enabled = 0;
  2018. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2019. pause_enabled = 1;
  2020. REG_WR(bp, BAR_USTRORM_INTMEM +
  2021. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2022. pause_enabled);
  2023. }
  2024. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2025. struct host_port_stats *pstats;
  2026. pstats = bnx2x_sp(bp, port_stats);
  2027. /* reset old mac stats */
  2028. memset(&(pstats->mac_stx[0]), 0,
  2029. sizeof(struct mac_stx));
  2030. }
  2031. if (bp->state == BNX2X_STATE_OPEN)
  2032. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2033. }
  2034. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2035. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2036. if (cmng_fns != CMNG_FNS_NONE) {
  2037. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2038. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2039. } else
  2040. /* rate shaping and fairness are disabled */
  2041. DP(NETIF_MSG_IFUP,
  2042. "single function mode without fairness\n");
  2043. }
  2044. __bnx2x_link_report(bp);
  2045. if (IS_MF(bp))
  2046. bnx2x_link_sync_notify(bp);
  2047. }
  2048. void bnx2x__link_status_update(struct bnx2x *bp)
  2049. {
  2050. if (bp->state != BNX2X_STATE_OPEN)
  2051. return;
  2052. /* read updated dcb configuration */
  2053. bnx2x_dcbx_pmf_update(bp);
  2054. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2055. if (bp->link_vars.link_up)
  2056. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2057. else
  2058. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2059. /* indicate link status */
  2060. bnx2x_link_report(bp);
  2061. }
  2062. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2063. u16 vlan_val, u8 allowed_prio)
  2064. {
  2065. struct bnx2x_func_state_params func_params = {0};
  2066. struct bnx2x_func_afex_update_params *f_update_params =
  2067. &func_params.params.afex_update;
  2068. func_params.f_obj = &bp->func_obj;
  2069. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2070. /* no need to wait for RAMROD completion, so don't
  2071. * set RAMROD_COMP_WAIT flag
  2072. */
  2073. f_update_params->vif_id = vifid;
  2074. f_update_params->afex_default_vlan = vlan_val;
  2075. f_update_params->allowed_priorities = allowed_prio;
  2076. /* if ramrod can not be sent, response to MCP immediately */
  2077. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2078. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2079. return 0;
  2080. }
  2081. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2082. u16 vif_index, u8 func_bit_map)
  2083. {
  2084. struct bnx2x_func_state_params func_params = {0};
  2085. struct bnx2x_func_afex_viflists_params *update_params =
  2086. &func_params.params.afex_viflists;
  2087. int rc;
  2088. u32 drv_msg_code;
  2089. /* validate only LIST_SET and LIST_GET are received from switch */
  2090. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2091. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2092. cmd_type);
  2093. func_params.f_obj = &bp->func_obj;
  2094. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2095. /* set parameters according to cmd_type */
  2096. update_params->afex_vif_list_command = cmd_type;
  2097. update_params->vif_list_index = cpu_to_le16(vif_index);
  2098. update_params->func_bit_map =
  2099. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2100. update_params->func_to_clear = 0;
  2101. drv_msg_code =
  2102. (cmd_type == VIF_LIST_RULE_GET) ?
  2103. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2104. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2105. /* if ramrod can not be sent, respond to MCP immediately for
  2106. * SET and GET requests (other are not triggered from MCP)
  2107. */
  2108. rc = bnx2x_func_state_change(bp, &func_params);
  2109. if (rc < 0)
  2110. bnx2x_fw_command(bp, drv_msg_code, 0);
  2111. return 0;
  2112. }
  2113. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2114. {
  2115. struct afex_stats afex_stats;
  2116. u32 func = BP_ABS_FUNC(bp);
  2117. u32 mf_config;
  2118. u16 vlan_val;
  2119. u32 vlan_prio;
  2120. u16 vif_id;
  2121. u8 allowed_prio;
  2122. u8 vlan_mode;
  2123. u32 addr_to_write, vifid, addrs, stats_type, i;
  2124. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2125. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2126. DP(BNX2X_MSG_MCP,
  2127. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2128. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2129. }
  2130. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2131. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2132. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2133. DP(BNX2X_MSG_MCP,
  2134. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2135. vifid, addrs);
  2136. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2137. addrs);
  2138. }
  2139. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2140. addr_to_write = SHMEM2_RD(bp,
  2141. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2142. stats_type = SHMEM2_RD(bp,
  2143. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2144. DP(BNX2X_MSG_MCP,
  2145. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2146. addr_to_write);
  2147. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2148. /* write response to scratchpad, for MCP */
  2149. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2150. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2151. *(((u32 *)(&afex_stats))+i));
  2152. /* send ack message to MCP */
  2153. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2154. }
  2155. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2156. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2157. bp->mf_config[BP_VN(bp)] = mf_config;
  2158. DP(BNX2X_MSG_MCP,
  2159. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2160. mf_config);
  2161. /* if VIF_SET is "enabled" */
  2162. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2163. /* set rate limit directly to internal RAM */
  2164. struct cmng_init_input cmng_input;
  2165. struct rate_shaping_vars_per_vn m_rs_vn;
  2166. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2167. u32 addr = BAR_XSTRORM_INTMEM +
  2168. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2169. bp->mf_config[BP_VN(bp)] = mf_config;
  2170. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2171. m_rs_vn.vn_counter.rate =
  2172. cmng_input.vnic_max_rate[BP_VN(bp)];
  2173. m_rs_vn.vn_counter.quota =
  2174. (m_rs_vn.vn_counter.rate *
  2175. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2176. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2177. /* read relevant values from mf_cfg struct in shmem */
  2178. vif_id =
  2179. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2180. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2181. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2182. vlan_val =
  2183. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2184. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2185. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2186. vlan_prio = (mf_config &
  2187. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2188. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2189. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2190. vlan_mode =
  2191. (MF_CFG_RD(bp,
  2192. func_mf_config[func].afex_config) &
  2193. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2194. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2195. allowed_prio =
  2196. (MF_CFG_RD(bp,
  2197. func_mf_config[func].afex_config) &
  2198. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2199. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2200. /* send ramrod to FW, return in case of failure */
  2201. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2202. allowed_prio))
  2203. return;
  2204. bp->afex_def_vlan_tag = vlan_val;
  2205. bp->afex_vlan_mode = vlan_mode;
  2206. } else {
  2207. /* notify link down because BP->flags is disabled */
  2208. bnx2x_link_report(bp);
  2209. /* send INVALID VIF ramrod to FW */
  2210. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2211. /* Reset the default afex VLAN */
  2212. bp->afex_def_vlan_tag = -1;
  2213. }
  2214. }
  2215. }
  2216. static void bnx2x_pmf_update(struct bnx2x *bp)
  2217. {
  2218. int port = BP_PORT(bp);
  2219. u32 val;
  2220. bp->port.pmf = 1;
  2221. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2222. /*
  2223. * We need the mb() to ensure the ordering between the writing to
  2224. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2225. */
  2226. smp_mb();
  2227. /* queue a periodic task */
  2228. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2229. bnx2x_dcbx_pmf_update(bp);
  2230. /* enable nig attention */
  2231. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2232. if (bp->common.int_block == INT_BLOCK_HC) {
  2233. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2234. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2235. } else if (!CHIP_IS_E1x(bp)) {
  2236. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2237. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2238. }
  2239. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2240. }
  2241. /* end of Link */
  2242. /* slow path */
  2243. /*
  2244. * General service functions
  2245. */
  2246. /* send the MCP a request, block until there is a reply */
  2247. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2248. {
  2249. int mb_idx = BP_FW_MB_IDX(bp);
  2250. u32 seq;
  2251. u32 rc = 0;
  2252. u32 cnt = 1;
  2253. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2254. mutex_lock(&bp->fw_mb_mutex);
  2255. seq = ++bp->fw_seq;
  2256. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2257. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2258. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2259. (command | seq), param);
  2260. do {
  2261. /* let the FW do it's magic ... */
  2262. msleep(delay);
  2263. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2264. /* Give the FW up to 5 second (500*10ms) */
  2265. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2266. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2267. cnt*delay, rc, seq);
  2268. /* is this a reply to our command? */
  2269. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2270. rc &= FW_MSG_CODE_MASK;
  2271. else {
  2272. /* FW BUG! */
  2273. BNX2X_ERR("FW failed to respond!\n");
  2274. bnx2x_fw_dump(bp);
  2275. rc = 0;
  2276. }
  2277. mutex_unlock(&bp->fw_mb_mutex);
  2278. return rc;
  2279. }
  2280. static void storm_memset_func_cfg(struct bnx2x *bp,
  2281. struct tstorm_eth_function_common_config *tcfg,
  2282. u16 abs_fid)
  2283. {
  2284. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2285. u32 addr = BAR_TSTRORM_INTMEM +
  2286. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2287. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2288. }
  2289. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2290. {
  2291. if (CHIP_IS_E1x(bp)) {
  2292. struct tstorm_eth_function_common_config tcfg = {0};
  2293. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2294. }
  2295. /* Enable the function in the FW */
  2296. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2297. storm_memset_func_en(bp, p->func_id, 1);
  2298. /* spq */
  2299. if (p->func_flgs & FUNC_FLG_SPQ) {
  2300. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2301. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2302. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2303. }
  2304. }
  2305. /**
  2306. * bnx2x_get_tx_only_flags - Return common flags
  2307. *
  2308. * @bp device handle
  2309. * @fp queue handle
  2310. * @zero_stats TRUE if statistics zeroing is needed
  2311. *
  2312. * Return the flags that are common for the Tx-only and not normal connections.
  2313. */
  2314. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2315. struct bnx2x_fastpath *fp,
  2316. bool zero_stats)
  2317. {
  2318. unsigned long flags = 0;
  2319. /* PF driver will always initialize the Queue to an ACTIVE state */
  2320. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2321. /* tx only connections collect statistics (on the same index as the
  2322. * parent connection). The statistics are zeroed when the parent
  2323. * connection is initialized.
  2324. */
  2325. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2326. if (zero_stats)
  2327. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2328. return flags;
  2329. }
  2330. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2331. struct bnx2x_fastpath *fp,
  2332. bool leading)
  2333. {
  2334. unsigned long flags = 0;
  2335. /* calculate other queue flags */
  2336. if (IS_MF_SD(bp))
  2337. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2338. if (IS_FCOE_FP(fp)) {
  2339. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2340. /* For FCoE - force usage of default priority (for afex) */
  2341. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2342. }
  2343. if (!fp->disable_tpa) {
  2344. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2345. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2346. if (fp->mode == TPA_MODE_GRO)
  2347. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2348. }
  2349. if (leading) {
  2350. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2351. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2352. }
  2353. /* Always set HW VLAN stripping */
  2354. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2355. /* configure silent vlan removal */
  2356. if (IS_MF_AFEX(bp))
  2357. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2358. return flags | bnx2x_get_common_flags(bp, fp, true);
  2359. }
  2360. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2361. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2362. u8 cos)
  2363. {
  2364. gen_init->stat_id = bnx2x_stats_id(fp);
  2365. gen_init->spcl_id = fp->cl_id;
  2366. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2367. if (IS_FCOE_FP(fp))
  2368. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2369. else
  2370. gen_init->mtu = bp->dev->mtu;
  2371. gen_init->cos = cos;
  2372. }
  2373. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2374. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2375. struct bnx2x_rxq_setup_params *rxq_init)
  2376. {
  2377. u8 max_sge = 0;
  2378. u16 sge_sz = 0;
  2379. u16 tpa_agg_size = 0;
  2380. if (!fp->disable_tpa) {
  2381. pause->sge_th_lo = SGE_TH_LO(bp);
  2382. pause->sge_th_hi = SGE_TH_HI(bp);
  2383. /* validate SGE ring has enough to cross high threshold */
  2384. WARN_ON(bp->dropless_fc &&
  2385. pause->sge_th_hi + FW_PREFETCH_CNT >
  2386. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2387. tpa_agg_size = min_t(u32,
  2388. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2389. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2390. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2391. SGE_PAGE_SHIFT;
  2392. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2393. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2394. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2395. 0xffff);
  2396. }
  2397. /* pause - not for e1 */
  2398. if (!CHIP_IS_E1(bp)) {
  2399. pause->bd_th_lo = BD_TH_LO(bp);
  2400. pause->bd_th_hi = BD_TH_HI(bp);
  2401. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2402. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2403. /*
  2404. * validate that rings have enough entries to cross
  2405. * high thresholds
  2406. */
  2407. WARN_ON(bp->dropless_fc &&
  2408. pause->bd_th_hi + FW_PREFETCH_CNT >
  2409. bp->rx_ring_size);
  2410. WARN_ON(bp->dropless_fc &&
  2411. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2412. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2413. pause->pri_map = 1;
  2414. }
  2415. /* rxq setup */
  2416. rxq_init->dscr_map = fp->rx_desc_mapping;
  2417. rxq_init->sge_map = fp->rx_sge_mapping;
  2418. rxq_init->rcq_map = fp->rx_comp_mapping;
  2419. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2420. /* This should be a maximum number of data bytes that may be
  2421. * placed on the BD (not including paddings).
  2422. */
  2423. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2424. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2425. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2426. rxq_init->tpa_agg_sz = tpa_agg_size;
  2427. rxq_init->sge_buf_sz = sge_sz;
  2428. rxq_init->max_sges_pkt = max_sge;
  2429. rxq_init->rss_engine_id = BP_FUNC(bp);
  2430. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2431. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2432. *
  2433. * For PF Clients it should be the maximum avaliable number.
  2434. * VF driver(s) may want to define it to a smaller value.
  2435. */
  2436. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2437. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2438. rxq_init->fw_sb_id = fp->fw_sb_id;
  2439. if (IS_FCOE_FP(fp))
  2440. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2441. else
  2442. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2443. /* configure silent vlan removal
  2444. * if multi function mode is afex, then mask default vlan
  2445. */
  2446. if (IS_MF_AFEX(bp)) {
  2447. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2448. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2449. }
  2450. }
  2451. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2452. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2453. u8 cos)
  2454. {
  2455. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2456. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2457. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2458. txq_init->fw_sb_id = fp->fw_sb_id;
  2459. /*
  2460. * set the tss leading client id for TX classfication ==
  2461. * leading RSS client id
  2462. */
  2463. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2464. if (IS_FCOE_FP(fp)) {
  2465. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2466. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2467. }
  2468. }
  2469. static void bnx2x_pf_init(struct bnx2x *bp)
  2470. {
  2471. struct bnx2x_func_init_params func_init = {0};
  2472. struct event_ring_data eq_data = { {0} };
  2473. u16 flags;
  2474. if (!CHIP_IS_E1x(bp)) {
  2475. /* reset IGU PF statistics: MSIX + ATTN */
  2476. /* PF */
  2477. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2478. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2479. (CHIP_MODE_IS_4_PORT(bp) ?
  2480. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2481. /* ATTN */
  2482. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2483. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2484. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2485. (CHIP_MODE_IS_4_PORT(bp) ?
  2486. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2487. }
  2488. /* function setup flags */
  2489. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2490. /* This flag is relevant for E1x only.
  2491. * E2 doesn't have a TPA configuration in a function level.
  2492. */
  2493. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2494. func_init.func_flgs = flags;
  2495. func_init.pf_id = BP_FUNC(bp);
  2496. func_init.func_id = BP_FUNC(bp);
  2497. func_init.spq_map = bp->spq_mapping;
  2498. func_init.spq_prod = bp->spq_prod_idx;
  2499. bnx2x_func_init(bp, &func_init);
  2500. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2501. /*
  2502. * Congestion management values depend on the link rate
  2503. * There is no active link so initial link rate is set to 10 Gbps.
  2504. * When the link comes up The congestion management values are
  2505. * re-calculated according to the actual link rate.
  2506. */
  2507. bp->link_vars.line_speed = SPEED_10000;
  2508. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2509. /* Only the PMF sets the HW */
  2510. if (bp->port.pmf)
  2511. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2512. /* init Event Queue */
  2513. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2514. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2515. eq_data.producer = bp->eq_prod;
  2516. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2517. eq_data.sb_id = DEF_SB_ID;
  2518. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2519. }
  2520. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2521. {
  2522. int port = BP_PORT(bp);
  2523. bnx2x_tx_disable(bp);
  2524. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2525. }
  2526. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2527. {
  2528. int port = BP_PORT(bp);
  2529. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2530. /* Tx queue should be only reenabled */
  2531. netif_tx_wake_all_queues(bp->dev);
  2532. /*
  2533. * Should not call netif_carrier_on since it will be called if the link
  2534. * is up when checking for link state
  2535. */
  2536. }
  2537. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2538. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2539. {
  2540. struct eth_stats_info *ether_stat =
  2541. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2542. /* leave last char as NULL */
  2543. memcpy(ether_stat->version, DRV_MODULE_VERSION,
  2544. ETH_STAT_INFO_VERSION_LEN - 1);
  2545. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2546. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2547. ether_stat->mac_local);
  2548. ether_stat->mtu_size = bp->dev->mtu;
  2549. if (bp->dev->features & NETIF_F_RXCSUM)
  2550. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2551. if (bp->dev->features & NETIF_F_TSO)
  2552. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2553. ether_stat->feature_flags |= bp->common.boot_mode;
  2554. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2555. ether_stat->txq_size = bp->tx_ring_size;
  2556. ether_stat->rxq_size = bp->rx_ring_size;
  2557. }
  2558. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2559. {
  2560. #ifdef BCM_CNIC
  2561. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2562. struct fcoe_stats_info *fcoe_stat =
  2563. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2564. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2565. bp->fip_mac, ETH_ALEN);
  2566. fcoe_stat->qos_priority =
  2567. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2568. /* insert FCoE stats from ramrod response */
  2569. if (!NO_FCOE(bp)) {
  2570. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2571. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2572. tstorm_queue_statistics;
  2573. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2574. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2575. xstorm_queue_statistics;
  2576. struct fcoe_statistics_params *fw_fcoe_stat =
  2577. &bp->fw_stats_data->fcoe;
  2578. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2579. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2580. ADD_64(fcoe_stat->rx_bytes_hi,
  2581. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2582. fcoe_stat->rx_bytes_lo,
  2583. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2584. ADD_64(fcoe_stat->rx_bytes_hi,
  2585. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2586. fcoe_stat->rx_bytes_lo,
  2587. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2588. ADD_64(fcoe_stat->rx_bytes_hi,
  2589. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2590. fcoe_stat->rx_bytes_lo,
  2591. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2592. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2593. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2594. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2595. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2596. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2597. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2598. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2599. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2600. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2601. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2602. ADD_64(fcoe_stat->tx_bytes_hi,
  2603. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2604. fcoe_stat->tx_bytes_lo,
  2605. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2606. ADD_64(fcoe_stat->tx_bytes_hi,
  2607. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2608. fcoe_stat->tx_bytes_lo,
  2609. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2610. ADD_64(fcoe_stat->tx_bytes_hi,
  2611. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2612. fcoe_stat->tx_bytes_lo,
  2613. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2614. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2615. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2616. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2617. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2618. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2619. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2620. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2621. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2622. }
  2623. /* ask L5 driver to add data to the struct */
  2624. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2625. #endif
  2626. }
  2627. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2628. {
  2629. #ifdef BCM_CNIC
  2630. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2631. struct iscsi_stats_info *iscsi_stat =
  2632. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2633. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2634. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2635. iscsi_stat->qos_priority =
  2636. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2637. /* ask L5 driver to add data to the struct */
  2638. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2639. #endif
  2640. }
  2641. /* called due to MCP event (on pmf):
  2642. * reread new bandwidth configuration
  2643. * configure FW
  2644. * notify others function about the change
  2645. */
  2646. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2647. {
  2648. if (bp->link_vars.link_up) {
  2649. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2650. bnx2x_link_sync_notify(bp);
  2651. }
  2652. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2653. }
  2654. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2655. {
  2656. bnx2x_config_mf_bw(bp);
  2657. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2658. }
  2659. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2660. {
  2661. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2662. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2663. }
  2664. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2665. {
  2666. enum drv_info_opcode op_code;
  2667. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2668. /* if drv_info version supported by MFW doesn't match - send NACK */
  2669. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2670. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2671. return;
  2672. }
  2673. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2674. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2675. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2676. sizeof(union drv_info_to_mcp));
  2677. switch (op_code) {
  2678. case ETH_STATS_OPCODE:
  2679. bnx2x_drv_info_ether_stat(bp);
  2680. break;
  2681. case FCOE_STATS_OPCODE:
  2682. bnx2x_drv_info_fcoe_stat(bp);
  2683. break;
  2684. case ISCSI_STATS_OPCODE:
  2685. bnx2x_drv_info_iscsi_stat(bp);
  2686. break;
  2687. default:
  2688. /* if op code isn't supported - send NACK */
  2689. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2690. return;
  2691. }
  2692. /* if we got drv_info attn from MFW then these fields are defined in
  2693. * shmem2 for sure
  2694. */
  2695. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2696. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2697. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2698. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2699. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2700. }
  2701. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2702. {
  2703. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2704. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2705. /*
  2706. * This is the only place besides the function initialization
  2707. * where the bp->flags can change so it is done without any
  2708. * locks
  2709. */
  2710. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2711. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2712. bp->flags |= MF_FUNC_DIS;
  2713. bnx2x_e1h_disable(bp);
  2714. } else {
  2715. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2716. bp->flags &= ~MF_FUNC_DIS;
  2717. bnx2x_e1h_enable(bp);
  2718. }
  2719. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2720. }
  2721. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2722. bnx2x_config_mf_bw(bp);
  2723. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2724. }
  2725. /* Report results to MCP */
  2726. if (dcc_event)
  2727. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2728. else
  2729. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2730. }
  2731. /* must be called under the spq lock */
  2732. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2733. {
  2734. struct eth_spe *next_spe = bp->spq_prod_bd;
  2735. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2736. bp->spq_prod_bd = bp->spq;
  2737. bp->spq_prod_idx = 0;
  2738. DP(BNX2X_MSG_SP, "end of spq\n");
  2739. } else {
  2740. bp->spq_prod_bd++;
  2741. bp->spq_prod_idx++;
  2742. }
  2743. return next_spe;
  2744. }
  2745. /* must be called under the spq lock */
  2746. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2747. {
  2748. int func = BP_FUNC(bp);
  2749. /*
  2750. * Make sure that BD data is updated before writing the producer:
  2751. * BD data is written to the memory, the producer is read from the
  2752. * memory, thus we need a full memory barrier to ensure the ordering.
  2753. */
  2754. mb();
  2755. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2756. bp->spq_prod_idx);
  2757. mmiowb();
  2758. }
  2759. /**
  2760. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2761. *
  2762. * @cmd: command to check
  2763. * @cmd_type: command type
  2764. */
  2765. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2766. {
  2767. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2768. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2769. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2770. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2771. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2772. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2773. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2774. return true;
  2775. else
  2776. return false;
  2777. }
  2778. /**
  2779. * bnx2x_sp_post - place a single command on an SP ring
  2780. *
  2781. * @bp: driver handle
  2782. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2783. * @cid: SW CID the command is related to
  2784. * @data_hi: command private data address (high 32 bits)
  2785. * @data_lo: command private data address (low 32 bits)
  2786. * @cmd_type: command type (e.g. NONE, ETH)
  2787. *
  2788. * SP data is handled as if it's always an address pair, thus data fields are
  2789. * not swapped to little endian in upper functions. Instead this function swaps
  2790. * data as if it's two u32 fields.
  2791. */
  2792. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2793. u32 data_hi, u32 data_lo, int cmd_type)
  2794. {
  2795. struct eth_spe *spe;
  2796. u16 type;
  2797. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2798. #ifdef BNX2X_STOP_ON_ERROR
  2799. if (unlikely(bp->panic)) {
  2800. BNX2X_ERR("Can't post SP when there is panic\n");
  2801. return -EIO;
  2802. }
  2803. #endif
  2804. spin_lock_bh(&bp->spq_lock);
  2805. if (common) {
  2806. if (!atomic_read(&bp->eq_spq_left)) {
  2807. BNX2X_ERR("BUG! EQ ring full!\n");
  2808. spin_unlock_bh(&bp->spq_lock);
  2809. bnx2x_panic();
  2810. return -EBUSY;
  2811. }
  2812. } else if (!atomic_read(&bp->cq_spq_left)) {
  2813. BNX2X_ERR("BUG! SPQ ring full!\n");
  2814. spin_unlock_bh(&bp->spq_lock);
  2815. bnx2x_panic();
  2816. return -EBUSY;
  2817. }
  2818. spe = bnx2x_sp_get_next(bp);
  2819. /* CID needs port number to be encoded int it */
  2820. spe->hdr.conn_and_cmd_data =
  2821. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2822. HW_CID(bp, cid));
  2823. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2824. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2825. SPE_HDR_FUNCTION_ID);
  2826. spe->hdr.type = cpu_to_le16(type);
  2827. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2828. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2829. /*
  2830. * It's ok if the actual decrement is issued towards the memory
  2831. * somewhere between the spin_lock and spin_unlock. Thus no
  2832. * more explict memory barrier is needed.
  2833. */
  2834. if (common)
  2835. atomic_dec(&bp->eq_spq_left);
  2836. else
  2837. atomic_dec(&bp->cq_spq_left);
  2838. DP(BNX2X_MSG_SP,
  2839. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2840. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2841. (u32)(U64_LO(bp->spq_mapping) +
  2842. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2843. HW_CID(bp, cid), data_hi, data_lo, type,
  2844. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2845. bnx2x_sp_prod_update(bp);
  2846. spin_unlock_bh(&bp->spq_lock);
  2847. return 0;
  2848. }
  2849. /* acquire split MCP access lock register */
  2850. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2851. {
  2852. u32 j, val;
  2853. int rc = 0;
  2854. might_sleep();
  2855. for (j = 0; j < 1000; j++) {
  2856. val = (1UL << 31);
  2857. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2858. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2859. if (val & (1L << 31))
  2860. break;
  2861. msleep(5);
  2862. }
  2863. if (!(val & (1L << 31))) {
  2864. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2865. rc = -EBUSY;
  2866. }
  2867. return rc;
  2868. }
  2869. /* release split MCP access lock register */
  2870. static void bnx2x_release_alr(struct bnx2x *bp)
  2871. {
  2872. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2873. }
  2874. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2875. #define BNX2X_DEF_SB_IDX 0x0002
  2876. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2877. {
  2878. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2879. u16 rc = 0;
  2880. barrier(); /* status block is written to by the chip */
  2881. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2882. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2883. rc |= BNX2X_DEF_SB_ATT_IDX;
  2884. }
  2885. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2886. bp->def_idx = def_sb->sp_sb.running_index;
  2887. rc |= BNX2X_DEF_SB_IDX;
  2888. }
  2889. /* Do not reorder: indecies reading should complete before handling */
  2890. barrier();
  2891. return rc;
  2892. }
  2893. /*
  2894. * slow path service functions
  2895. */
  2896. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2897. {
  2898. int port = BP_PORT(bp);
  2899. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2900. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2901. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2902. NIG_REG_MASK_INTERRUPT_PORT0;
  2903. u32 aeu_mask;
  2904. u32 nig_mask = 0;
  2905. u32 reg_addr;
  2906. if (bp->attn_state & asserted)
  2907. BNX2X_ERR("IGU ERROR\n");
  2908. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2909. aeu_mask = REG_RD(bp, aeu_addr);
  2910. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2911. aeu_mask, asserted);
  2912. aeu_mask &= ~(asserted & 0x3ff);
  2913. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2914. REG_WR(bp, aeu_addr, aeu_mask);
  2915. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2916. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2917. bp->attn_state |= asserted;
  2918. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2919. if (asserted & ATTN_HARD_WIRED_MASK) {
  2920. if (asserted & ATTN_NIG_FOR_FUNC) {
  2921. bnx2x_acquire_phy_lock(bp);
  2922. /* save nig interrupt mask */
  2923. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2924. /* If nig_mask is not set, no need to call the update
  2925. * function.
  2926. */
  2927. if (nig_mask) {
  2928. REG_WR(bp, nig_int_mask_addr, 0);
  2929. bnx2x_link_attn(bp);
  2930. }
  2931. /* handle unicore attn? */
  2932. }
  2933. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2934. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2935. if (asserted & GPIO_2_FUNC)
  2936. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2937. if (asserted & GPIO_3_FUNC)
  2938. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2939. if (asserted & GPIO_4_FUNC)
  2940. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2941. if (port == 0) {
  2942. if (asserted & ATTN_GENERAL_ATTN_1) {
  2943. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2944. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2945. }
  2946. if (asserted & ATTN_GENERAL_ATTN_2) {
  2947. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2948. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2949. }
  2950. if (asserted & ATTN_GENERAL_ATTN_3) {
  2951. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2952. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2953. }
  2954. } else {
  2955. if (asserted & ATTN_GENERAL_ATTN_4) {
  2956. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2957. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2958. }
  2959. if (asserted & ATTN_GENERAL_ATTN_5) {
  2960. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2961. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2962. }
  2963. if (asserted & ATTN_GENERAL_ATTN_6) {
  2964. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2965. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2966. }
  2967. }
  2968. } /* if hardwired */
  2969. if (bp->common.int_block == INT_BLOCK_HC)
  2970. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2971. COMMAND_REG_ATTN_BITS_SET);
  2972. else
  2973. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2974. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2975. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2976. REG_WR(bp, reg_addr, asserted);
  2977. /* now set back the mask */
  2978. if (asserted & ATTN_NIG_FOR_FUNC) {
  2979. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2980. bnx2x_release_phy_lock(bp);
  2981. }
  2982. }
  2983. static void bnx2x_fan_failure(struct bnx2x *bp)
  2984. {
  2985. int port = BP_PORT(bp);
  2986. u32 ext_phy_config;
  2987. /* mark the failure */
  2988. ext_phy_config =
  2989. SHMEM_RD(bp,
  2990. dev_info.port_hw_config[port].external_phy_config);
  2991. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2992. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2993. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2994. ext_phy_config);
  2995. /* log the failure */
  2996. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  2997. "Please contact OEM Support for assistance\n");
  2998. /*
  2999. * Scheudle device reset (unload)
  3000. * This is due to some boards consuming sufficient power when driver is
  3001. * up to overheat if fan fails.
  3002. */
  3003. smp_mb__before_clear_bit();
  3004. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3005. smp_mb__after_clear_bit();
  3006. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3007. }
  3008. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3009. {
  3010. int port = BP_PORT(bp);
  3011. int reg_offset;
  3012. u32 val;
  3013. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3014. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3015. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3016. val = REG_RD(bp, reg_offset);
  3017. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3018. REG_WR(bp, reg_offset, val);
  3019. BNX2X_ERR("SPIO5 hw attention\n");
  3020. /* Fan failure attention */
  3021. bnx2x_hw_reset_phy(&bp->link_params);
  3022. bnx2x_fan_failure(bp);
  3023. }
  3024. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3025. bnx2x_acquire_phy_lock(bp);
  3026. bnx2x_handle_module_detect_int(&bp->link_params);
  3027. bnx2x_release_phy_lock(bp);
  3028. }
  3029. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3030. val = REG_RD(bp, reg_offset);
  3031. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3032. REG_WR(bp, reg_offset, val);
  3033. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3034. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3035. bnx2x_panic();
  3036. }
  3037. }
  3038. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3039. {
  3040. u32 val;
  3041. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3042. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3043. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3044. /* DORQ discard attention */
  3045. if (val & 0x2)
  3046. BNX2X_ERR("FATAL error from DORQ\n");
  3047. }
  3048. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3049. int port = BP_PORT(bp);
  3050. int reg_offset;
  3051. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3052. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3053. val = REG_RD(bp, reg_offset);
  3054. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3055. REG_WR(bp, reg_offset, val);
  3056. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3057. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3058. bnx2x_panic();
  3059. }
  3060. }
  3061. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3062. {
  3063. u32 val;
  3064. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3065. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3066. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3067. /* CFC error attention */
  3068. if (val & 0x2)
  3069. BNX2X_ERR("FATAL error from CFC\n");
  3070. }
  3071. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3072. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3073. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3074. /* RQ_USDMDP_FIFO_OVERFLOW */
  3075. if (val & 0x18000)
  3076. BNX2X_ERR("FATAL error from PXP\n");
  3077. if (!CHIP_IS_E1x(bp)) {
  3078. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3079. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3080. }
  3081. }
  3082. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3083. int port = BP_PORT(bp);
  3084. int reg_offset;
  3085. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3086. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3087. val = REG_RD(bp, reg_offset);
  3088. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3089. REG_WR(bp, reg_offset, val);
  3090. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3091. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3092. bnx2x_panic();
  3093. }
  3094. }
  3095. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3096. {
  3097. u32 val;
  3098. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3099. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3100. int func = BP_FUNC(bp);
  3101. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3102. bnx2x_read_mf_cfg(bp);
  3103. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3104. func_mf_config[BP_ABS_FUNC(bp)].config);
  3105. val = SHMEM_RD(bp,
  3106. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3107. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3108. bnx2x_dcc_event(bp,
  3109. (val & DRV_STATUS_DCC_EVENT_MASK));
  3110. if (val & DRV_STATUS_SET_MF_BW)
  3111. bnx2x_set_mf_bw(bp);
  3112. if (val & DRV_STATUS_DRV_INFO_REQ)
  3113. bnx2x_handle_drv_info_req(bp);
  3114. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3115. bnx2x_pmf_update(bp);
  3116. if (bp->port.pmf &&
  3117. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3118. bp->dcbx_enabled > 0)
  3119. /* start dcbx state machine */
  3120. bnx2x_dcbx_set_params(bp,
  3121. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3122. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3123. bnx2x_handle_afex_cmd(bp,
  3124. val & DRV_STATUS_AFEX_EVENT_MASK);
  3125. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3126. bnx2x_handle_eee_event(bp);
  3127. if (bp->link_vars.periodic_flags &
  3128. PERIODIC_FLAGS_LINK_EVENT) {
  3129. /* sync with link */
  3130. bnx2x_acquire_phy_lock(bp);
  3131. bp->link_vars.periodic_flags &=
  3132. ~PERIODIC_FLAGS_LINK_EVENT;
  3133. bnx2x_release_phy_lock(bp);
  3134. if (IS_MF(bp))
  3135. bnx2x_link_sync_notify(bp);
  3136. bnx2x_link_report(bp);
  3137. }
  3138. /* Always call it here: bnx2x_link_report() will
  3139. * prevent the link indication duplication.
  3140. */
  3141. bnx2x__link_status_update(bp);
  3142. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3143. BNX2X_ERR("MC assert!\n");
  3144. bnx2x_mc_assert(bp);
  3145. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3146. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3147. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3148. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3149. bnx2x_panic();
  3150. } else if (attn & BNX2X_MCP_ASSERT) {
  3151. BNX2X_ERR("MCP assert!\n");
  3152. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3153. bnx2x_fw_dump(bp);
  3154. } else
  3155. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3156. }
  3157. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3158. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3159. if (attn & BNX2X_GRC_TIMEOUT) {
  3160. val = CHIP_IS_E1(bp) ? 0 :
  3161. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3162. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3163. }
  3164. if (attn & BNX2X_GRC_RSV) {
  3165. val = CHIP_IS_E1(bp) ? 0 :
  3166. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3167. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3168. }
  3169. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3170. }
  3171. }
  3172. /*
  3173. * Bits map:
  3174. * 0-7 - Engine0 load counter.
  3175. * 8-15 - Engine1 load counter.
  3176. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3177. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3178. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3179. * on the engine
  3180. * 19 - Engine1 ONE_IS_LOADED.
  3181. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3182. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3183. * just the one belonging to its engine).
  3184. *
  3185. */
  3186. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3187. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3188. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3189. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3190. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3191. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3192. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3193. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3194. /*
  3195. * Set the GLOBAL_RESET bit.
  3196. *
  3197. * Should be run under rtnl lock
  3198. */
  3199. void bnx2x_set_reset_global(struct bnx2x *bp)
  3200. {
  3201. u32 val;
  3202. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3203. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3204. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3205. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3206. }
  3207. /*
  3208. * Clear the GLOBAL_RESET bit.
  3209. *
  3210. * Should be run under rtnl lock
  3211. */
  3212. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3213. {
  3214. u32 val;
  3215. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3216. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3217. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3218. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3219. }
  3220. /*
  3221. * Checks the GLOBAL_RESET bit.
  3222. *
  3223. * should be run under rtnl lock
  3224. */
  3225. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3226. {
  3227. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3228. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3229. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3230. }
  3231. /*
  3232. * Clear RESET_IN_PROGRESS bit for the current engine.
  3233. *
  3234. * Should be run under rtnl lock
  3235. */
  3236. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3237. {
  3238. u32 val;
  3239. u32 bit = BP_PATH(bp) ?
  3240. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3241. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3242. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3243. /* Clear the bit */
  3244. val &= ~bit;
  3245. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3246. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3247. }
  3248. /*
  3249. * Set RESET_IN_PROGRESS for the current engine.
  3250. *
  3251. * should be run under rtnl lock
  3252. */
  3253. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3254. {
  3255. u32 val;
  3256. u32 bit = BP_PATH(bp) ?
  3257. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3258. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3259. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3260. /* Set the bit */
  3261. val |= bit;
  3262. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3263. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3264. }
  3265. /*
  3266. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3267. * should be run under rtnl lock
  3268. */
  3269. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3270. {
  3271. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3272. u32 bit = engine ?
  3273. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3274. /* return false if bit is set */
  3275. return (val & bit) ? false : true;
  3276. }
  3277. /*
  3278. * set pf load for the current pf.
  3279. *
  3280. * should be run under rtnl lock
  3281. */
  3282. void bnx2x_set_pf_load(struct bnx2x *bp)
  3283. {
  3284. u32 val1, val;
  3285. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3286. BNX2X_PATH0_LOAD_CNT_MASK;
  3287. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3288. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3289. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3290. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3291. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3292. /* get the current counter value */
  3293. val1 = (val & mask) >> shift;
  3294. /* set bit of that PF */
  3295. val1 |= (1 << bp->pf_num);
  3296. /* clear the old value */
  3297. val &= ~mask;
  3298. /* set the new one */
  3299. val |= ((val1 << shift) & mask);
  3300. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3301. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3302. }
  3303. /**
  3304. * bnx2x_clear_pf_load - clear pf load mark
  3305. *
  3306. * @bp: driver handle
  3307. *
  3308. * Should be run under rtnl lock.
  3309. * Decrements the load counter for the current engine. Returns
  3310. * whether other functions are still loaded
  3311. */
  3312. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3313. {
  3314. u32 val1, val;
  3315. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3316. BNX2X_PATH0_LOAD_CNT_MASK;
  3317. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3318. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3319. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3320. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3321. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3322. /* get the current counter value */
  3323. val1 = (val & mask) >> shift;
  3324. /* clear bit of that PF */
  3325. val1 &= ~(1 << bp->pf_num);
  3326. /* clear the old value */
  3327. val &= ~mask;
  3328. /* set the new one */
  3329. val |= ((val1 << shift) & mask);
  3330. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3331. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3332. return val1 != 0;
  3333. }
  3334. /*
  3335. * Read the load status for the current engine.
  3336. *
  3337. * should be run under rtnl lock
  3338. */
  3339. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3340. {
  3341. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3342. BNX2X_PATH0_LOAD_CNT_MASK);
  3343. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3344. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3345. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3346. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3347. val = (val & mask) >> shift;
  3348. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3349. engine, val);
  3350. return val != 0;
  3351. }
  3352. /*
  3353. * Reset the load status for the current engine.
  3354. */
  3355. static void bnx2x_clear_load_status(struct bnx2x *bp)
  3356. {
  3357. u32 val;
  3358. u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3359. BNX2X_PATH0_LOAD_CNT_MASK);
  3360. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3361. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3362. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
  3363. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3364. }
  3365. static void _print_next_block(int idx, const char *blk)
  3366. {
  3367. pr_cont("%s%s", idx ? ", " : "", blk);
  3368. }
  3369. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3370. bool print)
  3371. {
  3372. int i = 0;
  3373. u32 cur_bit = 0;
  3374. for (i = 0; sig; i++) {
  3375. cur_bit = ((u32)0x1 << i);
  3376. if (sig & cur_bit) {
  3377. switch (cur_bit) {
  3378. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3379. if (print)
  3380. _print_next_block(par_num++, "BRB");
  3381. break;
  3382. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3383. if (print)
  3384. _print_next_block(par_num++, "PARSER");
  3385. break;
  3386. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3387. if (print)
  3388. _print_next_block(par_num++, "TSDM");
  3389. break;
  3390. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3391. if (print)
  3392. _print_next_block(par_num++,
  3393. "SEARCHER");
  3394. break;
  3395. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3396. if (print)
  3397. _print_next_block(par_num++, "TCM");
  3398. break;
  3399. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3400. if (print)
  3401. _print_next_block(par_num++, "TSEMI");
  3402. break;
  3403. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3404. if (print)
  3405. _print_next_block(par_num++, "XPB");
  3406. break;
  3407. }
  3408. /* Clear the bit */
  3409. sig &= ~cur_bit;
  3410. }
  3411. }
  3412. return par_num;
  3413. }
  3414. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3415. bool *global, bool print)
  3416. {
  3417. int i = 0;
  3418. u32 cur_bit = 0;
  3419. for (i = 0; sig; i++) {
  3420. cur_bit = ((u32)0x1 << i);
  3421. if (sig & cur_bit) {
  3422. switch (cur_bit) {
  3423. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3424. if (print)
  3425. _print_next_block(par_num++, "PBF");
  3426. break;
  3427. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3428. if (print)
  3429. _print_next_block(par_num++, "QM");
  3430. break;
  3431. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3432. if (print)
  3433. _print_next_block(par_num++, "TM");
  3434. break;
  3435. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3436. if (print)
  3437. _print_next_block(par_num++, "XSDM");
  3438. break;
  3439. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3440. if (print)
  3441. _print_next_block(par_num++, "XCM");
  3442. break;
  3443. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3444. if (print)
  3445. _print_next_block(par_num++, "XSEMI");
  3446. break;
  3447. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3448. if (print)
  3449. _print_next_block(par_num++,
  3450. "DOORBELLQ");
  3451. break;
  3452. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3453. if (print)
  3454. _print_next_block(par_num++, "NIG");
  3455. break;
  3456. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3457. if (print)
  3458. _print_next_block(par_num++,
  3459. "VAUX PCI CORE");
  3460. *global = true;
  3461. break;
  3462. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3463. if (print)
  3464. _print_next_block(par_num++, "DEBUG");
  3465. break;
  3466. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3467. if (print)
  3468. _print_next_block(par_num++, "USDM");
  3469. break;
  3470. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3471. if (print)
  3472. _print_next_block(par_num++, "UCM");
  3473. break;
  3474. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3475. if (print)
  3476. _print_next_block(par_num++, "USEMI");
  3477. break;
  3478. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3479. if (print)
  3480. _print_next_block(par_num++, "UPB");
  3481. break;
  3482. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3483. if (print)
  3484. _print_next_block(par_num++, "CSDM");
  3485. break;
  3486. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3487. if (print)
  3488. _print_next_block(par_num++, "CCM");
  3489. break;
  3490. }
  3491. /* Clear the bit */
  3492. sig &= ~cur_bit;
  3493. }
  3494. }
  3495. return par_num;
  3496. }
  3497. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3498. bool print)
  3499. {
  3500. int i = 0;
  3501. u32 cur_bit = 0;
  3502. for (i = 0; sig; i++) {
  3503. cur_bit = ((u32)0x1 << i);
  3504. if (sig & cur_bit) {
  3505. switch (cur_bit) {
  3506. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3507. if (print)
  3508. _print_next_block(par_num++, "CSEMI");
  3509. break;
  3510. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3511. if (print)
  3512. _print_next_block(par_num++, "PXP");
  3513. break;
  3514. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3515. if (print)
  3516. _print_next_block(par_num++,
  3517. "PXPPCICLOCKCLIENT");
  3518. break;
  3519. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3520. if (print)
  3521. _print_next_block(par_num++, "CFC");
  3522. break;
  3523. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3524. if (print)
  3525. _print_next_block(par_num++, "CDU");
  3526. break;
  3527. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3528. if (print)
  3529. _print_next_block(par_num++, "DMAE");
  3530. break;
  3531. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3532. if (print)
  3533. _print_next_block(par_num++, "IGU");
  3534. break;
  3535. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3536. if (print)
  3537. _print_next_block(par_num++, "MISC");
  3538. break;
  3539. }
  3540. /* Clear the bit */
  3541. sig &= ~cur_bit;
  3542. }
  3543. }
  3544. return par_num;
  3545. }
  3546. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3547. bool *global, bool print)
  3548. {
  3549. int i = 0;
  3550. u32 cur_bit = 0;
  3551. for (i = 0; sig; i++) {
  3552. cur_bit = ((u32)0x1 << i);
  3553. if (sig & cur_bit) {
  3554. switch (cur_bit) {
  3555. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3556. if (print)
  3557. _print_next_block(par_num++, "MCP ROM");
  3558. *global = true;
  3559. break;
  3560. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3561. if (print)
  3562. _print_next_block(par_num++,
  3563. "MCP UMP RX");
  3564. *global = true;
  3565. break;
  3566. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3567. if (print)
  3568. _print_next_block(par_num++,
  3569. "MCP UMP TX");
  3570. *global = true;
  3571. break;
  3572. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3573. if (print)
  3574. _print_next_block(par_num++,
  3575. "MCP SCPAD");
  3576. *global = true;
  3577. break;
  3578. }
  3579. /* Clear the bit */
  3580. sig &= ~cur_bit;
  3581. }
  3582. }
  3583. return par_num;
  3584. }
  3585. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3586. bool print)
  3587. {
  3588. int i = 0;
  3589. u32 cur_bit = 0;
  3590. for (i = 0; sig; i++) {
  3591. cur_bit = ((u32)0x1 << i);
  3592. if (sig & cur_bit) {
  3593. switch (cur_bit) {
  3594. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3595. if (print)
  3596. _print_next_block(par_num++, "PGLUE_B");
  3597. break;
  3598. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3599. if (print)
  3600. _print_next_block(par_num++, "ATC");
  3601. break;
  3602. }
  3603. /* Clear the bit */
  3604. sig &= ~cur_bit;
  3605. }
  3606. }
  3607. return par_num;
  3608. }
  3609. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3610. u32 *sig)
  3611. {
  3612. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3613. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3614. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3615. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3616. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3617. int par_num = 0;
  3618. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3619. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3620. sig[0] & HW_PRTY_ASSERT_SET_0,
  3621. sig[1] & HW_PRTY_ASSERT_SET_1,
  3622. sig[2] & HW_PRTY_ASSERT_SET_2,
  3623. sig[3] & HW_PRTY_ASSERT_SET_3,
  3624. sig[4] & HW_PRTY_ASSERT_SET_4);
  3625. if (print)
  3626. netdev_err(bp->dev,
  3627. "Parity errors detected in blocks: ");
  3628. par_num = bnx2x_check_blocks_with_parity0(
  3629. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3630. par_num = bnx2x_check_blocks_with_parity1(
  3631. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3632. par_num = bnx2x_check_blocks_with_parity2(
  3633. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3634. par_num = bnx2x_check_blocks_with_parity3(
  3635. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3636. par_num = bnx2x_check_blocks_with_parity4(
  3637. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3638. if (print)
  3639. pr_cont("\n");
  3640. return true;
  3641. } else
  3642. return false;
  3643. }
  3644. /**
  3645. * bnx2x_chk_parity_attn - checks for parity attentions.
  3646. *
  3647. * @bp: driver handle
  3648. * @global: true if there was a global attention
  3649. * @print: show parity attention in syslog
  3650. */
  3651. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3652. {
  3653. struct attn_route attn = { {0} };
  3654. int port = BP_PORT(bp);
  3655. attn.sig[0] = REG_RD(bp,
  3656. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3657. port*4);
  3658. attn.sig[1] = REG_RD(bp,
  3659. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3660. port*4);
  3661. attn.sig[2] = REG_RD(bp,
  3662. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3663. port*4);
  3664. attn.sig[3] = REG_RD(bp,
  3665. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3666. port*4);
  3667. if (!CHIP_IS_E1x(bp))
  3668. attn.sig[4] = REG_RD(bp,
  3669. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3670. port*4);
  3671. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3672. }
  3673. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3674. {
  3675. u32 val;
  3676. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3677. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3678. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3679. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3680. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3681. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3682. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3683. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3684. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3685. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3686. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3687. if (val &
  3688. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3689. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3690. if (val &
  3691. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3692. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3693. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3694. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3695. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3696. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3697. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3698. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3699. }
  3700. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3701. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3702. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3703. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3704. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3705. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3706. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3707. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3708. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3709. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3710. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3711. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3712. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3713. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3714. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3715. }
  3716. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3717. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3718. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3719. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3720. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3721. }
  3722. }
  3723. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3724. {
  3725. struct attn_route attn, *group_mask;
  3726. int port = BP_PORT(bp);
  3727. int index;
  3728. u32 reg_addr;
  3729. u32 val;
  3730. u32 aeu_mask;
  3731. bool global = false;
  3732. /* need to take HW lock because MCP or other port might also
  3733. try to handle this event */
  3734. bnx2x_acquire_alr(bp);
  3735. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3736. #ifndef BNX2X_STOP_ON_ERROR
  3737. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3738. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3739. /* Disable HW interrupts */
  3740. bnx2x_int_disable(bp);
  3741. /* In case of parity errors don't handle attentions so that
  3742. * other function would "see" parity errors.
  3743. */
  3744. #else
  3745. bnx2x_panic();
  3746. #endif
  3747. bnx2x_release_alr(bp);
  3748. return;
  3749. }
  3750. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3751. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3752. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3753. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3754. if (!CHIP_IS_E1x(bp))
  3755. attn.sig[4] =
  3756. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3757. else
  3758. attn.sig[4] = 0;
  3759. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3760. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3761. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3762. if (deasserted & (1 << index)) {
  3763. group_mask = &bp->attn_group[index];
  3764. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3765. index,
  3766. group_mask->sig[0], group_mask->sig[1],
  3767. group_mask->sig[2], group_mask->sig[3],
  3768. group_mask->sig[4]);
  3769. bnx2x_attn_int_deasserted4(bp,
  3770. attn.sig[4] & group_mask->sig[4]);
  3771. bnx2x_attn_int_deasserted3(bp,
  3772. attn.sig[3] & group_mask->sig[3]);
  3773. bnx2x_attn_int_deasserted1(bp,
  3774. attn.sig[1] & group_mask->sig[1]);
  3775. bnx2x_attn_int_deasserted2(bp,
  3776. attn.sig[2] & group_mask->sig[2]);
  3777. bnx2x_attn_int_deasserted0(bp,
  3778. attn.sig[0] & group_mask->sig[0]);
  3779. }
  3780. }
  3781. bnx2x_release_alr(bp);
  3782. if (bp->common.int_block == INT_BLOCK_HC)
  3783. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3784. COMMAND_REG_ATTN_BITS_CLR);
  3785. else
  3786. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3787. val = ~deasserted;
  3788. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3789. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3790. REG_WR(bp, reg_addr, val);
  3791. if (~bp->attn_state & deasserted)
  3792. BNX2X_ERR("IGU ERROR\n");
  3793. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3794. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3795. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3796. aeu_mask = REG_RD(bp, reg_addr);
  3797. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3798. aeu_mask, deasserted);
  3799. aeu_mask |= (deasserted & 0x3ff);
  3800. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3801. REG_WR(bp, reg_addr, aeu_mask);
  3802. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3803. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3804. bp->attn_state &= ~deasserted;
  3805. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3806. }
  3807. static void bnx2x_attn_int(struct bnx2x *bp)
  3808. {
  3809. /* read local copy of bits */
  3810. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3811. attn_bits);
  3812. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3813. attn_bits_ack);
  3814. u32 attn_state = bp->attn_state;
  3815. /* look for changed bits */
  3816. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3817. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3818. DP(NETIF_MSG_HW,
  3819. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3820. attn_bits, attn_ack, asserted, deasserted);
  3821. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3822. BNX2X_ERR("BAD attention state\n");
  3823. /* handle bits that were raised */
  3824. if (asserted)
  3825. bnx2x_attn_int_asserted(bp, asserted);
  3826. if (deasserted)
  3827. bnx2x_attn_int_deasserted(bp, deasserted);
  3828. }
  3829. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3830. u16 index, u8 op, u8 update)
  3831. {
  3832. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3833. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3834. igu_addr);
  3835. }
  3836. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3837. {
  3838. /* No memory barriers */
  3839. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3840. mmiowb(); /* keep prod updates ordered */
  3841. }
  3842. #ifdef BCM_CNIC
  3843. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3844. union event_ring_elem *elem)
  3845. {
  3846. u8 err = elem->message.error;
  3847. if (!bp->cnic_eth_dev.starting_cid ||
  3848. (cid < bp->cnic_eth_dev.starting_cid &&
  3849. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3850. return 1;
  3851. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3852. if (unlikely(err)) {
  3853. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3854. cid);
  3855. bnx2x_panic_dump(bp);
  3856. }
  3857. bnx2x_cnic_cfc_comp(bp, cid, err);
  3858. return 0;
  3859. }
  3860. #endif
  3861. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3862. {
  3863. struct bnx2x_mcast_ramrod_params rparam;
  3864. int rc;
  3865. memset(&rparam, 0, sizeof(rparam));
  3866. rparam.mcast_obj = &bp->mcast_obj;
  3867. netif_addr_lock_bh(bp->dev);
  3868. /* Clear pending state for the last command */
  3869. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3870. /* If there are pending mcast commands - send them */
  3871. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3872. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3873. if (rc < 0)
  3874. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3875. rc);
  3876. }
  3877. netif_addr_unlock_bh(bp->dev);
  3878. }
  3879. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3880. union event_ring_elem *elem)
  3881. {
  3882. unsigned long ramrod_flags = 0;
  3883. int rc = 0;
  3884. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3885. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3886. /* Always push next commands out, don't wait here */
  3887. __set_bit(RAMROD_CONT, &ramrod_flags);
  3888. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3889. case BNX2X_FILTER_MAC_PENDING:
  3890. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3891. #ifdef BCM_CNIC
  3892. if (cid == BNX2X_ISCSI_ETH_CID(bp))
  3893. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3894. else
  3895. #endif
  3896. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  3897. break;
  3898. case BNX2X_FILTER_MCAST_PENDING:
  3899. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3900. /* This is only relevant for 57710 where multicast MACs are
  3901. * configured as unicast MACs using the same ramrod.
  3902. */
  3903. bnx2x_handle_mcast_eqe(bp);
  3904. return;
  3905. default:
  3906. BNX2X_ERR("Unsupported classification command: %d\n",
  3907. elem->message.data.eth_event.echo);
  3908. return;
  3909. }
  3910. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3911. if (rc < 0)
  3912. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3913. else if (rc > 0)
  3914. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3915. }
  3916. #ifdef BCM_CNIC
  3917. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3918. #endif
  3919. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3920. {
  3921. netif_addr_lock_bh(bp->dev);
  3922. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3923. /* Send rx_mode command again if was requested */
  3924. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3925. bnx2x_set_storm_rx_mode(bp);
  3926. #ifdef BCM_CNIC
  3927. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3928. &bp->sp_state))
  3929. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3930. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3931. &bp->sp_state))
  3932. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3933. #endif
  3934. netif_addr_unlock_bh(bp->dev);
  3935. }
  3936. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  3937. union event_ring_elem *elem)
  3938. {
  3939. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  3940. DP(BNX2X_MSG_SP,
  3941. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  3942. elem->message.data.vif_list_event.func_bit_map);
  3943. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  3944. elem->message.data.vif_list_event.func_bit_map);
  3945. } else if (elem->message.data.vif_list_event.echo ==
  3946. VIF_LIST_RULE_SET) {
  3947. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  3948. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  3949. }
  3950. }
  3951. /* called with rtnl_lock */
  3952. static void bnx2x_after_function_update(struct bnx2x *bp)
  3953. {
  3954. int q, rc;
  3955. struct bnx2x_fastpath *fp;
  3956. struct bnx2x_queue_state_params queue_params = {NULL};
  3957. struct bnx2x_queue_update_params *q_update_params =
  3958. &queue_params.params.update;
  3959. /* Send Q update command with afex vlan removal values for all Qs */
  3960. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  3961. /* set silent vlan removal values according to vlan mode */
  3962. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3963. &q_update_params->update_flags);
  3964. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  3965. &q_update_params->update_flags);
  3966. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3967. /* in access mode mark mask and value are 0 to strip all vlans */
  3968. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  3969. q_update_params->silent_removal_value = 0;
  3970. q_update_params->silent_removal_mask = 0;
  3971. } else {
  3972. q_update_params->silent_removal_value =
  3973. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  3974. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  3975. }
  3976. for_each_eth_queue(bp, q) {
  3977. /* Set the appropriate Queue object */
  3978. fp = &bp->fp[q];
  3979. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3980. /* send the ramrod */
  3981. rc = bnx2x_queue_state_change(bp, &queue_params);
  3982. if (rc < 0)
  3983. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3984. q);
  3985. }
  3986. #ifdef BCM_CNIC
  3987. if (!NO_FCOE(bp)) {
  3988. fp = &bp->fp[FCOE_IDX(bp)];
  3989. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3990. /* clear pending completion bit */
  3991. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3992. /* mark latest Q bit */
  3993. smp_mb__before_clear_bit();
  3994. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  3995. smp_mb__after_clear_bit();
  3996. /* send Q update ramrod for FCoE Q */
  3997. rc = bnx2x_queue_state_change(bp, &queue_params);
  3998. if (rc < 0)
  3999. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4000. q);
  4001. } else {
  4002. /* If no FCoE ring - ACK MCP now */
  4003. bnx2x_link_report(bp);
  4004. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4005. }
  4006. #else
  4007. /* If no FCoE ring - ACK MCP now */
  4008. bnx2x_link_report(bp);
  4009. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4010. #endif /* BCM_CNIC */
  4011. }
  4012. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4013. struct bnx2x *bp, u32 cid)
  4014. {
  4015. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4016. #ifdef BCM_CNIC
  4017. if (cid == BNX2X_FCOE_ETH_CID(bp))
  4018. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4019. else
  4020. #endif
  4021. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4022. }
  4023. static void bnx2x_eq_int(struct bnx2x *bp)
  4024. {
  4025. u16 hw_cons, sw_cons, sw_prod;
  4026. union event_ring_elem *elem;
  4027. u32 cid;
  4028. u8 opcode;
  4029. int spqe_cnt = 0;
  4030. struct bnx2x_queue_sp_obj *q_obj;
  4031. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4032. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4033. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4034. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4035. * when we get the the next-page we nned to adjust so the loop
  4036. * condition below will be met. The next element is the size of a
  4037. * regular element and hence incrementing by 1
  4038. */
  4039. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4040. hw_cons++;
  4041. /* This function may never run in parallel with itself for a
  4042. * specific bp, thus there is no need in "paired" read memory
  4043. * barrier here.
  4044. */
  4045. sw_cons = bp->eq_cons;
  4046. sw_prod = bp->eq_prod;
  4047. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4048. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4049. for (; sw_cons != hw_cons;
  4050. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4051. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4052. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4053. opcode = elem->message.opcode;
  4054. /* handle eq element */
  4055. switch (opcode) {
  4056. case EVENT_RING_OPCODE_STAT_QUERY:
  4057. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4058. "got statistics comp event %d\n",
  4059. bp->stats_comp++);
  4060. /* nothing to do with stats comp */
  4061. goto next_spqe;
  4062. case EVENT_RING_OPCODE_CFC_DEL:
  4063. /* handle according to cid range */
  4064. /*
  4065. * we may want to verify here that the bp state is
  4066. * HALTING
  4067. */
  4068. DP(BNX2X_MSG_SP,
  4069. "got delete ramrod for MULTI[%d]\n", cid);
  4070. #ifdef BCM_CNIC
  4071. if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4072. goto next_spqe;
  4073. #endif
  4074. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4075. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4076. break;
  4077. goto next_spqe;
  4078. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4079. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4080. if (f_obj->complete_cmd(bp, f_obj,
  4081. BNX2X_F_CMD_TX_STOP))
  4082. break;
  4083. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4084. goto next_spqe;
  4085. case EVENT_RING_OPCODE_START_TRAFFIC:
  4086. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4087. if (f_obj->complete_cmd(bp, f_obj,
  4088. BNX2X_F_CMD_TX_START))
  4089. break;
  4090. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4091. goto next_spqe;
  4092. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4093. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4094. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4095. f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_AFEX_UPDATE);
  4096. /* We will perform the Queues update from sp_rtnl task
  4097. * as all Queue SP operations should run under
  4098. * rtnl_lock.
  4099. */
  4100. smp_mb__before_clear_bit();
  4101. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4102. &bp->sp_rtnl_state);
  4103. smp_mb__after_clear_bit();
  4104. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4105. goto next_spqe;
  4106. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4107. f_obj->complete_cmd(bp, f_obj,
  4108. BNX2X_F_CMD_AFEX_VIFLISTS);
  4109. bnx2x_after_afex_vif_lists(bp, elem);
  4110. goto next_spqe;
  4111. case EVENT_RING_OPCODE_FUNCTION_START:
  4112. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4113. "got FUNC_START ramrod\n");
  4114. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4115. break;
  4116. goto next_spqe;
  4117. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4118. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4119. "got FUNC_STOP ramrod\n");
  4120. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4121. break;
  4122. goto next_spqe;
  4123. }
  4124. switch (opcode | bp->state) {
  4125. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4126. BNX2X_STATE_OPEN):
  4127. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4128. BNX2X_STATE_OPENING_WAIT4_PORT):
  4129. cid = elem->message.data.eth_event.echo &
  4130. BNX2X_SWCID_MASK;
  4131. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4132. cid);
  4133. rss_raw->clear_pending(rss_raw);
  4134. break;
  4135. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4136. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4137. case (EVENT_RING_OPCODE_SET_MAC |
  4138. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4139. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4140. BNX2X_STATE_OPEN):
  4141. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4142. BNX2X_STATE_DIAG):
  4143. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4144. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4145. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4146. bnx2x_handle_classification_eqe(bp, elem);
  4147. break;
  4148. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4149. BNX2X_STATE_OPEN):
  4150. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4151. BNX2X_STATE_DIAG):
  4152. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4153. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4154. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4155. bnx2x_handle_mcast_eqe(bp);
  4156. break;
  4157. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4158. BNX2X_STATE_OPEN):
  4159. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4160. BNX2X_STATE_DIAG):
  4161. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4162. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4163. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4164. bnx2x_handle_rx_mode_eqe(bp);
  4165. break;
  4166. default:
  4167. /* unknown event log error and continue */
  4168. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4169. elem->message.opcode, bp->state);
  4170. }
  4171. next_spqe:
  4172. spqe_cnt++;
  4173. } /* for */
  4174. smp_mb__before_atomic_inc();
  4175. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4176. bp->eq_cons = sw_cons;
  4177. bp->eq_prod = sw_prod;
  4178. /* Make sure that above mem writes were issued towards the memory */
  4179. smp_wmb();
  4180. /* update producer */
  4181. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4182. }
  4183. static void bnx2x_sp_task(struct work_struct *work)
  4184. {
  4185. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4186. u16 status;
  4187. status = bnx2x_update_dsb_idx(bp);
  4188. /* if (status == 0) */
  4189. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  4190. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  4191. /* HW attentions */
  4192. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4193. bnx2x_attn_int(bp);
  4194. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4195. }
  4196. /* SP events: STAT_QUERY and others */
  4197. if (status & BNX2X_DEF_SB_IDX) {
  4198. #ifdef BCM_CNIC
  4199. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4200. if ((!NO_FCOE(bp)) &&
  4201. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4202. /*
  4203. * Prevent local bottom-halves from running as
  4204. * we are going to change the local NAPI list.
  4205. */
  4206. local_bh_disable();
  4207. napi_schedule(&bnx2x_fcoe(bp, napi));
  4208. local_bh_enable();
  4209. }
  4210. #endif
  4211. /* Handle EQ completions */
  4212. bnx2x_eq_int(bp);
  4213. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4214. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4215. status &= ~BNX2X_DEF_SB_IDX;
  4216. }
  4217. if (unlikely(status))
  4218. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  4219. status);
  4220. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4221. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4222. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4223. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4224. &bp->sp_state)) {
  4225. bnx2x_link_report(bp);
  4226. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4227. }
  4228. }
  4229. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4230. {
  4231. struct net_device *dev = dev_instance;
  4232. struct bnx2x *bp = netdev_priv(dev);
  4233. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4234. IGU_INT_DISABLE, 0);
  4235. #ifdef BNX2X_STOP_ON_ERROR
  4236. if (unlikely(bp->panic))
  4237. return IRQ_HANDLED;
  4238. #endif
  4239. #ifdef BCM_CNIC
  4240. {
  4241. struct cnic_ops *c_ops;
  4242. rcu_read_lock();
  4243. c_ops = rcu_dereference(bp->cnic_ops);
  4244. if (c_ops)
  4245. c_ops->cnic_handler(bp->cnic_data, NULL);
  4246. rcu_read_unlock();
  4247. }
  4248. #endif
  4249. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  4250. return IRQ_HANDLED;
  4251. }
  4252. /* end of slow path */
  4253. void bnx2x_drv_pulse(struct bnx2x *bp)
  4254. {
  4255. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4256. bp->fw_drv_pulse_wr_seq);
  4257. }
  4258. static void bnx2x_timer(unsigned long data)
  4259. {
  4260. struct bnx2x *bp = (struct bnx2x *) data;
  4261. if (!netif_running(bp->dev))
  4262. return;
  4263. if (!BP_NOMCP(bp)) {
  4264. int mb_idx = BP_FW_MB_IDX(bp);
  4265. u32 drv_pulse;
  4266. u32 mcp_pulse;
  4267. ++bp->fw_drv_pulse_wr_seq;
  4268. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4269. /* TBD - add SYSTEM_TIME */
  4270. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4271. bnx2x_drv_pulse(bp);
  4272. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4273. MCP_PULSE_SEQ_MASK);
  4274. /* The delta between driver pulse and mcp response
  4275. * should be 1 (before mcp response) or 0 (after mcp response)
  4276. */
  4277. if ((drv_pulse != mcp_pulse) &&
  4278. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4279. /* someone lost a heartbeat... */
  4280. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4281. drv_pulse, mcp_pulse);
  4282. }
  4283. }
  4284. if (bp->state == BNX2X_STATE_OPEN)
  4285. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4286. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4287. }
  4288. /* end of Statistics */
  4289. /* nic init */
  4290. /*
  4291. * nic init service functions
  4292. */
  4293. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4294. {
  4295. u32 i;
  4296. if (!(len%4) && !(addr%4))
  4297. for (i = 0; i < len; i += 4)
  4298. REG_WR(bp, addr + i, fill);
  4299. else
  4300. for (i = 0; i < len; i++)
  4301. REG_WR8(bp, addr + i, fill);
  4302. }
  4303. /* helper: writes FP SP data to FW - data_size in dwords */
  4304. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4305. int fw_sb_id,
  4306. u32 *sb_data_p,
  4307. u32 data_size)
  4308. {
  4309. int index;
  4310. for (index = 0; index < data_size; index++)
  4311. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4312. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4313. sizeof(u32)*index,
  4314. *(sb_data_p + index));
  4315. }
  4316. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4317. {
  4318. u32 *sb_data_p;
  4319. u32 data_size = 0;
  4320. struct hc_status_block_data_e2 sb_data_e2;
  4321. struct hc_status_block_data_e1x sb_data_e1x;
  4322. /* disable the function first */
  4323. if (!CHIP_IS_E1x(bp)) {
  4324. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4325. sb_data_e2.common.state = SB_DISABLED;
  4326. sb_data_e2.common.p_func.vf_valid = false;
  4327. sb_data_p = (u32 *)&sb_data_e2;
  4328. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4329. } else {
  4330. memset(&sb_data_e1x, 0,
  4331. sizeof(struct hc_status_block_data_e1x));
  4332. sb_data_e1x.common.state = SB_DISABLED;
  4333. sb_data_e1x.common.p_func.vf_valid = false;
  4334. sb_data_p = (u32 *)&sb_data_e1x;
  4335. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4336. }
  4337. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4338. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4339. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4340. CSTORM_STATUS_BLOCK_SIZE);
  4341. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4342. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4343. CSTORM_SYNC_BLOCK_SIZE);
  4344. }
  4345. /* helper: writes SP SB data to FW */
  4346. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4347. struct hc_sp_status_block_data *sp_sb_data)
  4348. {
  4349. int func = BP_FUNC(bp);
  4350. int i;
  4351. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4352. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4353. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4354. i*sizeof(u32),
  4355. *((u32 *)sp_sb_data + i));
  4356. }
  4357. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4358. {
  4359. int func = BP_FUNC(bp);
  4360. struct hc_sp_status_block_data sp_sb_data;
  4361. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4362. sp_sb_data.state = SB_DISABLED;
  4363. sp_sb_data.p_func.vf_valid = false;
  4364. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4365. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4366. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4367. CSTORM_SP_STATUS_BLOCK_SIZE);
  4368. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4369. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4370. CSTORM_SP_SYNC_BLOCK_SIZE);
  4371. }
  4372. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4373. int igu_sb_id, int igu_seg_id)
  4374. {
  4375. hc_sm->igu_sb_id = igu_sb_id;
  4376. hc_sm->igu_seg_id = igu_seg_id;
  4377. hc_sm->timer_value = 0xFF;
  4378. hc_sm->time_to_expire = 0xFFFFFFFF;
  4379. }
  4380. /* allocates state machine ids. */
  4381. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4382. {
  4383. /* zero out state machine indices */
  4384. /* rx indices */
  4385. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4386. /* tx indices */
  4387. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4388. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4389. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4390. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4391. /* map indices */
  4392. /* rx indices */
  4393. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4394. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4395. /* tx indices */
  4396. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4397. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4398. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4399. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4400. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4401. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4402. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4403. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4404. }
  4405. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4406. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4407. {
  4408. int igu_seg_id;
  4409. struct hc_status_block_data_e2 sb_data_e2;
  4410. struct hc_status_block_data_e1x sb_data_e1x;
  4411. struct hc_status_block_sm *hc_sm_p;
  4412. int data_size;
  4413. u32 *sb_data_p;
  4414. if (CHIP_INT_MODE_IS_BC(bp))
  4415. igu_seg_id = HC_SEG_ACCESS_NORM;
  4416. else
  4417. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4418. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4419. if (!CHIP_IS_E1x(bp)) {
  4420. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4421. sb_data_e2.common.state = SB_ENABLED;
  4422. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4423. sb_data_e2.common.p_func.vf_id = vfid;
  4424. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4425. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4426. sb_data_e2.common.same_igu_sb_1b = true;
  4427. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4428. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4429. hc_sm_p = sb_data_e2.common.state_machine;
  4430. sb_data_p = (u32 *)&sb_data_e2;
  4431. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4432. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4433. } else {
  4434. memset(&sb_data_e1x, 0,
  4435. sizeof(struct hc_status_block_data_e1x));
  4436. sb_data_e1x.common.state = SB_ENABLED;
  4437. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4438. sb_data_e1x.common.p_func.vf_id = 0xff;
  4439. sb_data_e1x.common.p_func.vf_valid = false;
  4440. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4441. sb_data_e1x.common.same_igu_sb_1b = true;
  4442. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4443. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4444. hc_sm_p = sb_data_e1x.common.state_machine;
  4445. sb_data_p = (u32 *)&sb_data_e1x;
  4446. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4447. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4448. }
  4449. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4450. igu_sb_id, igu_seg_id);
  4451. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4452. igu_sb_id, igu_seg_id);
  4453. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4454. /* write indecies to HW */
  4455. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4456. }
  4457. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4458. u16 tx_usec, u16 rx_usec)
  4459. {
  4460. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4461. false, rx_usec);
  4462. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4463. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4464. tx_usec);
  4465. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4466. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4467. tx_usec);
  4468. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4469. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4470. tx_usec);
  4471. }
  4472. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4473. {
  4474. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4475. dma_addr_t mapping = bp->def_status_blk_mapping;
  4476. int igu_sp_sb_index;
  4477. int igu_seg_id;
  4478. int port = BP_PORT(bp);
  4479. int func = BP_FUNC(bp);
  4480. int reg_offset, reg_offset_en5;
  4481. u64 section;
  4482. int index;
  4483. struct hc_sp_status_block_data sp_sb_data;
  4484. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4485. if (CHIP_INT_MODE_IS_BC(bp)) {
  4486. igu_sp_sb_index = DEF_SB_IGU_ID;
  4487. igu_seg_id = HC_SEG_ACCESS_DEF;
  4488. } else {
  4489. igu_sp_sb_index = bp->igu_dsb_id;
  4490. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4491. }
  4492. /* ATTN */
  4493. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4494. atten_status_block);
  4495. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4496. bp->attn_state = 0;
  4497. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4498. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4499. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4500. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4501. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4502. int sindex;
  4503. /* take care of sig[0]..sig[4] */
  4504. for (sindex = 0; sindex < 4; sindex++)
  4505. bp->attn_group[index].sig[sindex] =
  4506. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4507. if (!CHIP_IS_E1x(bp))
  4508. /*
  4509. * enable5 is separate from the rest of the registers,
  4510. * and therefore the address skip is 4
  4511. * and not 16 between the different groups
  4512. */
  4513. bp->attn_group[index].sig[4] = REG_RD(bp,
  4514. reg_offset_en5 + 0x4*index);
  4515. else
  4516. bp->attn_group[index].sig[4] = 0;
  4517. }
  4518. if (bp->common.int_block == INT_BLOCK_HC) {
  4519. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4520. HC_REG_ATTN_MSG0_ADDR_L);
  4521. REG_WR(bp, reg_offset, U64_LO(section));
  4522. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4523. } else if (!CHIP_IS_E1x(bp)) {
  4524. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4525. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4526. }
  4527. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4528. sp_sb);
  4529. bnx2x_zero_sp_sb(bp);
  4530. sp_sb_data.state = SB_ENABLED;
  4531. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4532. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4533. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4534. sp_sb_data.igu_seg_id = igu_seg_id;
  4535. sp_sb_data.p_func.pf_id = func;
  4536. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4537. sp_sb_data.p_func.vf_id = 0xff;
  4538. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4539. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4540. }
  4541. void bnx2x_update_coalesce(struct bnx2x *bp)
  4542. {
  4543. int i;
  4544. for_each_eth_queue(bp, i)
  4545. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4546. bp->tx_ticks, bp->rx_ticks);
  4547. }
  4548. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4549. {
  4550. spin_lock_init(&bp->spq_lock);
  4551. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4552. bp->spq_prod_idx = 0;
  4553. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4554. bp->spq_prod_bd = bp->spq;
  4555. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4556. }
  4557. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4558. {
  4559. int i;
  4560. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4561. union event_ring_elem *elem =
  4562. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4563. elem->next_page.addr.hi =
  4564. cpu_to_le32(U64_HI(bp->eq_mapping +
  4565. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4566. elem->next_page.addr.lo =
  4567. cpu_to_le32(U64_LO(bp->eq_mapping +
  4568. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4569. }
  4570. bp->eq_cons = 0;
  4571. bp->eq_prod = NUM_EQ_DESC;
  4572. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4573. /* we want a warning message before it gets rought... */
  4574. atomic_set(&bp->eq_spq_left,
  4575. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4576. }
  4577. /* called with netif_addr_lock_bh() */
  4578. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4579. unsigned long rx_mode_flags,
  4580. unsigned long rx_accept_flags,
  4581. unsigned long tx_accept_flags,
  4582. unsigned long ramrod_flags)
  4583. {
  4584. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4585. int rc;
  4586. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4587. /* Prepare ramrod parameters */
  4588. ramrod_param.cid = 0;
  4589. ramrod_param.cl_id = cl_id;
  4590. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4591. ramrod_param.func_id = BP_FUNC(bp);
  4592. ramrod_param.pstate = &bp->sp_state;
  4593. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4594. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4595. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4596. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4597. ramrod_param.ramrod_flags = ramrod_flags;
  4598. ramrod_param.rx_mode_flags = rx_mode_flags;
  4599. ramrod_param.rx_accept_flags = rx_accept_flags;
  4600. ramrod_param.tx_accept_flags = tx_accept_flags;
  4601. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4602. if (rc < 0) {
  4603. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4604. return;
  4605. }
  4606. }
  4607. /* called with netif_addr_lock_bh() */
  4608. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4609. {
  4610. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4611. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4612. #ifdef BCM_CNIC
  4613. if (!NO_FCOE(bp))
  4614. /* Configure rx_mode of FCoE Queue */
  4615. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4616. #endif
  4617. switch (bp->rx_mode) {
  4618. case BNX2X_RX_MODE_NONE:
  4619. /*
  4620. * 'drop all' supersedes any accept flags that may have been
  4621. * passed to the function.
  4622. */
  4623. break;
  4624. case BNX2X_RX_MODE_NORMAL:
  4625. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4626. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4627. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4628. /* internal switching mode */
  4629. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4630. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4631. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4632. break;
  4633. case BNX2X_RX_MODE_ALLMULTI:
  4634. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4635. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4636. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4637. /* internal switching mode */
  4638. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4639. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4640. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4641. break;
  4642. case BNX2X_RX_MODE_PROMISC:
  4643. /* According to deffinition of SI mode, iface in promisc mode
  4644. * should receive matched and unmatched (in resolution of port)
  4645. * unicast packets.
  4646. */
  4647. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4648. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4649. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4650. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4651. /* internal switching mode */
  4652. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4653. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4654. if (IS_MF_SI(bp))
  4655. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4656. else
  4657. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4658. break;
  4659. default:
  4660. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4661. return;
  4662. }
  4663. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4664. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4665. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4666. }
  4667. __set_bit(RAMROD_RX, &ramrod_flags);
  4668. __set_bit(RAMROD_TX, &ramrod_flags);
  4669. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4670. tx_accept_flags, ramrod_flags);
  4671. }
  4672. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4673. {
  4674. int i;
  4675. if (IS_MF_SI(bp))
  4676. /*
  4677. * In switch independent mode, the TSTORM needs to accept
  4678. * packets that failed classification, since approximate match
  4679. * mac addresses aren't written to NIG LLH
  4680. */
  4681. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4682. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4683. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4684. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4685. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4686. /* Zero this manually as its initialization is
  4687. currently missing in the initTool */
  4688. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4689. REG_WR(bp, BAR_USTRORM_INTMEM +
  4690. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4691. if (!CHIP_IS_E1x(bp)) {
  4692. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4693. CHIP_INT_MODE_IS_BC(bp) ?
  4694. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4695. }
  4696. }
  4697. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4698. {
  4699. switch (load_code) {
  4700. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4701. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4702. bnx2x_init_internal_common(bp);
  4703. /* no break */
  4704. case FW_MSG_CODE_DRV_LOAD_PORT:
  4705. /* nothing to do */
  4706. /* no break */
  4707. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4708. /* internal memory per function is
  4709. initialized inside bnx2x_pf_init */
  4710. break;
  4711. default:
  4712. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4713. break;
  4714. }
  4715. }
  4716. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4717. {
  4718. return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
  4719. }
  4720. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4721. {
  4722. return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
  4723. }
  4724. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4725. {
  4726. if (CHIP_IS_E1x(fp->bp))
  4727. return BP_L_ID(fp->bp) + fp->index;
  4728. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4729. return bnx2x_fp_igu_sb_id(fp);
  4730. }
  4731. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4732. {
  4733. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4734. u8 cos;
  4735. unsigned long q_type = 0;
  4736. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4737. fp->rx_queue = fp_idx;
  4738. fp->cid = fp_idx;
  4739. fp->cl_id = bnx2x_fp_cl_id(fp);
  4740. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4741. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4742. /* qZone id equals to FW (per path) client id */
  4743. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4744. /* init shortcut */
  4745. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4746. /* Setup SB indicies */
  4747. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4748. /* Configure Queue State object */
  4749. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4750. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4751. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4752. /* init tx data */
  4753. for_each_cos_in_tx_queue(fp, cos) {
  4754. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4755. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4756. FP_COS_TO_TXQ(fp, cos, bp),
  4757. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4758. cids[cos] = fp->txdata_ptr[cos]->cid;
  4759. }
  4760. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4761. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4762. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4763. /**
  4764. * Configure classification DBs: Always enable Tx switching
  4765. */
  4766. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4767. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4768. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4769. fp->igu_sb_id);
  4770. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4771. fp->fw_sb_id, fp->igu_sb_id);
  4772. bnx2x_update_fpsb_idx(fp);
  4773. }
  4774. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4775. {
  4776. int i;
  4777. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4778. struct eth_tx_next_bd *tx_next_bd =
  4779. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4780. tx_next_bd->addr_hi =
  4781. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4782. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4783. tx_next_bd->addr_lo =
  4784. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4785. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4786. }
  4787. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4788. txdata->tx_db.data.zero_fill1 = 0;
  4789. txdata->tx_db.data.prod = 0;
  4790. txdata->tx_pkt_prod = 0;
  4791. txdata->tx_pkt_cons = 0;
  4792. txdata->tx_bd_prod = 0;
  4793. txdata->tx_bd_cons = 0;
  4794. txdata->tx_pkt = 0;
  4795. }
  4796. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4797. {
  4798. int i;
  4799. u8 cos;
  4800. for_each_tx_queue(bp, i)
  4801. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4802. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4803. }
  4804. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4805. {
  4806. int i;
  4807. for_each_eth_queue(bp, i)
  4808. bnx2x_init_eth_fp(bp, i);
  4809. #ifdef BCM_CNIC
  4810. if (!NO_FCOE(bp))
  4811. bnx2x_init_fcoe_fp(bp);
  4812. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4813. BNX2X_VF_ID_INVALID, false,
  4814. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4815. #endif
  4816. /* Initialize MOD_ABS interrupts */
  4817. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4818. bp->common.shmem_base, bp->common.shmem2_base,
  4819. BP_PORT(bp));
  4820. /* ensure status block indices were read */
  4821. rmb();
  4822. bnx2x_init_def_sb(bp);
  4823. bnx2x_update_dsb_idx(bp);
  4824. bnx2x_init_rx_rings(bp);
  4825. bnx2x_init_tx_rings(bp);
  4826. bnx2x_init_sp_ring(bp);
  4827. bnx2x_init_eq_ring(bp);
  4828. bnx2x_init_internal(bp, load_code);
  4829. bnx2x_pf_init(bp);
  4830. bnx2x_stats_init(bp);
  4831. /* flush all before enabling interrupts */
  4832. mb();
  4833. mmiowb();
  4834. bnx2x_int_enable(bp);
  4835. /* Check for SPIO5 */
  4836. bnx2x_attn_int_deasserted0(bp,
  4837. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4838. AEU_INPUTS_ATTN_BITS_SPIO5);
  4839. }
  4840. /* end of nic init */
  4841. /*
  4842. * gzip service functions
  4843. */
  4844. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4845. {
  4846. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4847. &bp->gunzip_mapping, GFP_KERNEL);
  4848. if (bp->gunzip_buf == NULL)
  4849. goto gunzip_nomem1;
  4850. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4851. if (bp->strm == NULL)
  4852. goto gunzip_nomem2;
  4853. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4854. if (bp->strm->workspace == NULL)
  4855. goto gunzip_nomem3;
  4856. return 0;
  4857. gunzip_nomem3:
  4858. kfree(bp->strm);
  4859. bp->strm = NULL;
  4860. gunzip_nomem2:
  4861. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4862. bp->gunzip_mapping);
  4863. bp->gunzip_buf = NULL;
  4864. gunzip_nomem1:
  4865. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4866. return -ENOMEM;
  4867. }
  4868. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4869. {
  4870. if (bp->strm) {
  4871. vfree(bp->strm->workspace);
  4872. kfree(bp->strm);
  4873. bp->strm = NULL;
  4874. }
  4875. if (bp->gunzip_buf) {
  4876. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4877. bp->gunzip_mapping);
  4878. bp->gunzip_buf = NULL;
  4879. }
  4880. }
  4881. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4882. {
  4883. int n, rc;
  4884. /* check gzip header */
  4885. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4886. BNX2X_ERR("Bad gzip header\n");
  4887. return -EINVAL;
  4888. }
  4889. n = 10;
  4890. #define FNAME 0x8
  4891. if (zbuf[3] & FNAME)
  4892. while ((zbuf[n++] != 0) && (n < len));
  4893. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4894. bp->strm->avail_in = len - n;
  4895. bp->strm->next_out = bp->gunzip_buf;
  4896. bp->strm->avail_out = FW_BUF_SIZE;
  4897. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4898. if (rc != Z_OK)
  4899. return rc;
  4900. rc = zlib_inflate(bp->strm, Z_FINISH);
  4901. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4902. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4903. bp->strm->msg);
  4904. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4905. if (bp->gunzip_outlen & 0x3)
  4906. netdev_err(bp->dev,
  4907. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4908. bp->gunzip_outlen);
  4909. bp->gunzip_outlen >>= 2;
  4910. zlib_inflateEnd(bp->strm);
  4911. if (rc == Z_STREAM_END)
  4912. return 0;
  4913. return rc;
  4914. }
  4915. /* nic load/unload */
  4916. /*
  4917. * General service functions
  4918. */
  4919. /* send a NIG loopback debug packet */
  4920. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4921. {
  4922. u32 wb_write[3];
  4923. /* Ethernet source and destination addresses */
  4924. wb_write[0] = 0x55555555;
  4925. wb_write[1] = 0x55555555;
  4926. wb_write[2] = 0x20; /* SOP */
  4927. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4928. /* NON-IP protocol */
  4929. wb_write[0] = 0x09000000;
  4930. wb_write[1] = 0x55555555;
  4931. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4932. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4933. }
  4934. /* some of the internal memories
  4935. * are not directly readable from the driver
  4936. * to test them we send debug packets
  4937. */
  4938. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4939. {
  4940. int factor;
  4941. int count, i;
  4942. u32 val = 0;
  4943. if (CHIP_REV_IS_FPGA(bp))
  4944. factor = 120;
  4945. else if (CHIP_REV_IS_EMUL(bp))
  4946. factor = 200;
  4947. else
  4948. factor = 1;
  4949. /* Disable inputs of parser neighbor blocks */
  4950. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4951. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4952. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4953. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4954. /* Write 0 to parser credits for CFC search request */
  4955. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4956. /* send Ethernet packet */
  4957. bnx2x_lb_pckt(bp);
  4958. /* TODO do i reset NIG statistic? */
  4959. /* Wait until NIG register shows 1 packet of size 0x10 */
  4960. count = 1000 * factor;
  4961. while (count) {
  4962. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4963. val = *bnx2x_sp(bp, wb_data[0]);
  4964. if (val == 0x10)
  4965. break;
  4966. msleep(10);
  4967. count--;
  4968. }
  4969. if (val != 0x10) {
  4970. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4971. return -1;
  4972. }
  4973. /* Wait until PRS register shows 1 packet */
  4974. count = 1000 * factor;
  4975. while (count) {
  4976. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4977. if (val == 1)
  4978. break;
  4979. msleep(10);
  4980. count--;
  4981. }
  4982. if (val != 0x1) {
  4983. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4984. return -2;
  4985. }
  4986. /* Reset and init BRB, PRS */
  4987. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4988. msleep(50);
  4989. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4990. msleep(50);
  4991. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4992. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4993. DP(NETIF_MSG_HW, "part2\n");
  4994. /* Disable inputs of parser neighbor blocks */
  4995. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4996. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4997. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4998. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4999. /* Write 0 to parser credits for CFC search request */
  5000. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5001. /* send 10 Ethernet packets */
  5002. for (i = 0; i < 10; i++)
  5003. bnx2x_lb_pckt(bp);
  5004. /* Wait until NIG register shows 10 + 1
  5005. packets of size 11*0x10 = 0xb0 */
  5006. count = 1000 * factor;
  5007. while (count) {
  5008. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5009. val = *bnx2x_sp(bp, wb_data[0]);
  5010. if (val == 0xb0)
  5011. break;
  5012. msleep(10);
  5013. count--;
  5014. }
  5015. if (val != 0xb0) {
  5016. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5017. return -3;
  5018. }
  5019. /* Wait until PRS register shows 2 packets */
  5020. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5021. if (val != 2)
  5022. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5023. /* Write 1 to parser credits for CFC search request */
  5024. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5025. /* Wait until PRS register shows 3 packets */
  5026. msleep(10 * factor);
  5027. /* Wait until NIG register shows 1 packet of size 0x10 */
  5028. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5029. if (val != 3)
  5030. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5031. /* clear NIG EOP FIFO */
  5032. for (i = 0; i < 11; i++)
  5033. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5034. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5035. if (val != 1) {
  5036. BNX2X_ERR("clear of NIG failed\n");
  5037. return -4;
  5038. }
  5039. /* Reset and init BRB, PRS, NIG */
  5040. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5041. msleep(50);
  5042. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5043. msleep(50);
  5044. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5045. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5046. #ifndef BCM_CNIC
  5047. /* set NIC mode */
  5048. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5049. #endif
  5050. /* Enable inputs of parser neighbor blocks */
  5051. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5052. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5053. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5054. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5055. DP(NETIF_MSG_HW, "done\n");
  5056. return 0; /* OK */
  5057. }
  5058. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5059. {
  5060. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5061. if (!CHIP_IS_E1x(bp))
  5062. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5063. else
  5064. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5065. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5066. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5067. /*
  5068. * mask read length error interrupts in brb for parser
  5069. * (parsing unit and 'checksum and crc' unit)
  5070. * these errors are legal (PU reads fixed length and CAC can cause
  5071. * read length error on truncated packets)
  5072. */
  5073. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5074. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5075. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5076. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5077. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5078. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5079. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5080. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5081. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5082. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5083. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5084. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5085. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5086. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5087. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5088. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5089. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5090. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5091. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5092. if (CHIP_REV_IS_FPGA(bp))
  5093. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  5094. else if (!CHIP_IS_E1x(bp))
  5095. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  5096. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  5097. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  5098. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  5099. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  5100. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  5101. else
  5102. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  5103. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5104. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5105. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5106. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5107. if (!CHIP_IS_E1x(bp))
  5108. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5109. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5110. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5111. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5112. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5113. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5114. }
  5115. static void bnx2x_reset_common(struct bnx2x *bp)
  5116. {
  5117. u32 val = 0x1400;
  5118. /* reset_common */
  5119. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5120. 0xd3ffff7f);
  5121. if (CHIP_IS_E3(bp)) {
  5122. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5123. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5124. }
  5125. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5126. }
  5127. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5128. {
  5129. bp->dmae_ready = 0;
  5130. spin_lock_init(&bp->dmae_lock);
  5131. }
  5132. static void bnx2x_init_pxp(struct bnx2x *bp)
  5133. {
  5134. u16 devctl;
  5135. int r_order, w_order;
  5136. pci_read_config_word(bp->pdev,
  5137. pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
  5138. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5139. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5140. if (bp->mrrs == -1)
  5141. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5142. else {
  5143. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5144. r_order = bp->mrrs;
  5145. }
  5146. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5147. }
  5148. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5149. {
  5150. int is_required;
  5151. u32 val;
  5152. int port;
  5153. if (BP_NOMCP(bp))
  5154. return;
  5155. is_required = 0;
  5156. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5157. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5158. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5159. is_required = 1;
  5160. /*
  5161. * The fan failure mechanism is usually related to the PHY type since
  5162. * the power consumption of the board is affected by the PHY. Currently,
  5163. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5164. */
  5165. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5166. for (port = PORT_0; port < PORT_MAX; port++) {
  5167. is_required |=
  5168. bnx2x_fan_failure_det_req(
  5169. bp,
  5170. bp->common.shmem_base,
  5171. bp->common.shmem2_base,
  5172. port);
  5173. }
  5174. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5175. if (is_required == 0)
  5176. return;
  5177. /* Fan failure is indicated by SPIO 5 */
  5178. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  5179. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  5180. /* set to active low mode */
  5181. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5182. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  5183. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  5184. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5185. /* enable interrupt to signal the IGU */
  5186. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5187. val |= (1 << MISC_REGISTERS_SPIO_5);
  5188. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5189. }
  5190. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  5191. {
  5192. u32 offset = 0;
  5193. if (CHIP_IS_E1(bp))
  5194. return;
  5195. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  5196. return;
  5197. switch (BP_ABS_FUNC(bp)) {
  5198. case 0:
  5199. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  5200. break;
  5201. case 1:
  5202. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  5203. break;
  5204. case 2:
  5205. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  5206. break;
  5207. case 3:
  5208. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  5209. break;
  5210. case 4:
  5211. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  5212. break;
  5213. case 5:
  5214. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  5215. break;
  5216. case 6:
  5217. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  5218. break;
  5219. case 7:
  5220. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  5221. break;
  5222. default:
  5223. return;
  5224. }
  5225. REG_WR(bp, offset, pretend_func_num);
  5226. REG_RD(bp, offset);
  5227. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  5228. }
  5229. void bnx2x_pf_disable(struct bnx2x *bp)
  5230. {
  5231. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5232. val &= ~IGU_PF_CONF_FUNC_EN;
  5233. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5234. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5235. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5236. }
  5237. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5238. {
  5239. u32 shmem_base[2], shmem2_base[2];
  5240. shmem_base[0] = bp->common.shmem_base;
  5241. shmem2_base[0] = bp->common.shmem2_base;
  5242. if (!CHIP_IS_E1x(bp)) {
  5243. shmem_base[1] =
  5244. SHMEM2_RD(bp, other_shmem_base_addr);
  5245. shmem2_base[1] =
  5246. SHMEM2_RD(bp, other_shmem2_base_addr);
  5247. }
  5248. bnx2x_acquire_phy_lock(bp);
  5249. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5250. bp->common.chip_id);
  5251. bnx2x_release_phy_lock(bp);
  5252. }
  5253. /**
  5254. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5255. *
  5256. * @bp: driver handle
  5257. */
  5258. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5259. {
  5260. u32 val;
  5261. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5262. /*
  5263. * take the UNDI lock to protect undi_unload flow from accessing
  5264. * registers while we're resetting the chip
  5265. */
  5266. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5267. bnx2x_reset_common(bp);
  5268. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5269. val = 0xfffc;
  5270. if (CHIP_IS_E3(bp)) {
  5271. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5272. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5273. }
  5274. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5275. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5276. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5277. if (!CHIP_IS_E1x(bp)) {
  5278. u8 abs_func_id;
  5279. /**
  5280. * 4-port mode or 2-port mode we need to turn of master-enable
  5281. * for everyone, after that, turn it back on for self.
  5282. * so, we disregard multi-function or not, and always disable
  5283. * for all functions on the given path, this means 0,2,4,6 for
  5284. * path 0 and 1,3,5,7 for path 1
  5285. */
  5286. for (abs_func_id = BP_PATH(bp);
  5287. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5288. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5289. REG_WR(bp,
  5290. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5291. 1);
  5292. continue;
  5293. }
  5294. bnx2x_pretend_func(bp, abs_func_id);
  5295. /* clear pf enable */
  5296. bnx2x_pf_disable(bp);
  5297. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5298. }
  5299. }
  5300. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5301. if (CHIP_IS_E1(bp)) {
  5302. /* enable HW interrupt from PXP on USDM overflow
  5303. bit 16 on INT_MASK_0 */
  5304. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5305. }
  5306. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5307. bnx2x_init_pxp(bp);
  5308. #ifdef __BIG_ENDIAN
  5309. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5310. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5311. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5312. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5313. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5314. /* make sure this value is 0 */
  5315. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5316. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5317. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5318. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5319. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5320. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5321. #endif
  5322. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5323. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5324. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5325. /* let the HW do it's magic ... */
  5326. msleep(100);
  5327. /* finish PXP init */
  5328. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5329. if (val != 1) {
  5330. BNX2X_ERR("PXP2 CFG failed\n");
  5331. return -EBUSY;
  5332. }
  5333. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5334. if (val != 1) {
  5335. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5336. return -EBUSY;
  5337. }
  5338. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5339. * have entries with value "0" and valid bit on.
  5340. * This needs to be done by the first PF that is loaded in a path
  5341. * (i.e. common phase)
  5342. */
  5343. if (!CHIP_IS_E1x(bp)) {
  5344. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5345. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5346. * This occurs when a different function (func2,3) is being marked
  5347. * as "scan-off". Real-life scenario for example: if a driver is being
  5348. * load-unloaded while func6,7 are down. This will cause the timer to access
  5349. * the ilt, translate to a logical address and send a request to read/write.
  5350. * Since the ilt for the function that is down is not valid, this will cause
  5351. * a translation error which is unrecoverable.
  5352. * The Workaround is intended to make sure that when this happens nothing fatal
  5353. * will occur. The workaround:
  5354. * 1. First PF driver which loads on a path will:
  5355. * a. After taking the chip out of reset, by using pretend,
  5356. * it will write "0" to the following registers of
  5357. * the other vnics.
  5358. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5359. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5360. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5361. * And for itself it will write '1' to
  5362. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5363. * dmae-operations (writing to pram for example.)
  5364. * note: can be done for only function 6,7 but cleaner this
  5365. * way.
  5366. * b. Write zero+valid to the entire ILT.
  5367. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5368. * VNIC3 (of that port). The range allocated will be the
  5369. * entire ILT. This is needed to prevent ILT range error.
  5370. * 2. Any PF driver load flow:
  5371. * a. ILT update with the physical addresses of the allocated
  5372. * logical pages.
  5373. * b. Wait 20msec. - note that this timeout is needed to make
  5374. * sure there are no requests in one of the PXP internal
  5375. * queues with "old" ILT addresses.
  5376. * c. PF enable in the PGLC.
  5377. * d. Clear the was_error of the PF in the PGLC. (could have
  5378. * occured while driver was down)
  5379. * e. PF enable in the CFC (WEAK + STRONG)
  5380. * f. Timers scan enable
  5381. * 3. PF driver unload flow:
  5382. * a. Clear the Timers scan_en.
  5383. * b. Polling for scan_on=0 for that PF.
  5384. * c. Clear the PF enable bit in the PXP.
  5385. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5386. * e. Write zero+valid to all ILT entries (The valid bit must
  5387. * stay set)
  5388. * f. If this is VNIC 3 of a port then also init
  5389. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5390. * to the last enrty in the ILT.
  5391. *
  5392. * Notes:
  5393. * Currently the PF error in the PGLC is non recoverable.
  5394. * In the future the there will be a recovery routine for this error.
  5395. * Currently attention is masked.
  5396. * Having an MCP lock on the load/unload process does not guarantee that
  5397. * there is no Timer disable during Func6/7 enable. This is because the
  5398. * Timers scan is currently being cleared by the MCP on FLR.
  5399. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5400. * there is error before clearing it. But the flow above is simpler and
  5401. * more general.
  5402. * All ILT entries are written by zero+valid and not just PF6/7
  5403. * ILT entries since in the future the ILT entries allocation for
  5404. * PF-s might be dynamic.
  5405. */
  5406. struct ilt_client_info ilt_cli;
  5407. struct bnx2x_ilt ilt;
  5408. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5409. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5410. /* initialize dummy TM client */
  5411. ilt_cli.start = 0;
  5412. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5413. ilt_cli.client_num = ILT_CLIENT_TM;
  5414. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5415. * Step 2: set the timers first/last ilt entry to point
  5416. * to the entire range to prevent ILT range error for 3rd/4th
  5417. * vnic (this code assumes existance of the vnic)
  5418. *
  5419. * both steps performed by call to bnx2x_ilt_client_init_op()
  5420. * with dummy TM client
  5421. *
  5422. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5423. * and his brother are split registers
  5424. */
  5425. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5426. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5427. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5428. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5429. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5430. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5431. }
  5432. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5433. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5434. if (!CHIP_IS_E1x(bp)) {
  5435. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5436. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5437. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5438. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5439. /* let the HW do it's magic ... */
  5440. do {
  5441. msleep(200);
  5442. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5443. } while (factor-- && (val != 1));
  5444. if (val != 1) {
  5445. BNX2X_ERR("ATC_INIT failed\n");
  5446. return -EBUSY;
  5447. }
  5448. }
  5449. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5450. /* clean the DMAE memory */
  5451. bp->dmae_ready = 1;
  5452. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5453. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5454. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5455. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5456. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5457. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5458. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5459. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5460. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5461. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5462. /* QM queues pointers table */
  5463. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5464. /* soft reset pulse */
  5465. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5466. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5467. #ifdef BCM_CNIC
  5468. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5469. #endif
  5470. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5471. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5472. if (!CHIP_REV_IS_SLOW(bp))
  5473. /* enable hw interrupt from doorbell Q */
  5474. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5475. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5476. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5477. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5478. if (!CHIP_IS_E1(bp))
  5479. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5480. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5481. if (IS_MF_AFEX(bp)) {
  5482. /* configure that VNTag and VLAN headers must be
  5483. * received in afex mode
  5484. */
  5485. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5486. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5487. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5488. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5489. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5490. } else {
  5491. /* Bit-map indicating which L2 hdrs may appear
  5492. * after the basic Ethernet header
  5493. */
  5494. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5495. bp->path_has_ovlan ? 7 : 6);
  5496. }
  5497. }
  5498. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5499. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5500. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5501. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5502. if (!CHIP_IS_E1x(bp)) {
  5503. /* reset VFC memories */
  5504. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5505. VFC_MEMORIES_RST_REG_CAM_RST |
  5506. VFC_MEMORIES_RST_REG_RAM_RST);
  5507. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5508. VFC_MEMORIES_RST_REG_CAM_RST |
  5509. VFC_MEMORIES_RST_REG_RAM_RST);
  5510. msleep(20);
  5511. }
  5512. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5513. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5514. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5515. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5516. /* sync semi rtc */
  5517. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5518. 0x80000000);
  5519. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5520. 0x80000000);
  5521. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5522. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5523. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5524. if (!CHIP_IS_E1x(bp)) {
  5525. if (IS_MF_AFEX(bp)) {
  5526. /* configure that VNTag and VLAN headers must be
  5527. * sent in afex mode
  5528. */
  5529. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5530. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5531. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5532. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5533. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5534. } else {
  5535. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5536. bp->path_has_ovlan ? 7 : 6);
  5537. }
  5538. }
  5539. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5540. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5541. #ifdef BCM_CNIC
  5542. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5543. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5544. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5545. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5546. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5547. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5548. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5549. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5550. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5551. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5552. #endif
  5553. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5554. if (sizeof(union cdu_context) != 1024)
  5555. /* we currently assume that a context is 1024 bytes */
  5556. dev_alert(&bp->pdev->dev,
  5557. "please adjust the size of cdu_context(%ld)\n",
  5558. (long)sizeof(union cdu_context));
  5559. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5560. val = (4 << 24) + (0 << 12) + 1024;
  5561. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5562. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5563. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5564. /* enable context validation interrupt from CFC */
  5565. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5566. /* set the thresholds to prevent CFC/CDU race */
  5567. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5568. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5569. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5570. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5571. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5572. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5573. /* Reset PCIE errors for debug */
  5574. REG_WR(bp, 0x2814, 0xffffffff);
  5575. REG_WR(bp, 0x3820, 0xffffffff);
  5576. if (!CHIP_IS_E1x(bp)) {
  5577. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5578. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5579. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5580. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5581. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5582. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5583. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5584. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5585. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5586. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5587. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5588. }
  5589. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5590. if (!CHIP_IS_E1(bp)) {
  5591. /* in E3 this done in per-port section */
  5592. if (!CHIP_IS_E3(bp))
  5593. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5594. }
  5595. if (CHIP_IS_E1H(bp))
  5596. /* not applicable for E2 (and above ...) */
  5597. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5598. if (CHIP_REV_IS_SLOW(bp))
  5599. msleep(200);
  5600. /* finish CFC init */
  5601. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5602. if (val != 1) {
  5603. BNX2X_ERR("CFC LL_INIT failed\n");
  5604. return -EBUSY;
  5605. }
  5606. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5607. if (val != 1) {
  5608. BNX2X_ERR("CFC AC_INIT failed\n");
  5609. return -EBUSY;
  5610. }
  5611. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5612. if (val != 1) {
  5613. BNX2X_ERR("CFC CAM_INIT failed\n");
  5614. return -EBUSY;
  5615. }
  5616. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5617. if (CHIP_IS_E1(bp)) {
  5618. /* read NIG statistic
  5619. to see if this is our first up since powerup */
  5620. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5621. val = *bnx2x_sp(bp, wb_data[0]);
  5622. /* do internal memory self test */
  5623. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5624. BNX2X_ERR("internal mem self test failed\n");
  5625. return -EBUSY;
  5626. }
  5627. }
  5628. bnx2x_setup_fan_failure_detection(bp);
  5629. /* clear PXP2 attentions */
  5630. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5631. bnx2x_enable_blocks_attention(bp);
  5632. bnx2x_enable_blocks_parity(bp);
  5633. if (!BP_NOMCP(bp)) {
  5634. if (CHIP_IS_E1x(bp))
  5635. bnx2x__common_init_phy(bp);
  5636. } else
  5637. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5638. return 0;
  5639. }
  5640. /**
  5641. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5642. *
  5643. * @bp: driver handle
  5644. */
  5645. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5646. {
  5647. int rc = bnx2x_init_hw_common(bp);
  5648. if (rc)
  5649. return rc;
  5650. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5651. if (!BP_NOMCP(bp))
  5652. bnx2x__common_init_phy(bp);
  5653. return 0;
  5654. }
  5655. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5656. {
  5657. int port = BP_PORT(bp);
  5658. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5659. u32 low, high;
  5660. u32 val;
  5661. bnx2x__link_reset(bp);
  5662. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5663. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5664. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5665. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5666. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5667. /* Timers bug workaround: disables the pf_master bit in pglue at
  5668. * common phase, we need to enable it here before any dmae access are
  5669. * attempted. Therefore we manually added the enable-master to the
  5670. * port phase (it also happens in the function phase)
  5671. */
  5672. if (!CHIP_IS_E1x(bp))
  5673. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5674. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5675. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5676. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5677. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5678. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5679. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5680. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5681. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5682. /* QM cid (connection) count */
  5683. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5684. #ifdef BCM_CNIC
  5685. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5686. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5687. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5688. #endif
  5689. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5690. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5691. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5692. if (IS_MF(bp))
  5693. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5694. else if (bp->dev->mtu > 4096) {
  5695. if (bp->flags & ONE_PORT_FLAG)
  5696. low = 160;
  5697. else {
  5698. val = bp->dev->mtu;
  5699. /* (24*1024 + val*4)/256 */
  5700. low = 96 + (val/64) +
  5701. ((val % 64) ? 1 : 0);
  5702. }
  5703. } else
  5704. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5705. high = low + 56; /* 14*1024/256 */
  5706. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5707. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5708. }
  5709. if (CHIP_MODE_IS_4_PORT(bp))
  5710. REG_WR(bp, (BP_PORT(bp) ?
  5711. BRB1_REG_MAC_GUARANTIED_1 :
  5712. BRB1_REG_MAC_GUARANTIED_0), 40);
  5713. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5714. if (CHIP_IS_E3B0(bp)) {
  5715. if (IS_MF_AFEX(bp)) {
  5716. /* configure headers for AFEX mode */
  5717. REG_WR(bp, BP_PORT(bp) ?
  5718. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5719. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5720. REG_WR(bp, BP_PORT(bp) ?
  5721. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5722. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5723. REG_WR(bp, BP_PORT(bp) ?
  5724. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5725. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5726. } else {
  5727. /* Ovlan exists only if we are in multi-function +
  5728. * switch-dependent mode, in switch-independent there
  5729. * is no ovlan headers
  5730. */
  5731. REG_WR(bp, BP_PORT(bp) ?
  5732. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5733. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5734. (bp->path_has_ovlan ? 7 : 6));
  5735. }
  5736. }
  5737. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5738. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5739. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5740. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5741. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5742. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5743. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5744. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5745. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5746. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5747. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5748. if (CHIP_IS_E1x(bp)) {
  5749. /* configure PBF to work without PAUSE mtu 9000 */
  5750. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5751. /* update threshold */
  5752. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5753. /* update init credit */
  5754. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5755. /* probe changes */
  5756. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5757. udelay(50);
  5758. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5759. }
  5760. #ifdef BCM_CNIC
  5761. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5762. #endif
  5763. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5764. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5765. if (CHIP_IS_E1(bp)) {
  5766. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5767. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5768. }
  5769. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5770. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5771. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5772. /* init aeu_mask_attn_func_0/1:
  5773. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5774. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5775. * bits 4-7 are used for "per vn group attention" */
  5776. val = IS_MF(bp) ? 0xF7 : 0x7;
  5777. /* Enable DCBX attention for all but E1 */
  5778. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5779. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5780. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5781. if (!CHIP_IS_E1x(bp)) {
  5782. /* Bit-map indicating which L2 hdrs may appear after the
  5783. * basic Ethernet header
  5784. */
  5785. if (IS_MF_AFEX(bp))
  5786. REG_WR(bp, BP_PORT(bp) ?
  5787. NIG_REG_P1_HDRS_AFTER_BASIC :
  5788. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5789. else
  5790. REG_WR(bp, BP_PORT(bp) ?
  5791. NIG_REG_P1_HDRS_AFTER_BASIC :
  5792. NIG_REG_P0_HDRS_AFTER_BASIC,
  5793. IS_MF_SD(bp) ? 7 : 6);
  5794. if (CHIP_IS_E3(bp))
  5795. REG_WR(bp, BP_PORT(bp) ?
  5796. NIG_REG_LLH1_MF_MODE :
  5797. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5798. }
  5799. if (!CHIP_IS_E3(bp))
  5800. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5801. if (!CHIP_IS_E1(bp)) {
  5802. /* 0x2 disable mf_ov, 0x1 enable */
  5803. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5804. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5805. if (!CHIP_IS_E1x(bp)) {
  5806. val = 0;
  5807. switch (bp->mf_mode) {
  5808. case MULTI_FUNCTION_SD:
  5809. val = 1;
  5810. break;
  5811. case MULTI_FUNCTION_SI:
  5812. case MULTI_FUNCTION_AFEX:
  5813. val = 2;
  5814. break;
  5815. }
  5816. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5817. NIG_REG_LLH0_CLS_TYPE), val);
  5818. }
  5819. {
  5820. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5821. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5822. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5823. }
  5824. }
  5825. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5826. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5827. if (val & (1 << MISC_REGISTERS_SPIO_5)) {
  5828. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5829. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5830. val = REG_RD(bp, reg_addr);
  5831. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5832. REG_WR(bp, reg_addr, val);
  5833. }
  5834. return 0;
  5835. }
  5836. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5837. {
  5838. int reg;
  5839. u32 wb_write[2];
  5840. if (CHIP_IS_E1(bp))
  5841. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5842. else
  5843. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5844. wb_write[0] = ONCHIP_ADDR1(addr);
  5845. wb_write[1] = ONCHIP_ADDR2(addr);
  5846. REG_WR_DMAE(bp, reg, wb_write, 2);
  5847. }
  5848. static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
  5849. u8 idu_sb_id, bool is_Pf)
  5850. {
  5851. u32 data, ctl, cnt = 100;
  5852. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5853. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  5854. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  5855. u32 sb_bit = 1 << (idu_sb_id%32);
  5856. u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  5857. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  5858. /* Not supported in BC mode */
  5859. if (CHIP_INT_MODE_IS_BC(bp))
  5860. return;
  5861. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  5862. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  5863. IGU_REGULAR_CLEANUP_SET |
  5864. IGU_REGULAR_BCLEANUP;
  5865. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  5866. func_encode << IGU_CTRL_REG_FID_SHIFT |
  5867. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  5868. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5869. data, igu_addr_data);
  5870. REG_WR(bp, igu_addr_data, data);
  5871. mmiowb();
  5872. barrier();
  5873. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5874. ctl, igu_addr_ctl);
  5875. REG_WR(bp, igu_addr_ctl, ctl);
  5876. mmiowb();
  5877. barrier();
  5878. /* wait for clean up to finish */
  5879. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  5880. msleep(20);
  5881. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  5882. DP(NETIF_MSG_HW,
  5883. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  5884. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  5885. }
  5886. }
  5887. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5888. {
  5889. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5890. }
  5891. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5892. {
  5893. u32 i, base = FUNC_ILT_BASE(func);
  5894. for (i = base; i < base + ILT_PER_FUNC; i++)
  5895. bnx2x_ilt_wr(bp, i, 0);
  5896. }
  5897. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5898. {
  5899. int port = BP_PORT(bp);
  5900. int func = BP_FUNC(bp);
  5901. int init_phase = PHASE_PF0 + func;
  5902. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5903. u16 cdu_ilt_start;
  5904. u32 addr, val;
  5905. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5906. int i, main_mem_width, rc;
  5907. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  5908. /* FLR cleanup - hmmm */
  5909. if (!CHIP_IS_E1x(bp)) {
  5910. rc = bnx2x_pf_flr_clnup(bp);
  5911. if (rc)
  5912. return rc;
  5913. }
  5914. /* set MSI reconfigure capability */
  5915. if (bp->common.int_block == INT_BLOCK_HC) {
  5916. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5917. val = REG_RD(bp, addr);
  5918. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5919. REG_WR(bp, addr, val);
  5920. }
  5921. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5922. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5923. ilt = BP_ILT(bp);
  5924. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  5925. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  5926. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  5927. ilt->lines[cdu_ilt_start + i].page_mapping =
  5928. bp->context[i].cxt_mapping;
  5929. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  5930. }
  5931. bnx2x_ilt_init_op(bp, INITOP_SET);
  5932. #ifdef BCM_CNIC
  5933. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5934. /* T1 hash bits value determines the T1 number of entries */
  5935. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5936. #endif
  5937. #ifndef BCM_CNIC
  5938. /* set NIC mode */
  5939. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5940. #endif /* BCM_CNIC */
  5941. if (!CHIP_IS_E1x(bp)) {
  5942. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  5943. /* Turn on a single ISR mode in IGU if driver is going to use
  5944. * INT#x or MSI
  5945. */
  5946. if (!(bp->flags & USING_MSIX_FLAG))
  5947. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  5948. /*
  5949. * Timers workaround bug: function init part.
  5950. * Need to wait 20msec after initializing ILT,
  5951. * needed to make sure there are no requests in
  5952. * one of the PXP internal queues with "old" ILT addresses
  5953. */
  5954. msleep(20);
  5955. /*
  5956. * Master enable - Due to WB DMAE writes performed before this
  5957. * register is re-initialized as part of the regular function
  5958. * init
  5959. */
  5960. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5961. /* Enable the function in IGU */
  5962. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  5963. }
  5964. bp->dmae_ready = 1;
  5965. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5966. if (!CHIP_IS_E1x(bp))
  5967. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  5968. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5969. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5970. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5971. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5972. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5973. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5974. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5975. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5976. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5977. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5978. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5979. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5980. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5981. if (!CHIP_IS_E1x(bp))
  5982. REG_WR(bp, QM_REG_PF_EN, 1);
  5983. if (!CHIP_IS_E1x(bp)) {
  5984. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5985. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5986. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5987. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5988. }
  5989. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5990. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5991. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5992. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5993. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5994. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5995. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5996. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5997. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5998. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5999. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6000. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6001. if (!CHIP_IS_E1x(bp))
  6002. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6003. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6004. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6005. if (!CHIP_IS_E1x(bp))
  6006. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6007. if (IS_MF(bp)) {
  6008. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6009. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6010. }
  6011. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6012. /* HC init per function */
  6013. if (bp->common.int_block == INT_BLOCK_HC) {
  6014. if (CHIP_IS_E1H(bp)) {
  6015. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6016. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6017. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6018. }
  6019. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6020. } else {
  6021. int num_segs, sb_idx, prod_offset;
  6022. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6023. if (!CHIP_IS_E1x(bp)) {
  6024. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6025. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6026. }
  6027. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6028. if (!CHIP_IS_E1x(bp)) {
  6029. int dsb_idx = 0;
  6030. /**
  6031. * Producer memory:
  6032. * E2 mode: address 0-135 match to the mapping memory;
  6033. * 136 - PF0 default prod; 137 - PF1 default prod;
  6034. * 138 - PF2 default prod; 139 - PF3 default prod;
  6035. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6036. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6037. * 144-147 reserved.
  6038. *
  6039. * E1.5 mode - In backward compatible mode;
  6040. * for non default SB; each even line in the memory
  6041. * holds the U producer and each odd line hold
  6042. * the C producer. The first 128 producers are for
  6043. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6044. * producers are for the DSB for each PF.
  6045. * Each PF has five segments: (the order inside each
  6046. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6047. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6048. * 144-147 attn prods;
  6049. */
  6050. /* non-default-status-blocks */
  6051. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6052. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6053. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6054. prod_offset = (bp->igu_base_sb + sb_idx) *
  6055. num_segs;
  6056. for (i = 0; i < num_segs; i++) {
  6057. addr = IGU_REG_PROD_CONS_MEMORY +
  6058. (prod_offset + i) * 4;
  6059. REG_WR(bp, addr, 0);
  6060. }
  6061. /* send consumer update with value 0 */
  6062. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6063. USTORM_ID, 0, IGU_INT_NOP, 1);
  6064. bnx2x_igu_clear_sb(bp,
  6065. bp->igu_base_sb + sb_idx);
  6066. }
  6067. /* default-status-blocks */
  6068. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6069. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6070. if (CHIP_MODE_IS_4_PORT(bp))
  6071. dsb_idx = BP_FUNC(bp);
  6072. else
  6073. dsb_idx = BP_VN(bp);
  6074. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6075. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6076. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6077. /*
  6078. * igu prods come in chunks of E1HVN_MAX (4) -
  6079. * does not matters what is the current chip mode
  6080. */
  6081. for (i = 0; i < (num_segs * E1HVN_MAX);
  6082. i += E1HVN_MAX) {
  6083. addr = IGU_REG_PROD_CONS_MEMORY +
  6084. (prod_offset + i)*4;
  6085. REG_WR(bp, addr, 0);
  6086. }
  6087. /* send consumer update with 0 */
  6088. if (CHIP_INT_MODE_IS_BC(bp)) {
  6089. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6090. USTORM_ID, 0, IGU_INT_NOP, 1);
  6091. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6092. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6093. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6094. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6095. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6096. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6097. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6098. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6099. } else {
  6100. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6101. USTORM_ID, 0, IGU_INT_NOP, 1);
  6102. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6103. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6104. }
  6105. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6106. /* !!! these should become driver const once
  6107. rf-tool supports split-68 const */
  6108. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6109. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6110. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6111. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6112. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6113. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6114. }
  6115. }
  6116. /* Reset PCIE errors for debug */
  6117. REG_WR(bp, 0x2114, 0xffffffff);
  6118. REG_WR(bp, 0x2120, 0xffffffff);
  6119. if (CHIP_IS_E1x(bp)) {
  6120. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6121. main_mem_base = HC_REG_MAIN_MEMORY +
  6122. BP_PORT(bp) * (main_mem_size * 4);
  6123. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6124. main_mem_width = 8;
  6125. val = REG_RD(bp, main_mem_prty_clr);
  6126. if (val)
  6127. DP(NETIF_MSG_HW,
  6128. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6129. val);
  6130. /* Clear "false" parity errors in MSI-X table */
  6131. for (i = main_mem_base;
  6132. i < main_mem_base + main_mem_size * 4;
  6133. i += main_mem_width) {
  6134. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6135. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6136. i, main_mem_width / 4);
  6137. }
  6138. /* Clear HC parity attention */
  6139. REG_RD(bp, main_mem_prty_clr);
  6140. }
  6141. #ifdef BNX2X_STOP_ON_ERROR
  6142. /* Enable STORMs SP logging */
  6143. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6144. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6145. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6146. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6147. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6148. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6149. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6150. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6151. #endif
  6152. bnx2x_phy_probe(&bp->link_params);
  6153. return 0;
  6154. }
  6155. void bnx2x_free_mem(struct bnx2x *bp)
  6156. {
  6157. int i;
  6158. /* fastpath */
  6159. bnx2x_free_fp_mem(bp);
  6160. /* end of fastpath */
  6161. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6162. sizeof(struct host_sp_status_block));
  6163. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6164. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6165. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6166. sizeof(struct bnx2x_slowpath));
  6167. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6168. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6169. bp->context[i].size);
  6170. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6171. BNX2X_FREE(bp->ilt->lines);
  6172. #ifdef BCM_CNIC
  6173. if (!CHIP_IS_E1x(bp))
  6174. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6175. sizeof(struct host_hc_status_block_e2));
  6176. else
  6177. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6178. sizeof(struct host_hc_status_block_e1x));
  6179. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6180. #endif
  6181. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6182. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6183. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6184. }
  6185. static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  6186. {
  6187. int num_groups;
  6188. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  6189. /* number of queues for statistics is number of eth queues + FCoE */
  6190. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  6191. /* Total number of FW statistics requests =
  6192. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  6193. * num of queues
  6194. */
  6195. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  6196. /* Request is built from stats_query_header and an array of
  6197. * stats_query_cmd_group each of which contains
  6198. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  6199. * configured in the stats_query_header.
  6200. */
  6201. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  6202. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  6203. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  6204. num_groups * sizeof(struct stats_query_cmd_group);
  6205. /* Data for statistics requests + stats_conter
  6206. *
  6207. * stats_counter holds per-STORM counters that are incremented
  6208. * when STORM has finished with the current request.
  6209. *
  6210. * memory for FCoE offloaded statistics are counted anyway,
  6211. * even if they will not be sent.
  6212. */
  6213. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  6214. sizeof(struct per_pf_stats) +
  6215. sizeof(struct fcoe_statistics_params) +
  6216. sizeof(struct per_queue_stats) * num_queue_stats +
  6217. sizeof(struct stats_counter);
  6218. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  6219. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6220. /* Set shortcuts */
  6221. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  6222. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  6223. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  6224. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  6225. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  6226. bp->fw_stats_req_sz;
  6227. return 0;
  6228. alloc_mem_err:
  6229. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6230. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6231. BNX2X_ERR("Can't allocate memory\n");
  6232. return -ENOMEM;
  6233. }
  6234. int bnx2x_alloc_mem(struct bnx2x *bp)
  6235. {
  6236. int i, allocated, context_size;
  6237. #ifdef BCM_CNIC
  6238. if (!CHIP_IS_E1x(bp))
  6239. /* size = the status block + ramrod buffers */
  6240. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6241. sizeof(struct host_hc_status_block_e2));
  6242. else
  6243. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
  6244. sizeof(struct host_hc_status_block_e1x));
  6245. /* allocate searcher T2 table */
  6246. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6247. #endif
  6248. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6249. sizeof(struct host_sp_status_block));
  6250. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6251. sizeof(struct bnx2x_slowpath));
  6252. #ifdef BCM_CNIC
  6253. /* write address to which L5 should insert its values */
  6254. bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
  6255. #endif
  6256. /* Allocated memory for FW statistics */
  6257. if (bnx2x_alloc_fw_stats_mem(bp))
  6258. goto alloc_mem_err;
  6259. /* Allocate memory for CDU context:
  6260. * This memory is allocated separately and not in the generic ILT
  6261. * functions because CDU differs in few aspects:
  6262. * 1. There are multiple entities allocating memory for context -
  6263. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6264. * its own ILT lines.
  6265. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6266. * for the other ILT clients), to be efficient we want to support
  6267. * allocation of sub-page-size in the last entry.
  6268. * 3. Context pointers are used by the driver to pass to FW / update
  6269. * the context (for the other ILT clients the pointers are used just to
  6270. * free the memory during unload).
  6271. */
  6272. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6273. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6274. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6275. (context_size - allocated));
  6276. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6277. &bp->context[i].cxt_mapping,
  6278. bp->context[i].size);
  6279. allocated += bp->context[i].size;
  6280. }
  6281. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6282. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6283. goto alloc_mem_err;
  6284. /* Slow path ring */
  6285. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6286. /* EQ */
  6287. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6288. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6289. /* fastpath */
  6290. /* need to be done at the end, since it's self adjusting to amount
  6291. * of memory available for RSS queues
  6292. */
  6293. if (bnx2x_alloc_fp_mem(bp))
  6294. goto alloc_mem_err;
  6295. return 0;
  6296. alloc_mem_err:
  6297. bnx2x_free_mem(bp);
  6298. BNX2X_ERR("Can't allocate memory\n");
  6299. return -ENOMEM;
  6300. }
  6301. /*
  6302. * Init service functions
  6303. */
  6304. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6305. struct bnx2x_vlan_mac_obj *obj, bool set,
  6306. int mac_type, unsigned long *ramrod_flags)
  6307. {
  6308. int rc;
  6309. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6310. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6311. /* Fill general parameters */
  6312. ramrod_param.vlan_mac_obj = obj;
  6313. ramrod_param.ramrod_flags = *ramrod_flags;
  6314. /* Fill a user request section if needed */
  6315. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6316. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6317. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6318. /* Set the command: ADD or DEL */
  6319. if (set)
  6320. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6321. else
  6322. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6323. }
  6324. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6325. if (rc < 0)
  6326. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6327. return rc;
  6328. }
  6329. int bnx2x_del_all_macs(struct bnx2x *bp,
  6330. struct bnx2x_vlan_mac_obj *mac_obj,
  6331. int mac_type, bool wait_for_comp)
  6332. {
  6333. int rc;
  6334. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6335. /* Wait for completion of requested */
  6336. if (wait_for_comp)
  6337. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6338. /* Set the mac type of addresses we want to clear */
  6339. __set_bit(mac_type, &vlan_mac_flags);
  6340. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6341. if (rc < 0)
  6342. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6343. return rc;
  6344. }
  6345. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6346. {
  6347. unsigned long ramrod_flags = 0;
  6348. #ifdef BCM_CNIC
  6349. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6350. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6351. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6352. "Ignoring Zero MAC for STORAGE SD mode\n");
  6353. return 0;
  6354. }
  6355. #endif
  6356. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6357. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6358. /* Eth MAC is set on RSS leading client (fp[0]) */
  6359. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6360. set, BNX2X_ETH_MAC, &ramrod_flags);
  6361. }
  6362. int bnx2x_setup_leading(struct bnx2x *bp)
  6363. {
  6364. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6365. }
  6366. /**
  6367. * bnx2x_set_int_mode - configure interrupt mode
  6368. *
  6369. * @bp: driver handle
  6370. *
  6371. * In case of MSI-X it will also try to enable MSI-X.
  6372. */
  6373. void bnx2x_set_int_mode(struct bnx2x *bp)
  6374. {
  6375. switch (int_mode) {
  6376. case INT_MODE_MSI:
  6377. bnx2x_enable_msi(bp);
  6378. /* falling through... */
  6379. case INT_MODE_INTx:
  6380. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6381. BNX2X_DEV_INFO("set number of queues to 1\n");
  6382. break;
  6383. default:
  6384. /* if we can't use MSI-X we only need one fp,
  6385. * so try to enable MSI-X with the requested number of fp's
  6386. * and fallback to MSI or legacy INTx with one fp
  6387. */
  6388. if (bnx2x_enable_msix(bp) ||
  6389. bp->flags & USING_SINGLE_MSIX_FLAG) {
  6390. /* failed to enable multiple MSI-X */
  6391. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6392. bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
  6393. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6394. /* Try to enable MSI */
  6395. if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
  6396. !(bp->flags & DISABLE_MSI_FLAG))
  6397. bnx2x_enable_msi(bp);
  6398. }
  6399. break;
  6400. }
  6401. }
  6402. /* must be called prioir to any HW initializations */
  6403. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6404. {
  6405. return L2_ILT_LINES(bp);
  6406. }
  6407. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6408. {
  6409. struct ilt_client_info *ilt_client;
  6410. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6411. u16 line = 0;
  6412. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6413. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6414. /* CDU */
  6415. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6416. ilt_client->client_num = ILT_CLIENT_CDU;
  6417. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6418. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6419. ilt_client->start = line;
  6420. line += bnx2x_cid_ilt_lines(bp);
  6421. #ifdef BCM_CNIC
  6422. line += CNIC_ILT_LINES;
  6423. #endif
  6424. ilt_client->end = line - 1;
  6425. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6426. ilt_client->start,
  6427. ilt_client->end,
  6428. ilt_client->page_size,
  6429. ilt_client->flags,
  6430. ilog2(ilt_client->page_size >> 12));
  6431. /* QM */
  6432. if (QM_INIT(bp->qm_cid_count)) {
  6433. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6434. ilt_client->client_num = ILT_CLIENT_QM;
  6435. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6436. ilt_client->flags = 0;
  6437. ilt_client->start = line;
  6438. /* 4 bytes for each cid */
  6439. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6440. QM_ILT_PAGE_SZ);
  6441. ilt_client->end = line - 1;
  6442. DP(NETIF_MSG_IFUP,
  6443. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6444. ilt_client->start,
  6445. ilt_client->end,
  6446. ilt_client->page_size,
  6447. ilt_client->flags,
  6448. ilog2(ilt_client->page_size >> 12));
  6449. }
  6450. /* SRC */
  6451. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6452. #ifdef BCM_CNIC
  6453. ilt_client->client_num = ILT_CLIENT_SRC;
  6454. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6455. ilt_client->flags = 0;
  6456. ilt_client->start = line;
  6457. line += SRC_ILT_LINES;
  6458. ilt_client->end = line - 1;
  6459. DP(NETIF_MSG_IFUP,
  6460. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6461. ilt_client->start,
  6462. ilt_client->end,
  6463. ilt_client->page_size,
  6464. ilt_client->flags,
  6465. ilog2(ilt_client->page_size >> 12));
  6466. #else
  6467. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6468. #endif
  6469. /* TM */
  6470. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6471. #ifdef BCM_CNIC
  6472. ilt_client->client_num = ILT_CLIENT_TM;
  6473. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6474. ilt_client->flags = 0;
  6475. ilt_client->start = line;
  6476. line += TM_ILT_LINES;
  6477. ilt_client->end = line - 1;
  6478. DP(NETIF_MSG_IFUP,
  6479. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6480. ilt_client->start,
  6481. ilt_client->end,
  6482. ilt_client->page_size,
  6483. ilt_client->flags,
  6484. ilog2(ilt_client->page_size >> 12));
  6485. #else
  6486. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6487. #endif
  6488. BUG_ON(line > ILT_MAX_LINES);
  6489. }
  6490. /**
  6491. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6492. *
  6493. * @bp: driver handle
  6494. * @fp: pointer to fastpath
  6495. * @init_params: pointer to parameters structure
  6496. *
  6497. * parameters configured:
  6498. * - HC configuration
  6499. * - Queue's CDU context
  6500. */
  6501. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6502. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6503. {
  6504. u8 cos;
  6505. int cxt_index, cxt_offset;
  6506. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6507. if (!IS_FCOE_FP(fp)) {
  6508. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6509. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6510. /* If HC is supporterd, enable host coalescing in the transition
  6511. * to INIT state.
  6512. */
  6513. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6514. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6515. /* HC rate */
  6516. init_params->rx.hc_rate = bp->rx_ticks ?
  6517. (1000000 / bp->rx_ticks) : 0;
  6518. init_params->tx.hc_rate = bp->tx_ticks ?
  6519. (1000000 / bp->tx_ticks) : 0;
  6520. /* FW SB ID */
  6521. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6522. fp->fw_sb_id;
  6523. /*
  6524. * CQ index among the SB indices: FCoE clients uses the default
  6525. * SB, therefore it's different.
  6526. */
  6527. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6528. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6529. }
  6530. /* set maximum number of COSs supported by this queue */
  6531. init_params->max_cos = fp->max_cos;
  6532. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6533. fp->index, init_params->max_cos);
  6534. /* set the context pointers queue object */
  6535. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6536. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6537. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6538. ILT_PAGE_CIDS);
  6539. init_params->cxts[cos] =
  6540. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6541. }
  6542. }
  6543. int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6544. struct bnx2x_queue_state_params *q_params,
  6545. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6546. int tx_index, bool leading)
  6547. {
  6548. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6549. /* Set the command */
  6550. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6551. /* Set tx-only QUEUE flags: don't zero statistics */
  6552. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6553. /* choose the index of the cid to send the slow path on */
  6554. tx_only_params->cid_index = tx_index;
  6555. /* Set general TX_ONLY_SETUP parameters */
  6556. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6557. /* Set Tx TX_ONLY_SETUP parameters */
  6558. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6559. DP(NETIF_MSG_IFUP,
  6560. "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n",
  6561. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6562. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6563. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6564. /* send the ramrod */
  6565. return bnx2x_queue_state_change(bp, q_params);
  6566. }
  6567. /**
  6568. * bnx2x_setup_queue - setup queue
  6569. *
  6570. * @bp: driver handle
  6571. * @fp: pointer to fastpath
  6572. * @leading: is leading
  6573. *
  6574. * This function performs 2 steps in a Queue state machine
  6575. * actually: 1) RESET->INIT 2) INIT->SETUP
  6576. */
  6577. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6578. bool leading)
  6579. {
  6580. struct bnx2x_queue_state_params q_params = {NULL};
  6581. struct bnx2x_queue_setup_params *setup_params =
  6582. &q_params.params.setup;
  6583. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6584. &q_params.params.tx_only;
  6585. int rc;
  6586. u8 tx_index;
  6587. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6588. /* reset IGU state skip FCoE L2 queue */
  6589. if (!IS_FCOE_FP(fp))
  6590. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6591. IGU_INT_ENABLE, 0);
  6592. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6593. /* We want to wait for completion in this context */
  6594. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6595. /* Prepare the INIT parameters */
  6596. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6597. /* Set the command */
  6598. q_params.cmd = BNX2X_Q_CMD_INIT;
  6599. /* Change the state to INIT */
  6600. rc = bnx2x_queue_state_change(bp, &q_params);
  6601. if (rc) {
  6602. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6603. return rc;
  6604. }
  6605. DP(NETIF_MSG_IFUP, "init complete\n");
  6606. /* Now move the Queue to the SETUP state... */
  6607. memset(setup_params, 0, sizeof(*setup_params));
  6608. /* Set QUEUE flags */
  6609. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6610. /* Set general SETUP parameters */
  6611. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6612. FIRST_TX_COS_INDEX);
  6613. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6614. &setup_params->rxq_params);
  6615. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6616. FIRST_TX_COS_INDEX);
  6617. /* Set the command */
  6618. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6619. /* Change the state to SETUP */
  6620. rc = bnx2x_queue_state_change(bp, &q_params);
  6621. if (rc) {
  6622. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6623. return rc;
  6624. }
  6625. /* loop through the relevant tx-only indices */
  6626. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6627. tx_index < fp->max_cos;
  6628. tx_index++) {
  6629. /* prepare and send tx-only ramrod*/
  6630. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6631. tx_only_params, tx_index, leading);
  6632. if (rc) {
  6633. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6634. fp->index, tx_index);
  6635. return rc;
  6636. }
  6637. }
  6638. return rc;
  6639. }
  6640. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6641. {
  6642. struct bnx2x_fastpath *fp = &bp->fp[index];
  6643. struct bnx2x_fp_txdata *txdata;
  6644. struct bnx2x_queue_state_params q_params = {NULL};
  6645. int rc, tx_index;
  6646. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6647. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6648. /* We want to wait for completion in this context */
  6649. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6650. /* close tx-only connections */
  6651. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6652. tx_index < fp->max_cos;
  6653. tx_index++){
  6654. /* ascertain this is a normal queue*/
  6655. txdata = fp->txdata_ptr[tx_index];
  6656. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6657. txdata->txq_index);
  6658. /* send halt terminate on tx-only connection */
  6659. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6660. memset(&q_params.params.terminate, 0,
  6661. sizeof(q_params.params.terminate));
  6662. q_params.params.terminate.cid_index = tx_index;
  6663. rc = bnx2x_queue_state_change(bp, &q_params);
  6664. if (rc)
  6665. return rc;
  6666. /* send halt terminate on tx-only connection */
  6667. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6668. memset(&q_params.params.cfc_del, 0,
  6669. sizeof(q_params.params.cfc_del));
  6670. q_params.params.cfc_del.cid_index = tx_index;
  6671. rc = bnx2x_queue_state_change(bp, &q_params);
  6672. if (rc)
  6673. return rc;
  6674. }
  6675. /* Stop the primary connection: */
  6676. /* ...halt the connection */
  6677. q_params.cmd = BNX2X_Q_CMD_HALT;
  6678. rc = bnx2x_queue_state_change(bp, &q_params);
  6679. if (rc)
  6680. return rc;
  6681. /* ...terminate the connection */
  6682. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6683. memset(&q_params.params.terminate, 0,
  6684. sizeof(q_params.params.terminate));
  6685. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6686. rc = bnx2x_queue_state_change(bp, &q_params);
  6687. if (rc)
  6688. return rc;
  6689. /* ...delete cfc entry */
  6690. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6691. memset(&q_params.params.cfc_del, 0,
  6692. sizeof(q_params.params.cfc_del));
  6693. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6694. return bnx2x_queue_state_change(bp, &q_params);
  6695. }
  6696. static void bnx2x_reset_func(struct bnx2x *bp)
  6697. {
  6698. int port = BP_PORT(bp);
  6699. int func = BP_FUNC(bp);
  6700. int i;
  6701. /* Disable the function in the FW */
  6702. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6703. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6704. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6705. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6706. /* FP SBs */
  6707. for_each_eth_queue(bp, i) {
  6708. struct bnx2x_fastpath *fp = &bp->fp[i];
  6709. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6710. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6711. SB_DISABLED);
  6712. }
  6713. #ifdef BCM_CNIC
  6714. /* CNIC SB */
  6715. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6716. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
  6717. SB_DISABLED);
  6718. #endif
  6719. /* SP SB */
  6720. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6721. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6722. SB_DISABLED);
  6723. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6724. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6725. 0);
  6726. /* Configure IGU */
  6727. if (bp->common.int_block == INT_BLOCK_HC) {
  6728. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6729. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6730. } else {
  6731. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6732. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6733. }
  6734. #ifdef BCM_CNIC
  6735. /* Disable Timer scan */
  6736. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6737. /*
  6738. * Wait for at least 10ms and up to 2 second for the timers scan to
  6739. * complete
  6740. */
  6741. for (i = 0; i < 200; i++) {
  6742. msleep(10);
  6743. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6744. break;
  6745. }
  6746. #endif
  6747. /* Clear ILT */
  6748. bnx2x_clear_func_ilt(bp, func);
  6749. /* Timers workaround bug for E2: if this is vnic-3,
  6750. * we need to set the entire ilt range for this timers.
  6751. */
  6752. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6753. struct ilt_client_info ilt_cli;
  6754. /* use dummy TM client */
  6755. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6756. ilt_cli.start = 0;
  6757. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6758. ilt_cli.client_num = ILT_CLIENT_TM;
  6759. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6760. }
  6761. /* this assumes that reset_port() called before reset_func()*/
  6762. if (!CHIP_IS_E1x(bp))
  6763. bnx2x_pf_disable(bp);
  6764. bp->dmae_ready = 0;
  6765. }
  6766. static void bnx2x_reset_port(struct bnx2x *bp)
  6767. {
  6768. int port = BP_PORT(bp);
  6769. u32 val;
  6770. /* Reset physical Link */
  6771. bnx2x__link_reset(bp);
  6772. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6773. /* Do not rcv packets to BRB */
  6774. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6775. /* Do not direct rcv packets that are not for MCP to the BRB */
  6776. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6777. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6778. /* Configure AEU */
  6779. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6780. msleep(100);
  6781. /* Check for BRB port occupancy */
  6782. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6783. if (val)
  6784. DP(NETIF_MSG_IFDOWN,
  6785. "BRB1 is not empty %d blocks are occupied\n", val);
  6786. /* TODO: Close Doorbell port? */
  6787. }
  6788. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6789. {
  6790. struct bnx2x_func_state_params func_params = {NULL};
  6791. /* Prepare parameters for function state transitions */
  6792. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6793. func_params.f_obj = &bp->func_obj;
  6794. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6795. func_params.params.hw_init.load_phase = load_code;
  6796. return bnx2x_func_state_change(bp, &func_params);
  6797. }
  6798. static int bnx2x_func_stop(struct bnx2x *bp)
  6799. {
  6800. struct bnx2x_func_state_params func_params = {NULL};
  6801. int rc;
  6802. /* Prepare parameters for function state transitions */
  6803. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6804. func_params.f_obj = &bp->func_obj;
  6805. func_params.cmd = BNX2X_F_CMD_STOP;
  6806. /*
  6807. * Try to stop the function the 'good way'. If fails (in case
  6808. * of a parity error during bnx2x_chip_cleanup()) and we are
  6809. * not in a debug mode, perform a state transaction in order to
  6810. * enable further HW_RESET transaction.
  6811. */
  6812. rc = bnx2x_func_state_change(bp, &func_params);
  6813. if (rc) {
  6814. #ifdef BNX2X_STOP_ON_ERROR
  6815. return rc;
  6816. #else
  6817. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6818. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6819. return bnx2x_func_state_change(bp, &func_params);
  6820. #endif
  6821. }
  6822. return 0;
  6823. }
  6824. /**
  6825. * bnx2x_send_unload_req - request unload mode from the MCP.
  6826. *
  6827. * @bp: driver handle
  6828. * @unload_mode: requested function's unload mode
  6829. *
  6830. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6831. */
  6832. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6833. {
  6834. u32 reset_code = 0;
  6835. int port = BP_PORT(bp);
  6836. /* Select the UNLOAD request mode */
  6837. if (unload_mode == UNLOAD_NORMAL)
  6838. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6839. else if (bp->flags & NO_WOL_FLAG)
  6840. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6841. else if (bp->wol) {
  6842. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6843. u8 *mac_addr = bp->dev->dev_addr;
  6844. u32 val;
  6845. u16 pmc;
  6846. /* The mac address is written to entries 1-4 to
  6847. * preserve entry 0 which is used by the PMF
  6848. */
  6849. u8 entry = (BP_VN(bp) + 1)*8;
  6850. val = (mac_addr[0] << 8) | mac_addr[1];
  6851. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6852. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6853. (mac_addr[4] << 8) | mac_addr[5];
  6854. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6855. /* Enable the PME and clear the status */
  6856. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6857. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6858. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6859. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6860. } else
  6861. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6862. /* Send the request to the MCP */
  6863. if (!BP_NOMCP(bp))
  6864. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6865. else {
  6866. int path = BP_PATH(bp);
  6867. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  6868. path, load_count[path][0], load_count[path][1],
  6869. load_count[path][2]);
  6870. load_count[path][0]--;
  6871. load_count[path][1 + port]--;
  6872. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  6873. path, load_count[path][0], load_count[path][1],
  6874. load_count[path][2]);
  6875. if (load_count[path][0] == 0)
  6876. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6877. else if (load_count[path][1 + port] == 0)
  6878. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6879. else
  6880. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6881. }
  6882. return reset_code;
  6883. }
  6884. /**
  6885. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6886. *
  6887. * @bp: driver handle
  6888. */
  6889. void bnx2x_send_unload_done(struct bnx2x *bp)
  6890. {
  6891. /* Report UNLOAD_DONE to MCP */
  6892. if (!BP_NOMCP(bp))
  6893. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6894. }
  6895. static int bnx2x_func_wait_started(struct bnx2x *bp)
  6896. {
  6897. int tout = 50;
  6898. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  6899. if (!bp->port.pmf)
  6900. return 0;
  6901. /*
  6902. * (assumption: No Attention from MCP at this stage)
  6903. * PMF probably in the middle of TXdisable/enable transaction
  6904. * 1. Sync IRS for default SB
  6905. * 2. Sync SP queue - this guarantes us that attention handling started
  6906. * 3. Wait, that TXdisable/enable transaction completes
  6907. *
  6908. * 1+2 guranty that if DCBx attention was scheduled it already changed
  6909. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  6910. * received complettion for the transaction the state is TX_STOPPED.
  6911. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  6912. * transaction.
  6913. */
  6914. /* make sure default SB ISR is done */
  6915. if (msix)
  6916. synchronize_irq(bp->msix_table[0].vector);
  6917. else
  6918. synchronize_irq(bp->pdev->irq);
  6919. flush_workqueue(bnx2x_wq);
  6920. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6921. BNX2X_F_STATE_STARTED && tout--)
  6922. msleep(20);
  6923. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6924. BNX2X_F_STATE_STARTED) {
  6925. #ifdef BNX2X_STOP_ON_ERROR
  6926. BNX2X_ERR("Wrong function state\n");
  6927. return -EBUSY;
  6928. #else
  6929. /*
  6930. * Failed to complete the transaction in a "good way"
  6931. * Force both transactions with CLR bit
  6932. */
  6933. struct bnx2x_func_state_params func_params = {NULL};
  6934. DP(NETIF_MSG_IFDOWN,
  6935. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  6936. func_params.f_obj = &bp->func_obj;
  6937. __set_bit(RAMROD_DRV_CLR_ONLY,
  6938. &func_params.ramrod_flags);
  6939. /* STARTED-->TX_ST0PPED */
  6940. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  6941. bnx2x_func_state_change(bp, &func_params);
  6942. /* TX_ST0PPED-->STARTED */
  6943. func_params.cmd = BNX2X_F_CMD_TX_START;
  6944. return bnx2x_func_state_change(bp, &func_params);
  6945. #endif
  6946. }
  6947. return 0;
  6948. }
  6949. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
  6950. {
  6951. int port = BP_PORT(bp);
  6952. int i, rc = 0;
  6953. u8 cos;
  6954. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  6955. u32 reset_code;
  6956. /* Wait until tx fastpath tasks complete */
  6957. for_each_tx_queue(bp, i) {
  6958. struct bnx2x_fastpath *fp = &bp->fp[i];
  6959. for_each_cos_in_tx_queue(fp, cos)
  6960. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  6961. #ifdef BNX2X_STOP_ON_ERROR
  6962. if (rc)
  6963. return;
  6964. #endif
  6965. }
  6966. /* Give HW time to discard old tx messages */
  6967. usleep_range(1000, 1000);
  6968. /* Clean all ETH MACs */
  6969. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  6970. false);
  6971. if (rc < 0)
  6972. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  6973. /* Clean up UC list */
  6974. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  6975. true);
  6976. if (rc < 0)
  6977. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  6978. rc);
  6979. /* Disable LLH */
  6980. if (!CHIP_IS_E1(bp))
  6981. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6982. /* Set "drop all" (stop Rx).
  6983. * We need to take a netif_addr_lock() here in order to prevent
  6984. * a race between the completion code and this code.
  6985. */
  6986. netif_addr_lock_bh(bp->dev);
  6987. /* Schedule the rx_mode command */
  6988. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  6989. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  6990. else
  6991. bnx2x_set_storm_rx_mode(bp);
  6992. /* Cleanup multicast configuration */
  6993. rparam.mcast_obj = &bp->mcast_obj;
  6994. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  6995. if (rc < 0)
  6996. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  6997. netif_addr_unlock_bh(bp->dev);
  6998. /*
  6999. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7000. * this function should perform FUNC, PORT or COMMON HW
  7001. * reset.
  7002. */
  7003. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7004. /*
  7005. * (assumption: No Attention from MCP at this stage)
  7006. * PMF probably in the middle of TXdisable/enable transaction
  7007. */
  7008. rc = bnx2x_func_wait_started(bp);
  7009. if (rc) {
  7010. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7011. #ifdef BNX2X_STOP_ON_ERROR
  7012. return;
  7013. #endif
  7014. }
  7015. /* Close multi and leading connections
  7016. * Completions for ramrods are collected in a synchronous way
  7017. */
  7018. for_each_queue(bp, i)
  7019. if (bnx2x_stop_queue(bp, i))
  7020. #ifdef BNX2X_STOP_ON_ERROR
  7021. return;
  7022. #else
  7023. goto unload_error;
  7024. #endif
  7025. /* If SP settings didn't get completed so far - something
  7026. * very wrong has happen.
  7027. */
  7028. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7029. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7030. #ifndef BNX2X_STOP_ON_ERROR
  7031. unload_error:
  7032. #endif
  7033. rc = bnx2x_func_stop(bp);
  7034. if (rc) {
  7035. BNX2X_ERR("Function stop failed!\n");
  7036. #ifdef BNX2X_STOP_ON_ERROR
  7037. return;
  7038. #endif
  7039. }
  7040. /* Disable HW interrupts, NAPI */
  7041. bnx2x_netif_stop(bp, 1);
  7042. /* Release IRQs */
  7043. bnx2x_free_irq(bp);
  7044. /* Reset the chip */
  7045. rc = bnx2x_reset_hw(bp, reset_code);
  7046. if (rc)
  7047. BNX2X_ERR("HW_RESET failed\n");
  7048. /* Report UNLOAD_DONE to MCP */
  7049. bnx2x_send_unload_done(bp);
  7050. }
  7051. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7052. {
  7053. u32 val;
  7054. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7055. if (CHIP_IS_E1(bp)) {
  7056. int port = BP_PORT(bp);
  7057. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7058. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7059. val = REG_RD(bp, addr);
  7060. val &= ~(0x300);
  7061. REG_WR(bp, addr, val);
  7062. } else {
  7063. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7064. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7065. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7066. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7067. }
  7068. }
  7069. /* Close gates #2, #3 and #4: */
  7070. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7071. {
  7072. u32 val;
  7073. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7074. if (!CHIP_IS_E1(bp)) {
  7075. /* #4 */
  7076. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7077. /* #2 */
  7078. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7079. }
  7080. /* #3 */
  7081. if (CHIP_IS_E1x(bp)) {
  7082. /* Prevent interrupts from HC on both ports */
  7083. val = REG_RD(bp, HC_REG_CONFIG_1);
  7084. REG_WR(bp, HC_REG_CONFIG_1,
  7085. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7086. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7087. val = REG_RD(bp, HC_REG_CONFIG_0);
  7088. REG_WR(bp, HC_REG_CONFIG_0,
  7089. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7090. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7091. } else {
  7092. /* Prevent incomming interrupts in IGU */
  7093. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7094. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7095. (!close) ?
  7096. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7097. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7098. }
  7099. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7100. close ? "closing" : "opening");
  7101. mmiowb();
  7102. }
  7103. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7104. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7105. {
  7106. /* Do some magic... */
  7107. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7108. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7109. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7110. }
  7111. /**
  7112. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7113. *
  7114. * @bp: driver handle
  7115. * @magic_val: old value of the `magic' bit.
  7116. */
  7117. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7118. {
  7119. /* Restore the `magic' bit value... */
  7120. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7121. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7122. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7123. }
  7124. /**
  7125. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7126. *
  7127. * @bp: driver handle
  7128. * @magic_val: old value of 'magic' bit.
  7129. *
  7130. * Takes care of CLP configurations.
  7131. */
  7132. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7133. {
  7134. u32 shmem;
  7135. u32 validity_offset;
  7136. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7137. /* Set `magic' bit in order to save MF config */
  7138. if (!CHIP_IS_E1(bp))
  7139. bnx2x_clp_reset_prep(bp, magic_val);
  7140. /* Get shmem offset */
  7141. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7142. validity_offset = offsetof(struct shmem_region, validity_map[0]);
  7143. /* Clear validity map flags */
  7144. if (shmem > 0)
  7145. REG_WR(bp, shmem + validity_offset, 0);
  7146. }
  7147. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7148. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7149. /**
  7150. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7151. *
  7152. * @bp: driver handle
  7153. */
  7154. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7155. {
  7156. /* special handling for emulation and FPGA,
  7157. wait 10 times longer */
  7158. if (CHIP_REV_IS_SLOW(bp))
  7159. msleep(MCP_ONE_TIMEOUT*10);
  7160. else
  7161. msleep(MCP_ONE_TIMEOUT);
  7162. }
  7163. /*
  7164. * initializes bp->common.shmem_base and waits for validity signature to appear
  7165. */
  7166. static int bnx2x_init_shmem(struct bnx2x *bp)
  7167. {
  7168. int cnt = 0;
  7169. u32 val = 0;
  7170. do {
  7171. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7172. if (bp->common.shmem_base) {
  7173. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7174. if (val & SHR_MEM_VALIDITY_MB)
  7175. return 0;
  7176. }
  7177. bnx2x_mcp_wait_one(bp);
  7178. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7179. BNX2X_ERR("BAD MCP validity signature\n");
  7180. return -ENODEV;
  7181. }
  7182. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7183. {
  7184. int rc = bnx2x_init_shmem(bp);
  7185. /* Restore the `magic' bit value */
  7186. if (!CHIP_IS_E1(bp))
  7187. bnx2x_clp_reset_done(bp, magic_val);
  7188. return rc;
  7189. }
  7190. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7191. {
  7192. if (!CHIP_IS_E1(bp)) {
  7193. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7194. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7195. mmiowb();
  7196. }
  7197. }
  7198. /*
  7199. * Reset the whole chip except for:
  7200. * - PCIE core
  7201. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7202. * one reset bit)
  7203. * - IGU
  7204. * - MISC (including AEU)
  7205. * - GRC
  7206. * - RBCN, RBCP
  7207. */
  7208. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7209. {
  7210. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7211. u32 global_bits2, stay_reset2;
  7212. /*
  7213. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7214. * (per chip) blocks.
  7215. */
  7216. global_bits2 =
  7217. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7218. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7219. /* Don't reset the following blocks */
  7220. not_reset_mask1 =
  7221. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7222. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7223. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7224. not_reset_mask2 =
  7225. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7226. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7227. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7228. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7229. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7230. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7231. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7232. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7233. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7234. MISC_REGISTERS_RESET_REG_2_PGLC;
  7235. /*
  7236. * Keep the following blocks in reset:
  7237. * - all xxMACs are handled by the bnx2x_link code.
  7238. */
  7239. stay_reset2 =
  7240. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7241. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7242. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7243. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7244. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7245. MISC_REGISTERS_RESET_REG_2_UMAC1 |
  7246. MISC_REGISTERS_RESET_REG_2_XMAC |
  7247. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7248. /* Full reset masks according to the chip */
  7249. reset_mask1 = 0xffffffff;
  7250. if (CHIP_IS_E1(bp))
  7251. reset_mask2 = 0xffff;
  7252. else if (CHIP_IS_E1H(bp))
  7253. reset_mask2 = 0x1ffff;
  7254. else if (CHIP_IS_E2(bp))
  7255. reset_mask2 = 0xfffff;
  7256. else /* CHIP_IS_E3 */
  7257. reset_mask2 = 0x3ffffff;
  7258. /* Don't reset global blocks unless we need to */
  7259. if (!global)
  7260. reset_mask2 &= ~global_bits2;
  7261. /*
  7262. * In case of attention in the QM, we need to reset PXP
  7263. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7264. * because otherwise QM reset would release 'close the gates' shortly
  7265. * before resetting the PXP, then the PSWRQ would send a write
  7266. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7267. * read the payload data from PSWWR, but PSWWR would not
  7268. * respond. The write queue in PGLUE would stuck, dmae commands
  7269. * would not return. Therefore it's important to reset the second
  7270. * reset register (containing the
  7271. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7272. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7273. * bit).
  7274. */
  7275. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7276. reset_mask2 & (~not_reset_mask2));
  7277. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7278. reset_mask1 & (~not_reset_mask1));
  7279. barrier();
  7280. mmiowb();
  7281. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7282. reset_mask2 & (~stay_reset2));
  7283. barrier();
  7284. mmiowb();
  7285. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7286. mmiowb();
  7287. }
  7288. /**
  7289. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7290. * It should get cleared in no more than 1s.
  7291. *
  7292. * @bp: driver handle
  7293. *
  7294. * It should get cleared in no more than 1s. Returns 0 if
  7295. * pending writes bit gets cleared.
  7296. */
  7297. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7298. {
  7299. u32 cnt = 1000;
  7300. u32 pend_bits = 0;
  7301. do {
  7302. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7303. if (pend_bits == 0)
  7304. break;
  7305. usleep_range(1000, 1000);
  7306. } while (cnt-- > 0);
  7307. if (cnt <= 0) {
  7308. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7309. pend_bits);
  7310. return -EBUSY;
  7311. }
  7312. return 0;
  7313. }
  7314. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7315. {
  7316. int cnt = 1000;
  7317. u32 val = 0;
  7318. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7319. /* Empty the Tetris buffer, wait for 1s */
  7320. do {
  7321. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7322. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7323. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7324. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7325. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7326. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7327. ((port_is_idle_0 & 0x1) == 0x1) &&
  7328. ((port_is_idle_1 & 0x1) == 0x1) &&
  7329. (pgl_exp_rom2 == 0xffffffff))
  7330. break;
  7331. usleep_range(1000, 1000);
  7332. } while (cnt-- > 0);
  7333. if (cnt <= 0) {
  7334. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7335. BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
  7336. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7337. pgl_exp_rom2);
  7338. return -EAGAIN;
  7339. }
  7340. barrier();
  7341. /* Close gates #2, #3 and #4 */
  7342. bnx2x_set_234_gates(bp, true);
  7343. /* Poll for IGU VQs for 57712 and newer chips */
  7344. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7345. return -EAGAIN;
  7346. /* TBD: Indicate that "process kill" is in progress to MCP */
  7347. /* Clear "unprepared" bit */
  7348. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7349. barrier();
  7350. /* Make sure all is written to the chip before the reset */
  7351. mmiowb();
  7352. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7353. * PSWHST, GRC and PSWRD Tetris buffer.
  7354. */
  7355. usleep_range(1000, 1000);
  7356. /* Prepare to chip reset: */
  7357. /* MCP */
  7358. if (global)
  7359. bnx2x_reset_mcp_prep(bp, &val);
  7360. /* PXP */
  7361. bnx2x_pxp_prep(bp);
  7362. barrier();
  7363. /* reset the chip */
  7364. bnx2x_process_kill_chip_reset(bp, global);
  7365. barrier();
  7366. /* Recover after reset: */
  7367. /* MCP */
  7368. if (global && bnx2x_reset_mcp_comp(bp, val))
  7369. return -EAGAIN;
  7370. /* TBD: Add resetting the NO_MCP mode DB here */
  7371. /* PXP */
  7372. bnx2x_pxp_prep(bp);
  7373. /* Open the gates #2, #3 and #4 */
  7374. bnx2x_set_234_gates(bp, false);
  7375. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7376. * reset state, re-enable attentions. */
  7377. return 0;
  7378. }
  7379. int bnx2x_leader_reset(struct bnx2x *bp)
  7380. {
  7381. int rc = 0;
  7382. bool global = bnx2x_reset_is_global(bp);
  7383. u32 load_code;
  7384. /* if not going to reset MCP - load "fake" driver to reset HW while
  7385. * driver is owner of the HW
  7386. */
  7387. if (!global && !BP_NOMCP(bp)) {
  7388. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
  7389. if (!load_code) {
  7390. BNX2X_ERR("MCP response failure, aborting\n");
  7391. rc = -EAGAIN;
  7392. goto exit_leader_reset;
  7393. }
  7394. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7395. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7396. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7397. rc = -EAGAIN;
  7398. goto exit_leader_reset2;
  7399. }
  7400. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7401. if (!load_code) {
  7402. BNX2X_ERR("MCP response failure, aborting\n");
  7403. rc = -EAGAIN;
  7404. goto exit_leader_reset2;
  7405. }
  7406. }
  7407. /* Try to recover after the failure */
  7408. if (bnx2x_process_kill(bp, global)) {
  7409. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7410. BP_PATH(bp));
  7411. rc = -EAGAIN;
  7412. goto exit_leader_reset2;
  7413. }
  7414. /*
  7415. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7416. * state.
  7417. */
  7418. bnx2x_set_reset_done(bp);
  7419. if (global)
  7420. bnx2x_clear_reset_global(bp);
  7421. exit_leader_reset2:
  7422. /* unload "fake driver" if it was loaded */
  7423. if (!global && !BP_NOMCP(bp)) {
  7424. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7425. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7426. }
  7427. exit_leader_reset:
  7428. bp->is_leader = 0;
  7429. bnx2x_release_leader_lock(bp);
  7430. smp_mb();
  7431. return rc;
  7432. }
  7433. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7434. {
  7435. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7436. /* Disconnect this device */
  7437. netif_device_detach(bp->dev);
  7438. /*
  7439. * Block ifup for all function on this engine until "process kill"
  7440. * or power cycle.
  7441. */
  7442. bnx2x_set_reset_in_progress(bp);
  7443. /* Shut down the power */
  7444. bnx2x_set_power_state(bp, PCI_D3hot);
  7445. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7446. smp_mb();
  7447. }
  7448. /*
  7449. * Assumption: runs under rtnl lock. This together with the fact
  7450. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7451. * will never be called when netif_running(bp->dev) is false.
  7452. */
  7453. static void bnx2x_parity_recover(struct bnx2x *bp)
  7454. {
  7455. bool global = false;
  7456. u32 error_recovered, error_unrecovered;
  7457. bool is_parity;
  7458. DP(NETIF_MSG_HW, "Handling parity\n");
  7459. while (1) {
  7460. switch (bp->recovery_state) {
  7461. case BNX2X_RECOVERY_INIT:
  7462. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7463. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7464. WARN_ON(!is_parity);
  7465. /* Try to get a LEADER_LOCK HW lock */
  7466. if (bnx2x_trylock_leader_lock(bp)) {
  7467. bnx2x_set_reset_in_progress(bp);
  7468. /*
  7469. * Check if there is a global attention and if
  7470. * there was a global attention, set the global
  7471. * reset bit.
  7472. */
  7473. if (global)
  7474. bnx2x_set_reset_global(bp);
  7475. bp->is_leader = 1;
  7476. }
  7477. /* Stop the driver */
  7478. /* If interface has been removed - break */
  7479. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
  7480. return;
  7481. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7482. /* Ensure "is_leader", MCP command sequence and
  7483. * "recovery_state" update values are seen on other
  7484. * CPUs.
  7485. */
  7486. smp_mb();
  7487. break;
  7488. case BNX2X_RECOVERY_WAIT:
  7489. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7490. if (bp->is_leader) {
  7491. int other_engine = BP_PATH(bp) ? 0 : 1;
  7492. bool other_load_status =
  7493. bnx2x_get_load_status(bp, other_engine);
  7494. bool load_status =
  7495. bnx2x_get_load_status(bp, BP_PATH(bp));
  7496. global = bnx2x_reset_is_global(bp);
  7497. /*
  7498. * In case of a parity in a global block, let
  7499. * the first leader that performs a
  7500. * leader_reset() reset the global blocks in
  7501. * order to clear global attentions. Otherwise
  7502. * the the gates will remain closed for that
  7503. * engine.
  7504. */
  7505. if (load_status ||
  7506. (global && other_load_status)) {
  7507. /* Wait until all other functions get
  7508. * down.
  7509. */
  7510. schedule_delayed_work(&bp->sp_rtnl_task,
  7511. HZ/10);
  7512. return;
  7513. } else {
  7514. /* If all other functions got down -
  7515. * try to bring the chip back to
  7516. * normal. In any case it's an exit
  7517. * point for a leader.
  7518. */
  7519. if (bnx2x_leader_reset(bp)) {
  7520. bnx2x_recovery_failed(bp);
  7521. return;
  7522. }
  7523. /* If we are here, means that the
  7524. * leader has succeeded and doesn't
  7525. * want to be a leader any more. Try
  7526. * to continue as a none-leader.
  7527. */
  7528. break;
  7529. }
  7530. } else { /* non-leader */
  7531. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7532. /* Try to get a LEADER_LOCK HW lock as
  7533. * long as a former leader may have
  7534. * been unloaded by the user or
  7535. * released a leadership by another
  7536. * reason.
  7537. */
  7538. if (bnx2x_trylock_leader_lock(bp)) {
  7539. /* I'm a leader now! Restart a
  7540. * switch case.
  7541. */
  7542. bp->is_leader = 1;
  7543. break;
  7544. }
  7545. schedule_delayed_work(&bp->sp_rtnl_task,
  7546. HZ/10);
  7547. return;
  7548. } else {
  7549. /*
  7550. * If there was a global attention, wait
  7551. * for it to be cleared.
  7552. */
  7553. if (bnx2x_reset_is_global(bp)) {
  7554. schedule_delayed_work(
  7555. &bp->sp_rtnl_task,
  7556. HZ/10);
  7557. return;
  7558. }
  7559. error_recovered =
  7560. bp->eth_stats.recoverable_error;
  7561. error_unrecovered =
  7562. bp->eth_stats.unrecoverable_error;
  7563. bp->recovery_state =
  7564. BNX2X_RECOVERY_NIC_LOADING;
  7565. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7566. error_unrecovered++;
  7567. netdev_err(bp->dev,
  7568. "Recovery failed. Power cycle needed\n");
  7569. /* Disconnect this device */
  7570. netif_device_detach(bp->dev);
  7571. /* Shut down the power */
  7572. bnx2x_set_power_state(
  7573. bp, PCI_D3hot);
  7574. smp_mb();
  7575. } else {
  7576. bp->recovery_state =
  7577. BNX2X_RECOVERY_DONE;
  7578. error_recovered++;
  7579. smp_mb();
  7580. }
  7581. bp->eth_stats.recoverable_error =
  7582. error_recovered;
  7583. bp->eth_stats.unrecoverable_error =
  7584. error_unrecovered;
  7585. return;
  7586. }
  7587. }
  7588. default:
  7589. return;
  7590. }
  7591. }
  7592. }
  7593. static int bnx2x_close(struct net_device *dev);
  7594. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7595. * scheduled on a general queue in order to prevent a dead lock.
  7596. */
  7597. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7598. {
  7599. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7600. rtnl_lock();
  7601. if (!netif_running(bp->dev))
  7602. goto sp_rtnl_exit;
  7603. /* if stop on error is defined no recovery flows should be executed */
  7604. #ifdef BNX2X_STOP_ON_ERROR
  7605. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7606. "you will need to reboot when done\n");
  7607. goto sp_rtnl_not_reset;
  7608. #endif
  7609. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7610. /*
  7611. * Clear all pending SP commands as we are going to reset the
  7612. * function anyway.
  7613. */
  7614. bp->sp_rtnl_state = 0;
  7615. smp_mb();
  7616. bnx2x_parity_recover(bp);
  7617. goto sp_rtnl_exit;
  7618. }
  7619. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7620. /*
  7621. * Clear all pending SP commands as we are going to reset the
  7622. * function anyway.
  7623. */
  7624. bp->sp_rtnl_state = 0;
  7625. smp_mb();
  7626. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7627. bnx2x_nic_load(bp, LOAD_NORMAL);
  7628. goto sp_rtnl_exit;
  7629. }
  7630. #ifdef BNX2X_STOP_ON_ERROR
  7631. sp_rtnl_not_reset:
  7632. #endif
  7633. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7634. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7635. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7636. bnx2x_after_function_update(bp);
  7637. /*
  7638. * in case of fan failure we need to reset id if the "stop on error"
  7639. * debug flag is set, since we trying to prevent permanent overheating
  7640. * damage
  7641. */
  7642. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7643. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7644. netif_device_detach(bp->dev);
  7645. bnx2x_close(bp->dev);
  7646. }
  7647. sp_rtnl_exit:
  7648. rtnl_unlock();
  7649. }
  7650. /* end of nic load/unload */
  7651. static void bnx2x_period_task(struct work_struct *work)
  7652. {
  7653. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7654. if (!netif_running(bp->dev))
  7655. goto period_task_exit;
  7656. if (CHIP_REV_IS_SLOW(bp)) {
  7657. BNX2X_ERR("period task called on emulation, ignoring\n");
  7658. goto period_task_exit;
  7659. }
  7660. bnx2x_acquire_phy_lock(bp);
  7661. /*
  7662. * The barrier is needed to ensure the ordering between the writing to
  7663. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7664. * the reading here.
  7665. */
  7666. smp_mb();
  7667. if (bp->port.pmf) {
  7668. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7669. /* Re-queue task in 1 sec */
  7670. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7671. }
  7672. bnx2x_release_phy_lock(bp);
  7673. period_task_exit:
  7674. return;
  7675. }
  7676. /*
  7677. * Init service functions
  7678. */
  7679. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7680. {
  7681. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7682. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7683. return base + (BP_ABS_FUNC(bp)) * stride;
  7684. }
  7685. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7686. {
  7687. u32 reg = bnx2x_get_pretend_reg(bp);
  7688. /* Flush all outstanding writes */
  7689. mmiowb();
  7690. /* Pretend to be function 0 */
  7691. REG_WR(bp, reg, 0);
  7692. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7693. /* From now we are in the "like-E1" mode */
  7694. bnx2x_int_disable(bp);
  7695. /* Flush all outstanding writes */
  7696. mmiowb();
  7697. /* Restore the original function */
  7698. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7699. REG_RD(bp, reg);
  7700. }
  7701. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7702. {
  7703. if (CHIP_IS_E1(bp))
  7704. bnx2x_int_disable(bp);
  7705. else
  7706. bnx2x_undi_int_disable_e1h(bp);
  7707. }
  7708. static void __devinit bnx2x_prev_unload_close_mac(struct bnx2x *bp)
  7709. {
  7710. u32 val, base_addr, offset, mask, reset_reg;
  7711. bool mac_stopped = false;
  7712. u8 port = BP_PORT(bp);
  7713. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7714. if (!CHIP_IS_E3(bp)) {
  7715. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7716. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7717. if ((mask & reset_reg) && val) {
  7718. u32 wb_data[2];
  7719. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7720. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7721. : NIG_REG_INGRESS_BMAC0_MEM;
  7722. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7723. : BIGMAC_REGISTER_BMAC_CONTROL;
  7724. /*
  7725. * use rd/wr since we cannot use dmae. This is safe
  7726. * since MCP won't access the bus due to the request
  7727. * to unload, and no function on the path can be
  7728. * loaded at this time.
  7729. */
  7730. wb_data[0] = REG_RD(bp, base_addr + offset);
  7731. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  7732. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  7733. REG_WR(bp, base_addr + offset, wb_data[0]);
  7734. REG_WR(bp, base_addr + offset + 0x4, wb_data[1]);
  7735. }
  7736. BNX2X_DEV_INFO("Disable emac Rx\n");
  7737. REG_WR(bp, NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4, 0);
  7738. mac_stopped = true;
  7739. } else {
  7740. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  7741. BNX2X_DEV_INFO("Disable xmac Rx\n");
  7742. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  7743. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  7744. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7745. val & ~(1 << 1));
  7746. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7747. val | (1 << 1));
  7748. REG_WR(bp, base_addr + XMAC_REG_CTRL, 0);
  7749. mac_stopped = true;
  7750. }
  7751. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  7752. if (mask & reset_reg) {
  7753. BNX2X_DEV_INFO("Disable umac Rx\n");
  7754. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  7755. REG_WR(bp, base_addr + UMAC_REG_COMMAND_CONFIG, 0);
  7756. mac_stopped = true;
  7757. }
  7758. }
  7759. if (mac_stopped)
  7760. msleep(20);
  7761. }
  7762. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  7763. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  7764. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  7765. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  7766. static void __devinit bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port,
  7767. u8 inc)
  7768. {
  7769. u16 rcq, bd;
  7770. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  7771. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  7772. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  7773. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  7774. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  7775. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  7776. port, bd, rcq);
  7777. }
  7778. static int __devinit bnx2x_prev_mcp_done(struct bnx2x *bp)
  7779. {
  7780. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7781. if (!rc) {
  7782. BNX2X_ERR("MCP response failure, aborting\n");
  7783. return -EBUSY;
  7784. }
  7785. return 0;
  7786. }
  7787. static bool __devinit bnx2x_prev_is_path_marked(struct bnx2x *bp)
  7788. {
  7789. struct bnx2x_prev_path_list *tmp_list;
  7790. int rc = false;
  7791. if (down_trylock(&bnx2x_prev_sem))
  7792. return false;
  7793. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  7794. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7795. bp->pdev->bus->number == tmp_list->bus &&
  7796. BP_PATH(bp) == tmp_list->path) {
  7797. rc = true;
  7798. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  7799. BP_PATH(bp));
  7800. break;
  7801. }
  7802. }
  7803. up(&bnx2x_prev_sem);
  7804. return rc;
  7805. }
  7806. static int __devinit bnx2x_prev_mark_path(struct bnx2x *bp)
  7807. {
  7808. struct bnx2x_prev_path_list *tmp_list;
  7809. int rc;
  7810. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  7811. if (!tmp_list) {
  7812. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  7813. return -ENOMEM;
  7814. }
  7815. tmp_list->bus = bp->pdev->bus->number;
  7816. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  7817. tmp_list->path = BP_PATH(bp);
  7818. rc = down_interruptible(&bnx2x_prev_sem);
  7819. if (rc) {
  7820. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  7821. kfree(tmp_list);
  7822. } else {
  7823. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  7824. BP_PATH(bp));
  7825. list_add(&tmp_list->list, &bnx2x_prev_list);
  7826. up(&bnx2x_prev_sem);
  7827. }
  7828. return rc;
  7829. }
  7830. static bool __devinit bnx2x_can_flr(struct bnx2x *bp)
  7831. {
  7832. int pos;
  7833. u32 cap;
  7834. struct pci_dev *dev = bp->pdev;
  7835. pos = pci_pcie_cap(dev);
  7836. if (!pos)
  7837. return false;
  7838. pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP, &cap);
  7839. if (!(cap & PCI_EXP_DEVCAP_FLR))
  7840. return false;
  7841. return true;
  7842. }
  7843. static int __devinit bnx2x_do_flr(struct bnx2x *bp)
  7844. {
  7845. int i, pos;
  7846. u16 status;
  7847. struct pci_dev *dev = bp->pdev;
  7848. /* probe the capability first */
  7849. if (bnx2x_can_flr(bp))
  7850. return -ENOTTY;
  7851. pos = pci_pcie_cap(dev);
  7852. if (!pos)
  7853. return -ENOTTY;
  7854. /* Wait for Transaction Pending bit clean */
  7855. for (i = 0; i < 4; i++) {
  7856. if (i)
  7857. msleep((1 << (i - 1)) * 100);
  7858. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  7859. if (!(status & PCI_EXP_DEVSTA_TRPND))
  7860. goto clear;
  7861. }
  7862. dev_err(&dev->dev,
  7863. "transaction is not cleared; proceeding with reset anyway\n");
  7864. clear:
  7865. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  7866. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  7867. bp->common.bc_ver);
  7868. return -EINVAL;
  7869. }
  7870. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  7871. return 0;
  7872. }
  7873. static int __devinit bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  7874. {
  7875. int rc;
  7876. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  7877. /* Test if previous unload process was already finished for this path */
  7878. if (bnx2x_prev_is_path_marked(bp))
  7879. return bnx2x_prev_mcp_done(bp);
  7880. /* If function has FLR capabilities, and existing FW version matches
  7881. * the one required, then FLR will be sufficient to clean any residue
  7882. * left by previous driver
  7883. */
  7884. if (bnx2x_test_firmware_version(bp, false) && bnx2x_can_flr(bp))
  7885. return bnx2x_do_flr(bp);
  7886. /* Close the MCP request, return failure*/
  7887. rc = bnx2x_prev_mcp_done(bp);
  7888. if (!rc)
  7889. rc = BNX2X_PREV_WAIT_NEEDED;
  7890. return rc;
  7891. }
  7892. static int __devinit bnx2x_prev_unload_common(struct bnx2x *bp)
  7893. {
  7894. u32 reset_reg, tmp_reg = 0, rc;
  7895. /* It is possible a previous function received 'common' answer,
  7896. * but hasn't loaded yet, therefore creating a scenario of
  7897. * multiple functions receiving 'common' on the same path.
  7898. */
  7899. BNX2X_DEV_INFO("Common unload Flow\n");
  7900. if (bnx2x_prev_is_path_marked(bp))
  7901. return bnx2x_prev_mcp_done(bp);
  7902. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7903. /* Reset should be performed after BRB is emptied */
  7904. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  7905. u32 timer_count = 1000;
  7906. bool prev_undi = false;
  7907. /* Close the MAC Rx to prevent BRB from filling up */
  7908. bnx2x_prev_unload_close_mac(bp);
  7909. /* Check if the UNDI driver was previously loaded
  7910. * UNDI driver initializes CID offset for normal bell to 0x7
  7911. */
  7912. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  7913. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  7914. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  7915. if (tmp_reg == 0x7) {
  7916. BNX2X_DEV_INFO("UNDI previously loaded\n");
  7917. prev_undi = true;
  7918. /* clear the UNDI indication */
  7919. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  7920. }
  7921. }
  7922. /* wait until BRB is empty */
  7923. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7924. while (timer_count) {
  7925. u32 prev_brb = tmp_reg;
  7926. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  7927. if (!tmp_reg)
  7928. break;
  7929. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  7930. /* reset timer as long as BRB actually gets emptied */
  7931. if (prev_brb > tmp_reg)
  7932. timer_count = 1000;
  7933. else
  7934. timer_count--;
  7935. /* If UNDI resides in memory, manually increment it */
  7936. if (prev_undi)
  7937. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  7938. udelay(10);
  7939. }
  7940. if (!timer_count)
  7941. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  7942. }
  7943. /* No packets are in the pipeline, path is ready for reset */
  7944. bnx2x_reset_common(bp);
  7945. rc = bnx2x_prev_mark_path(bp);
  7946. if (rc) {
  7947. bnx2x_prev_mcp_done(bp);
  7948. return rc;
  7949. }
  7950. return bnx2x_prev_mcp_done(bp);
  7951. }
  7952. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  7953. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  7954. * the addresses of the transaction, resulting in was-error bit set in the pci
  7955. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  7956. * to clear the interrupt which detected this from the pglueb and the was done
  7957. * bit
  7958. */
  7959. static void __devinit bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  7960. {
  7961. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  7962. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  7963. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  7964. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, 1 << BP_FUNC(bp));
  7965. }
  7966. }
  7967. static int __devinit bnx2x_prev_unload(struct bnx2x *bp)
  7968. {
  7969. int time_counter = 10;
  7970. u32 rc, fw, hw_lock_reg, hw_lock_val;
  7971. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  7972. /* clear hw from errors which may have resulted from an interrupted
  7973. * dmae transaction.
  7974. */
  7975. bnx2x_prev_interrupted_dmae(bp);
  7976. /* Release previously held locks */
  7977. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  7978. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  7979. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  7980. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  7981. if (hw_lock_val) {
  7982. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  7983. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  7984. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  7985. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  7986. }
  7987. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  7988. REG_WR(bp, hw_lock_reg, 0xffffffff);
  7989. } else
  7990. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  7991. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  7992. BNX2X_DEV_INFO("Release previously held alr\n");
  7993. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  7994. }
  7995. do {
  7996. /* Lock MCP using an unload request */
  7997. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  7998. if (!fw) {
  7999. BNX2X_ERR("MCP response failure, aborting\n");
  8000. rc = -EBUSY;
  8001. break;
  8002. }
  8003. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8004. rc = bnx2x_prev_unload_common(bp);
  8005. break;
  8006. }
  8007. /* non-common reply from MCP night require looping */
  8008. rc = bnx2x_prev_unload_uncommon(bp);
  8009. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8010. break;
  8011. msleep(20);
  8012. } while (--time_counter);
  8013. if (!time_counter || rc) {
  8014. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8015. rc = -EBUSY;
  8016. }
  8017. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8018. return rc;
  8019. }
  8020. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8021. {
  8022. u32 val, val2, val3, val4, id, boot_mode;
  8023. u16 pmc;
  8024. /* Get the chip revision id and number. */
  8025. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8026. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8027. id = ((val & 0xffff) << 16);
  8028. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8029. id |= ((val & 0xf) << 12);
  8030. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8031. id |= ((val & 0xff) << 4);
  8032. val = REG_RD(bp, MISC_REG_BOND_ID);
  8033. id |= (val & 0xf);
  8034. bp->common.chip_id = id;
  8035. /* force 57811 according to MISC register */
  8036. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8037. if (CHIP_IS_57810(bp))
  8038. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8039. (bp->common.chip_id & 0x0000FFFF);
  8040. else if (CHIP_IS_57810_MF(bp))
  8041. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8042. (bp->common.chip_id & 0x0000FFFF);
  8043. bp->common.chip_id |= 0x1;
  8044. }
  8045. /* Set doorbell size */
  8046. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8047. if (!CHIP_IS_E1x(bp)) {
  8048. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8049. if ((val & 1) == 0)
  8050. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8051. else
  8052. val = (val >> 1) & 1;
  8053. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8054. "2_PORT_MODE");
  8055. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8056. CHIP_2_PORT_MODE;
  8057. if (CHIP_MODE_IS_4_PORT(bp))
  8058. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8059. else
  8060. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8061. } else {
  8062. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8063. bp->pfid = bp->pf_num; /* 0..7 */
  8064. }
  8065. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8066. bp->link_params.chip_id = bp->common.chip_id;
  8067. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8068. val = (REG_RD(bp, 0x2874) & 0x55);
  8069. if ((bp->common.chip_id & 0x1) ||
  8070. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8071. bp->flags |= ONE_PORT_FLAG;
  8072. BNX2X_DEV_INFO("single port device\n");
  8073. }
  8074. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8075. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8076. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8077. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8078. bp->common.flash_size, bp->common.flash_size);
  8079. bnx2x_init_shmem(bp);
  8080. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8081. MISC_REG_GENERIC_CR_1 :
  8082. MISC_REG_GENERIC_CR_0));
  8083. bp->link_params.shmem_base = bp->common.shmem_base;
  8084. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8085. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8086. bp->common.shmem_base, bp->common.shmem2_base);
  8087. if (!bp->common.shmem_base) {
  8088. BNX2X_DEV_INFO("MCP not active\n");
  8089. bp->flags |= NO_MCP_FLAG;
  8090. return;
  8091. }
  8092. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8093. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8094. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8095. SHARED_HW_CFG_LED_MODE_MASK) >>
  8096. SHARED_HW_CFG_LED_MODE_SHIFT);
  8097. bp->link_params.feature_config_flags = 0;
  8098. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8099. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8100. bp->link_params.feature_config_flags |=
  8101. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8102. else
  8103. bp->link_params.feature_config_flags &=
  8104. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8105. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8106. bp->common.bc_ver = val;
  8107. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8108. if (val < BNX2X_BC_VER) {
  8109. /* for now only warn
  8110. * later we might need to enforce this */
  8111. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8112. BNX2X_BC_VER, val);
  8113. }
  8114. bp->link_params.feature_config_flags |=
  8115. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8116. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8117. bp->link_params.feature_config_flags |=
  8118. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8119. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8120. bp->link_params.feature_config_flags |=
  8121. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8122. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8123. bp->link_params.feature_config_flags |=
  8124. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8125. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8126. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8127. BC_SUPPORTS_PFC_STATS : 0;
  8128. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8129. BC_SUPPORTS_FCOE_FEATURES : 0;
  8130. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8131. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8132. boot_mode = SHMEM_RD(bp,
  8133. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8134. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8135. switch (boot_mode) {
  8136. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8137. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8138. break;
  8139. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8140. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8141. break;
  8142. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8143. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8144. break;
  8145. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8146. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8147. break;
  8148. }
  8149. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8150. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8151. BNX2X_DEV_INFO("%sWoL capable\n",
  8152. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8153. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8154. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8155. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8156. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8157. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8158. val, val2, val3, val4);
  8159. }
  8160. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8161. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8162. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8163. {
  8164. int pfid = BP_FUNC(bp);
  8165. int igu_sb_id;
  8166. u32 val;
  8167. u8 fid, igu_sb_cnt = 0;
  8168. bp->igu_base_sb = 0xff;
  8169. if (CHIP_INT_MODE_IS_BC(bp)) {
  8170. int vn = BP_VN(bp);
  8171. igu_sb_cnt = bp->igu_sb_cnt;
  8172. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8173. FP_SB_MAX_E1x;
  8174. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8175. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8176. return;
  8177. }
  8178. /* IGU in normal mode - read CAM */
  8179. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8180. igu_sb_id++) {
  8181. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8182. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8183. continue;
  8184. fid = IGU_FID(val);
  8185. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8186. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8187. continue;
  8188. if (IGU_VEC(val) == 0)
  8189. /* default status block */
  8190. bp->igu_dsb_id = igu_sb_id;
  8191. else {
  8192. if (bp->igu_base_sb == 0xff)
  8193. bp->igu_base_sb = igu_sb_id;
  8194. igu_sb_cnt++;
  8195. }
  8196. }
  8197. }
  8198. #ifdef CONFIG_PCI_MSI
  8199. /*
  8200. * It's expected that number of CAM entries for this functions is equal
  8201. * to the number evaluated based on the MSI-X table size. We want a
  8202. * harsh warning if these values are different!
  8203. */
  8204. WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
  8205. #endif
  8206. if (igu_sb_cnt == 0)
  8207. BNX2X_ERR("CAM configuration error\n");
  8208. }
  8209. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  8210. u32 switch_cfg)
  8211. {
  8212. int cfg_size = 0, idx, port = BP_PORT(bp);
  8213. /* Aggregation of supported attributes of all external phys */
  8214. bp->port.supported[0] = 0;
  8215. bp->port.supported[1] = 0;
  8216. switch (bp->link_params.num_phys) {
  8217. case 1:
  8218. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8219. cfg_size = 1;
  8220. break;
  8221. case 2:
  8222. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8223. cfg_size = 1;
  8224. break;
  8225. case 3:
  8226. if (bp->link_params.multi_phy_config &
  8227. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8228. bp->port.supported[1] =
  8229. bp->link_params.phy[EXT_PHY1].supported;
  8230. bp->port.supported[0] =
  8231. bp->link_params.phy[EXT_PHY2].supported;
  8232. } else {
  8233. bp->port.supported[0] =
  8234. bp->link_params.phy[EXT_PHY1].supported;
  8235. bp->port.supported[1] =
  8236. bp->link_params.phy[EXT_PHY2].supported;
  8237. }
  8238. cfg_size = 2;
  8239. break;
  8240. }
  8241. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8242. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8243. SHMEM_RD(bp,
  8244. dev_info.port_hw_config[port].external_phy_config),
  8245. SHMEM_RD(bp,
  8246. dev_info.port_hw_config[port].external_phy_config2));
  8247. return;
  8248. }
  8249. if (CHIP_IS_E3(bp))
  8250. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8251. else {
  8252. switch (switch_cfg) {
  8253. case SWITCH_CFG_1G:
  8254. bp->port.phy_addr = REG_RD(
  8255. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8256. break;
  8257. case SWITCH_CFG_10G:
  8258. bp->port.phy_addr = REG_RD(
  8259. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8260. break;
  8261. default:
  8262. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8263. bp->port.link_config[0]);
  8264. return;
  8265. }
  8266. }
  8267. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8268. /* mask what we support according to speed_cap_mask per configuration */
  8269. for (idx = 0; idx < cfg_size; idx++) {
  8270. if (!(bp->link_params.speed_cap_mask[idx] &
  8271. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8272. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8273. if (!(bp->link_params.speed_cap_mask[idx] &
  8274. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8275. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8276. if (!(bp->link_params.speed_cap_mask[idx] &
  8277. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8278. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8279. if (!(bp->link_params.speed_cap_mask[idx] &
  8280. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8281. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8282. if (!(bp->link_params.speed_cap_mask[idx] &
  8283. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8284. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8285. SUPPORTED_1000baseT_Full);
  8286. if (!(bp->link_params.speed_cap_mask[idx] &
  8287. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8288. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8289. if (!(bp->link_params.speed_cap_mask[idx] &
  8290. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8291. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8292. }
  8293. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8294. bp->port.supported[1]);
  8295. }
  8296. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  8297. {
  8298. u32 link_config, idx, cfg_size = 0;
  8299. bp->port.advertising[0] = 0;
  8300. bp->port.advertising[1] = 0;
  8301. switch (bp->link_params.num_phys) {
  8302. case 1:
  8303. case 2:
  8304. cfg_size = 1;
  8305. break;
  8306. case 3:
  8307. cfg_size = 2;
  8308. break;
  8309. }
  8310. for (idx = 0; idx < cfg_size; idx++) {
  8311. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8312. link_config = bp->port.link_config[idx];
  8313. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8314. case PORT_FEATURE_LINK_SPEED_AUTO:
  8315. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8316. bp->link_params.req_line_speed[idx] =
  8317. SPEED_AUTO_NEG;
  8318. bp->port.advertising[idx] |=
  8319. bp->port.supported[idx];
  8320. if (bp->link_params.phy[EXT_PHY1].type ==
  8321. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8322. bp->port.advertising[idx] |=
  8323. (SUPPORTED_100baseT_Half |
  8324. SUPPORTED_100baseT_Full);
  8325. } else {
  8326. /* force 10G, no AN */
  8327. bp->link_params.req_line_speed[idx] =
  8328. SPEED_10000;
  8329. bp->port.advertising[idx] |=
  8330. (ADVERTISED_10000baseT_Full |
  8331. ADVERTISED_FIBRE);
  8332. continue;
  8333. }
  8334. break;
  8335. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8336. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8337. bp->link_params.req_line_speed[idx] =
  8338. SPEED_10;
  8339. bp->port.advertising[idx] |=
  8340. (ADVERTISED_10baseT_Full |
  8341. ADVERTISED_TP);
  8342. } else {
  8343. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8344. link_config,
  8345. bp->link_params.speed_cap_mask[idx]);
  8346. return;
  8347. }
  8348. break;
  8349. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8350. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8351. bp->link_params.req_line_speed[idx] =
  8352. SPEED_10;
  8353. bp->link_params.req_duplex[idx] =
  8354. DUPLEX_HALF;
  8355. bp->port.advertising[idx] |=
  8356. (ADVERTISED_10baseT_Half |
  8357. ADVERTISED_TP);
  8358. } else {
  8359. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8360. link_config,
  8361. bp->link_params.speed_cap_mask[idx]);
  8362. return;
  8363. }
  8364. break;
  8365. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8366. if (bp->port.supported[idx] &
  8367. SUPPORTED_100baseT_Full) {
  8368. bp->link_params.req_line_speed[idx] =
  8369. SPEED_100;
  8370. bp->port.advertising[idx] |=
  8371. (ADVERTISED_100baseT_Full |
  8372. ADVERTISED_TP);
  8373. } else {
  8374. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8375. link_config,
  8376. bp->link_params.speed_cap_mask[idx]);
  8377. return;
  8378. }
  8379. break;
  8380. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8381. if (bp->port.supported[idx] &
  8382. SUPPORTED_100baseT_Half) {
  8383. bp->link_params.req_line_speed[idx] =
  8384. SPEED_100;
  8385. bp->link_params.req_duplex[idx] =
  8386. DUPLEX_HALF;
  8387. bp->port.advertising[idx] |=
  8388. (ADVERTISED_100baseT_Half |
  8389. ADVERTISED_TP);
  8390. } else {
  8391. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8392. link_config,
  8393. bp->link_params.speed_cap_mask[idx]);
  8394. return;
  8395. }
  8396. break;
  8397. case PORT_FEATURE_LINK_SPEED_1G:
  8398. if (bp->port.supported[idx] &
  8399. SUPPORTED_1000baseT_Full) {
  8400. bp->link_params.req_line_speed[idx] =
  8401. SPEED_1000;
  8402. bp->port.advertising[idx] |=
  8403. (ADVERTISED_1000baseT_Full |
  8404. ADVERTISED_TP);
  8405. } else {
  8406. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8407. link_config,
  8408. bp->link_params.speed_cap_mask[idx]);
  8409. return;
  8410. }
  8411. break;
  8412. case PORT_FEATURE_LINK_SPEED_2_5G:
  8413. if (bp->port.supported[idx] &
  8414. SUPPORTED_2500baseX_Full) {
  8415. bp->link_params.req_line_speed[idx] =
  8416. SPEED_2500;
  8417. bp->port.advertising[idx] |=
  8418. (ADVERTISED_2500baseX_Full |
  8419. ADVERTISED_TP);
  8420. } else {
  8421. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8422. link_config,
  8423. bp->link_params.speed_cap_mask[idx]);
  8424. return;
  8425. }
  8426. break;
  8427. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8428. if (bp->port.supported[idx] &
  8429. SUPPORTED_10000baseT_Full) {
  8430. bp->link_params.req_line_speed[idx] =
  8431. SPEED_10000;
  8432. bp->port.advertising[idx] |=
  8433. (ADVERTISED_10000baseT_Full |
  8434. ADVERTISED_FIBRE);
  8435. } else {
  8436. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8437. link_config,
  8438. bp->link_params.speed_cap_mask[idx]);
  8439. return;
  8440. }
  8441. break;
  8442. case PORT_FEATURE_LINK_SPEED_20G:
  8443. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8444. break;
  8445. default:
  8446. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8447. link_config);
  8448. bp->link_params.req_line_speed[idx] =
  8449. SPEED_AUTO_NEG;
  8450. bp->port.advertising[idx] =
  8451. bp->port.supported[idx];
  8452. break;
  8453. }
  8454. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8455. PORT_FEATURE_FLOW_CONTROL_MASK);
  8456. if ((bp->link_params.req_flow_ctrl[idx] ==
  8457. BNX2X_FLOW_CTRL_AUTO) &&
  8458. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  8459. bp->link_params.req_flow_ctrl[idx] =
  8460. BNX2X_FLOW_CTRL_NONE;
  8461. }
  8462. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8463. bp->link_params.req_line_speed[idx],
  8464. bp->link_params.req_duplex[idx],
  8465. bp->link_params.req_flow_ctrl[idx],
  8466. bp->port.advertising[idx]);
  8467. }
  8468. }
  8469. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8470. {
  8471. mac_hi = cpu_to_be16(mac_hi);
  8472. mac_lo = cpu_to_be32(mac_lo);
  8473. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8474. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8475. }
  8476. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8477. {
  8478. int port = BP_PORT(bp);
  8479. u32 config;
  8480. u32 ext_phy_type, ext_phy_config, eee_mode;
  8481. bp->link_params.bp = bp;
  8482. bp->link_params.port = port;
  8483. bp->link_params.lane_config =
  8484. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8485. bp->link_params.speed_cap_mask[0] =
  8486. SHMEM_RD(bp,
  8487. dev_info.port_hw_config[port].speed_capability_mask);
  8488. bp->link_params.speed_cap_mask[1] =
  8489. SHMEM_RD(bp,
  8490. dev_info.port_hw_config[port].speed_capability_mask2);
  8491. bp->port.link_config[0] =
  8492. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8493. bp->port.link_config[1] =
  8494. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8495. bp->link_params.multi_phy_config =
  8496. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8497. /* If the device is capable of WoL, set the default state according
  8498. * to the HW
  8499. */
  8500. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8501. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8502. (config & PORT_FEATURE_WOL_ENABLED));
  8503. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8504. bp->link_params.lane_config,
  8505. bp->link_params.speed_cap_mask[0],
  8506. bp->port.link_config[0]);
  8507. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8508. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8509. bnx2x_phy_probe(&bp->link_params);
  8510. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8511. bnx2x_link_settings_requested(bp);
  8512. /*
  8513. * If connected directly, work with the internal PHY, otherwise, work
  8514. * with the external PHY
  8515. */
  8516. ext_phy_config =
  8517. SHMEM_RD(bp,
  8518. dev_info.port_hw_config[port].external_phy_config);
  8519. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8520. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8521. bp->mdio.prtad = bp->port.phy_addr;
  8522. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8523. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8524. bp->mdio.prtad =
  8525. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8526. /*
  8527. * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
  8528. * In MF mode, it is set to cover self test cases
  8529. */
  8530. if (IS_MF(bp))
  8531. bp->port.need_hw_lock = 1;
  8532. else
  8533. bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
  8534. bp->common.shmem_base,
  8535. bp->common.shmem2_base);
  8536. /* Configure link feature according to nvram value */
  8537. eee_mode = (((SHMEM_RD(bp, dev_info.
  8538. port_feature_config[port].eee_power_mode)) &
  8539. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8540. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8541. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8542. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8543. EEE_MODE_ENABLE_LPI |
  8544. EEE_MODE_OUTPUT_TIME;
  8545. } else {
  8546. bp->link_params.eee_mode = 0;
  8547. }
  8548. }
  8549. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8550. {
  8551. u32 no_flags = NO_ISCSI_FLAG;
  8552. #ifdef BCM_CNIC
  8553. int port = BP_PORT(bp);
  8554. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8555. drv_lic_key[port].max_iscsi_conn);
  8556. /* Get the number of maximum allowed iSCSI connections */
  8557. bp->cnic_eth_dev.max_iscsi_conn =
  8558. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8559. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8560. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8561. bp->cnic_eth_dev.max_iscsi_conn);
  8562. /*
  8563. * If maximum allowed number of connections is zero -
  8564. * disable the feature.
  8565. */
  8566. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8567. bp->flags |= no_flags;
  8568. #else
  8569. bp->flags |= no_flags;
  8570. #endif
  8571. }
  8572. #ifdef BCM_CNIC
  8573. static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8574. {
  8575. /* Port info */
  8576. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8577. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8578. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8579. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8580. /* Node info */
  8581. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8582. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8583. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8584. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8585. }
  8586. #endif
  8587. static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
  8588. {
  8589. #ifdef BCM_CNIC
  8590. int port = BP_PORT(bp);
  8591. int func = BP_ABS_FUNC(bp);
  8592. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8593. drv_lic_key[port].max_fcoe_conn);
  8594. /* Get the number of maximum allowed FCoE connections */
  8595. bp->cnic_eth_dev.max_fcoe_conn =
  8596. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8597. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8598. /* Read the WWN: */
  8599. if (!IS_MF(bp)) {
  8600. /* Port info */
  8601. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8602. SHMEM_RD(bp,
  8603. dev_info.port_hw_config[port].
  8604. fcoe_wwn_port_name_upper);
  8605. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8606. SHMEM_RD(bp,
  8607. dev_info.port_hw_config[port].
  8608. fcoe_wwn_port_name_lower);
  8609. /* Node info */
  8610. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8611. SHMEM_RD(bp,
  8612. dev_info.port_hw_config[port].
  8613. fcoe_wwn_node_name_upper);
  8614. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8615. SHMEM_RD(bp,
  8616. dev_info.port_hw_config[port].
  8617. fcoe_wwn_node_name_lower);
  8618. } else if (!IS_MF_SD(bp)) {
  8619. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8620. /*
  8621. * Read the WWN info only if the FCoE feature is enabled for
  8622. * this function.
  8623. */
  8624. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
  8625. bnx2x_get_ext_wwn_info(bp, func);
  8626. } else if (IS_MF_FCOE_SD(bp))
  8627. bnx2x_get_ext_wwn_info(bp, func);
  8628. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8629. /*
  8630. * If maximum allowed number of connections is zero -
  8631. * disable the feature.
  8632. */
  8633. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8634. bp->flags |= NO_FCOE_FLAG;
  8635. #else
  8636. bp->flags |= NO_FCOE_FLAG;
  8637. #endif
  8638. }
  8639. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  8640. {
  8641. /*
  8642. * iSCSI may be dynamically disabled but reading
  8643. * info here we will decrease memory usage by driver
  8644. * if the feature is disabled for good
  8645. */
  8646. bnx2x_get_iscsi_info(bp);
  8647. bnx2x_get_fcoe_info(bp);
  8648. }
  8649. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8650. {
  8651. u32 val, val2;
  8652. int func = BP_ABS_FUNC(bp);
  8653. int port = BP_PORT(bp);
  8654. #ifdef BCM_CNIC
  8655. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8656. u8 *fip_mac = bp->fip_mac;
  8657. #endif
  8658. /* Zero primary MAC configuration */
  8659. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8660. if (BP_NOMCP(bp)) {
  8661. BNX2X_ERROR("warning: random MAC workaround active\n");
  8662. eth_hw_addr_random(bp->dev);
  8663. } else if (IS_MF(bp)) {
  8664. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8665. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8666. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8667. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8668. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8669. #ifdef BCM_CNIC
  8670. /*
  8671. * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8672. * FCoE MAC then the appropriate feature should be disabled.
  8673. *
  8674. * In non SD mode features configuration comes from
  8675. * struct func_ext_config.
  8676. */
  8677. if (!IS_MF_SD(bp)) {
  8678. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8679. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8680. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8681. iscsi_mac_addr_upper);
  8682. val = MF_CFG_RD(bp, func_ext_config[func].
  8683. iscsi_mac_addr_lower);
  8684. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8685. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8686. iscsi_mac);
  8687. } else
  8688. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8689. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8690. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8691. fcoe_mac_addr_upper);
  8692. val = MF_CFG_RD(bp, func_ext_config[func].
  8693. fcoe_mac_addr_lower);
  8694. bnx2x_set_mac_buf(fip_mac, val, val2);
  8695. BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
  8696. fip_mac);
  8697. } else
  8698. bp->flags |= NO_FCOE_FLAG;
  8699. bp->mf_ext_config = cfg;
  8700. } else { /* SD MODE */
  8701. if (IS_MF_STORAGE_SD(bp)) {
  8702. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8703. /* use primary mac as iscsi mac */
  8704. memcpy(iscsi_mac, bp->dev->dev_addr,
  8705. ETH_ALEN);
  8706. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8707. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8708. iscsi_mac);
  8709. } else { /* FCoE */
  8710. memcpy(fip_mac, bp->dev->dev_addr,
  8711. ETH_ALEN);
  8712. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8713. BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
  8714. fip_mac);
  8715. }
  8716. /* Zero primary MAC configuration */
  8717. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8718. }
  8719. }
  8720. if (IS_MF_FCOE_AFEX(bp))
  8721. /* use FIP MAC as primary MAC */
  8722. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  8723. #endif
  8724. } else {
  8725. /* in SF read MACs from port configuration */
  8726. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8727. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8728. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8729. #ifdef BCM_CNIC
  8730. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8731. iscsi_mac_upper);
  8732. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8733. iscsi_mac_lower);
  8734. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8735. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8736. fcoe_fip_mac_upper);
  8737. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8738. fcoe_fip_mac_lower);
  8739. bnx2x_set_mac_buf(fip_mac, val, val2);
  8740. #endif
  8741. }
  8742. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8743. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8744. #ifdef BCM_CNIC
  8745. /* Disable iSCSI if MAC configuration is
  8746. * invalid.
  8747. */
  8748. if (!is_valid_ether_addr(iscsi_mac)) {
  8749. bp->flags |= NO_ISCSI_FLAG;
  8750. memset(iscsi_mac, 0, ETH_ALEN);
  8751. }
  8752. /* Disable FCoE if MAC configuration is
  8753. * invalid.
  8754. */
  8755. if (!is_valid_ether_addr(fip_mac)) {
  8756. bp->flags |= NO_FCOE_FLAG;
  8757. memset(bp->fip_mac, 0, ETH_ALEN);
  8758. }
  8759. #endif
  8760. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8761. dev_err(&bp->pdev->dev,
  8762. "bad Ethernet MAC address configuration: %pM\n"
  8763. "change it manually before bringing up the appropriate network interface\n",
  8764. bp->dev->dev_addr);
  8765. }
  8766. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  8767. {
  8768. int /*abs*/func = BP_ABS_FUNC(bp);
  8769. int vn;
  8770. u32 val = 0;
  8771. int rc = 0;
  8772. bnx2x_get_common_hwinfo(bp);
  8773. /*
  8774. * initialize IGU parameters
  8775. */
  8776. if (CHIP_IS_E1x(bp)) {
  8777. bp->common.int_block = INT_BLOCK_HC;
  8778. bp->igu_dsb_id = DEF_SB_IGU_ID;
  8779. bp->igu_base_sb = 0;
  8780. } else {
  8781. bp->common.int_block = INT_BLOCK_IGU;
  8782. /* do not allow device reset during IGU info preocessing */
  8783. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8784. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  8785. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8786. int tout = 5000;
  8787. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  8788. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  8789. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  8790. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  8791. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8792. tout--;
  8793. usleep_range(1000, 1000);
  8794. }
  8795. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8796. dev_err(&bp->pdev->dev,
  8797. "FORCING Normal Mode failed!!!\n");
  8798. return -EPERM;
  8799. }
  8800. }
  8801. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8802. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  8803. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  8804. } else
  8805. BNX2X_DEV_INFO("IGU Normal Mode\n");
  8806. bnx2x_get_igu_cam_info(bp);
  8807. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8808. }
  8809. /*
  8810. * set base FW non-default (fast path) status block id, this value is
  8811. * used to initialize the fw_sb_id saved on the fp/queue structure to
  8812. * determine the id used by the FW.
  8813. */
  8814. if (CHIP_IS_E1x(bp))
  8815. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  8816. else /*
  8817. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  8818. * the same queue are indicated on the same IGU SB). So we prefer
  8819. * FW and IGU SBs to be the same value.
  8820. */
  8821. bp->base_fw_ndsb = bp->igu_base_sb;
  8822. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  8823. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  8824. bp->igu_sb_cnt, bp->base_fw_ndsb);
  8825. /*
  8826. * Initialize MF configuration
  8827. */
  8828. bp->mf_ov = 0;
  8829. bp->mf_mode = 0;
  8830. vn = BP_VN(bp);
  8831. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  8832. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  8833. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  8834. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  8835. if (SHMEM2_HAS(bp, mf_cfg_addr))
  8836. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  8837. else
  8838. bp->common.mf_cfg_base = bp->common.shmem_base +
  8839. offsetof(struct shmem_region, func_mb) +
  8840. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  8841. /*
  8842. * get mf configuration:
  8843. * 1. existence of MF configuration
  8844. * 2. MAC address must be legal (check only upper bytes)
  8845. * for Switch-Independent mode;
  8846. * OVLAN must be legal for Switch-Dependent mode
  8847. * 3. SF_MODE configures specific MF mode
  8848. */
  8849. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8850. /* get mf configuration */
  8851. val = SHMEM_RD(bp,
  8852. dev_info.shared_feature_config.config);
  8853. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  8854. switch (val) {
  8855. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  8856. val = MF_CFG_RD(bp, func_mf_config[func].
  8857. mac_upper);
  8858. /* check for legal mac (upper bytes)*/
  8859. if (val != 0xffff) {
  8860. bp->mf_mode = MULTI_FUNCTION_SI;
  8861. bp->mf_config[vn] = MF_CFG_RD(bp,
  8862. func_mf_config[func].config);
  8863. } else
  8864. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  8865. break;
  8866. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  8867. if ((!CHIP_IS_E1x(bp)) &&
  8868. (MF_CFG_RD(bp, func_mf_config[func].
  8869. mac_upper) != 0xffff) &&
  8870. (SHMEM2_HAS(bp,
  8871. afex_driver_support))) {
  8872. bp->mf_mode = MULTI_FUNCTION_AFEX;
  8873. bp->mf_config[vn] = MF_CFG_RD(bp,
  8874. func_mf_config[func].config);
  8875. } else {
  8876. BNX2X_DEV_INFO("can not configure afex mode\n");
  8877. }
  8878. break;
  8879. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  8880. /* get OV configuration */
  8881. val = MF_CFG_RD(bp,
  8882. func_mf_config[FUNC_0].e1hov_tag);
  8883. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  8884. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8885. bp->mf_mode = MULTI_FUNCTION_SD;
  8886. bp->mf_config[vn] = MF_CFG_RD(bp,
  8887. func_mf_config[func].config);
  8888. } else
  8889. BNX2X_DEV_INFO("illegal OV for SD\n");
  8890. break;
  8891. default:
  8892. /* Unknown configuration: reset mf_config */
  8893. bp->mf_config[vn] = 0;
  8894. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  8895. }
  8896. }
  8897. BNX2X_DEV_INFO("%s function mode\n",
  8898. IS_MF(bp) ? "multi" : "single");
  8899. switch (bp->mf_mode) {
  8900. case MULTI_FUNCTION_SD:
  8901. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  8902. FUNC_MF_CFG_E1HOV_TAG_MASK;
  8903. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8904. bp->mf_ov = val;
  8905. bp->path_has_ovlan = true;
  8906. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  8907. func, bp->mf_ov, bp->mf_ov);
  8908. } else {
  8909. dev_err(&bp->pdev->dev,
  8910. "No valid MF OV for func %d, aborting\n",
  8911. func);
  8912. return -EPERM;
  8913. }
  8914. break;
  8915. case MULTI_FUNCTION_AFEX:
  8916. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  8917. break;
  8918. case MULTI_FUNCTION_SI:
  8919. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  8920. func);
  8921. break;
  8922. default:
  8923. if (vn) {
  8924. dev_err(&bp->pdev->dev,
  8925. "VN %d is in a single function mode, aborting\n",
  8926. vn);
  8927. return -EPERM;
  8928. }
  8929. break;
  8930. }
  8931. /* check if other port on the path needs ovlan:
  8932. * Since MF configuration is shared between ports
  8933. * Possible mixed modes are only
  8934. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  8935. */
  8936. if (CHIP_MODE_IS_4_PORT(bp) &&
  8937. !bp->path_has_ovlan &&
  8938. !IS_MF(bp) &&
  8939. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8940. u8 other_port = !BP_PORT(bp);
  8941. u8 other_func = BP_PATH(bp) + 2*other_port;
  8942. val = MF_CFG_RD(bp,
  8943. func_mf_config[other_func].e1hov_tag);
  8944. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  8945. bp->path_has_ovlan = true;
  8946. }
  8947. }
  8948. /* adjust igu_sb_cnt to MF for E1x */
  8949. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  8950. bp->igu_sb_cnt /= E1HVN_MAX;
  8951. /* port info */
  8952. bnx2x_get_port_hwinfo(bp);
  8953. /* Get MAC addresses */
  8954. bnx2x_get_mac_hwinfo(bp);
  8955. bnx2x_get_cnic_info(bp);
  8956. return rc;
  8957. }
  8958. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  8959. {
  8960. int cnt, i, block_end, rodi;
  8961. char vpd_start[BNX2X_VPD_LEN+1];
  8962. char str_id_reg[VENDOR_ID_LEN+1];
  8963. char str_id_cap[VENDOR_ID_LEN+1];
  8964. char *vpd_data;
  8965. char *vpd_extended_data = NULL;
  8966. u8 len;
  8967. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  8968. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  8969. if (cnt < BNX2X_VPD_LEN)
  8970. goto out_not_found;
  8971. /* VPD RO tag should be first tag after identifier string, hence
  8972. * we should be able to find it in first BNX2X_VPD_LEN chars
  8973. */
  8974. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  8975. PCI_VPD_LRDT_RO_DATA);
  8976. if (i < 0)
  8977. goto out_not_found;
  8978. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  8979. pci_vpd_lrdt_size(&vpd_start[i]);
  8980. i += PCI_VPD_LRDT_TAG_SIZE;
  8981. if (block_end > BNX2X_VPD_LEN) {
  8982. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  8983. if (vpd_extended_data == NULL)
  8984. goto out_not_found;
  8985. /* read rest of vpd image into vpd_extended_data */
  8986. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  8987. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  8988. block_end - BNX2X_VPD_LEN,
  8989. vpd_extended_data + BNX2X_VPD_LEN);
  8990. if (cnt < (block_end - BNX2X_VPD_LEN))
  8991. goto out_not_found;
  8992. vpd_data = vpd_extended_data;
  8993. } else
  8994. vpd_data = vpd_start;
  8995. /* now vpd_data holds full vpd content in both cases */
  8996. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8997. PCI_VPD_RO_KEYWORD_MFR_ID);
  8998. if (rodi < 0)
  8999. goto out_not_found;
  9000. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9001. if (len != VENDOR_ID_LEN)
  9002. goto out_not_found;
  9003. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9004. /* vendor specific info */
  9005. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9006. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9007. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9008. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9009. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9010. PCI_VPD_RO_KEYWORD_VENDOR0);
  9011. if (rodi >= 0) {
  9012. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9013. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9014. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9015. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9016. bp->fw_ver[len] = ' ';
  9017. }
  9018. }
  9019. kfree(vpd_extended_data);
  9020. return;
  9021. }
  9022. out_not_found:
  9023. kfree(vpd_extended_data);
  9024. return;
  9025. }
  9026. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9027. {
  9028. u32 flags = 0;
  9029. if (CHIP_REV_IS_FPGA(bp))
  9030. SET_FLAGS(flags, MODE_FPGA);
  9031. else if (CHIP_REV_IS_EMUL(bp))
  9032. SET_FLAGS(flags, MODE_EMUL);
  9033. else
  9034. SET_FLAGS(flags, MODE_ASIC);
  9035. if (CHIP_MODE_IS_4_PORT(bp))
  9036. SET_FLAGS(flags, MODE_PORT4);
  9037. else
  9038. SET_FLAGS(flags, MODE_PORT2);
  9039. if (CHIP_IS_E2(bp))
  9040. SET_FLAGS(flags, MODE_E2);
  9041. else if (CHIP_IS_E3(bp)) {
  9042. SET_FLAGS(flags, MODE_E3);
  9043. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9044. SET_FLAGS(flags, MODE_E3_A0);
  9045. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9046. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9047. }
  9048. if (IS_MF(bp)) {
  9049. SET_FLAGS(flags, MODE_MF);
  9050. switch (bp->mf_mode) {
  9051. case MULTI_FUNCTION_SD:
  9052. SET_FLAGS(flags, MODE_MF_SD);
  9053. break;
  9054. case MULTI_FUNCTION_SI:
  9055. SET_FLAGS(flags, MODE_MF_SI);
  9056. break;
  9057. case MULTI_FUNCTION_AFEX:
  9058. SET_FLAGS(flags, MODE_MF_AFEX);
  9059. break;
  9060. }
  9061. } else
  9062. SET_FLAGS(flags, MODE_SF);
  9063. #if defined(__LITTLE_ENDIAN)
  9064. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9065. #else /*(__BIG_ENDIAN)*/
  9066. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9067. #endif
  9068. INIT_MODE_FLAGS(bp) = flags;
  9069. }
  9070. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  9071. {
  9072. int func;
  9073. int rc;
  9074. mutex_init(&bp->port.phy_mutex);
  9075. mutex_init(&bp->fw_mb_mutex);
  9076. spin_lock_init(&bp->stats_lock);
  9077. #ifdef BCM_CNIC
  9078. mutex_init(&bp->cnic_mutex);
  9079. #endif
  9080. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9081. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9082. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9083. rc = bnx2x_get_hwinfo(bp);
  9084. if (rc)
  9085. return rc;
  9086. bnx2x_set_modes_bitmap(bp);
  9087. rc = bnx2x_alloc_mem_bp(bp);
  9088. if (rc)
  9089. return rc;
  9090. bnx2x_read_fwinfo(bp);
  9091. func = BP_FUNC(bp);
  9092. /* need to reset chip if undi was active */
  9093. if (!BP_NOMCP(bp)) {
  9094. /* init fw_seq */
  9095. bp->fw_seq =
  9096. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9097. DRV_MSG_SEQ_NUMBER_MASK;
  9098. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9099. bnx2x_prev_unload(bp);
  9100. }
  9101. if (CHIP_REV_IS_FPGA(bp))
  9102. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9103. if (BP_NOMCP(bp) && (func == 0))
  9104. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9105. bp->disable_tpa = disable_tpa;
  9106. #ifdef BCM_CNIC
  9107. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9108. #endif
  9109. /* Set TPA flags */
  9110. if (bp->disable_tpa) {
  9111. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9112. bp->dev->features &= ~NETIF_F_LRO;
  9113. } else {
  9114. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9115. bp->dev->features |= NETIF_F_LRO;
  9116. }
  9117. if (CHIP_IS_E1(bp))
  9118. bp->dropless_fc = 0;
  9119. else
  9120. bp->dropless_fc = dropless_fc;
  9121. bp->mrrs = mrrs;
  9122. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9123. /* make sure that the numbers are in the right granularity */
  9124. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9125. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9126. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9127. init_timer(&bp->timer);
  9128. bp->timer.expires = jiffies + bp->current_interval;
  9129. bp->timer.data = (unsigned long) bp;
  9130. bp->timer.function = bnx2x_timer;
  9131. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9132. bnx2x_dcbx_init_params(bp);
  9133. #ifdef BCM_CNIC
  9134. if (CHIP_IS_E1x(bp))
  9135. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9136. else
  9137. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9138. #endif
  9139. /* multiple tx priority */
  9140. if (CHIP_IS_E1x(bp))
  9141. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9142. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9143. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9144. if (CHIP_IS_E3B0(bp))
  9145. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9146. return rc;
  9147. }
  9148. /****************************************************************************
  9149. * General service functions
  9150. ****************************************************************************/
  9151. /*
  9152. * net_device service functions
  9153. */
  9154. /* called with rtnl_lock */
  9155. static int bnx2x_open(struct net_device *dev)
  9156. {
  9157. struct bnx2x *bp = netdev_priv(dev);
  9158. bool global = false;
  9159. int other_engine = BP_PATH(bp) ? 0 : 1;
  9160. bool other_load_status, load_status;
  9161. bp->stats_init = true;
  9162. netif_carrier_off(dev);
  9163. bnx2x_set_power_state(bp, PCI_D0);
  9164. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9165. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9166. /*
  9167. * If parity had happen during the unload, then attentions
  9168. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9169. * want the first function loaded on the current engine to
  9170. * complete the recovery.
  9171. */
  9172. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9173. bnx2x_chk_parity_attn(bp, &global, true))
  9174. do {
  9175. /*
  9176. * If there are attentions and they are in a global
  9177. * blocks, set the GLOBAL_RESET bit regardless whether
  9178. * it will be this function that will complete the
  9179. * recovery or not.
  9180. */
  9181. if (global)
  9182. bnx2x_set_reset_global(bp);
  9183. /*
  9184. * Only the first function on the current engine should
  9185. * try to recover in open. In case of attentions in
  9186. * global blocks only the first in the chip should try
  9187. * to recover.
  9188. */
  9189. if ((!load_status &&
  9190. (!global || !other_load_status)) &&
  9191. bnx2x_trylock_leader_lock(bp) &&
  9192. !bnx2x_leader_reset(bp)) {
  9193. netdev_info(bp->dev, "Recovered in open\n");
  9194. break;
  9195. }
  9196. /* recovery has failed... */
  9197. bnx2x_set_power_state(bp, PCI_D3hot);
  9198. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9199. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9200. "If you still see this message after a few retries then power cycle is required.\n");
  9201. return -EAGAIN;
  9202. } while (0);
  9203. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9204. return bnx2x_nic_load(bp, LOAD_OPEN);
  9205. }
  9206. /* called with rtnl_lock */
  9207. static int bnx2x_close(struct net_device *dev)
  9208. {
  9209. struct bnx2x *bp = netdev_priv(dev);
  9210. /* Unload the driver, release IRQs */
  9211. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  9212. /* Power off */
  9213. bnx2x_set_power_state(bp, PCI_D3hot);
  9214. return 0;
  9215. }
  9216. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9217. struct bnx2x_mcast_ramrod_params *p)
  9218. {
  9219. int mc_count = netdev_mc_count(bp->dev);
  9220. struct bnx2x_mcast_list_elem *mc_mac =
  9221. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9222. struct netdev_hw_addr *ha;
  9223. if (!mc_mac)
  9224. return -ENOMEM;
  9225. INIT_LIST_HEAD(&p->mcast_list);
  9226. netdev_for_each_mc_addr(ha, bp->dev) {
  9227. mc_mac->mac = bnx2x_mc_addr(ha);
  9228. list_add_tail(&mc_mac->link, &p->mcast_list);
  9229. mc_mac++;
  9230. }
  9231. p->mcast_list_len = mc_count;
  9232. return 0;
  9233. }
  9234. static void bnx2x_free_mcast_macs_list(
  9235. struct bnx2x_mcast_ramrod_params *p)
  9236. {
  9237. struct bnx2x_mcast_list_elem *mc_mac =
  9238. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9239. link);
  9240. WARN_ON(!mc_mac);
  9241. kfree(mc_mac);
  9242. }
  9243. /**
  9244. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9245. *
  9246. * @bp: driver handle
  9247. *
  9248. * We will use zero (0) as a MAC type for these MACs.
  9249. */
  9250. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9251. {
  9252. int rc;
  9253. struct net_device *dev = bp->dev;
  9254. struct netdev_hw_addr *ha;
  9255. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9256. unsigned long ramrod_flags = 0;
  9257. /* First schedule a cleanup up of old configuration */
  9258. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9259. if (rc < 0) {
  9260. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9261. return rc;
  9262. }
  9263. netdev_for_each_uc_addr(ha, dev) {
  9264. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9265. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9266. if (rc < 0) {
  9267. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9268. rc);
  9269. return rc;
  9270. }
  9271. }
  9272. /* Execute the pending commands */
  9273. __set_bit(RAMROD_CONT, &ramrod_flags);
  9274. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9275. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9276. }
  9277. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9278. {
  9279. struct net_device *dev = bp->dev;
  9280. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9281. int rc = 0;
  9282. rparam.mcast_obj = &bp->mcast_obj;
  9283. /* first, clear all configured multicast MACs */
  9284. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9285. if (rc < 0) {
  9286. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9287. return rc;
  9288. }
  9289. /* then, configure a new MACs list */
  9290. if (netdev_mc_count(dev)) {
  9291. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9292. if (rc) {
  9293. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9294. rc);
  9295. return rc;
  9296. }
  9297. /* Now add the new MACs */
  9298. rc = bnx2x_config_mcast(bp, &rparam,
  9299. BNX2X_MCAST_CMD_ADD);
  9300. if (rc < 0)
  9301. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9302. rc);
  9303. bnx2x_free_mcast_macs_list(&rparam);
  9304. }
  9305. return rc;
  9306. }
  9307. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9308. void bnx2x_set_rx_mode(struct net_device *dev)
  9309. {
  9310. struct bnx2x *bp = netdev_priv(dev);
  9311. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9312. if (bp->state != BNX2X_STATE_OPEN) {
  9313. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9314. return;
  9315. }
  9316. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9317. if (dev->flags & IFF_PROMISC)
  9318. rx_mode = BNX2X_RX_MODE_PROMISC;
  9319. else if ((dev->flags & IFF_ALLMULTI) ||
  9320. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9321. CHIP_IS_E1(bp)))
  9322. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9323. else {
  9324. /* some multicasts */
  9325. if (bnx2x_set_mc_list(bp) < 0)
  9326. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9327. if (bnx2x_set_uc_list(bp) < 0)
  9328. rx_mode = BNX2X_RX_MODE_PROMISC;
  9329. }
  9330. bp->rx_mode = rx_mode;
  9331. #ifdef BCM_CNIC
  9332. /* handle ISCSI SD mode */
  9333. if (IS_MF_ISCSI_SD(bp))
  9334. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9335. #endif
  9336. /* Schedule the rx_mode command */
  9337. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9338. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9339. return;
  9340. }
  9341. bnx2x_set_storm_rx_mode(bp);
  9342. }
  9343. /* called with rtnl_lock */
  9344. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9345. int devad, u16 addr)
  9346. {
  9347. struct bnx2x *bp = netdev_priv(netdev);
  9348. u16 value;
  9349. int rc;
  9350. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9351. prtad, devad, addr);
  9352. /* The HW expects different devad if CL22 is used */
  9353. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9354. bnx2x_acquire_phy_lock(bp);
  9355. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9356. bnx2x_release_phy_lock(bp);
  9357. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9358. if (!rc)
  9359. rc = value;
  9360. return rc;
  9361. }
  9362. /* called with rtnl_lock */
  9363. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9364. u16 addr, u16 value)
  9365. {
  9366. struct bnx2x *bp = netdev_priv(netdev);
  9367. int rc;
  9368. DP(NETIF_MSG_LINK,
  9369. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9370. prtad, devad, addr, value);
  9371. /* The HW expects different devad if CL22 is used */
  9372. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9373. bnx2x_acquire_phy_lock(bp);
  9374. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9375. bnx2x_release_phy_lock(bp);
  9376. return rc;
  9377. }
  9378. /* called with rtnl_lock */
  9379. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9380. {
  9381. struct bnx2x *bp = netdev_priv(dev);
  9382. struct mii_ioctl_data *mdio = if_mii(ifr);
  9383. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9384. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9385. if (!netif_running(dev))
  9386. return -EAGAIN;
  9387. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9388. }
  9389. #ifdef CONFIG_NET_POLL_CONTROLLER
  9390. static void poll_bnx2x(struct net_device *dev)
  9391. {
  9392. struct bnx2x *bp = netdev_priv(dev);
  9393. disable_irq(bp->pdev->irq);
  9394. bnx2x_interrupt(bp->pdev->irq, dev);
  9395. enable_irq(bp->pdev->irq);
  9396. }
  9397. #endif
  9398. static int bnx2x_validate_addr(struct net_device *dev)
  9399. {
  9400. struct bnx2x *bp = netdev_priv(dev);
  9401. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9402. BNX2X_ERR("Non-valid Ethernet address\n");
  9403. return -EADDRNOTAVAIL;
  9404. }
  9405. return 0;
  9406. }
  9407. static const struct net_device_ops bnx2x_netdev_ops = {
  9408. .ndo_open = bnx2x_open,
  9409. .ndo_stop = bnx2x_close,
  9410. .ndo_start_xmit = bnx2x_start_xmit,
  9411. .ndo_select_queue = bnx2x_select_queue,
  9412. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9413. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9414. .ndo_validate_addr = bnx2x_validate_addr,
  9415. .ndo_do_ioctl = bnx2x_ioctl,
  9416. .ndo_change_mtu = bnx2x_change_mtu,
  9417. .ndo_fix_features = bnx2x_fix_features,
  9418. .ndo_set_features = bnx2x_set_features,
  9419. .ndo_tx_timeout = bnx2x_tx_timeout,
  9420. #ifdef CONFIG_NET_POLL_CONTROLLER
  9421. .ndo_poll_controller = poll_bnx2x,
  9422. #endif
  9423. .ndo_setup_tc = bnx2x_setup_tc,
  9424. #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
  9425. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9426. #endif
  9427. };
  9428. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9429. {
  9430. struct device *dev = &bp->pdev->dev;
  9431. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9432. bp->flags |= USING_DAC_FLAG;
  9433. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9434. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9435. return -EIO;
  9436. }
  9437. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9438. dev_err(dev, "System does not support DMA, aborting\n");
  9439. return -EIO;
  9440. }
  9441. return 0;
  9442. }
  9443. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  9444. struct net_device *dev,
  9445. unsigned long board_type)
  9446. {
  9447. struct bnx2x *bp;
  9448. int rc;
  9449. u32 pci_cfg_dword;
  9450. bool chip_is_e1x = (board_type == BCM57710 ||
  9451. board_type == BCM57711 ||
  9452. board_type == BCM57711E);
  9453. SET_NETDEV_DEV(dev, &pdev->dev);
  9454. bp = netdev_priv(dev);
  9455. bp->dev = dev;
  9456. bp->pdev = pdev;
  9457. bp->flags = 0;
  9458. rc = pci_enable_device(pdev);
  9459. if (rc) {
  9460. dev_err(&bp->pdev->dev,
  9461. "Cannot enable PCI device, aborting\n");
  9462. goto err_out;
  9463. }
  9464. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9465. dev_err(&bp->pdev->dev,
  9466. "Cannot find PCI device base address, aborting\n");
  9467. rc = -ENODEV;
  9468. goto err_out_disable;
  9469. }
  9470. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9471. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  9472. " base address, aborting\n");
  9473. rc = -ENODEV;
  9474. goto err_out_disable;
  9475. }
  9476. if (atomic_read(&pdev->enable_cnt) == 1) {
  9477. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9478. if (rc) {
  9479. dev_err(&bp->pdev->dev,
  9480. "Cannot obtain PCI resources, aborting\n");
  9481. goto err_out_disable;
  9482. }
  9483. pci_set_master(pdev);
  9484. pci_save_state(pdev);
  9485. }
  9486. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9487. if (bp->pm_cap == 0) {
  9488. dev_err(&bp->pdev->dev,
  9489. "Cannot find power management capability, aborting\n");
  9490. rc = -EIO;
  9491. goto err_out_release;
  9492. }
  9493. if (!pci_is_pcie(pdev)) {
  9494. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9495. rc = -EIO;
  9496. goto err_out_release;
  9497. }
  9498. rc = bnx2x_set_coherency_mask(bp);
  9499. if (rc)
  9500. goto err_out_release;
  9501. dev->mem_start = pci_resource_start(pdev, 0);
  9502. dev->base_addr = dev->mem_start;
  9503. dev->mem_end = pci_resource_end(pdev, 0);
  9504. dev->irq = pdev->irq;
  9505. bp->regview = pci_ioremap_bar(pdev, 0);
  9506. if (!bp->regview) {
  9507. dev_err(&bp->pdev->dev,
  9508. "Cannot map register space, aborting\n");
  9509. rc = -ENOMEM;
  9510. goto err_out_release;
  9511. }
  9512. /* In E1/E1H use pci device function given by kernel.
  9513. * In E2/E3 read physical function from ME register since these chips
  9514. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9515. * (depending on hypervisor).
  9516. */
  9517. if (chip_is_e1x)
  9518. bp->pf_num = PCI_FUNC(pdev->devfn);
  9519. else {/* chip is E2/3*/
  9520. pci_read_config_dword(bp->pdev,
  9521. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9522. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9523. ME_REG_ABS_PF_NUM_SHIFT);
  9524. }
  9525. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9526. bnx2x_set_power_state(bp, PCI_D0);
  9527. /* clean indirect addresses */
  9528. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9529. PCICFG_VENDOR_ID_OFFSET);
  9530. /*
  9531. * Clean the following indirect addresses for all functions since it
  9532. * is not used by the driver.
  9533. */
  9534. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9535. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9536. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9537. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9538. if (chip_is_e1x) {
  9539. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9540. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9541. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9542. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9543. }
  9544. /*
  9545. * Enable internal target-read (in case we are probed after PF FLR).
  9546. * Must be done prior to any BAR read access. Only for 57712 and up
  9547. */
  9548. if (!chip_is_e1x)
  9549. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9550. /* Reset the load counter */
  9551. bnx2x_clear_load_status(bp);
  9552. dev->watchdog_timeo = TX_TIMEOUT;
  9553. dev->netdev_ops = &bnx2x_netdev_ops;
  9554. bnx2x_set_ethtool_ops(dev);
  9555. dev->priv_flags |= IFF_UNICAST_FLT;
  9556. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9557. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9558. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9559. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9560. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9561. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9562. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9563. if (bp->flags & USING_DAC_FLAG)
  9564. dev->features |= NETIF_F_HIGHDMA;
  9565. /* Add Loopback capability to the device */
  9566. dev->hw_features |= NETIF_F_LOOPBACK;
  9567. #ifdef BCM_DCBNL
  9568. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9569. #endif
  9570. /* get_port_hwinfo() will set prtad and mmds properly */
  9571. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9572. bp->mdio.mmds = 0;
  9573. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9574. bp->mdio.dev = dev;
  9575. bp->mdio.mdio_read = bnx2x_mdio_read;
  9576. bp->mdio.mdio_write = bnx2x_mdio_write;
  9577. return 0;
  9578. err_out_release:
  9579. if (atomic_read(&pdev->enable_cnt) == 1)
  9580. pci_release_regions(pdev);
  9581. err_out_disable:
  9582. pci_disable_device(pdev);
  9583. pci_set_drvdata(pdev, NULL);
  9584. err_out:
  9585. return rc;
  9586. }
  9587. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  9588. int *width, int *speed)
  9589. {
  9590. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9591. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9592. /* return value of 1=2.5GHz 2=5GHz */
  9593. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9594. }
  9595. static int bnx2x_check_firmware(struct bnx2x *bp)
  9596. {
  9597. const struct firmware *firmware = bp->firmware;
  9598. struct bnx2x_fw_file_hdr *fw_hdr;
  9599. struct bnx2x_fw_file_section *sections;
  9600. u32 offset, len, num_ops;
  9601. u16 *ops_offsets;
  9602. int i;
  9603. const u8 *fw_ver;
  9604. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9605. BNX2X_ERR("Wrong FW size\n");
  9606. return -EINVAL;
  9607. }
  9608. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9609. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9610. /* Make sure none of the offsets and sizes make us read beyond
  9611. * the end of the firmware data */
  9612. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9613. offset = be32_to_cpu(sections[i].offset);
  9614. len = be32_to_cpu(sections[i].len);
  9615. if (offset + len > firmware->size) {
  9616. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9617. return -EINVAL;
  9618. }
  9619. }
  9620. /* Likewise for the init_ops offsets */
  9621. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9622. ops_offsets = (u16 *)(firmware->data + offset);
  9623. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9624. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9625. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9626. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  9627. return -EINVAL;
  9628. }
  9629. }
  9630. /* Check FW version */
  9631. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9632. fw_ver = firmware->data + offset;
  9633. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9634. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9635. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9636. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9637. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  9638. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  9639. BCM_5710_FW_MAJOR_VERSION,
  9640. BCM_5710_FW_MINOR_VERSION,
  9641. BCM_5710_FW_REVISION_VERSION,
  9642. BCM_5710_FW_ENGINEERING_VERSION);
  9643. return -EINVAL;
  9644. }
  9645. return 0;
  9646. }
  9647. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9648. {
  9649. const __be32 *source = (const __be32 *)_source;
  9650. u32 *target = (u32 *)_target;
  9651. u32 i;
  9652. for (i = 0; i < n/4; i++)
  9653. target[i] = be32_to_cpu(source[i]);
  9654. }
  9655. /*
  9656. Ops array is stored in the following format:
  9657. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9658. */
  9659. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9660. {
  9661. const __be32 *source = (const __be32 *)_source;
  9662. struct raw_op *target = (struct raw_op *)_target;
  9663. u32 i, j, tmp;
  9664. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9665. tmp = be32_to_cpu(source[j]);
  9666. target[i].op = (tmp >> 24) & 0xff;
  9667. target[i].offset = tmp & 0xffffff;
  9668. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9669. }
  9670. }
  9671. /* IRO array is stored in the following format:
  9672. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9673. */
  9674. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9675. {
  9676. const __be32 *source = (const __be32 *)_source;
  9677. struct iro *target = (struct iro *)_target;
  9678. u32 i, j, tmp;
  9679. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9680. target[i].base = be32_to_cpu(source[j]);
  9681. j++;
  9682. tmp = be32_to_cpu(source[j]);
  9683. target[i].m1 = (tmp >> 16) & 0xffff;
  9684. target[i].m2 = tmp & 0xffff;
  9685. j++;
  9686. tmp = be32_to_cpu(source[j]);
  9687. target[i].m3 = (tmp >> 16) & 0xffff;
  9688. target[i].size = tmp & 0xffff;
  9689. j++;
  9690. }
  9691. }
  9692. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9693. {
  9694. const __be16 *source = (const __be16 *)_source;
  9695. u16 *target = (u16 *)_target;
  9696. u32 i;
  9697. for (i = 0; i < n/2; i++)
  9698. target[i] = be16_to_cpu(source[i]);
  9699. }
  9700. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9701. do { \
  9702. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9703. bp->arr = kmalloc(len, GFP_KERNEL); \
  9704. if (!bp->arr) \
  9705. goto lbl; \
  9706. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9707. (u8 *)bp->arr, len); \
  9708. } while (0)
  9709. static int bnx2x_init_firmware(struct bnx2x *bp)
  9710. {
  9711. const char *fw_file_name;
  9712. struct bnx2x_fw_file_hdr *fw_hdr;
  9713. int rc;
  9714. if (bp->firmware)
  9715. return 0;
  9716. if (CHIP_IS_E1(bp))
  9717. fw_file_name = FW_FILE_NAME_E1;
  9718. else if (CHIP_IS_E1H(bp))
  9719. fw_file_name = FW_FILE_NAME_E1H;
  9720. else if (!CHIP_IS_E1x(bp))
  9721. fw_file_name = FW_FILE_NAME_E2;
  9722. else {
  9723. BNX2X_ERR("Unsupported chip revision\n");
  9724. return -EINVAL;
  9725. }
  9726. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9727. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9728. if (rc) {
  9729. BNX2X_ERR("Can't load firmware file %s\n",
  9730. fw_file_name);
  9731. goto request_firmware_exit;
  9732. }
  9733. rc = bnx2x_check_firmware(bp);
  9734. if (rc) {
  9735. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9736. goto request_firmware_exit;
  9737. }
  9738. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  9739. /* Initialize the pointers to the init arrays */
  9740. /* Blob */
  9741. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  9742. /* Opcodes */
  9743. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  9744. /* Offsets */
  9745. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  9746. be16_to_cpu_n);
  9747. /* STORMs firmware */
  9748. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9749. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  9750. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  9751. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  9752. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9753. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  9754. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  9755. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  9756. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9757. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  9758. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  9759. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  9760. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9761. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  9762. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  9763. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  9764. /* IRO */
  9765. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  9766. return 0;
  9767. iro_alloc_err:
  9768. kfree(bp->init_ops_offsets);
  9769. init_offsets_alloc_err:
  9770. kfree(bp->init_ops);
  9771. init_ops_alloc_err:
  9772. kfree(bp->init_data);
  9773. request_firmware_exit:
  9774. release_firmware(bp->firmware);
  9775. bp->firmware = NULL;
  9776. return rc;
  9777. }
  9778. static void bnx2x_release_firmware(struct bnx2x *bp)
  9779. {
  9780. kfree(bp->init_ops_offsets);
  9781. kfree(bp->init_ops);
  9782. kfree(bp->init_data);
  9783. release_firmware(bp->firmware);
  9784. bp->firmware = NULL;
  9785. }
  9786. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  9787. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  9788. .init_hw_cmn = bnx2x_init_hw_common,
  9789. .init_hw_port = bnx2x_init_hw_port,
  9790. .init_hw_func = bnx2x_init_hw_func,
  9791. .reset_hw_cmn = bnx2x_reset_common,
  9792. .reset_hw_port = bnx2x_reset_port,
  9793. .reset_hw_func = bnx2x_reset_func,
  9794. .gunzip_init = bnx2x_gunzip_init,
  9795. .gunzip_end = bnx2x_gunzip_end,
  9796. .init_fw = bnx2x_init_firmware,
  9797. .release_fw = bnx2x_release_firmware,
  9798. };
  9799. void bnx2x__init_func_obj(struct bnx2x *bp)
  9800. {
  9801. /* Prepare DMAE related driver resources */
  9802. bnx2x_setup_dmae(bp);
  9803. bnx2x_init_func_obj(bp, &bp->func_obj,
  9804. bnx2x_sp(bp, func_rdata),
  9805. bnx2x_sp_mapping(bp, func_rdata),
  9806. bnx2x_sp(bp, func_afex_rdata),
  9807. bnx2x_sp_mapping(bp, func_afex_rdata),
  9808. &bnx2x_func_sp_drv);
  9809. }
  9810. /* must be called after sriov-enable */
  9811. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  9812. {
  9813. int cid_count = BNX2X_L2_MAX_CID(bp);
  9814. #ifdef BCM_CNIC
  9815. cid_count += CNIC_CID_MAX;
  9816. #endif
  9817. return roundup(cid_count, QM_CID_ROUND);
  9818. }
  9819. /**
  9820. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  9821. *
  9822. * @dev: pci device
  9823. *
  9824. */
  9825. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
  9826. {
  9827. int pos;
  9828. u16 control;
  9829. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  9830. /*
  9831. * If MSI-X is not supported - return number of SBs needed to support
  9832. * one fast path queue: one FP queue + SB for CNIC
  9833. */
  9834. if (!pos)
  9835. return 1 + CNIC_PRESENT;
  9836. /*
  9837. * The value in the PCI configuration space is the index of the last
  9838. * entry, namely one less than the actual size of the table, which is
  9839. * exactly what we want to return from this function: number of all SBs
  9840. * without the default SB.
  9841. */
  9842. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  9843. return control & PCI_MSIX_FLAGS_QSIZE;
  9844. }
  9845. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  9846. const struct pci_device_id *ent)
  9847. {
  9848. struct net_device *dev = NULL;
  9849. struct bnx2x *bp;
  9850. int pcie_width, pcie_speed;
  9851. int rc, max_non_def_sbs;
  9852. int rx_count, tx_count, rss_count, doorbell_size;
  9853. /*
  9854. * An estimated maximum supported CoS number according to the chip
  9855. * version.
  9856. * We will try to roughly estimate the maximum number of CoSes this chip
  9857. * may support in order to minimize the memory allocated for Tx
  9858. * netdev_queue's. This number will be accurately calculated during the
  9859. * initialization of bp->max_cos based on the chip versions AND chip
  9860. * revision in the bnx2x_init_bp().
  9861. */
  9862. u8 max_cos_est = 0;
  9863. switch (ent->driver_data) {
  9864. case BCM57710:
  9865. case BCM57711:
  9866. case BCM57711E:
  9867. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  9868. break;
  9869. case BCM57712:
  9870. case BCM57712_MF:
  9871. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  9872. break;
  9873. case BCM57800:
  9874. case BCM57800_MF:
  9875. case BCM57810:
  9876. case BCM57810_MF:
  9877. case BCM57840_O:
  9878. case BCM57840_4_10:
  9879. case BCM57840_2_20:
  9880. case BCM57840_MFO:
  9881. case BCM57840_MF:
  9882. case BCM57811:
  9883. case BCM57811_MF:
  9884. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  9885. break;
  9886. default:
  9887. pr_err("Unknown board_type (%ld), aborting\n",
  9888. ent->driver_data);
  9889. return -ENODEV;
  9890. }
  9891. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
  9892. WARN_ON(!max_non_def_sbs);
  9893. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  9894. rss_count = max_non_def_sbs - CNIC_PRESENT;
  9895. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  9896. rx_count = rss_count + FCOE_PRESENT;
  9897. /*
  9898. * Maximum number of netdev Tx queues:
  9899. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  9900. */
  9901. tx_count = rss_count * max_cos_est + FCOE_PRESENT;
  9902. /* dev zeroed in init_etherdev */
  9903. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  9904. if (!dev)
  9905. return -ENOMEM;
  9906. bp = netdev_priv(dev);
  9907. bp->igu_sb_cnt = max_non_def_sbs;
  9908. bp->msg_enable = debug;
  9909. pci_set_drvdata(pdev, dev);
  9910. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  9911. if (rc < 0) {
  9912. free_netdev(dev);
  9913. return rc;
  9914. }
  9915. BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
  9916. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  9917. tx_count, rx_count);
  9918. rc = bnx2x_init_bp(bp);
  9919. if (rc)
  9920. goto init_one_exit;
  9921. /*
  9922. * Map doorbels here as we need the real value of bp->max_cos which
  9923. * is initialized in bnx2x_init_bp().
  9924. */
  9925. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  9926. if (doorbell_size > pci_resource_len(pdev, 2)) {
  9927. dev_err(&bp->pdev->dev,
  9928. "Cannot map doorbells, bar size too small, aborting\n");
  9929. rc = -ENOMEM;
  9930. goto init_one_exit;
  9931. }
  9932. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  9933. doorbell_size);
  9934. if (!bp->doorbells) {
  9935. dev_err(&bp->pdev->dev,
  9936. "Cannot map doorbell space, aborting\n");
  9937. rc = -ENOMEM;
  9938. goto init_one_exit;
  9939. }
  9940. /* calc qm_cid_count */
  9941. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  9942. #ifdef BCM_CNIC
  9943. /* disable FCOE L2 queue for E1x */
  9944. if (CHIP_IS_E1x(bp))
  9945. bp->flags |= NO_FCOE_FLAG;
  9946. #endif
  9947. /* Set bp->num_queues for MSI-X mode*/
  9948. bnx2x_set_num_queues(bp);
  9949. /* Configure interrupt mode: try to enable MSI-X/MSI if
  9950. * needed.
  9951. */
  9952. bnx2x_set_int_mode(bp);
  9953. /* Add all NAPI objects */
  9954. bnx2x_add_all_napi(bp);
  9955. rc = register_netdev(dev);
  9956. if (rc) {
  9957. dev_err(&pdev->dev, "Cannot register net device\n");
  9958. goto init_one_exit;
  9959. }
  9960. #ifdef BCM_CNIC
  9961. if (!NO_FCOE(bp)) {
  9962. /* Add storage MAC address */
  9963. rtnl_lock();
  9964. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9965. rtnl_unlock();
  9966. }
  9967. #endif
  9968. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  9969. BNX2X_DEV_INFO(
  9970. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  9971. board_info[ent->driver_data].name,
  9972. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  9973. pcie_width,
  9974. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  9975. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  9976. "5GHz (Gen2)" : "2.5GHz",
  9977. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  9978. return 0;
  9979. init_one_exit:
  9980. if (bp->regview)
  9981. iounmap(bp->regview);
  9982. if (bp->doorbells)
  9983. iounmap(bp->doorbells);
  9984. free_netdev(dev);
  9985. if (atomic_read(&pdev->enable_cnt) == 1)
  9986. pci_release_regions(pdev);
  9987. pci_disable_device(pdev);
  9988. pci_set_drvdata(pdev, NULL);
  9989. return rc;
  9990. }
  9991. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  9992. {
  9993. struct net_device *dev = pci_get_drvdata(pdev);
  9994. struct bnx2x *bp;
  9995. if (!dev) {
  9996. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  9997. return;
  9998. }
  9999. bp = netdev_priv(dev);
  10000. #ifdef BCM_CNIC
  10001. /* Delete storage MAC address */
  10002. if (!NO_FCOE(bp)) {
  10003. rtnl_lock();
  10004. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10005. rtnl_unlock();
  10006. }
  10007. #endif
  10008. #ifdef BCM_DCBNL
  10009. /* Delete app tlvs from dcbnl */
  10010. bnx2x_dcbnl_update_applist(bp, true);
  10011. #endif
  10012. unregister_netdev(dev);
  10013. /* Delete all NAPI objects */
  10014. bnx2x_del_all_napi(bp);
  10015. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10016. bnx2x_set_power_state(bp, PCI_D0);
  10017. /* Disable MSI/MSI-X */
  10018. bnx2x_disable_msi(bp);
  10019. /* Power off */
  10020. bnx2x_set_power_state(bp, PCI_D3hot);
  10021. /* Make sure RESET task is not scheduled before continuing */
  10022. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10023. if (bp->regview)
  10024. iounmap(bp->regview);
  10025. if (bp->doorbells)
  10026. iounmap(bp->doorbells);
  10027. bnx2x_release_firmware(bp);
  10028. bnx2x_free_mem_bp(bp);
  10029. free_netdev(dev);
  10030. if (atomic_read(&pdev->enable_cnt) == 1)
  10031. pci_release_regions(pdev);
  10032. pci_disable_device(pdev);
  10033. pci_set_drvdata(pdev, NULL);
  10034. }
  10035. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10036. {
  10037. int i;
  10038. bp->state = BNX2X_STATE_ERROR;
  10039. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10040. #ifdef BCM_CNIC
  10041. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10042. #endif
  10043. /* Stop Tx */
  10044. bnx2x_tx_disable(bp);
  10045. bnx2x_netif_stop(bp, 0);
  10046. del_timer_sync(&bp->timer);
  10047. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10048. /* Release IRQs */
  10049. bnx2x_free_irq(bp);
  10050. /* Free SKBs, SGEs, TPA pool and driver internals */
  10051. bnx2x_free_skbs(bp);
  10052. for_each_rx_queue(bp, i)
  10053. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10054. bnx2x_free_mem(bp);
  10055. bp->state = BNX2X_STATE_CLOSED;
  10056. netif_carrier_off(bp->dev);
  10057. return 0;
  10058. }
  10059. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10060. {
  10061. u32 val;
  10062. mutex_init(&bp->port.phy_mutex);
  10063. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10064. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10065. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10066. BNX2X_ERR("BAD MCP validity signature\n");
  10067. }
  10068. /**
  10069. * bnx2x_io_error_detected - called when PCI error is detected
  10070. * @pdev: Pointer to PCI device
  10071. * @state: The current pci connection state
  10072. *
  10073. * This function is called after a PCI bus error affecting
  10074. * this device has been detected.
  10075. */
  10076. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10077. pci_channel_state_t state)
  10078. {
  10079. struct net_device *dev = pci_get_drvdata(pdev);
  10080. struct bnx2x *bp = netdev_priv(dev);
  10081. rtnl_lock();
  10082. netif_device_detach(dev);
  10083. if (state == pci_channel_io_perm_failure) {
  10084. rtnl_unlock();
  10085. return PCI_ERS_RESULT_DISCONNECT;
  10086. }
  10087. if (netif_running(dev))
  10088. bnx2x_eeh_nic_unload(bp);
  10089. pci_disable_device(pdev);
  10090. rtnl_unlock();
  10091. /* Request a slot reset */
  10092. return PCI_ERS_RESULT_NEED_RESET;
  10093. }
  10094. /**
  10095. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10096. * @pdev: Pointer to PCI device
  10097. *
  10098. * Restart the card from scratch, as if from a cold-boot.
  10099. */
  10100. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10101. {
  10102. struct net_device *dev = pci_get_drvdata(pdev);
  10103. struct bnx2x *bp = netdev_priv(dev);
  10104. rtnl_lock();
  10105. if (pci_enable_device(pdev)) {
  10106. dev_err(&pdev->dev,
  10107. "Cannot re-enable PCI device after reset\n");
  10108. rtnl_unlock();
  10109. return PCI_ERS_RESULT_DISCONNECT;
  10110. }
  10111. pci_set_master(pdev);
  10112. pci_restore_state(pdev);
  10113. if (netif_running(dev))
  10114. bnx2x_set_power_state(bp, PCI_D0);
  10115. rtnl_unlock();
  10116. return PCI_ERS_RESULT_RECOVERED;
  10117. }
  10118. /**
  10119. * bnx2x_io_resume - called when traffic can start flowing again
  10120. * @pdev: Pointer to PCI device
  10121. *
  10122. * This callback is called when the error recovery driver tells us that
  10123. * its OK to resume normal operation.
  10124. */
  10125. static void bnx2x_io_resume(struct pci_dev *pdev)
  10126. {
  10127. struct net_device *dev = pci_get_drvdata(pdev);
  10128. struct bnx2x *bp = netdev_priv(dev);
  10129. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10130. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10131. return;
  10132. }
  10133. rtnl_lock();
  10134. bnx2x_eeh_recover(bp);
  10135. if (netif_running(dev))
  10136. bnx2x_nic_load(bp, LOAD_NORMAL);
  10137. netif_device_attach(dev);
  10138. rtnl_unlock();
  10139. }
  10140. static struct pci_error_handlers bnx2x_err_handler = {
  10141. .error_detected = bnx2x_io_error_detected,
  10142. .slot_reset = bnx2x_io_slot_reset,
  10143. .resume = bnx2x_io_resume,
  10144. };
  10145. static struct pci_driver bnx2x_pci_driver = {
  10146. .name = DRV_MODULE_NAME,
  10147. .id_table = bnx2x_pci_tbl,
  10148. .probe = bnx2x_init_one,
  10149. .remove = __devexit_p(bnx2x_remove_one),
  10150. .suspend = bnx2x_suspend,
  10151. .resume = bnx2x_resume,
  10152. .err_handler = &bnx2x_err_handler,
  10153. };
  10154. static int __init bnx2x_init(void)
  10155. {
  10156. int ret;
  10157. pr_info("%s", version);
  10158. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10159. if (bnx2x_wq == NULL) {
  10160. pr_err("Cannot create workqueue\n");
  10161. return -ENOMEM;
  10162. }
  10163. ret = pci_register_driver(&bnx2x_pci_driver);
  10164. if (ret) {
  10165. pr_err("Cannot register driver\n");
  10166. destroy_workqueue(bnx2x_wq);
  10167. }
  10168. return ret;
  10169. }
  10170. static void __exit bnx2x_cleanup(void)
  10171. {
  10172. struct list_head *pos, *q;
  10173. pci_unregister_driver(&bnx2x_pci_driver);
  10174. destroy_workqueue(bnx2x_wq);
  10175. /* Free globablly allocated resources */
  10176. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10177. struct bnx2x_prev_path_list *tmp =
  10178. list_entry(pos, struct bnx2x_prev_path_list, list);
  10179. list_del(pos);
  10180. kfree(tmp);
  10181. }
  10182. }
  10183. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10184. {
  10185. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10186. }
  10187. module_init(bnx2x_init);
  10188. module_exit(bnx2x_cleanup);
  10189. #ifdef BCM_CNIC
  10190. /**
  10191. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10192. *
  10193. * @bp: driver handle
  10194. * @set: set or clear the CAM entry
  10195. *
  10196. * This function will wait until the ramdord completion returns.
  10197. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10198. */
  10199. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10200. {
  10201. unsigned long ramrod_flags = 0;
  10202. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10203. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10204. &bp->iscsi_l2_mac_obj, true,
  10205. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10206. }
  10207. /* count denotes the number of new completions we have seen */
  10208. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10209. {
  10210. struct eth_spe *spe;
  10211. int cxt_index, cxt_offset;
  10212. #ifdef BNX2X_STOP_ON_ERROR
  10213. if (unlikely(bp->panic))
  10214. return;
  10215. #endif
  10216. spin_lock_bh(&bp->spq_lock);
  10217. BUG_ON(bp->cnic_spq_pending < count);
  10218. bp->cnic_spq_pending -= count;
  10219. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10220. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10221. & SPE_HDR_CONN_TYPE) >>
  10222. SPE_HDR_CONN_TYPE_SHIFT;
  10223. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10224. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10225. /* Set validation for iSCSI L2 client before sending SETUP
  10226. * ramrod
  10227. */
  10228. if (type == ETH_CONNECTION_TYPE) {
  10229. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10230. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10231. ILT_PAGE_CIDS;
  10232. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10233. (cxt_index * ILT_PAGE_CIDS);
  10234. bnx2x_set_ctx_validation(bp,
  10235. &bp->context[cxt_index].
  10236. vcxt[cxt_offset].eth,
  10237. BNX2X_ISCSI_ETH_CID(bp));
  10238. }
  10239. }
  10240. /*
  10241. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10242. * and in the air. We also check that number of outstanding
  10243. * COMMON ramrods is not more than the EQ and SPQ can
  10244. * accommodate.
  10245. */
  10246. if (type == ETH_CONNECTION_TYPE) {
  10247. if (!atomic_read(&bp->cq_spq_left))
  10248. break;
  10249. else
  10250. atomic_dec(&bp->cq_spq_left);
  10251. } else if (type == NONE_CONNECTION_TYPE) {
  10252. if (!atomic_read(&bp->eq_spq_left))
  10253. break;
  10254. else
  10255. atomic_dec(&bp->eq_spq_left);
  10256. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10257. (type == FCOE_CONNECTION_TYPE)) {
  10258. if (bp->cnic_spq_pending >=
  10259. bp->cnic_eth_dev.max_kwqe_pending)
  10260. break;
  10261. else
  10262. bp->cnic_spq_pending++;
  10263. } else {
  10264. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10265. bnx2x_panic();
  10266. break;
  10267. }
  10268. spe = bnx2x_sp_get_next(bp);
  10269. *spe = *bp->cnic_kwq_cons;
  10270. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10271. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10272. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10273. bp->cnic_kwq_cons = bp->cnic_kwq;
  10274. else
  10275. bp->cnic_kwq_cons++;
  10276. }
  10277. bnx2x_sp_prod_update(bp);
  10278. spin_unlock_bh(&bp->spq_lock);
  10279. }
  10280. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10281. struct kwqe_16 *kwqes[], u32 count)
  10282. {
  10283. struct bnx2x *bp = netdev_priv(dev);
  10284. int i;
  10285. #ifdef BNX2X_STOP_ON_ERROR
  10286. if (unlikely(bp->panic)) {
  10287. BNX2X_ERR("Can't post to SP queue while panic\n");
  10288. return -EIO;
  10289. }
  10290. #endif
  10291. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10292. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10293. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10294. return -EAGAIN;
  10295. }
  10296. spin_lock_bh(&bp->spq_lock);
  10297. for (i = 0; i < count; i++) {
  10298. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10299. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10300. break;
  10301. *bp->cnic_kwq_prod = *spe;
  10302. bp->cnic_kwq_pending++;
  10303. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10304. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10305. spe->data.update_data_addr.hi,
  10306. spe->data.update_data_addr.lo,
  10307. bp->cnic_kwq_pending);
  10308. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10309. bp->cnic_kwq_prod = bp->cnic_kwq;
  10310. else
  10311. bp->cnic_kwq_prod++;
  10312. }
  10313. spin_unlock_bh(&bp->spq_lock);
  10314. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10315. bnx2x_cnic_sp_post(bp, 0);
  10316. return i;
  10317. }
  10318. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10319. {
  10320. struct cnic_ops *c_ops;
  10321. int rc = 0;
  10322. mutex_lock(&bp->cnic_mutex);
  10323. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10324. lockdep_is_held(&bp->cnic_mutex));
  10325. if (c_ops)
  10326. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10327. mutex_unlock(&bp->cnic_mutex);
  10328. return rc;
  10329. }
  10330. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10331. {
  10332. struct cnic_ops *c_ops;
  10333. int rc = 0;
  10334. rcu_read_lock();
  10335. c_ops = rcu_dereference(bp->cnic_ops);
  10336. if (c_ops)
  10337. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10338. rcu_read_unlock();
  10339. return rc;
  10340. }
  10341. /*
  10342. * for commands that have no data
  10343. */
  10344. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10345. {
  10346. struct cnic_ctl_info ctl = {0};
  10347. ctl.cmd = cmd;
  10348. return bnx2x_cnic_ctl_send(bp, &ctl);
  10349. }
  10350. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10351. {
  10352. struct cnic_ctl_info ctl = {0};
  10353. /* first we tell CNIC and only then we count this as a completion */
  10354. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10355. ctl.data.comp.cid = cid;
  10356. ctl.data.comp.error = err;
  10357. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10358. bnx2x_cnic_sp_post(bp, 0);
  10359. }
  10360. /* Called with netif_addr_lock_bh() taken.
  10361. * Sets an rx_mode config for an iSCSI ETH client.
  10362. * Doesn't block.
  10363. * Completion should be checked outside.
  10364. */
  10365. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10366. {
  10367. unsigned long accept_flags = 0, ramrod_flags = 0;
  10368. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10369. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10370. if (start) {
  10371. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10372. * because it's the only way for UIO Queue to accept
  10373. * multicasts (in non-promiscuous mode only one Queue per
  10374. * function will receive multicast packets (leading in our
  10375. * case).
  10376. */
  10377. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10378. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10379. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10380. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10381. /* Clear STOP_PENDING bit if START is requested */
  10382. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10383. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10384. } else
  10385. /* Clear START_PENDING bit if STOP is requested */
  10386. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10387. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10388. set_bit(sched_state, &bp->sp_state);
  10389. else {
  10390. __set_bit(RAMROD_RX, &ramrod_flags);
  10391. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10392. ramrod_flags);
  10393. }
  10394. }
  10395. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10396. {
  10397. struct bnx2x *bp = netdev_priv(dev);
  10398. int rc = 0;
  10399. switch (ctl->cmd) {
  10400. case DRV_CTL_CTXTBL_WR_CMD: {
  10401. u32 index = ctl->data.io.offset;
  10402. dma_addr_t addr = ctl->data.io.dma_addr;
  10403. bnx2x_ilt_wr(bp, index, addr);
  10404. break;
  10405. }
  10406. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10407. int count = ctl->data.credit.credit_count;
  10408. bnx2x_cnic_sp_post(bp, count);
  10409. break;
  10410. }
  10411. /* rtnl_lock is held. */
  10412. case DRV_CTL_START_L2_CMD: {
  10413. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10414. unsigned long sp_bits = 0;
  10415. /* Configure the iSCSI classification object */
  10416. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10417. cp->iscsi_l2_client_id,
  10418. cp->iscsi_l2_cid, BP_FUNC(bp),
  10419. bnx2x_sp(bp, mac_rdata),
  10420. bnx2x_sp_mapping(bp, mac_rdata),
  10421. BNX2X_FILTER_MAC_PENDING,
  10422. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10423. &bp->macs_pool);
  10424. /* Set iSCSI MAC address */
  10425. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10426. if (rc)
  10427. break;
  10428. mmiowb();
  10429. barrier();
  10430. /* Start accepting on iSCSI L2 ring */
  10431. netif_addr_lock_bh(dev);
  10432. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10433. netif_addr_unlock_bh(dev);
  10434. /* bits to wait on */
  10435. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10436. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10437. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10438. BNX2X_ERR("rx_mode completion timed out!\n");
  10439. break;
  10440. }
  10441. /* rtnl_lock is held. */
  10442. case DRV_CTL_STOP_L2_CMD: {
  10443. unsigned long sp_bits = 0;
  10444. /* Stop accepting on iSCSI L2 ring */
  10445. netif_addr_lock_bh(dev);
  10446. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10447. netif_addr_unlock_bh(dev);
  10448. /* bits to wait on */
  10449. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10450. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10451. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10452. BNX2X_ERR("rx_mode completion timed out!\n");
  10453. mmiowb();
  10454. barrier();
  10455. /* Unset iSCSI L2 MAC */
  10456. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10457. BNX2X_ISCSI_ETH_MAC, true);
  10458. break;
  10459. }
  10460. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10461. int count = ctl->data.credit.credit_count;
  10462. smp_mb__before_atomic_inc();
  10463. atomic_add(count, &bp->cq_spq_left);
  10464. smp_mb__after_atomic_inc();
  10465. break;
  10466. }
  10467. case DRV_CTL_ULP_REGISTER_CMD: {
  10468. int ulp_type = ctl->data.register_data.ulp_type;
  10469. if (CHIP_IS_E3(bp)) {
  10470. int idx = BP_FW_MB_IDX(bp);
  10471. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10472. int path = BP_PATH(bp);
  10473. int port = BP_PORT(bp);
  10474. int i;
  10475. u32 scratch_offset;
  10476. u32 *host_addr;
  10477. /* first write capability to shmem2 */
  10478. if (ulp_type == CNIC_ULP_ISCSI)
  10479. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10480. else if (ulp_type == CNIC_ULP_FCOE)
  10481. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10482. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10483. if ((ulp_type != CNIC_ULP_FCOE) ||
  10484. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  10485. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  10486. break;
  10487. /* if reached here - should write fcoe capabilities */
  10488. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  10489. if (!scratch_offset)
  10490. break;
  10491. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  10492. fcoe_features[path][port]);
  10493. host_addr = (u32 *) &(ctl->data.register_data.
  10494. fcoe_features);
  10495. for (i = 0; i < sizeof(struct fcoe_capabilities);
  10496. i += 4)
  10497. REG_WR(bp, scratch_offset + i,
  10498. *(host_addr + i/4));
  10499. }
  10500. break;
  10501. }
  10502. case DRV_CTL_ULP_UNREGISTER_CMD: {
  10503. int ulp_type = ctl->data.ulp_type;
  10504. if (CHIP_IS_E3(bp)) {
  10505. int idx = BP_FW_MB_IDX(bp);
  10506. u32 cap;
  10507. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10508. if (ulp_type == CNIC_ULP_ISCSI)
  10509. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10510. else if (ulp_type == CNIC_ULP_FCOE)
  10511. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10512. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10513. }
  10514. break;
  10515. }
  10516. default:
  10517. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10518. rc = -EINVAL;
  10519. }
  10520. return rc;
  10521. }
  10522. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10523. {
  10524. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10525. if (bp->flags & USING_MSIX_FLAG) {
  10526. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10527. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10528. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10529. } else {
  10530. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10531. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10532. }
  10533. if (!CHIP_IS_E1x(bp))
  10534. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  10535. else
  10536. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  10537. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  10538. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  10539. cp->irq_arr[1].status_blk = bp->def_status_blk;
  10540. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  10541. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  10542. cp->num_irq = 2;
  10543. }
  10544. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  10545. {
  10546. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10547. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10548. bnx2x_cid_ilt_lines(bp);
  10549. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10550. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10551. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10552. if (NO_ISCSI_OOO(bp))
  10553. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10554. }
  10555. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  10556. void *data)
  10557. {
  10558. struct bnx2x *bp = netdev_priv(dev);
  10559. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10560. if (ops == NULL) {
  10561. BNX2X_ERR("NULL ops received\n");
  10562. return -EINVAL;
  10563. }
  10564. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  10565. if (!bp->cnic_kwq)
  10566. return -ENOMEM;
  10567. bp->cnic_kwq_cons = bp->cnic_kwq;
  10568. bp->cnic_kwq_prod = bp->cnic_kwq;
  10569. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  10570. bp->cnic_spq_pending = 0;
  10571. bp->cnic_kwq_pending = 0;
  10572. bp->cnic_data = data;
  10573. cp->num_irq = 0;
  10574. cp->drv_state |= CNIC_DRV_STATE_REGD;
  10575. cp->iro_arr = bp->iro_arr;
  10576. bnx2x_setup_cnic_irq_info(bp);
  10577. rcu_assign_pointer(bp->cnic_ops, ops);
  10578. return 0;
  10579. }
  10580. static int bnx2x_unregister_cnic(struct net_device *dev)
  10581. {
  10582. struct bnx2x *bp = netdev_priv(dev);
  10583. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10584. mutex_lock(&bp->cnic_mutex);
  10585. cp->drv_state = 0;
  10586. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  10587. mutex_unlock(&bp->cnic_mutex);
  10588. synchronize_rcu();
  10589. kfree(bp->cnic_kwq);
  10590. bp->cnic_kwq = NULL;
  10591. return 0;
  10592. }
  10593. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  10594. {
  10595. struct bnx2x *bp = netdev_priv(dev);
  10596. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10597. /* If both iSCSI and FCoE are disabled - return NULL in
  10598. * order to indicate CNIC that it should not try to work
  10599. * with this device.
  10600. */
  10601. if (NO_ISCSI(bp) && NO_FCOE(bp))
  10602. return NULL;
  10603. cp->drv_owner = THIS_MODULE;
  10604. cp->chip_id = CHIP_ID(bp);
  10605. cp->pdev = bp->pdev;
  10606. cp->io_base = bp->regview;
  10607. cp->io_base2 = bp->doorbells;
  10608. cp->max_kwqe_pending = 8;
  10609. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  10610. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10611. bnx2x_cid_ilt_lines(bp);
  10612. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10613. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10614. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10615. cp->drv_ctl = bnx2x_drv_ctl;
  10616. cp->drv_register_cnic = bnx2x_register_cnic;
  10617. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10618. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10619. cp->iscsi_l2_client_id =
  10620. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10621. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10622. if (NO_ISCSI_OOO(bp))
  10623. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10624. if (NO_ISCSI(bp))
  10625. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  10626. if (NO_FCOE(bp))
  10627. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  10628. BNX2X_DEV_INFO(
  10629. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  10630. cp->ctx_blk_size,
  10631. cp->ctx_tbl_offset,
  10632. cp->ctx_tbl_len,
  10633. cp->starting_cid);
  10634. return cp;
  10635. }
  10636. EXPORT_SYMBOL(bnx2x_cnic_probe);
  10637. #endif /* BCM_CNIC */