bnx2x_main.c 327 KB

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