bnx2x_main.c 324 KB

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