bnx2x_main.c 352 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_dcb.h"
  60. #include "bnx2x_sp.h"
  61. #include <linux/firmware.h>
  62. #include "bnx2x_fw_file_hdr.h"
  63. /* FW files */
  64. #define FW_FILE_VERSION \
  65. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  66. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  68. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  69. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  70. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  72. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  73. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] =
  76. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  77. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  78. MODULE_AUTHOR("Eliezer Tamir");
  79. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  80. "BCM57710/57711/57711E/"
  81. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  82. "57840/57840_MF Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_MODULE_VERSION);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues,
  91. " Set number of queues (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. #define INT_MODE_INTx 1
  96. #define INT_MODE_MSI 2
  97. int int_mode;
  98. module_param(int_mode, int, 0);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, 0);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, 0);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, 0);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. struct workqueue_struct *bnx2x_wq;
  111. struct bnx2x_mac_vals {
  112. u32 xmac_addr;
  113. u32 xmac_val;
  114. u32 emac_addr;
  115. u32 emac_val;
  116. u32 umac_addr;
  117. u32 umac_val;
  118. u32 bmac_addr;
  119. u32 bmac_val[2];
  120. };
  121. enum bnx2x_board_type {
  122. BCM57710 = 0,
  123. BCM57711,
  124. BCM57711E,
  125. BCM57712,
  126. BCM57712_MF,
  127. BCM57800,
  128. BCM57800_MF,
  129. BCM57810,
  130. BCM57810_MF,
  131. BCM57840_O,
  132. BCM57840_4_10,
  133. BCM57840_2_20,
  134. BCM57840_MFO,
  135. BCM57840_MF,
  136. BCM57811,
  137. BCM57811_MF
  138. };
  139. /* indexed by board_type, above */
  140. static struct {
  141. char *name;
  142. } board_info[] = {
  143. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  144. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  145. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  146. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  147. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  148. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  149. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  150. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  151. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  152. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  153. { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  154. { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  155. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  156. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function"},
  157. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet"},
  158. { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function"},
  159. };
  160. #ifndef PCI_DEVICE_ID_NX2_57710
  161. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  162. #endif
  163. #ifndef PCI_DEVICE_ID_NX2_57711
  164. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  165. #endif
  166. #ifndef PCI_DEVICE_ID_NX2_57711E
  167. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  168. #endif
  169. #ifndef PCI_DEVICE_ID_NX2_57712
  170. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  171. #endif
  172. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  173. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  174. #endif
  175. #ifndef PCI_DEVICE_ID_NX2_57800
  176. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  177. #endif
  178. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  179. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  180. #endif
  181. #ifndef PCI_DEVICE_ID_NX2_57810
  182. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  183. #endif
  184. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  185. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  186. #endif
  187. #ifndef PCI_DEVICE_ID_NX2_57840_O
  188. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  189. #endif
  190. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  191. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  192. #endif
  193. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  194. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  195. #endif
  196. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  197. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  198. #endif
  199. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  200. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  201. #endif
  202. #ifndef PCI_DEVICE_ID_NX2_57811
  203. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  204. #endif
  205. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  206. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  207. #endif
  208. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  209. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  210. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  211. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  212. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  213. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  214. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  215. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  216. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  217. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  218. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  219. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  220. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  221. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  222. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  223. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  224. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  225. { 0 }
  226. };
  227. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  228. /* Global resources for unloading a previously loaded device */
  229. #define BNX2X_PREV_WAIT_NEEDED 1
  230. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  231. static LIST_HEAD(bnx2x_prev_list);
  232. /****************************************************************************
  233. * General service functions
  234. ****************************************************************************/
  235. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  236. u32 addr, dma_addr_t mapping)
  237. {
  238. REG_WR(bp, addr, U64_LO(mapping));
  239. REG_WR(bp, addr + 4, U64_HI(mapping));
  240. }
  241. static void storm_memset_spq_addr(struct bnx2x *bp,
  242. dma_addr_t mapping, u16 abs_fid)
  243. {
  244. u32 addr = XSEM_REG_FAST_MEMORY +
  245. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  246. __storm_memset_dma_mapping(bp, addr, mapping);
  247. }
  248. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  249. u16 pf_id)
  250. {
  251. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  252. pf_id);
  253. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  254. pf_id);
  255. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  256. pf_id);
  257. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  258. pf_id);
  259. }
  260. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  261. u8 enable)
  262. {
  263. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  264. enable);
  265. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  266. enable);
  267. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  268. enable);
  269. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  270. enable);
  271. }
  272. static void storm_memset_eq_data(struct bnx2x *bp,
  273. struct event_ring_data *eq_data,
  274. u16 pfid)
  275. {
  276. size_t size = sizeof(struct event_ring_data);
  277. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  278. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  279. }
  280. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  281. u16 pfid)
  282. {
  283. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  284. REG_WR16(bp, addr, eq_prod);
  285. }
  286. /* used only at init
  287. * locking is done by mcp
  288. */
  289. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  290. {
  291. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  292. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  293. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  294. PCICFG_VENDOR_ID_OFFSET);
  295. }
  296. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  297. {
  298. u32 val;
  299. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  300. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  301. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  302. PCICFG_VENDOR_ID_OFFSET);
  303. return val;
  304. }
  305. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  306. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  307. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  308. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  309. #define DMAE_DP_DST_NONE "dst_addr [none]"
  310. /* copy command into DMAE command memory and set DMAE command go */
  311. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  312. {
  313. u32 cmd_offset;
  314. int i;
  315. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  316. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  317. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  318. }
  319. REG_WR(bp, dmae_reg_go_c[idx], 1);
  320. }
  321. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  322. {
  323. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  324. DMAE_CMD_C_ENABLE);
  325. }
  326. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  327. {
  328. return opcode & ~DMAE_CMD_SRC_RESET;
  329. }
  330. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  331. bool with_comp, u8 comp_type)
  332. {
  333. u32 opcode = 0;
  334. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  335. (dst_type << DMAE_COMMAND_DST_SHIFT));
  336. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  337. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  338. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  339. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  340. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  341. #ifdef __BIG_ENDIAN
  342. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  343. #else
  344. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  345. #endif
  346. if (with_comp)
  347. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  348. return opcode;
  349. }
  350. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  351. struct dmae_command *dmae,
  352. u8 src_type, u8 dst_type)
  353. {
  354. memset(dmae, 0, sizeof(struct dmae_command));
  355. /* set the opcode */
  356. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  357. true, DMAE_COMP_PCI);
  358. /* fill in the completion parameters */
  359. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  360. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  361. dmae->comp_val = DMAE_COMP_VAL;
  362. }
  363. /* issue a dmae command over the init-channel and wailt for completion */
  364. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  365. struct dmae_command *dmae)
  366. {
  367. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  368. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  369. int rc = 0;
  370. /*
  371. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  372. * as long as this code is called both from syscall context and
  373. * from ndo_set_rx_mode() flow that may be called from BH.
  374. */
  375. spin_lock_bh(&bp->dmae_lock);
  376. /* reset completion */
  377. *wb_comp = 0;
  378. /* post the command on the channel used for initializations */
  379. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  380. /* wait for completion */
  381. udelay(5);
  382. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  383. if (!cnt ||
  384. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  385. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  386. BNX2X_ERR("DMAE timeout!\n");
  387. rc = DMAE_TIMEOUT;
  388. goto unlock;
  389. }
  390. cnt--;
  391. udelay(50);
  392. }
  393. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  394. BNX2X_ERR("DMAE PCI error!\n");
  395. rc = DMAE_PCI_ERROR;
  396. }
  397. unlock:
  398. spin_unlock_bh(&bp->dmae_lock);
  399. return rc;
  400. }
  401. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  402. u32 len32)
  403. {
  404. struct dmae_command dmae;
  405. if (!bp->dmae_ready) {
  406. u32 *data = bnx2x_sp(bp, wb_data[0]);
  407. if (CHIP_IS_E1(bp))
  408. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  409. else
  410. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  411. return;
  412. }
  413. /* set opcode and fixed command fields */
  414. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  415. /* fill in addresses and len */
  416. dmae.src_addr_lo = U64_LO(dma_addr);
  417. dmae.src_addr_hi = U64_HI(dma_addr);
  418. dmae.dst_addr_lo = dst_addr >> 2;
  419. dmae.dst_addr_hi = 0;
  420. dmae.len = len32;
  421. /* issue the command and wait for completion */
  422. bnx2x_issue_dmae_with_comp(bp, &dmae);
  423. }
  424. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  425. {
  426. struct dmae_command dmae;
  427. if (!bp->dmae_ready) {
  428. u32 *data = bnx2x_sp(bp, wb_data[0]);
  429. int i;
  430. if (CHIP_IS_E1(bp))
  431. for (i = 0; i < len32; i++)
  432. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  433. else
  434. for (i = 0; i < len32; i++)
  435. data[i] = REG_RD(bp, src_addr + i*4);
  436. return;
  437. }
  438. /* set opcode and fixed command fields */
  439. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  440. /* fill in addresses and len */
  441. dmae.src_addr_lo = src_addr >> 2;
  442. dmae.src_addr_hi = 0;
  443. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  444. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  445. dmae.len = len32;
  446. /* issue the command and wait for completion */
  447. bnx2x_issue_dmae_with_comp(bp, &dmae);
  448. }
  449. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  450. u32 addr, u32 len)
  451. {
  452. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  453. int offset = 0;
  454. while (len > dmae_wr_max) {
  455. bnx2x_write_dmae(bp, phys_addr + offset,
  456. addr + offset, dmae_wr_max);
  457. offset += dmae_wr_max * 4;
  458. len -= dmae_wr_max;
  459. }
  460. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  461. }
  462. static int bnx2x_mc_assert(struct bnx2x *bp)
  463. {
  464. char last_idx;
  465. int i, rc = 0;
  466. u32 row0, row1, row2, row3;
  467. /* XSTORM */
  468. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  469. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  470. if (last_idx)
  471. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  472. /* print the asserts */
  473. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  474. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  475. XSTORM_ASSERT_LIST_OFFSET(i));
  476. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  477. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  478. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  479. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  480. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  481. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  482. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  483. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  484. i, row3, row2, row1, row0);
  485. rc++;
  486. } else {
  487. break;
  488. }
  489. }
  490. /* TSTORM */
  491. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  492. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  493. if (last_idx)
  494. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  495. /* print the asserts */
  496. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  497. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  498. TSTORM_ASSERT_LIST_OFFSET(i));
  499. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  500. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  501. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  502. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  503. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  504. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  505. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  506. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  507. i, row3, row2, row1, row0);
  508. rc++;
  509. } else {
  510. break;
  511. }
  512. }
  513. /* CSTORM */
  514. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  515. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  516. if (last_idx)
  517. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  518. /* print the asserts */
  519. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  520. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  521. CSTORM_ASSERT_LIST_OFFSET(i));
  522. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  523. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  524. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  525. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  526. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  527. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  528. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  529. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  530. i, row3, row2, row1, row0);
  531. rc++;
  532. } else {
  533. break;
  534. }
  535. }
  536. /* USTORM */
  537. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  538. USTORM_ASSERT_LIST_INDEX_OFFSET);
  539. if (last_idx)
  540. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  541. /* print the asserts */
  542. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  543. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  544. USTORM_ASSERT_LIST_OFFSET(i));
  545. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  546. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  547. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  548. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  549. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  550. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  551. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  552. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  553. i, row3, row2, row1, row0);
  554. rc++;
  555. } else {
  556. break;
  557. }
  558. }
  559. return rc;
  560. }
  561. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  562. {
  563. u32 addr, val;
  564. u32 mark, offset;
  565. __be32 data[9];
  566. int word;
  567. u32 trace_shmem_base;
  568. if (BP_NOMCP(bp)) {
  569. BNX2X_ERR("NO MCP - can not dump\n");
  570. return;
  571. }
  572. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  573. (bp->common.bc_ver & 0xff0000) >> 16,
  574. (bp->common.bc_ver & 0xff00) >> 8,
  575. (bp->common.bc_ver & 0xff));
  576. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  577. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  578. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  579. if (BP_PATH(bp) == 0)
  580. trace_shmem_base = bp->common.shmem_base;
  581. else
  582. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  583. addr = trace_shmem_base - 0x800;
  584. /* validate TRCB signature */
  585. mark = REG_RD(bp, addr);
  586. if (mark != MFW_TRACE_SIGNATURE) {
  587. BNX2X_ERR("Trace buffer signature is missing.");
  588. return ;
  589. }
  590. /* read cyclic buffer pointer */
  591. addr += 4;
  592. mark = REG_RD(bp, addr);
  593. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  594. + ((mark + 0x3) & ~0x3) - 0x08000000;
  595. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  596. printk("%s", lvl);
  597. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  598. for (word = 0; word < 8; word++)
  599. data[word] = htonl(REG_RD(bp, offset + 4*word));
  600. data[8] = 0x0;
  601. pr_cont("%s", (char *)data);
  602. }
  603. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  604. for (word = 0; word < 8; word++)
  605. data[word] = htonl(REG_RD(bp, offset + 4*word));
  606. data[8] = 0x0;
  607. pr_cont("%s", (char *)data);
  608. }
  609. printk("%s" "end of fw dump\n", lvl);
  610. }
  611. static void bnx2x_fw_dump(struct bnx2x *bp)
  612. {
  613. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  614. }
  615. void bnx2x_panic_dump(struct bnx2x *bp)
  616. {
  617. int i;
  618. u16 j;
  619. struct hc_sp_status_block_data sp_sb_data;
  620. int func = BP_FUNC(bp);
  621. #ifdef BNX2X_STOP_ON_ERROR
  622. u16 start = 0, end = 0;
  623. u8 cos;
  624. #endif
  625. bp->stats_state = STATS_STATE_DISABLED;
  626. bp->eth_stats.unrecoverable_error++;
  627. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  628. BNX2X_ERR("begin crash dump -----------------\n");
  629. /* Indices */
  630. /* Common */
  631. 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",
  632. bp->def_idx, bp->def_att_idx, bp->attn_state,
  633. bp->spq_prod_idx, bp->stats_counter);
  634. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  635. bp->def_status_blk->atten_status_block.attn_bits,
  636. bp->def_status_blk->atten_status_block.attn_bits_ack,
  637. bp->def_status_blk->atten_status_block.status_block_id,
  638. bp->def_status_blk->atten_status_block.attn_bits_index);
  639. BNX2X_ERR(" def (");
  640. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  641. pr_cont("0x%x%s",
  642. bp->def_status_blk->sp_sb.index_values[i],
  643. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  644. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  645. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  646. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  647. i*sizeof(u32));
  648. 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",
  649. sp_sb_data.igu_sb_id,
  650. sp_sb_data.igu_seg_id,
  651. sp_sb_data.p_func.pf_id,
  652. sp_sb_data.p_func.vnic_id,
  653. sp_sb_data.p_func.vf_id,
  654. sp_sb_data.p_func.vf_valid,
  655. sp_sb_data.state);
  656. for_each_eth_queue(bp, i) {
  657. struct bnx2x_fastpath *fp = &bp->fp[i];
  658. int loop;
  659. struct hc_status_block_data_e2 sb_data_e2;
  660. struct hc_status_block_data_e1x sb_data_e1x;
  661. struct hc_status_block_sm *hc_sm_p =
  662. CHIP_IS_E1x(bp) ?
  663. sb_data_e1x.common.state_machine :
  664. sb_data_e2.common.state_machine;
  665. struct hc_index_data *hc_index_p =
  666. CHIP_IS_E1x(bp) ?
  667. sb_data_e1x.index_data :
  668. sb_data_e2.index_data;
  669. u8 data_size, cos;
  670. u32 *sb_data_p;
  671. struct bnx2x_fp_txdata txdata;
  672. /* Rx */
  673. 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",
  674. i, fp->rx_bd_prod, fp->rx_bd_cons,
  675. fp->rx_comp_prod,
  676. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  677. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  678. fp->rx_sge_prod, fp->last_max_sge,
  679. le16_to_cpu(fp->fp_hc_idx));
  680. /* Tx */
  681. for_each_cos_in_tx_queue(fp, cos)
  682. {
  683. txdata = *fp->txdata_ptr[cos];
  684. 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",
  685. i, txdata.tx_pkt_prod,
  686. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  687. txdata.tx_bd_cons,
  688. le16_to_cpu(*txdata.tx_cons_sb));
  689. }
  690. loop = CHIP_IS_E1x(bp) ?
  691. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  692. /* host sb data */
  693. if (IS_FCOE_FP(fp))
  694. continue;
  695. BNX2X_ERR(" run indexes (");
  696. for (j = 0; j < HC_SB_MAX_SM; j++)
  697. pr_cont("0x%x%s",
  698. fp->sb_running_index[j],
  699. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  700. BNX2X_ERR(" indexes (");
  701. for (j = 0; j < loop; j++)
  702. pr_cont("0x%x%s",
  703. fp->sb_index_values[j],
  704. (j == loop - 1) ? ")" : " ");
  705. /* fw sb data */
  706. data_size = CHIP_IS_E1x(bp) ?
  707. sizeof(struct hc_status_block_data_e1x) :
  708. sizeof(struct hc_status_block_data_e2);
  709. data_size /= sizeof(u32);
  710. sb_data_p = CHIP_IS_E1x(bp) ?
  711. (u32 *)&sb_data_e1x :
  712. (u32 *)&sb_data_e2;
  713. /* copy sb data in here */
  714. for (j = 0; j < data_size; j++)
  715. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  716. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  717. j * sizeof(u32));
  718. if (!CHIP_IS_E1x(bp)) {
  719. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  720. sb_data_e2.common.p_func.pf_id,
  721. sb_data_e2.common.p_func.vf_id,
  722. sb_data_e2.common.p_func.vf_valid,
  723. sb_data_e2.common.p_func.vnic_id,
  724. sb_data_e2.common.same_igu_sb_1b,
  725. sb_data_e2.common.state);
  726. } else {
  727. 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",
  728. sb_data_e1x.common.p_func.pf_id,
  729. sb_data_e1x.common.p_func.vf_id,
  730. sb_data_e1x.common.p_func.vf_valid,
  731. sb_data_e1x.common.p_func.vnic_id,
  732. sb_data_e1x.common.same_igu_sb_1b,
  733. sb_data_e1x.common.state);
  734. }
  735. /* SB_SMs data */
  736. for (j = 0; j < HC_SB_MAX_SM; j++) {
  737. 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",
  738. j, hc_sm_p[j].__flags,
  739. hc_sm_p[j].igu_sb_id,
  740. hc_sm_p[j].igu_seg_id,
  741. hc_sm_p[j].time_to_expire,
  742. hc_sm_p[j].timer_value);
  743. }
  744. /* Indecies data */
  745. for (j = 0; j < loop; j++) {
  746. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  747. hc_index_p[j].flags,
  748. hc_index_p[j].timeout);
  749. }
  750. }
  751. #ifdef BNX2X_STOP_ON_ERROR
  752. /* Rings */
  753. /* Rx */
  754. for_each_valid_rx_queue(bp, i) {
  755. struct bnx2x_fastpath *fp = &bp->fp[i];
  756. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  757. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  758. for (j = start; j != end; j = RX_BD(j + 1)) {
  759. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  760. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  761. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  762. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  763. }
  764. start = RX_SGE(fp->rx_sge_prod);
  765. end = RX_SGE(fp->last_max_sge);
  766. for (j = start; j != end; j = RX_SGE(j + 1)) {
  767. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  768. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  769. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  770. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  771. }
  772. start = RCQ_BD(fp->rx_comp_cons - 10);
  773. end = RCQ_BD(fp->rx_comp_cons + 503);
  774. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  775. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  776. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  777. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  778. }
  779. }
  780. /* Tx */
  781. for_each_valid_tx_queue(bp, i) {
  782. struct bnx2x_fastpath *fp = &bp->fp[i];
  783. for_each_cos_in_tx_queue(fp, cos) {
  784. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  785. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  786. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  787. for (j = start; j != end; j = TX_BD(j + 1)) {
  788. struct sw_tx_bd *sw_bd =
  789. &txdata->tx_buf_ring[j];
  790. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  791. i, cos, j, sw_bd->skb,
  792. sw_bd->first_bd);
  793. }
  794. start = TX_BD(txdata->tx_bd_cons - 10);
  795. end = TX_BD(txdata->tx_bd_cons + 254);
  796. for (j = start; j != end; j = TX_BD(j + 1)) {
  797. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  798. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  799. i, cos, j, tx_bd[0], tx_bd[1],
  800. tx_bd[2], tx_bd[3]);
  801. }
  802. }
  803. }
  804. #endif
  805. bnx2x_fw_dump(bp);
  806. bnx2x_mc_assert(bp);
  807. BNX2X_ERR("end crash dump -----------------\n");
  808. }
  809. /*
  810. * FLR Support for E2
  811. *
  812. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  813. * initialization.
  814. */
  815. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  816. #define FLR_WAIT_INTERVAL 50 /* usec */
  817. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  818. struct pbf_pN_buf_regs {
  819. int pN;
  820. u32 init_crd;
  821. u32 crd;
  822. u32 crd_freed;
  823. };
  824. struct pbf_pN_cmd_regs {
  825. int pN;
  826. u32 lines_occup;
  827. u32 lines_freed;
  828. };
  829. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  830. struct pbf_pN_buf_regs *regs,
  831. u32 poll_count)
  832. {
  833. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  834. u32 cur_cnt = poll_count;
  835. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  836. crd = crd_start = REG_RD(bp, regs->crd);
  837. init_crd = REG_RD(bp, regs->init_crd);
  838. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  839. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  840. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  841. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  842. (init_crd - crd_start))) {
  843. if (cur_cnt--) {
  844. udelay(FLR_WAIT_INTERVAL);
  845. crd = REG_RD(bp, regs->crd);
  846. crd_freed = REG_RD(bp, regs->crd_freed);
  847. } else {
  848. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  849. regs->pN);
  850. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  851. regs->pN, crd);
  852. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  853. regs->pN, crd_freed);
  854. break;
  855. }
  856. }
  857. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  858. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  859. }
  860. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  861. struct pbf_pN_cmd_regs *regs,
  862. u32 poll_count)
  863. {
  864. u32 occup, to_free, freed, freed_start;
  865. u32 cur_cnt = poll_count;
  866. occup = to_free = REG_RD(bp, regs->lines_occup);
  867. freed = freed_start = REG_RD(bp, regs->lines_freed);
  868. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  869. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  870. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  871. if (cur_cnt--) {
  872. udelay(FLR_WAIT_INTERVAL);
  873. occup = REG_RD(bp, regs->lines_occup);
  874. freed = REG_RD(bp, regs->lines_freed);
  875. } else {
  876. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  877. regs->pN);
  878. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  879. regs->pN, occup);
  880. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  881. regs->pN, freed);
  882. break;
  883. }
  884. }
  885. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  886. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  887. }
  888. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  889. u32 expected, u32 poll_count)
  890. {
  891. u32 cur_cnt = poll_count;
  892. u32 val;
  893. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  894. udelay(FLR_WAIT_INTERVAL);
  895. return val;
  896. }
  897. static int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  898. char *msg, u32 poll_cnt)
  899. {
  900. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  901. if (val != 0) {
  902. BNX2X_ERR("%s usage count=%d\n", msg, val);
  903. return 1;
  904. }
  905. return 0;
  906. }
  907. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  908. {
  909. /* adjust polling timeout */
  910. if (CHIP_REV_IS_EMUL(bp))
  911. return FLR_POLL_CNT * 2000;
  912. if (CHIP_REV_IS_FPGA(bp))
  913. return FLR_POLL_CNT * 120;
  914. return FLR_POLL_CNT;
  915. }
  916. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  917. {
  918. struct pbf_pN_cmd_regs cmd_regs[] = {
  919. {0, (CHIP_IS_E3B0(bp)) ?
  920. PBF_REG_TQ_OCCUPANCY_Q0 :
  921. PBF_REG_P0_TQ_OCCUPANCY,
  922. (CHIP_IS_E3B0(bp)) ?
  923. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  924. PBF_REG_P0_TQ_LINES_FREED_CNT},
  925. {1, (CHIP_IS_E3B0(bp)) ?
  926. PBF_REG_TQ_OCCUPANCY_Q1 :
  927. PBF_REG_P1_TQ_OCCUPANCY,
  928. (CHIP_IS_E3B0(bp)) ?
  929. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  930. PBF_REG_P1_TQ_LINES_FREED_CNT},
  931. {4, (CHIP_IS_E3B0(bp)) ?
  932. PBF_REG_TQ_OCCUPANCY_LB_Q :
  933. PBF_REG_P4_TQ_OCCUPANCY,
  934. (CHIP_IS_E3B0(bp)) ?
  935. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  936. PBF_REG_P4_TQ_LINES_FREED_CNT}
  937. };
  938. struct pbf_pN_buf_regs buf_regs[] = {
  939. {0, (CHIP_IS_E3B0(bp)) ?
  940. PBF_REG_INIT_CRD_Q0 :
  941. PBF_REG_P0_INIT_CRD ,
  942. (CHIP_IS_E3B0(bp)) ?
  943. PBF_REG_CREDIT_Q0 :
  944. PBF_REG_P0_CREDIT,
  945. (CHIP_IS_E3B0(bp)) ?
  946. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  947. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  948. {1, (CHIP_IS_E3B0(bp)) ?
  949. PBF_REG_INIT_CRD_Q1 :
  950. PBF_REG_P1_INIT_CRD,
  951. (CHIP_IS_E3B0(bp)) ?
  952. PBF_REG_CREDIT_Q1 :
  953. PBF_REG_P1_CREDIT,
  954. (CHIP_IS_E3B0(bp)) ?
  955. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  956. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  957. {4, (CHIP_IS_E3B0(bp)) ?
  958. PBF_REG_INIT_CRD_LB_Q :
  959. PBF_REG_P4_INIT_CRD,
  960. (CHIP_IS_E3B0(bp)) ?
  961. PBF_REG_CREDIT_LB_Q :
  962. PBF_REG_P4_CREDIT,
  963. (CHIP_IS_E3B0(bp)) ?
  964. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  965. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  966. };
  967. int i;
  968. /* Verify the command queues are flushed P0, P1, P4 */
  969. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  970. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  971. /* Verify the transmission buffers are flushed P0, P1, P4 */
  972. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  973. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  974. }
  975. #define OP_GEN_PARAM(param) \
  976. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  977. #define OP_GEN_TYPE(type) \
  978. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  979. #define OP_GEN_AGG_VECT(index) \
  980. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  981. static int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  982. u32 poll_cnt)
  983. {
  984. struct sdm_op_gen op_gen = {0};
  985. u32 comp_addr = BAR_CSTRORM_INTMEM +
  986. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  987. int ret = 0;
  988. if (REG_RD(bp, comp_addr)) {
  989. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  990. return 1;
  991. }
  992. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  993. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  994. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  995. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  996. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  997. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  998. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  999. BNX2X_ERR("FW final cleanup did not succeed\n");
  1000. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1001. (REG_RD(bp, comp_addr)));
  1002. ret = 1;
  1003. }
  1004. /* Zero completion for nxt FLR */
  1005. REG_WR(bp, comp_addr, 0);
  1006. return ret;
  1007. }
  1008. static u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1009. {
  1010. u16 status;
  1011. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1012. return status & PCI_EXP_DEVSTA_TRPND;
  1013. }
  1014. /* PF FLR specific routines
  1015. */
  1016. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1017. {
  1018. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1019. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1020. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1021. "CFC PF usage counter timed out",
  1022. poll_cnt))
  1023. return 1;
  1024. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1025. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1026. DORQ_REG_PF_USAGE_CNT,
  1027. "DQ PF usage counter timed out",
  1028. poll_cnt))
  1029. return 1;
  1030. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1031. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1032. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1033. "QM PF usage counter timed out",
  1034. poll_cnt))
  1035. return 1;
  1036. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1037. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1038. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1039. "Timers VNIC usage counter timed out",
  1040. poll_cnt))
  1041. return 1;
  1042. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1043. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1044. "Timers NUM_SCANS usage counter timed out",
  1045. poll_cnt))
  1046. return 1;
  1047. /* Wait DMAE PF usage counter to zero */
  1048. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1049. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1050. "DMAE dommand register timed out",
  1051. poll_cnt))
  1052. return 1;
  1053. return 0;
  1054. }
  1055. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1056. {
  1057. u32 val;
  1058. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1059. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1060. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1061. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1062. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1063. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1064. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1065. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1066. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1067. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1068. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1069. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1070. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1071. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1072. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1073. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1074. val);
  1075. }
  1076. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1077. {
  1078. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1079. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1080. /* Re-enable PF target read access */
  1081. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1082. /* Poll HW usage counters */
  1083. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1084. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1085. return -EBUSY;
  1086. /* Zero the igu 'trailing edge' and 'leading edge' */
  1087. /* Send the FW cleanup command */
  1088. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1089. return -EBUSY;
  1090. /* ATC cleanup */
  1091. /* Verify TX hw is flushed */
  1092. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1093. /* Wait 100ms (not adjusted according to platform) */
  1094. msleep(100);
  1095. /* Verify no pending pci transactions */
  1096. if (bnx2x_is_pcie_pending(bp->pdev))
  1097. BNX2X_ERR("PCIE Transactions still pending\n");
  1098. /* Debug */
  1099. bnx2x_hw_enable_status(bp);
  1100. /*
  1101. * Master enable - Due to WB DMAE writes performed before this
  1102. * register is re-initialized as part of the regular function init
  1103. */
  1104. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1105. return 0;
  1106. }
  1107. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1108. {
  1109. int port = BP_PORT(bp);
  1110. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1111. u32 val = REG_RD(bp, addr);
  1112. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1113. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1114. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1115. if (msix) {
  1116. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1117. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1118. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1119. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1120. if (single_msix)
  1121. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1122. } else if (msi) {
  1123. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1124. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1125. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1126. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1127. } else {
  1128. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1129. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1130. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1131. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1132. if (!CHIP_IS_E1(bp)) {
  1133. DP(NETIF_MSG_IFUP,
  1134. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1135. REG_WR(bp, addr, val);
  1136. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1137. }
  1138. }
  1139. if (CHIP_IS_E1(bp))
  1140. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1141. DP(NETIF_MSG_IFUP,
  1142. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1143. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1144. REG_WR(bp, addr, val);
  1145. /*
  1146. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1147. */
  1148. mmiowb();
  1149. barrier();
  1150. if (!CHIP_IS_E1(bp)) {
  1151. /* init leading/trailing edge */
  1152. if (IS_MF(bp)) {
  1153. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1154. if (bp->port.pmf)
  1155. /* enable nig and gpio3 attention */
  1156. val |= 0x1100;
  1157. } else
  1158. val = 0xffff;
  1159. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1160. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1161. }
  1162. /* Make sure that interrupts are indeed enabled from here on */
  1163. mmiowb();
  1164. }
  1165. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1166. {
  1167. u32 val;
  1168. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1169. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1170. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1171. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1172. if (msix) {
  1173. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1174. IGU_PF_CONF_SINGLE_ISR_EN);
  1175. val |= (IGU_PF_CONF_FUNC_EN |
  1176. IGU_PF_CONF_MSI_MSIX_EN |
  1177. IGU_PF_CONF_ATTN_BIT_EN);
  1178. if (single_msix)
  1179. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1180. } else if (msi) {
  1181. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1182. val |= (IGU_PF_CONF_FUNC_EN |
  1183. IGU_PF_CONF_MSI_MSIX_EN |
  1184. IGU_PF_CONF_ATTN_BIT_EN |
  1185. IGU_PF_CONF_SINGLE_ISR_EN);
  1186. } else {
  1187. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1188. val |= (IGU_PF_CONF_FUNC_EN |
  1189. IGU_PF_CONF_INT_LINE_EN |
  1190. IGU_PF_CONF_ATTN_BIT_EN |
  1191. IGU_PF_CONF_SINGLE_ISR_EN);
  1192. }
  1193. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1194. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1195. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1196. if (val & IGU_PF_CONF_INT_LINE_EN)
  1197. pci_intx(bp->pdev, true);
  1198. barrier();
  1199. /* init leading/trailing edge */
  1200. if (IS_MF(bp)) {
  1201. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1202. if (bp->port.pmf)
  1203. /* enable nig and gpio3 attention */
  1204. val |= 0x1100;
  1205. } else
  1206. val = 0xffff;
  1207. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1208. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1209. /* Make sure that interrupts are indeed enabled from here on */
  1210. mmiowb();
  1211. }
  1212. void bnx2x_int_enable(struct bnx2x *bp)
  1213. {
  1214. if (bp->common.int_block == INT_BLOCK_HC)
  1215. bnx2x_hc_int_enable(bp);
  1216. else
  1217. bnx2x_igu_int_enable(bp);
  1218. }
  1219. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1220. {
  1221. int port = BP_PORT(bp);
  1222. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1223. u32 val = REG_RD(bp, addr);
  1224. /*
  1225. * in E1 we must use only PCI configuration space to disable
  1226. * MSI/MSIX capablility
  1227. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1228. */
  1229. if (CHIP_IS_E1(bp)) {
  1230. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1231. * Use mask register to prevent from HC sending interrupts
  1232. * after we exit the function
  1233. */
  1234. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1235. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1236. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1237. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1238. } else
  1239. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1240. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1241. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1242. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1243. DP(NETIF_MSG_IFDOWN,
  1244. "write %x to HC %d (addr 0x%x)\n",
  1245. val, port, addr);
  1246. /* flush all outstanding writes */
  1247. mmiowb();
  1248. REG_WR(bp, addr, val);
  1249. if (REG_RD(bp, addr) != val)
  1250. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1251. }
  1252. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1253. {
  1254. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1255. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1256. IGU_PF_CONF_INT_LINE_EN |
  1257. IGU_PF_CONF_ATTN_BIT_EN);
  1258. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1259. /* flush all outstanding writes */
  1260. mmiowb();
  1261. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1262. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1263. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1264. }
  1265. static void bnx2x_int_disable(struct bnx2x *bp)
  1266. {
  1267. if (bp->common.int_block == INT_BLOCK_HC)
  1268. bnx2x_hc_int_disable(bp);
  1269. else
  1270. bnx2x_igu_int_disable(bp);
  1271. }
  1272. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1273. {
  1274. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1275. int i, offset;
  1276. if (disable_hw)
  1277. /* prevent the HW from sending interrupts */
  1278. bnx2x_int_disable(bp);
  1279. /* make sure all ISRs are done */
  1280. if (msix) {
  1281. synchronize_irq(bp->msix_table[0].vector);
  1282. offset = 1;
  1283. if (CNIC_SUPPORT(bp))
  1284. offset++;
  1285. for_each_eth_queue(bp, i)
  1286. synchronize_irq(bp->msix_table[offset++].vector);
  1287. } else
  1288. synchronize_irq(bp->pdev->irq);
  1289. /* make sure sp_task is not running */
  1290. cancel_delayed_work(&bp->sp_task);
  1291. cancel_delayed_work(&bp->period_task);
  1292. flush_workqueue(bnx2x_wq);
  1293. }
  1294. /* fast path */
  1295. /*
  1296. * General service functions
  1297. */
  1298. /* Return true if succeeded to acquire the lock */
  1299. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1300. {
  1301. u32 lock_status;
  1302. u32 resource_bit = (1 << resource);
  1303. int func = BP_FUNC(bp);
  1304. u32 hw_lock_control_reg;
  1305. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1306. "Trying to take a lock on resource %d\n", resource);
  1307. /* Validating that the resource is within range */
  1308. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1309. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1310. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1311. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1312. return false;
  1313. }
  1314. if (func <= 5)
  1315. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1316. else
  1317. hw_lock_control_reg =
  1318. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1319. /* Try to acquire the lock */
  1320. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1321. lock_status = REG_RD(bp, hw_lock_control_reg);
  1322. if (lock_status & resource_bit)
  1323. return true;
  1324. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1325. "Failed to get a lock on resource %d\n", resource);
  1326. return false;
  1327. }
  1328. /**
  1329. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1330. *
  1331. * @bp: driver handle
  1332. *
  1333. * Returns the recovery leader resource id according to the engine this function
  1334. * belongs to. Currently only only 2 engines is supported.
  1335. */
  1336. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1337. {
  1338. if (BP_PATH(bp))
  1339. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1340. else
  1341. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1342. }
  1343. /**
  1344. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1345. *
  1346. * @bp: driver handle
  1347. *
  1348. * Tries to aquire a leader lock for current engine.
  1349. */
  1350. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1351. {
  1352. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1353. }
  1354. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1355. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1356. {
  1357. struct bnx2x *bp = fp->bp;
  1358. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1359. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1360. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1361. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1362. DP(BNX2X_MSG_SP,
  1363. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1364. fp->index, cid, command, bp->state,
  1365. rr_cqe->ramrod_cqe.ramrod_type);
  1366. switch (command) {
  1367. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1368. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1369. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1370. break;
  1371. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1372. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1373. drv_cmd = BNX2X_Q_CMD_SETUP;
  1374. break;
  1375. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1376. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1377. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1378. break;
  1379. case (RAMROD_CMD_ID_ETH_HALT):
  1380. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1381. drv_cmd = BNX2X_Q_CMD_HALT;
  1382. break;
  1383. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1384. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1385. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1386. break;
  1387. case (RAMROD_CMD_ID_ETH_EMPTY):
  1388. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1389. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1390. break;
  1391. default:
  1392. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1393. command, fp->index);
  1394. return;
  1395. }
  1396. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1397. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1398. /* q_obj->complete_cmd() failure means that this was
  1399. * an unexpected completion.
  1400. *
  1401. * In this case we don't want to increase the bp->spq_left
  1402. * because apparently we haven't sent this command the first
  1403. * place.
  1404. */
  1405. #ifdef BNX2X_STOP_ON_ERROR
  1406. bnx2x_panic();
  1407. #else
  1408. return;
  1409. #endif
  1410. smp_mb__before_atomic_inc();
  1411. atomic_inc(&bp->cq_spq_left);
  1412. /* push the change in bp->spq_left and towards the memory */
  1413. smp_mb__after_atomic_inc();
  1414. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1415. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1416. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1417. /* if Q update ramrod is completed for last Q in AFEX vif set
  1418. * flow, then ACK MCP at the end
  1419. *
  1420. * mark pending ACK to MCP bit.
  1421. * prevent case that both bits are cleared.
  1422. * At the end of load/unload driver checks that
  1423. * sp_state is cleaerd, and this order prevents
  1424. * races
  1425. */
  1426. smp_mb__before_clear_bit();
  1427. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1428. wmb();
  1429. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1430. smp_mb__after_clear_bit();
  1431. /* schedule workqueue to send ack to MCP */
  1432. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1433. }
  1434. return;
  1435. }
  1436. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1437. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1438. {
  1439. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1440. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1441. start);
  1442. }
  1443. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1444. {
  1445. struct bnx2x *bp = netdev_priv(dev_instance);
  1446. u16 status = bnx2x_ack_int(bp);
  1447. u16 mask;
  1448. int i;
  1449. u8 cos;
  1450. /* Return here if interrupt is shared and it's not for us */
  1451. if (unlikely(status == 0)) {
  1452. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1453. return IRQ_NONE;
  1454. }
  1455. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1456. #ifdef BNX2X_STOP_ON_ERROR
  1457. if (unlikely(bp->panic))
  1458. return IRQ_HANDLED;
  1459. #endif
  1460. for_each_eth_queue(bp, i) {
  1461. struct bnx2x_fastpath *fp = &bp->fp[i];
  1462. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1463. if (status & mask) {
  1464. /* Handle Rx or Tx according to SB id */
  1465. prefetch(fp->rx_cons_sb);
  1466. for_each_cos_in_tx_queue(fp, cos)
  1467. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1468. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1469. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1470. status &= ~mask;
  1471. }
  1472. }
  1473. if (CNIC_SUPPORT(bp)) {
  1474. mask = 0x2;
  1475. if (status & (mask | 0x1)) {
  1476. struct cnic_ops *c_ops = NULL;
  1477. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1478. rcu_read_lock();
  1479. c_ops = rcu_dereference(bp->cnic_ops);
  1480. if (c_ops)
  1481. c_ops->cnic_handler(bp->cnic_data,
  1482. NULL);
  1483. rcu_read_unlock();
  1484. }
  1485. status &= ~mask;
  1486. }
  1487. }
  1488. if (unlikely(status & 0x1)) {
  1489. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1490. status &= ~0x1;
  1491. if (!status)
  1492. return IRQ_HANDLED;
  1493. }
  1494. if (unlikely(status))
  1495. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1496. status);
  1497. return IRQ_HANDLED;
  1498. }
  1499. /* Link */
  1500. /*
  1501. * General service functions
  1502. */
  1503. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1504. {
  1505. u32 lock_status;
  1506. u32 resource_bit = (1 << resource);
  1507. int func = BP_FUNC(bp);
  1508. u32 hw_lock_control_reg;
  1509. int cnt;
  1510. /* Validating that the resource is within range */
  1511. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1512. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1513. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1514. return -EINVAL;
  1515. }
  1516. if (func <= 5) {
  1517. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1518. } else {
  1519. hw_lock_control_reg =
  1520. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1521. }
  1522. /* Validating that the resource is not already taken */
  1523. lock_status = REG_RD(bp, hw_lock_control_reg);
  1524. if (lock_status & resource_bit) {
  1525. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1526. lock_status, resource_bit);
  1527. return -EEXIST;
  1528. }
  1529. /* Try for 5 second every 5ms */
  1530. for (cnt = 0; cnt < 1000; cnt++) {
  1531. /* Try to acquire the lock */
  1532. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1533. lock_status = REG_RD(bp, hw_lock_control_reg);
  1534. if (lock_status & resource_bit)
  1535. return 0;
  1536. msleep(5);
  1537. }
  1538. BNX2X_ERR("Timeout\n");
  1539. return -EAGAIN;
  1540. }
  1541. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1542. {
  1543. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1544. }
  1545. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1546. {
  1547. u32 lock_status;
  1548. u32 resource_bit = (1 << resource);
  1549. int func = BP_FUNC(bp);
  1550. u32 hw_lock_control_reg;
  1551. /* Validating that the resource is within range */
  1552. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1553. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1554. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1555. return -EINVAL;
  1556. }
  1557. if (func <= 5) {
  1558. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1559. } else {
  1560. hw_lock_control_reg =
  1561. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1562. }
  1563. /* Validating that the resource is currently taken */
  1564. lock_status = REG_RD(bp, hw_lock_control_reg);
  1565. if (!(lock_status & resource_bit)) {
  1566. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1567. lock_status, resource_bit);
  1568. return -EFAULT;
  1569. }
  1570. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1571. return 0;
  1572. }
  1573. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1574. {
  1575. /* The GPIO should be swapped if swap register is set and active */
  1576. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1577. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1578. int gpio_shift = gpio_num +
  1579. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1580. u32 gpio_mask = (1 << gpio_shift);
  1581. u32 gpio_reg;
  1582. int value;
  1583. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1584. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1585. return -EINVAL;
  1586. }
  1587. /* read GPIO value */
  1588. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1589. /* get the requested pin value */
  1590. if ((gpio_reg & gpio_mask) == gpio_mask)
  1591. value = 1;
  1592. else
  1593. value = 0;
  1594. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1595. return value;
  1596. }
  1597. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1598. {
  1599. /* The GPIO should be swapped if swap register is set and active */
  1600. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1601. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1602. int gpio_shift = gpio_num +
  1603. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1604. u32 gpio_mask = (1 << gpio_shift);
  1605. u32 gpio_reg;
  1606. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1607. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1608. return -EINVAL;
  1609. }
  1610. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1611. /* read GPIO and mask except the float bits */
  1612. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1613. switch (mode) {
  1614. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1615. DP(NETIF_MSG_LINK,
  1616. "Set GPIO %d (shift %d) -> output low\n",
  1617. gpio_num, gpio_shift);
  1618. /* clear FLOAT and set CLR */
  1619. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1620. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1621. break;
  1622. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1623. DP(NETIF_MSG_LINK,
  1624. "Set GPIO %d (shift %d) -> output high\n",
  1625. gpio_num, gpio_shift);
  1626. /* clear FLOAT and set SET */
  1627. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1628. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1629. break;
  1630. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1631. DP(NETIF_MSG_LINK,
  1632. "Set GPIO %d (shift %d) -> input\n",
  1633. gpio_num, gpio_shift);
  1634. /* set FLOAT */
  1635. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1636. break;
  1637. default:
  1638. break;
  1639. }
  1640. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1641. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1642. return 0;
  1643. }
  1644. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1645. {
  1646. u32 gpio_reg = 0;
  1647. int rc = 0;
  1648. /* Any port swapping should be handled by caller. */
  1649. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1650. /* read GPIO and mask except the float bits */
  1651. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1652. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1653. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1654. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1655. switch (mode) {
  1656. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1657. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1658. /* set CLR */
  1659. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1660. break;
  1661. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1662. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1663. /* set SET */
  1664. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1665. break;
  1666. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1667. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1668. /* set FLOAT */
  1669. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1670. break;
  1671. default:
  1672. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1673. rc = -EINVAL;
  1674. break;
  1675. }
  1676. if (rc == 0)
  1677. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1678. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1679. return rc;
  1680. }
  1681. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1682. {
  1683. /* The GPIO should be swapped if swap register is set and active */
  1684. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1685. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1686. int gpio_shift = gpio_num +
  1687. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1688. u32 gpio_mask = (1 << gpio_shift);
  1689. u32 gpio_reg;
  1690. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1691. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1692. return -EINVAL;
  1693. }
  1694. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1695. /* read GPIO int */
  1696. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1697. switch (mode) {
  1698. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1699. DP(NETIF_MSG_LINK,
  1700. "Clear GPIO INT %d (shift %d) -> output low\n",
  1701. gpio_num, gpio_shift);
  1702. /* clear SET and set CLR */
  1703. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1704. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1705. break;
  1706. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1707. DP(NETIF_MSG_LINK,
  1708. "Set GPIO INT %d (shift %d) -> output high\n",
  1709. gpio_num, gpio_shift);
  1710. /* clear CLR and set SET */
  1711. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1712. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1713. break;
  1714. default:
  1715. break;
  1716. }
  1717. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1718. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1719. return 0;
  1720. }
  1721. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1722. {
  1723. u32 spio_reg;
  1724. /* Only 2 SPIOs are configurable */
  1725. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1726. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1727. return -EINVAL;
  1728. }
  1729. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1730. /* read SPIO and mask except the float bits */
  1731. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1732. switch (mode) {
  1733. case MISC_SPIO_OUTPUT_LOW:
  1734. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1735. /* clear FLOAT and set CLR */
  1736. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1737. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1738. break;
  1739. case MISC_SPIO_OUTPUT_HIGH:
  1740. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1741. /* clear FLOAT and set SET */
  1742. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1743. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1744. break;
  1745. case MISC_SPIO_INPUT_HI_Z:
  1746. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1747. /* set FLOAT */
  1748. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1749. break;
  1750. default:
  1751. break;
  1752. }
  1753. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1754. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1755. return 0;
  1756. }
  1757. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1758. {
  1759. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1760. switch (bp->link_vars.ieee_fc &
  1761. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1762. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1763. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1764. ADVERTISED_Pause);
  1765. break;
  1766. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1767. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1768. ADVERTISED_Pause);
  1769. break;
  1770. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1771. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1772. break;
  1773. default:
  1774. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1775. ADVERTISED_Pause);
  1776. break;
  1777. }
  1778. }
  1779. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1780. {
  1781. /* Initialize link parameters structure variables
  1782. * It is recommended to turn off RX FC for jumbo frames
  1783. * for better performance
  1784. */
  1785. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1786. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1787. else
  1788. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1789. }
  1790. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1791. {
  1792. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1793. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1794. if (!BP_NOMCP(bp)) {
  1795. bnx2x_set_requested_fc(bp);
  1796. bnx2x_acquire_phy_lock(bp);
  1797. if (load_mode == LOAD_DIAG) {
  1798. struct link_params *lp = &bp->link_params;
  1799. lp->loopback_mode = LOOPBACK_XGXS;
  1800. /* do PHY loopback at 10G speed, if possible */
  1801. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1802. if (lp->speed_cap_mask[cfx_idx] &
  1803. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1804. lp->req_line_speed[cfx_idx] =
  1805. SPEED_10000;
  1806. else
  1807. lp->req_line_speed[cfx_idx] =
  1808. SPEED_1000;
  1809. }
  1810. }
  1811. if (load_mode == LOAD_LOOPBACK_EXT) {
  1812. struct link_params *lp = &bp->link_params;
  1813. lp->loopback_mode = LOOPBACK_EXT;
  1814. }
  1815. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1816. bnx2x_release_phy_lock(bp);
  1817. bnx2x_calc_fc_adv(bp);
  1818. if (bp->link_vars.link_up) {
  1819. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1820. bnx2x_link_report(bp);
  1821. }
  1822. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1823. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1824. return rc;
  1825. }
  1826. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1827. return -EINVAL;
  1828. }
  1829. void bnx2x_link_set(struct bnx2x *bp)
  1830. {
  1831. if (!BP_NOMCP(bp)) {
  1832. bnx2x_acquire_phy_lock(bp);
  1833. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1834. bnx2x_release_phy_lock(bp);
  1835. bnx2x_calc_fc_adv(bp);
  1836. } else
  1837. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1838. }
  1839. static void bnx2x__link_reset(struct bnx2x *bp)
  1840. {
  1841. if (!BP_NOMCP(bp)) {
  1842. bnx2x_acquire_phy_lock(bp);
  1843. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1844. bnx2x_release_phy_lock(bp);
  1845. } else
  1846. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1847. }
  1848. void bnx2x_force_link_reset(struct bnx2x *bp)
  1849. {
  1850. bnx2x_acquire_phy_lock(bp);
  1851. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1852. bnx2x_release_phy_lock(bp);
  1853. }
  1854. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1855. {
  1856. u8 rc = 0;
  1857. if (!BP_NOMCP(bp)) {
  1858. bnx2x_acquire_phy_lock(bp);
  1859. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1860. is_serdes);
  1861. bnx2x_release_phy_lock(bp);
  1862. } else
  1863. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1864. return rc;
  1865. }
  1866. /* Calculates the sum of vn_min_rates.
  1867. It's needed for further normalizing of the min_rates.
  1868. Returns:
  1869. sum of vn_min_rates.
  1870. or
  1871. 0 - if all the min_rates are 0.
  1872. In the later case fainess algorithm should be deactivated.
  1873. If not all min_rates are zero then those that are zeroes will be set to 1.
  1874. */
  1875. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1876. struct cmng_init_input *input)
  1877. {
  1878. int all_zero = 1;
  1879. int vn;
  1880. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1881. u32 vn_cfg = bp->mf_config[vn];
  1882. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1883. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1884. /* Skip hidden vns */
  1885. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1886. vn_min_rate = 0;
  1887. /* If min rate is zero - set it to 1 */
  1888. else if (!vn_min_rate)
  1889. vn_min_rate = DEF_MIN_RATE;
  1890. else
  1891. all_zero = 0;
  1892. input->vnic_min_rate[vn] = vn_min_rate;
  1893. }
  1894. /* if ETS or all min rates are zeros - disable fairness */
  1895. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1896. input->flags.cmng_enables &=
  1897. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1898. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1899. } else if (all_zero) {
  1900. input->flags.cmng_enables &=
  1901. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1902. DP(NETIF_MSG_IFUP,
  1903. "All MIN values are zeroes fairness will be disabled\n");
  1904. } else
  1905. input->flags.cmng_enables |=
  1906. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1907. }
  1908. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  1909. struct cmng_init_input *input)
  1910. {
  1911. u16 vn_max_rate;
  1912. u32 vn_cfg = bp->mf_config[vn];
  1913. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1914. vn_max_rate = 0;
  1915. else {
  1916. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1917. if (IS_MF_SI(bp)) {
  1918. /* maxCfg in percents of linkspeed */
  1919. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1920. } else /* SD modes */
  1921. /* maxCfg is absolute in 100Mb units */
  1922. vn_max_rate = maxCfg * 100;
  1923. }
  1924. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  1925. input->vnic_max_rate[vn] = vn_max_rate;
  1926. }
  1927. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  1928. {
  1929. if (CHIP_REV_IS_SLOW(bp))
  1930. return CMNG_FNS_NONE;
  1931. if (IS_MF(bp))
  1932. return CMNG_FNS_MINMAX;
  1933. return CMNG_FNS_NONE;
  1934. }
  1935. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  1936. {
  1937. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  1938. if (BP_NOMCP(bp))
  1939. return; /* what should be the default bvalue in this case */
  1940. /* For 2 port configuration the absolute function number formula
  1941. * is:
  1942. * abs_func = 2 * vn + BP_PORT + BP_PATH
  1943. *
  1944. * and there are 4 functions per port
  1945. *
  1946. * For 4 port configuration it is
  1947. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  1948. *
  1949. * and there are 2 functions per port
  1950. */
  1951. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1952. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  1953. if (func >= E1H_FUNC_MAX)
  1954. break;
  1955. bp->mf_config[vn] =
  1956. MF_CFG_RD(bp, func_mf_config[func].config);
  1957. }
  1958. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  1959. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  1960. bp->flags |= MF_FUNC_DIS;
  1961. } else {
  1962. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  1963. bp->flags &= ~MF_FUNC_DIS;
  1964. }
  1965. }
  1966. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  1967. {
  1968. struct cmng_init_input input;
  1969. memset(&input, 0, sizeof(struct cmng_init_input));
  1970. input.port_rate = bp->link_vars.line_speed;
  1971. if (cmng_type == CMNG_FNS_MINMAX) {
  1972. int vn;
  1973. /* read mf conf from shmem */
  1974. if (read_cfg)
  1975. bnx2x_read_mf_cfg(bp);
  1976. /* vn_weight_sum and enable fairness if not 0 */
  1977. bnx2x_calc_vn_min(bp, &input);
  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_calc_vn_max(bp, vn, &input);
  1982. /* always enable rate shaping and fairness */
  1983. input.flags.cmng_enables |=
  1984. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  1985. bnx2x_init_cmng(&input, &bp->cmng);
  1986. return;
  1987. }
  1988. /* rate shaping and fairness are disabled */
  1989. DP(NETIF_MSG_IFUP,
  1990. "rate shaping and fairness are disabled\n");
  1991. }
  1992. static void storm_memset_cmng(struct bnx2x *bp,
  1993. struct cmng_init *cmng,
  1994. u8 port)
  1995. {
  1996. int vn;
  1997. size_t size = sizeof(struct cmng_struct_per_port);
  1998. u32 addr = BAR_XSTRORM_INTMEM +
  1999. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2000. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2001. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2002. int func = func_by_vn(bp, vn);
  2003. addr = BAR_XSTRORM_INTMEM +
  2004. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2005. size = sizeof(struct rate_shaping_vars_per_vn);
  2006. __storm_memset_struct(bp, addr, size,
  2007. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2008. addr = BAR_XSTRORM_INTMEM +
  2009. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2010. size = sizeof(struct fairness_vars_per_vn);
  2011. __storm_memset_struct(bp, addr, size,
  2012. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2013. }
  2014. }
  2015. /* This function is called upon link interrupt */
  2016. static void bnx2x_link_attn(struct bnx2x *bp)
  2017. {
  2018. /* Make sure that we are synced with the current statistics */
  2019. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2020. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2021. if (bp->link_vars.link_up) {
  2022. /* dropless flow control */
  2023. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2024. int port = BP_PORT(bp);
  2025. u32 pause_enabled = 0;
  2026. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2027. pause_enabled = 1;
  2028. REG_WR(bp, BAR_USTRORM_INTMEM +
  2029. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2030. pause_enabled);
  2031. }
  2032. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2033. struct host_port_stats *pstats;
  2034. pstats = bnx2x_sp(bp, port_stats);
  2035. /* reset old mac stats */
  2036. memset(&(pstats->mac_stx[0]), 0,
  2037. sizeof(struct mac_stx));
  2038. }
  2039. if (bp->state == BNX2X_STATE_OPEN)
  2040. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2041. }
  2042. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2043. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2044. if (cmng_fns != CMNG_FNS_NONE) {
  2045. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2046. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2047. } else
  2048. /* rate shaping and fairness are disabled */
  2049. DP(NETIF_MSG_IFUP,
  2050. "single function mode without fairness\n");
  2051. }
  2052. __bnx2x_link_report(bp);
  2053. if (IS_MF(bp))
  2054. bnx2x_link_sync_notify(bp);
  2055. }
  2056. void bnx2x__link_status_update(struct bnx2x *bp)
  2057. {
  2058. if (bp->state != BNX2X_STATE_OPEN)
  2059. return;
  2060. /* read updated dcb configuration */
  2061. bnx2x_dcbx_pmf_update(bp);
  2062. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2063. if (bp->link_vars.link_up)
  2064. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2065. else
  2066. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2067. /* indicate link status */
  2068. bnx2x_link_report(bp);
  2069. }
  2070. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2071. u16 vlan_val, u8 allowed_prio)
  2072. {
  2073. struct bnx2x_func_state_params func_params = {0};
  2074. struct bnx2x_func_afex_update_params *f_update_params =
  2075. &func_params.params.afex_update;
  2076. func_params.f_obj = &bp->func_obj;
  2077. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2078. /* no need to wait for RAMROD completion, so don't
  2079. * set RAMROD_COMP_WAIT flag
  2080. */
  2081. f_update_params->vif_id = vifid;
  2082. f_update_params->afex_default_vlan = vlan_val;
  2083. f_update_params->allowed_priorities = allowed_prio;
  2084. /* if ramrod can not be sent, response to MCP immediately */
  2085. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2086. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2087. return 0;
  2088. }
  2089. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2090. u16 vif_index, u8 func_bit_map)
  2091. {
  2092. struct bnx2x_func_state_params func_params = {0};
  2093. struct bnx2x_func_afex_viflists_params *update_params =
  2094. &func_params.params.afex_viflists;
  2095. int rc;
  2096. u32 drv_msg_code;
  2097. /* validate only LIST_SET and LIST_GET are received from switch */
  2098. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2099. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2100. cmd_type);
  2101. func_params.f_obj = &bp->func_obj;
  2102. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2103. /* set parameters according to cmd_type */
  2104. update_params->afex_vif_list_command = cmd_type;
  2105. update_params->vif_list_index = cpu_to_le16(vif_index);
  2106. update_params->func_bit_map =
  2107. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2108. update_params->func_to_clear = 0;
  2109. drv_msg_code =
  2110. (cmd_type == VIF_LIST_RULE_GET) ?
  2111. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2112. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2113. /* if ramrod can not be sent, respond to MCP immediately for
  2114. * SET and GET requests (other are not triggered from MCP)
  2115. */
  2116. rc = bnx2x_func_state_change(bp, &func_params);
  2117. if (rc < 0)
  2118. bnx2x_fw_command(bp, drv_msg_code, 0);
  2119. return 0;
  2120. }
  2121. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2122. {
  2123. struct afex_stats afex_stats;
  2124. u32 func = BP_ABS_FUNC(bp);
  2125. u32 mf_config;
  2126. u16 vlan_val;
  2127. u32 vlan_prio;
  2128. u16 vif_id;
  2129. u8 allowed_prio;
  2130. u8 vlan_mode;
  2131. u32 addr_to_write, vifid, addrs, stats_type, i;
  2132. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2133. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2134. DP(BNX2X_MSG_MCP,
  2135. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2136. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2137. }
  2138. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2139. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2140. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2141. DP(BNX2X_MSG_MCP,
  2142. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2143. vifid, addrs);
  2144. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2145. addrs);
  2146. }
  2147. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2148. addr_to_write = SHMEM2_RD(bp,
  2149. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2150. stats_type = SHMEM2_RD(bp,
  2151. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2152. DP(BNX2X_MSG_MCP,
  2153. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2154. addr_to_write);
  2155. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2156. /* write response to scratchpad, for MCP */
  2157. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2158. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2159. *(((u32 *)(&afex_stats))+i));
  2160. /* send ack message to MCP */
  2161. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2162. }
  2163. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2164. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2165. bp->mf_config[BP_VN(bp)] = mf_config;
  2166. DP(BNX2X_MSG_MCP,
  2167. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2168. mf_config);
  2169. /* if VIF_SET is "enabled" */
  2170. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2171. /* set rate limit directly to internal RAM */
  2172. struct cmng_init_input cmng_input;
  2173. struct rate_shaping_vars_per_vn m_rs_vn;
  2174. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2175. u32 addr = BAR_XSTRORM_INTMEM +
  2176. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2177. bp->mf_config[BP_VN(bp)] = mf_config;
  2178. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2179. m_rs_vn.vn_counter.rate =
  2180. cmng_input.vnic_max_rate[BP_VN(bp)];
  2181. m_rs_vn.vn_counter.quota =
  2182. (m_rs_vn.vn_counter.rate *
  2183. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2184. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2185. /* read relevant values from mf_cfg struct in shmem */
  2186. vif_id =
  2187. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2188. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2189. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2190. vlan_val =
  2191. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2192. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2193. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2194. vlan_prio = (mf_config &
  2195. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2196. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2197. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2198. vlan_mode =
  2199. (MF_CFG_RD(bp,
  2200. func_mf_config[func].afex_config) &
  2201. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2202. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2203. allowed_prio =
  2204. (MF_CFG_RD(bp,
  2205. func_mf_config[func].afex_config) &
  2206. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2207. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2208. /* send ramrod to FW, return in case of failure */
  2209. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2210. allowed_prio))
  2211. return;
  2212. bp->afex_def_vlan_tag = vlan_val;
  2213. bp->afex_vlan_mode = vlan_mode;
  2214. } else {
  2215. /* notify link down because BP->flags is disabled */
  2216. bnx2x_link_report(bp);
  2217. /* send INVALID VIF ramrod to FW */
  2218. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2219. /* Reset the default afex VLAN */
  2220. bp->afex_def_vlan_tag = -1;
  2221. }
  2222. }
  2223. }
  2224. static void bnx2x_pmf_update(struct bnx2x *bp)
  2225. {
  2226. int port = BP_PORT(bp);
  2227. u32 val;
  2228. bp->port.pmf = 1;
  2229. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2230. /*
  2231. * We need the mb() to ensure the ordering between the writing to
  2232. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2233. */
  2234. smp_mb();
  2235. /* queue a periodic task */
  2236. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2237. bnx2x_dcbx_pmf_update(bp);
  2238. /* enable nig attention */
  2239. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2240. if (bp->common.int_block == INT_BLOCK_HC) {
  2241. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2242. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2243. } else if (!CHIP_IS_E1x(bp)) {
  2244. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2245. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2246. }
  2247. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2248. }
  2249. /* end of Link */
  2250. /* slow path */
  2251. /*
  2252. * General service functions
  2253. */
  2254. /* send the MCP a request, block until there is a reply */
  2255. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2256. {
  2257. int mb_idx = BP_FW_MB_IDX(bp);
  2258. u32 seq;
  2259. u32 rc = 0;
  2260. u32 cnt = 1;
  2261. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2262. mutex_lock(&bp->fw_mb_mutex);
  2263. seq = ++bp->fw_seq;
  2264. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2265. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2266. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2267. (command | seq), param);
  2268. do {
  2269. /* let the FW do it's magic ... */
  2270. msleep(delay);
  2271. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2272. /* Give the FW up to 5 second (500*10ms) */
  2273. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2274. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2275. cnt*delay, rc, seq);
  2276. /* is this a reply to our command? */
  2277. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2278. rc &= FW_MSG_CODE_MASK;
  2279. else {
  2280. /* FW BUG! */
  2281. BNX2X_ERR("FW failed to respond!\n");
  2282. bnx2x_fw_dump(bp);
  2283. rc = 0;
  2284. }
  2285. mutex_unlock(&bp->fw_mb_mutex);
  2286. return rc;
  2287. }
  2288. static void storm_memset_func_cfg(struct bnx2x *bp,
  2289. struct tstorm_eth_function_common_config *tcfg,
  2290. u16 abs_fid)
  2291. {
  2292. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2293. u32 addr = BAR_TSTRORM_INTMEM +
  2294. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2295. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2296. }
  2297. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2298. {
  2299. if (CHIP_IS_E1x(bp)) {
  2300. struct tstorm_eth_function_common_config tcfg = {0};
  2301. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2302. }
  2303. /* Enable the function in the FW */
  2304. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2305. storm_memset_func_en(bp, p->func_id, 1);
  2306. /* spq */
  2307. if (p->func_flgs & FUNC_FLG_SPQ) {
  2308. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2309. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2310. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2311. }
  2312. }
  2313. /**
  2314. * bnx2x_get_tx_only_flags - Return common flags
  2315. *
  2316. * @bp device handle
  2317. * @fp queue handle
  2318. * @zero_stats TRUE if statistics zeroing is needed
  2319. *
  2320. * Return the flags that are common for the Tx-only and not normal connections.
  2321. */
  2322. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2323. struct bnx2x_fastpath *fp,
  2324. bool zero_stats)
  2325. {
  2326. unsigned long flags = 0;
  2327. /* PF driver will always initialize the Queue to an ACTIVE state */
  2328. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2329. /* tx only connections collect statistics (on the same index as the
  2330. * parent connection). The statistics are zeroed when the parent
  2331. * connection is initialized.
  2332. */
  2333. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2334. if (zero_stats)
  2335. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2336. return flags;
  2337. }
  2338. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2339. struct bnx2x_fastpath *fp,
  2340. bool leading)
  2341. {
  2342. unsigned long flags = 0;
  2343. /* calculate other queue flags */
  2344. if (IS_MF_SD(bp))
  2345. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2346. if (IS_FCOE_FP(fp)) {
  2347. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2348. /* For FCoE - force usage of default priority (for afex) */
  2349. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2350. }
  2351. if (!fp->disable_tpa) {
  2352. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2353. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2354. if (fp->mode == TPA_MODE_GRO)
  2355. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2356. }
  2357. if (leading) {
  2358. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2359. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2360. }
  2361. /* Always set HW VLAN stripping */
  2362. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2363. /* configure silent vlan removal */
  2364. if (IS_MF_AFEX(bp))
  2365. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2366. return flags | bnx2x_get_common_flags(bp, fp, true);
  2367. }
  2368. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2369. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2370. u8 cos)
  2371. {
  2372. gen_init->stat_id = bnx2x_stats_id(fp);
  2373. gen_init->spcl_id = fp->cl_id;
  2374. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2375. if (IS_FCOE_FP(fp))
  2376. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2377. else
  2378. gen_init->mtu = bp->dev->mtu;
  2379. gen_init->cos = cos;
  2380. }
  2381. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2382. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2383. struct bnx2x_rxq_setup_params *rxq_init)
  2384. {
  2385. u8 max_sge = 0;
  2386. u16 sge_sz = 0;
  2387. u16 tpa_agg_size = 0;
  2388. if (!fp->disable_tpa) {
  2389. pause->sge_th_lo = SGE_TH_LO(bp);
  2390. pause->sge_th_hi = SGE_TH_HI(bp);
  2391. /* validate SGE ring has enough to cross high threshold */
  2392. WARN_ON(bp->dropless_fc &&
  2393. pause->sge_th_hi + FW_PREFETCH_CNT >
  2394. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2395. tpa_agg_size = min_t(u32,
  2396. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2397. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2398. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2399. SGE_PAGE_SHIFT;
  2400. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2401. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2402. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2403. 0xffff);
  2404. }
  2405. /* pause - not for e1 */
  2406. if (!CHIP_IS_E1(bp)) {
  2407. pause->bd_th_lo = BD_TH_LO(bp);
  2408. pause->bd_th_hi = BD_TH_HI(bp);
  2409. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2410. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2411. /*
  2412. * validate that rings have enough entries to cross
  2413. * high thresholds
  2414. */
  2415. WARN_ON(bp->dropless_fc &&
  2416. pause->bd_th_hi + FW_PREFETCH_CNT >
  2417. bp->rx_ring_size);
  2418. WARN_ON(bp->dropless_fc &&
  2419. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2420. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2421. pause->pri_map = 1;
  2422. }
  2423. /* rxq setup */
  2424. rxq_init->dscr_map = fp->rx_desc_mapping;
  2425. rxq_init->sge_map = fp->rx_sge_mapping;
  2426. rxq_init->rcq_map = fp->rx_comp_mapping;
  2427. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2428. /* This should be a maximum number of data bytes that may be
  2429. * placed on the BD (not including paddings).
  2430. */
  2431. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2432. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2433. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2434. rxq_init->tpa_agg_sz = tpa_agg_size;
  2435. rxq_init->sge_buf_sz = sge_sz;
  2436. rxq_init->max_sges_pkt = max_sge;
  2437. rxq_init->rss_engine_id = BP_FUNC(bp);
  2438. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2439. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2440. *
  2441. * For PF Clients it should be the maximum avaliable number.
  2442. * VF driver(s) may want to define it to a smaller value.
  2443. */
  2444. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2445. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2446. rxq_init->fw_sb_id = fp->fw_sb_id;
  2447. if (IS_FCOE_FP(fp))
  2448. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2449. else
  2450. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2451. /* configure silent vlan removal
  2452. * if multi function mode is afex, then mask default vlan
  2453. */
  2454. if (IS_MF_AFEX(bp)) {
  2455. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2456. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2457. }
  2458. }
  2459. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2460. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2461. u8 cos)
  2462. {
  2463. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2464. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2465. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2466. txq_init->fw_sb_id = fp->fw_sb_id;
  2467. /*
  2468. * set the tss leading client id for TX classfication ==
  2469. * leading RSS client id
  2470. */
  2471. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2472. if (IS_FCOE_FP(fp)) {
  2473. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2474. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2475. }
  2476. }
  2477. static void bnx2x_pf_init(struct bnx2x *bp)
  2478. {
  2479. struct bnx2x_func_init_params func_init = {0};
  2480. struct event_ring_data eq_data = { {0} };
  2481. u16 flags;
  2482. if (!CHIP_IS_E1x(bp)) {
  2483. /* reset IGU PF statistics: MSIX + ATTN */
  2484. /* PF */
  2485. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2486. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2487. (CHIP_MODE_IS_4_PORT(bp) ?
  2488. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2489. /* ATTN */
  2490. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2491. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2492. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2493. (CHIP_MODE_IS_4_PORT(bp) ?
  2494. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2495. }
  2496. /* function setup flags */
  2497. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2498. /* This flag is relevant for E1x only.
  2499. * E2 doesn't have a TPA configuration in a function level.
  2500. */
  2501. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2502. func_init.func_flgs = flags;
  2503. func_init.pf_id = BP_FUNC(bp);
  2504. func_init.func_id = BP_FUNC(bp);
  2505. func_init.spq_map = bp->spq_mapping;
  2506. func_init.spq_prod = bp->spq_prod_idx;
  2507. bnx2x_func_init(bp, &func_init);
  2508. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2509. /*
  2510. * Congestion management values depend on the link rate
  2511. * There is no active link so initial link rate is set to 10 Gbps.
  2512. * When the link comes up The congestion management values are
  2513. * re-calculated according to the actual link rate.
  2514. */
  2515. bp->link_vars.line_speed = SPEED_10000;
  2516. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2517. /* Only the PMF sets the HW */
  2518. if (bp->port.pmf)
  2519. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2520. /* init Event Queue */
  2521. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2522. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2523. eq_data.producer = bp->eq_prod;
  2524. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2525. eq_data.sb_id = DEF_SB_ID;
  2526. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2527. }
  2528. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2529. {
  2530. int port = BP_PORT(bp);
  2531. bnx2x_tx_disable(bp);
  2532. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2533. }
  2534. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2535. {
  2536. int port = BP_PORT(bp);
  2537. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2538. /* Tx queue should be only reenabled */
  2539. netif_tx_wake_all_queues(bp->dev);
  2540. /*
  2541. * Should not call netif_carrier_on since it will be called if the link
  2542. * is up when checking for link state
  2543. */
  2544. }
  2545. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2546. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2547. {
  2548. struct eth_stats_info *ether_stat =
  2549. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2550. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2551. ETH_STAT_INFO_VERSION_LEN);
  2552. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2553. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2554. ether_stat->mac_local);
  2555. ether_stat->mtu_size = bp->dev->mtu;
  2556. if (bp->dev->features & NETIF_F_RXCSUM)
  2557. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2558. if (bp->dev->features & NETIF_F_TSO)
  2559. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2560. ether_stat->feature_flags |= bp->common.boot_mode;
  2561. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2562. ether_stat->txq_size = bp->tx_ring_size;
  2563. ether_stat->rxq_size = bp->rx_ring_size;
  2564. }
  2565. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2566. {
  2567. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2568. struct fcoe_stats_info *fcoe_stat =
  2569. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2570. if (!CNIC_LOADED(bp))
  2571. return;
  2572. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2573. bp->fip_mac, ETH_ALEN);
  2574. fcoe_stat->qos_priority =
  2575. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2576. /* insert FCoE stats from ramrod response */
  2577. if (!NO_FCOE(bp)) {
  2578. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2579. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2580. tstorm_queue_statistics;
  2581. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2582. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2583. xstorm_queue_statistics;
  2584. struct fcoe_statistics_params *fw_fcoe_stat =
  2585. &bp->fw_stats_data->fcoe;
  2586. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2587. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2588. ADD_64(fcoe_stat->rx_bytes_hi,
  2589. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2590. fcoe_stat->rx_bytes_lo,
  2591. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2592. ADD_64(fcoe_stat->rx_bytes_hi,
  2593. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2594. fcoe_stat->rx_bytes_lo,
  2595. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2596. ADD_64(fcoe_stat->rx_bytes_hi,
  2597. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2598. fcoe_stat->rx_bytes_lo,
  2599. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2600. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2601. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2602. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2603. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2604. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2605. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2606. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2607. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2608. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2609. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2610. ADD_64(fcoe_stat->tx_bytes_hi,
  2611. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2612. fcoe_stat->tx_bytes_lo,
  2613. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2614. ADD_64(fcoe_stat->tx_bytes_hi,
  2615. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2616. fcoe_stat->tx_bytes_lo,
  2617. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2618. ADD_64(fcoe_stat->tx_bytes_hi,
  2619. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2620. fcoe_stat->tx_bytes_lo,
  2621. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2622. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2623. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2624. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2625. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2626. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2627. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2628. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2629. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2630. }
  2631. /* ask L5 driver to add data to the struct */
  2632. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2633. }
  2634. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2635. {
  2636. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2637. struct iscsi_stats_info *iscsi_stat =
  2638. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2639. if (!CNIC_LOADED(bp))
  2640. return;
  2641. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2642. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2643. iscsi_stat->qos_priority =
  2644. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2645. /* ask L5 driver to add data to the struct */
  2646. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2647. }
  2648. /* called due to MCP event (on pmf):
  2649. * reread new bandwidth configuration
  2650. * configure FW
  2651. * notify others function about the change
  2652. */
  2653. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2654. {
  2655. if (bp->link_vars.link_up) {
  2656. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2657. bnx2x_link_sync_notify(bp);
  2658. }
  2659. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2660. }
  2661. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2662. {
  2663. bnx2x_config_mf_bw(bp);
  2664. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2665. }
  2666. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2667. {
  2668. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2669. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2670. }
  2671. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2672. {
  2673. enum drv_info_opcode op_code;
  2674. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2675. /* if drv_info version supported by MFW doesn't match - send NACK */
  2676. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2677. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2678. return;
  2679. }
  2680. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2681. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2682. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2683. sizeof(union drv_info_to_mcp));
  2684. switch (op_code) {
  2685. case ETH_STATS_OPCODE:
  2686. bnx2x_drv_info_ether_stat(bp);
  2687. break;
  2688. case FCOE_STATS_OPCODE:
  2689. bnx2x_drv_info_fcoe_stat(bp);
  2690. break;
  2691. case ISCSI_STATS_OPCODE:
  2692. bnx2x_drv_info_iscsi_stat(bp);
  2693. break;
  2694. default:
  2695. /* if op code isn't supported - send NACK */
  2696. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2697. return;
  2698. }
  2699. /* if we got drv_info attn from MFW then these fields are defined in
  2700. * shmem2 for sure
  2701. */
  2702. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2703. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2704. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2705. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2706. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2707. }
  2708. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2709. {
  2710. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2711. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2712. /*
  2713. * This is the only place besides the function initialization
  2714. * where the bp->flags can change so it is done without any
  2715. * locks
  2716. */
  2717. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2718. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2719. bp->flags |= MF_FUNC_DIS;
  2720. bnx2x_e1h_disable(bp);
  2721. } else {
  2722. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2723. bp->flags &= ~MF_FUNC_DIS;
  2724. bnx2x_e1h_enable(bp);
  2725. }
  2726. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2727. }
  2728. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2729. bnx2x_config_mf_bw(bp);
  2730. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2731. }
  2732. /* Report results to MCP */
  2733. if (dcc_event)
  2734. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2735. else
  2736. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2737. }
  2738. /* must be called under the spq lock */
  2739. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2740. {
  2741. struct eth_spe *next_spe = bp->spq_prod_bd;
  2742. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2743. bp->spq_prod_bd = bp->spq;
  2744. bp->spq_prod_idx = 0;
  2745. DP(BNX2X_MSG_SP, "end of spq\n");
  2746. } else {
  2747. bp->spq_prod_bd++;
  2748. bp->spq_prod_idx++;
  2749. }
  2750. return next_spe;
  2751. }
  2752. /* must be called under the spq lock */
  2753. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2754. {
  2755. int func = BP_FUNC(bp);
  2756. /*
  2757. * Make sure that BD data is updated before writing the producer:
  2758. * BD data is written to the memory, the producer is read from the
  2759. * memory, thus we need a full memory barrier to ensure the ordering.
  2760. */
  2761. mb();
  2762. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2763. bp->spq_prod_idx);
  2764. mmiowb();
  2765. }
  2766. /**
  2767. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2768. *
  2769. * @cmd: command to check
  2770. * @cmd_type: command type
  2771. */
  2772. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2773. {
  2774. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2775. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2776. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2777. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2778. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2779. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2780. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2781. return true;
  2782. else
  2783. return false;
  2784. }
  2785. /**
  2786. * bnx2x_sp_post - place a single command on an SP ring
  2787. *
  2788. * @bp: driver handle
  2789. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2790. * @cid: SW CID the command is related to
  2791. * @data_hi: command private data address (high 32 bits)
  2792. * @data_lo: command private data address (low 32 bits)
  2793. * @cmd_type: command type (e.g. NONE, ETH)
  2794. *
  2795. * SP data is handled as if it's always an address pair, thus data fields are
  2796. * not swapped to little endian in upper functions. Instead this function swaps
  2797. * data as if it's two u32 fields.
  2798. */
  2799. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2800. u32 data_hi, u32 data_lo, int cmd_type)
  2801. {
  2802. struct eth_spe *spe;
  2803. u16 type;
  2804. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2805. #ifdef BNX2X_STOP_ON_ERROR
  2806. if (unlikely(bp->panic)) {
  2807. BNX2X_ERR("Can't post SP when there is panic\n");
  2808. return -EIO;
  2809. }
  2810. #endif
  2811. spin_lock_bh(&bp->spq_lock);
  2812. if (common) {
  2813. if (!atomic_read(&bp->eq_spq_left)) {
  2814. BNX2X_ERR("BUG! EQ ring full!\n");
  2815. spin_unlock_bh(&bp->spq_lock);
  2816. bnx2x_panic();
  2817. return -EBUSY;
  2818. }
  2819. } else if (!atomic_read(&bp->cq_spq_left)) {
  2820. BNX2X_ERR("BUG! SPQ ring full!\n");
  2821. spin_unlock_bh(&bp->spq_lock);
  2822. bnx2x_panic();
  2823. return -EBUSY;
  2824. }
  2825. spe = bnx2x_sp_get_next(bp);
  2826. /* CID needs port number to be encoded int it */
  2827. spe->hdr.conn_and_cmd_data =
  2828. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2829. HW_CID(bp, cid));
  2830. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2831. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2832. SPE_HDR_FUNCTION_ID);
  2833. spe->hdr.type = cpu_to_le16(type);
  2834. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2835. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2836. /*
  2837. * It's ok if the actual decrement is issued towards the memory
  2838. * somewhere between the spin_lock and spin_unlock. Thus no
  2839. * more explict memory barrier is needed.
  2840. */
  2841. if (common)
  2842. atomic_dec(&bp->eq_spq_left);
  2843. else
  2844. atomic_dec(&bp->cq_spq_left);
  2845. DP(BNX2X_MSG_SP,
  2846. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2847. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2848. (u32)(U64_LO(bp->spq_mapping) +
  2849. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2850. HW_CID(bp, cid), data_hi, data_lo, type,
  2851. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2852. bnx2x_sp_prod_update(bp);
  2853. spin_unlock_bh(&bp->spq_lock);
  2854. return 0;
  2855. }
  2856. /* acquire split MCP access lock register */
  2857. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2858. {
  2859. u32 j, val;
  2860. int rc = 0;
  2861. might_sleep();
  2862. for (j = 0; j < 1000; j++) {
  2863. val = (1UL << 31);
  2864. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2865. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2866. if (val & (1L << 31))
  2867. break;
  2868. msleep(5);
  2869. }
  2870. if (!(val & (1L << 31))) {
  2871. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2872. rc = -EBUSY;
  2873. }
  2874. return rc;
  2875. }
  2876. /* release split MCP access lock register */
  2877. static void bnx2x_release_alr(struct bnx2x *bp)
  2878. {
  2879. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2880. }
  2881. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2882. #define BNX2X_DEF_SB_IDX 0x0002
  2883. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2884. {
  2885. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2886. u16 rc = 0;
  2887. barrier(); /* status block is written to by the chip */
  2888. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2889. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2890. rc |= BNX2X_DEF_SB_ATT_IDX;
  2891. }
  2892. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2893. bp->def_idx = def_sb->sp_sb.running_index;
  2894. rc |= BNX2X_DEF_SB_IDX;
  2895. }
  2896. /* Do not reorder: indecies reading should complete before handling */
  2897. barrier();
  2898. return rc;
  2899. }
  2900. /*
  2901. * slow path service functions
  2902. */
  2903. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2904. {
  2905. int port = BP_PORT(bp);
  2906. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2907. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2908. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2909. NIG_REG_MASK_INTERRUPT_PORT0;
  2910. u32 aeu_mask;
  2911. u32 nig_mask = 0;
  2912. u32 reg_addr;
  2913. if (bp->attn_state & asserted)
  2914. BNX2X_ERR("IGU ERROR\n");
  2915. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2916. aeu_mask = REG_RD(bp, aeu_addr);
  2917. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2918. aeu_mask, asserted);
  2919. aeu_mask &= ~(asserted & 0x3ff);
  2920. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2921. REG_WR(bp, aeu_addr, aeu_mask);
  2922. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2923. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2924. bp->attn_state |= asserted;
  2925. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2926. if (asserted & ATTN_HARD_WIRED_MASK) {
  2927. if (asserted & ATTN_NIG_FOR_FUNC) {
  2928. bnx2x_acquire_phy_lock(bp);
  2929. /* save nig interrupt mask */
  2930. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2931. /* If nig_mask is not set, no need to call the update
  2932. * function.
  2933. */
  2934. if (nig_mask) {
  2935. REG_WR(bp, nig_int_mask_addr, 0);
  2936. bnx2x_link_attn(bp);
  2937. }
  2938. /* handle unicore attn? */
  2939. }
  2940. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2941. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2942. if (asserted & GPIO_2_FUNC)
  2943. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2944. if (asserted & GPIO_3_FUNC)
  2945. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2946. if (asserted & GPIO_4_FUNC)
  2947. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2948. if (port == 0) {
  2949. if (asserted & ATTN_GENERAL_ATTN_1) {
  2950. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2951. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2952. }
  2953. if (asserted & ATTN_GENERAL_ATTN_2) {
  2954. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2955. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2956. }
  2957. if (asserted & ATTN_GENERAL_ATTN_3) {
  2958. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2959. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2960. }
  2961. } else {
  2962. if (asserted & ATTN_GENERAL_ATTN_4) {
  2963. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2964. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2965. }
  2966. if (asserted & ATTN_GENERAL_ATTN_5) {
  2967. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2968. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2969. }
  2970. if (asserted & ATTN_GENERAL_ATTN_6) {
  2971. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2972. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2973. }
  2974. }
  2975. } /* if hardwired */
  2976. if (bp->common.int_block == INT_BLOCK_HC)
  2977. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2978. COMMAND_REG_ATTN_BITS_SET);
  2979. else
  2980. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2981. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2982. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2983. REG_WR(bp, reg_addr, asserted);
  2984. /* now set back the mask */
  2985. if (asserted & ATTN_NIG_FOR_FUNC) {
  2986. /* Verify that IGU ack through BAR was written before restoring
  2987. * NIG mask. This loop should exit after 2-3 iterations max.
  2988. */
  2989. if (bp->common.int_block != INT_BLOCK_HC) {
  2990. u32 cnt = 0, igu_acked;
  2991. do {
  2992. igu_acked = REG_RD(bp,
  2993. IGU_REG_ATTENTION_ACK_BITS);
  2994. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  2995. (++cnt < MAX_IGU_ATTN_ACK_TO));
  2996. if (!igu_acked)
  2997. DP(NETIF_MSG_HW,
  2998. "Failed to verify IGU ack on time\n");
  2999. barrier();
  3000. }
  3001. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3002. bnx2x_release_phy_lock(bp);
  3003. }
  3004. }
  3005. static void bnx2x_fan_failure(struct bnx2x *bp)
  3006. {
  3007. int port = BP_PORT(bp);
  3008. u32 ext_phy_config;
  3009. /* mark the failure */
  3010. ext_phy_config =
  3011. SHMEM_RD(bp,
  3012. dev_info.port_hw_config[port].external_phy_config);
  3013. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3014. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3015. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3016. ext_phy_config);
  3017. /* log the failure */
  3018. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3019. "Please contact OEM Support for assistance\n");
  3020. /*
  3021. * Scheudle device reset (unload)
  3022. * This is due to some boards consuming sufficient power when driver is
  3023. * up to overheat if fan fails.
  3024. */
  3025. smp_mb__before_clear_bit();
  3026. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3027. smp_mb__after_clear_bit();
  3028. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3029. }
  3030. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3031. {
  3032. int port = BP_PORT(bp);
  3033. int reg_offset;
  3034. u32 val;
  3035. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3036. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3037. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3038. val = REG_RD(bp, reg_offset);
  3039. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3040. REG_WR(bp, reg_offset, val);
  3041. BNX2X_ERR("SPIO5 hw attention\n");
  3042. /* Fan failure attention */
  3043. bnx2x_hw_reset_phy(&bp->link_params);
  3044. bnx2x_fan_failure(bp);
  3045. }
  3046. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3047. bnx2x_acquire_phy_lock(bp);
  3048. bnx2x_handle_module_detect_int(&bp->link_params);
  3049. bnx2x_release_phy_lock(bp);
  3050. }
  3051. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3052. val = REG_RD(bp, reg_offset);
  3053. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3054. REG_WR(bp, reg_offset, val);
  3055. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3056. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3057. bnx2x_panic();
  3058. }
  3059. }
  3060. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3061. {
  3062. u32 val;
  3063. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3064. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3065. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3066. /* DORQ discard attention */
  3067. if (val & 0x2)
  3068. BNX2X_ERR("FATAL error from DORQ\n");
  3069. }
  3070. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3071. int port = BP_PORT(bp);
  3072. int reg_offset;
  3073. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3074. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3075. val = REG_RD(bp, reg_offset);
  3076. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3077. REG_WR(bp, reg_offset, val);
  3078. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3079. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3080. bnx2x_panic();
  3081. }
  3082. }
  3083. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3084. {
  3085. u32 val;
  3086. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3087. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3088. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3089. /* CFC error attention */
  3090. if (val & 0x2)
  3091. BNX2X_ERR("FATAL error from CFC\n");
  3092. }
  3093. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3094. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3095. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3096. /* RQ_USDMDP_FIFO_OVERFLOW */
  3097. if (val & 0x18000)
  3098. BNX2X_ERR("FATAL error from PXP\n");
  3099. if (!CHIP_IS_E1x(bp)) {
  3100. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3101. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3102. }
  3103. }
  3104. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3105. int port = BP_PORT(bp);
  3106. int reg_offset;
  3107. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3108. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3109. val = REG_RD(bp, reg_offset);
  3110. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3111. REG_WR(bp, reg_offset, val);
  3112. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3113. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3114. bnx2x_panic();
  3115. }
  3116. }
  3117. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3118. {
  3119. u32 val;
  3120. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3121. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3122. int func = BP_FUNC(bp);
  3123. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3124. bnx2x_read_mf_cfg(bp);
  3125. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3126. func_mf_config[BP_ABS_FUNC(bp)].config);
  3127. val = SHMEM_RD(bp,
  3128. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3129. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3130. bnx2x_dcc_event(bp,
  3131. (val & DRV_STATUS_DCC_EVENT_MASK));
  3132. if (val & DRV_STATUS_SET_MF_BW)
  3133. bnx2x_set_mf_bw(bp);
  3134. if (val & DRV_STATUS_DRV_INFO_REQ)
  3135. bnx2x_handle_drv_info_req(bp);
  3136. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3137. bnx2x_pmf_update(bp);
  3138. if (bp->port.pmf &&
  3139. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3140. bp->dcbx_enabled > 0)
  3141. /* start dcbx state machine */
  3142. bnx2x_dcbx_set_params(bp,
  3143. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3144. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3145. bnx2x_handle_afex_cmd(bp,
  3146. val & DRV_STATUS_AFEX_EVENT_MASK);
  3147. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3148. bnx2x_handle_eee_event(bp);
  3149. if (bp->link_vars.periodic_flags &
  3150. PERIODIC_FLAGS_LINK_EVENT) {
  3151. /* sync with link */
  3152. bnx2x_acquire_phy_lock(bp);
  3153. bp->link_vars.periodic_flags &=
  3154. ~PERIODIC_FLAGS_LINK_EVENT;
  3155. bnx2x_release_phy_lock(bp);
  3156. if (IS_MF(bp))
  3157. bnx2x_link_sync_notify(bp);
  3158. bnx2x_link_report(bp);
  3159. }
  3160. /* Always call it here: bnx2x_link_report() will
  3161. * prevent the link indication duplication.
  3162. */
  3163. bnx2x__link_status_update(bp);
  3164. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3165. BNX2X_ERR("MC assert!\n");
  3166. bnx2x_mc_assert(bp);
  3167. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3168. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3169. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3170. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3171. bnx2x_panic();
  3172. } else if (attn & BNX2X_MCP_ASSERT) {
  3173. BNX2X_ERR("MCP assert!\n");
  3174. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3175. bnx2x_fw_dump(bp);
  3176. } else
  3177. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3178. }
  3179. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3180. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3181. if (attn & BNX2X_GRC_TIMEOUT) {
  3182. val = CHIP_IS_E1(bp) ? 0 :
  3183. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3184. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3185. }
  3186. if (attn & BNX2X_GRC_RSV) {
  3187. val = CHIP_IS_E1(bp) ? 0 :
  3188. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3189. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3190. }
  3191. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3192. }
  3193. }
  3194. /*
  3195. * Bits map:
  3196. * 0-7 - Engine0 load counter.
  3197. * 8-15 - Engine1 load counter.
  3198. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3199. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3200. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3201. * on the engine
  3202. * 19 - Engine1 ONE_IS_LOADED.
  3203. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3204. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3205. * just the one belonging to its engine).
  3206. *
  3207. */
  3208. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3209. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3210. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3211. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3212. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3213. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3214. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3215. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3216. /*
  3217. * Set the GLOBAL_RESET bit.
  3218. *
  3219. * Should be run under rtnl lock
  3220. */
  3221. void bnx2x_set_reset_global(struct bnx2x *bp)
  3222. {
  3223. u32 val;
  3224. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3225. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3226. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3227. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3228. }
  3229. /*
  3230. * Clear the GLOBAL_RESET bit.
  3231. *
  3232. * Should be run under rtnl lock
  3233. */
  3234. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3235. {
  3236. u32 val;
  3237. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3238. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3239. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3240. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3241. }
  3242. /*
  3243. * Checks the GLOBAL_RESET bit.
  3244. *
  3245. * should be run under rtnl lock
  3246. */
  3247. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3248. {
  3249. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3250. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3251. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3252. }
  3253. /*
  3254. * Clear RESET_IN_PROGRESS bit for the current engine.
  3255. *
  3256. * Should be run under rtnl lock
  3257. */
  3258. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3259. {
  3260. u32 val;
  3261. u32 bit = BP_PATH(bp) ?
  3262. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3263. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3264. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3265. /* Clear the bit */
  3266. val &= ~bit;
  3267. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3268. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3269. }
  3270. /*
  3271. * Set RESET_IN_PROGRESS for the current engine.
  3272. *
  3273. * should be run under rtnl lock
  3274. */
  3275. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3276. {
  3277. u32 val;
  3278. u32 bit = BP_PATH(bp) ?
  3279. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3280. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3281. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3282. /* Set the bit */
  3283. val |= bit;
  3284. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3285. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3286. }
  3287. /*
  3288. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3289. * should be run under rtnl lock
  3290. */
  3291. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3292. {
  3293. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3294. u32 bit = engine ?
  3295. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3296. /* return false if bit is set */
  3297. return (val & bit) ? false : true;
  3298. }
  3299. /*
  3300. * set pf load for the current pf.
  3301. *
  3302. * should be run under rtnl lock
  3303. */
  3304. void bnx2x_set_pf_load(struct bnx2x *bp)
  3305. {
  3306. u32 val1, val;
  3307. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3308. BNX2X_PATH0_LOAD_CNT_MASK;
  3309. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3310. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3311. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3312. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3313. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3314. /* get the current counter value */
  3315. val1 = (val & mask) >> shift;
  3316. /* set bit of that PF */
  3317. val1 |= (1 << bp->pf_num);
  3318. /* clear the old value */
  3319. val &= ~mask;
  3320. /* set the new one */
  3321. val |= ((val1 << shift) & mask);
  3322. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3323. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3324. }
  3325. /**
  3326. * bnx2x_clear_pf_load - clear pf load mark
  3327. *
  3328. * @bp: driver handle
  3329. *
  3330. * Should be run under rtnl lock.
  3331. * Decrements the load counter for the current engine. Returns
  3332. * whether other functions are still loaded
  3333. */
  3334. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3335. {
  3336. u32 val1, val;
  3337. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3338. BNX2X_PATH0_LOAD_CNT_MASK;
  3339. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3340. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3341. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3342. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3343. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3344. /* get the current counter value */
  3345. val1 = (val & mask) >> shift;
  3346. /* clear bit of that PF */
  3347. val1 &= ~(1 << bp->pf_num);
  3348. /* clear the old value */
  3349. val &= ~mask;
  3350. /* set the new one */
  3351. val |= ((val1 << shift) & mask);
  3352. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3353. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3354. return val1 != 0;
  3355. }
  3356. /*
  3357. * Read the load status for the current engine.
  3358. *
  3359. * should be run under rtnl lock
  3360. */
  3361. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3362. {
  3363. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3364. BNX2X_PATH0_LOAD_CNT_MASK);
  3365. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3366. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3367. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3368. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3369. val = (val & mask) >> shift;
  3370. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3371. engine, val);
  3372. return val != 0;
  3373. }
  3374. static void _print_next_block(int idx, const char *blk)
  3375. {
  3376. pr_cont("%s%s", idx ? ", " : "", blk);
  3377. }
  3378. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3379. bool print)
  3380. {
  3381. int i = 0;
  3382. u32 cur_bit = 0;
  3383. for (i = 0; sig; i++) {
  3384. cur_bit = ((u32)0x1 << i);
  3385. if (sig & cur_bit) {
  3386. switch (cur_bit) {
  3387. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3388. if (print)
  3389. _print_next_block(par_num++, "BRB");
  3390. break;
  3391. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3392. if (print)
  3393. _print_next_block(par_num++, "PARSER");
  3394. break;
  3395. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3396. if (print)
  3397. _print_next_block(par_num++, "TSDM");
  3398. break;
  3399. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3400. if (print)
  3401. _print_next_block(par_num++,
  3402. "SEARCHER");
  3403. break;
  3404. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3405. if (print)
  3406. _print_next_block(par_num++, "TCM");
  3407. break;
  3408. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3409. if (print)
  3410. _print_next_block(par_num++, "TSEMI");
  3411. break;
  3412. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3413. if (print)
  3414. _print_next_block(par_num++, "XPB");
  3415. break;
  3416. }
  3417. /* Clear the bit */
  3418. sig &= ~cur_bit;
  3419. }
  3420. }
  3421. return par_num;
  3422. }
  3423. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3424. bool *global, bool print)
  3425. {
  3426. int i = 0;
  3427. u32 cur_bit = 0;
  3428. for (i = 0; sig; i++) {
  3429. cur_bit = ((u32)0x1 << i);
  3430. if (sig & cur_bit) {
  3431. switch (cur_bit) {
  3432. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3433. if (print)
  3434. _print_next_block(par_num++, "PBF");
  3435. break;
  3436. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3437. if (print)
  3438. _print_next_block(par_num++, "QM");
  3439. break;
  3440. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3441. if (print)
  3442. _print_next_block(par_num++, "TM");
  3443. break;
  3444. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3445. if (print)
  3446. _print_next_block(par_num++, "XSDM");
  3447. break;
  3448. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3449. if (print)
  3450. _print_next_block(par_num++, "XCM");
  3451. break;
  3452. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3453. if (print)
  3454. _print_next_block(par_num++, "XSEMI");
  3455. break;
  3456. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3457. if (print)
  3458. _print_next_block(par_num++,
  3459. "DOORBELLQ");
  3460. break;
  3461. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3462. if (print)
  3463. _print_next_block(par_num++, "NIG");
  3464. break;
  3465. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3466. if (print)
  3467. _print_next_block(par_num++,
  3468. "VAUX PCI CORE");
  3469. *global = true;
  3470. break;
  3471. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3472. if (print)
  3473. _print_next_block(par_num++, "DEBUG");
  3474. break;
  3475. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3476. if (print)
  3477. _print_next_block(par_num++, "USDM");
  3478. break;
  3479. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3480. if (print)
  3481. _print_next_block(par_num++, "UCM");
  3482. break;
  3483. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3484. if (print)
  3485. _print_next_block(par_num++, "USEMI");
  3486. break;
  3487. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3488. if (print)
  3489. _print_next_block(par_num++, "UPB");
  3490. break;
  3491. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3492. if (print)
  3493. _print_next_block(par_num++, "CSDM");
  3494. break;
  3495. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3496. if (print)
  3497. _print_next_block(par_num++, "CCM");
  3498. break;
  3499. }
  3500. /* Clear the bit */
  3501. sig &= ~cur_bit;
  3502. }
  3503. }
  3504. return par_num;
  3505. }
  3506. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3507. bool print)
  3508. {
  3509. int i = 0;
  3510. u32 cur_bit = 0;
  3511. for (i = 0; sig; i++) {
  3512. cur_bit = ((u32)0x1 << i);
  3513. if (sig & cur_bit) {
  3514. switch (cur_bit) {
  3515. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3516. if (print)
  3517. _print_next_block(par_num++, "CSEMI");
  3518. break;
  3519. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3520. if (print)
  3521. _print_next_block(par_num++, "PXP");
  3522. break;
  3523. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3524. if (print)
  3525. _print_next_block(par_num++,
  3526. "PXPPCICLOCKCLIENT");
  3527. break;
  3528. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3529. if (print)
  3530. _print_next_block(par_num++, "CFC");
  3531. break;
  3532. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3533. if (print)
  3534. _print_next_block(par_num++, "CDU");
  3535. break;
  3536. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3537. if (print)
  3538. _print_next_block(par_num++, "DMAE");
  3539. break;
  3540. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3541. if (print)
  3542. _print_next_block(par_num++, "IGU");
  3543. break;
  3544. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3545. if (print)
  3546. _print_next_block(par_num++, "MISC");
  3547. break;
  3548. }
  3549. /* Clear the bit */
  3550. sig &= ~cur_bit;
  3551. }
  3552. }
  3553. return par_num;
  3554. }
  3555. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3556. bool *global, bool print)
  3557. {
  3558. int i = 0;
  3559. u32 cur_bit = 0;
  3560. for (i = 0; sig; i++) {
  3561. cur_bit = ((u32)0x1 << i);
  3562. if (sig & cur_bit) {
  3563. switch (cur_bit) {
  3564. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3565. if (print)
  3566. _print_next_block(par_num++, "MCP ROM");
  3567. *global = true;
  3568. break;
  3569. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3570. if (print)
  3571. _print_next_block(par_num++,
  3572. "MCP UMP RX");
  3573. *global = true;
  3574. break;
  3575. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3576. if (print)
  3577. _print_next_block(par_num++,
  3578. "MCP UMP TX");
  3579. *global = true;
  3580. break;
  3581. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3582. if (print)
  3583. _print_next_block(par_num++,
  3584. "MCP SCPAD");
  3585. *global = true;
  3586. break;
  3587. }
  3588. /* Clear the bit */
  3589. sig &= ~cur_bit;
  3590. }
  3591. }
  3592. return par_num;
  3593. }
  3594. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3595. bool print)
  3596. {
  3597. int i = 0;
  3598. u32 cur_bit = 0;
  3599. for (i = 0; sig; i++) {
  3600. cur_bit = ((u32)0x1 << i);
  3601. if (sig & cur_bit) {
  3602. switch (cur_bit) {
  3603. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3604. if (print)
  3605. _print_next_block(par_num++, "PGLUE_B");
  3606. break;
  3607. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3608. if (print)
  3609. _print_next_block(par_num++, "ATC");
  3610. break;
  3611. }
  3612. /* Clear the bit */
  3613. sig &= ~cur_bit;
  3614. }
  3615. }
  3616. return par_num;
  3617. }
  3618. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3619. u32 *sig)
  3620. {
  3621. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3622. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3623. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3624. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3625. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3626. int par_num = 0;
  3627. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3628. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3629. sig[0] & HW_PRTY_ASSERT_SET_0,
  3630. sig[1] & HW_PRTY_ASSERT_SET_1,
  3631. sig[2] & HW_PRTY_ASSERT_SET_2,
  3632. sig[3] & HW_PRTY_ASSERT_SET_3,
  3633. sig[4] & HW_PRTY_ASSERT_SET_4);
  3634. if (print)
  3635. netdev_err(bp->dev,
  3636. "Parity errors detected in blocks: ");
  3637. par_num = bnx2x_check_blocks_with_parity0(
  3638. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3639. par_num = bnx2x_check_blocks_with_parity1(
  3640. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3641. par_num = bnx2x_check_blocks_with_parity2(
  3642. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3643. par_num = bnx2x_check_blocks_with_parity3(
  3644. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3645. par_num = bnx2x_check_blocks_with_parity4(
  3646. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3647. if (print)
  3648. pr_cont("\n");
  3649. return true;
  3650. } else
  3651. return false;
  3652. }
  3653. /**
  3654. * bnx2x_chk_parity_attn - checks for parity attentions.
  3655. *
  3656. * @bp: driver handle
  3657. * @global: true if there was a global attention
  3658. * @print: show parity attention in syslog
  3659. */
  3660. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3661. {
  3662. struct attn_route attn = { {0} };
  3663. int port = BP_PORT(bp);
  3664. attn.sig[0] = REG_RD(bp,
  3665. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3666. port*4);
  3667. attn.sig[1] = REG_RD(bp,
  3668. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3669. port*4);
  3670. attn.sig[2] = REG_RD(bp,
  3671. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3672. port*4);
  3673. attn.sig[3] = REG_RD(bp,
  3674. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3675. port*4);
  3676. if (!CHIP_IS_E1x(bp))
  3677. attn.sig[4] = REG_RD(bp,
  3678. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3679. port*4);
  3680. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3681. }
  3682. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3683. {
  3684. u32 val;
  3685. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3686. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3687. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3688. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3689. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3690. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3691. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3692. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3693. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3694. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3695. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3696. if (val &
  3697. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3698. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3699. if (val &
  3700. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3701. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3702. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3703. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3704. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3705. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3706. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3707. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3708. }
  3709. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3710. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3711. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3712. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3713. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3714. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3715. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3716. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3717. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3718. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3719. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3720. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3721. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3722. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3723. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3724. }
  3725. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3726. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3727. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3728. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3729. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3730. }
  3731. }
  3732. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3733. {
  3734. struct attn_route attn, *group_mask;
  3735. int port = BP_PORT(bp);
  3736. int index;
  3737. u32 reg_addr;
  3738. u32 val;
  3739. u32 aeu_mask;
  3740. bool global = false;
  3741. /* need to take HW lock because MCP or other port might also
  3742. try to handle this event */
  3743. bnx2x_acquire_alr(bp);
  3744. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3745. #ifndef BNX2X_STOP_ON_ERROR
  3746. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3747. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3748. /* Disable HW interrupts */
  3749. bnx2x_int_disable(bp);
  3750. /* In case of parity errors don't handle attentions so that
  3751. * other function would "see" parity errors.
  3752. */
  3753. #else
  3754. bnx2x_panic();
  3755. #endif
  3756. bnx2x_release_alr(bp);
  3757. return;
  3758. }
  3759. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3760. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3761. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3762. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3763. if (!CHIP_IS_E1x(bp))
  3764. attn.sig[4] =
  3765. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3766. else
  3767. attn.sig[4] = 0;
  3768. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3769. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3770. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3771. if (deasserted & (1 << index)) {
  3772. group_mask = &bp->attn_group[index];
  3773. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3774. index,
  3775. group_mask->sig[0], group_mask->sig[1],
  3776. group_mask->sig[2], group_mask->sig[3],
  3777. group_mask->sig[4]);
  3778. bnx2x_attn_int_deasserted4(bp,
  3779. attn.sig[4] & group_mask->sig[4]);
  3780. bnx2x_attn_int_deasserted3(bp,
  3781. attn.sig[3] & group_mask->sig[3]);
  3782. bnx2x_attn_int_deasserted1(bp,
  3783. attn.sig[1] & group_mask->sig[1]);
  3784. bnx2x_attn_int_deasserted2(bp,
  3785. attn.sig[2] & group_mask->sig[2]);
  3786. bnx2x_attn_int_deasserted0(bp,
  3787. attn.sig[0] & group_mask->sig[0]);
  3788. }
  3789. }
  3790. bnx2x_release_alr(bp);
  3791. if (bp->common.int_block == INT_BLOCK_HC)
  3792. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3793. COMMAND_REG_ATTN_BITS_CLR);
  3794. else
  3795. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3796. val = ~deasserted;
  3797. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3798. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3799. REG_WR(bp, reg_addr, val);
  3800. if (~bp->attn_state & deasserted)
  3801. BNX2X_ERR("IGU ERROR\n");
  3802. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3803. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3804. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3805. aeu_mask = REG_RD(bp, reg_addr);
  3806. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3807. aeu_mask, deasserted);
  3808. aeu_mask |= (deasserted & 0x3ff);
  3809. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3810. REG_WR(bp, reg_addr, aeu_mask);
  3811. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3812. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3813. bp->attn_state &= ~deasserted;
  3814. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3815. }
  3816. static void bnx2x_attn_int(struct bnx2x *bp)
  3817. {
  3818. /* read local copy of bits */
  3819. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3820. attn_bits);
  3821. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3822. attn_bits_ack);
  3823. u32 attn_state = bp->attn_state;
  3824. /* look for changed bits */
  3825. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3826. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3827. DP(NETIF_MSG_HW,
  3828. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3829. attn_bits, attn_ack, asserted, deasserted);
  3830. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3831. BNX2X_ERR("BAD attention state\n");
  3832. /* handle bits that were raised */
  3833. if (asserted)
  3834. bnx2x_attn_int_asserted(bp, asserted);
  3835. if (deasserted)
  3836. bnx2x_attn_int_deasserted(bp, deasserted);
  3837. }
  3838. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3839. u16 index, u8 op, u8 update)
  3840. {
  3841. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3842. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3843. igu_addr);
  3844. }
  3845. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3846. {
  3847. /* No memory barriers */
  3848. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3849. mmiowb(); /* keep prod updates ordered */
  3850. }
  3851. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3852. union event_ring_elem *elem)
  3853. {
  3854. u8 err = elem->message.error;
  3855. if (!bp->cnic_eth_dev.starting_cid ||
  3856. (cid < bp->cnic_eth_dev.starting_cid &&
  3857. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3858. return 1;
  3859. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3860. if (unlikely(err)) {
  3861. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3862. cid);
  3863. bnx2x_panic_dump(bp);
  3864. }
  3865. bnx2x_cnic_cfc_comp(bp, cid, err);
  3866. return 0;
  3867. }
  3868. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3869. {
  3870. struct bnx2x_mcast_ramrod_params rparam;
  3871. int rc;
  3872. memset(&rparam, 0, sizeof(rparam));
  3873. rparam.mcast_obj = &bp->mcast_obj;
  3874. netif_addr_lock_bh(bp->dev);
  3875. /* Clear pending state for the last command */
  3876. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3877. /* If there are pending mcast commands - send them */
  3878. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3879. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3880. if (rc < 0)
  3881. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3882. rc);
  3883. }
  3884. netif_addr_unlock_bh(bp->dev);
  3885. }
  3886. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3887. union event_ring_elem *elem)
  3888. {
  3889. unsigned long ramrod_flags = 0;
  3890. int rc = 0;
  3891. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3892. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3893. /* Always push next commands out, don't wait here */
  3894. __set_bit(RAMROD_CONT, &ramrod_flags);
  3895. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3896. case BNX2X_FILTER_MAC_PENDING:
  3897. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3898. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  3899. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3900. else
  3901. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  3902. break;
  3903. case BNX2X_FILTER_MCAST_PENDING:
  3904. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3905. /* This is only relevant for 57710 where multicast MACs are
  3906. * configured as unicast MACs using the same ramrod.
  3907. */
  3908. bnx2x_handle_mcast_eqe(bp);
  3909. return;
  3910. default:
  3911. BNX2X_ERR("Unsupported classification command: %d\n",
  3912. elem->message.data.eth_event.echo);
  3913. return;
  3914. }
  3915. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3916. if (rc < 0)
  3917. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3918. else if (rc > 0)
  3919. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3920. }
  3921. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3922. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3923. {
  3924. netif_addr_lock_bh(bp->dev);
  3925. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3926. /* Send rx_mode command again if was requested */
  3927. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3928. bnx2x_set_storm_rx_mode(bp);
  3929. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3930. &bp->sp_state))
  3931. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3932. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3933. &bp->sp_state))
  3934. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3935. netif_addr_unlock_bh(bp->dev);
  3936. }
  3937. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  3938. union event_ring_elem *elem)
  3939. {
  3940. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  3941. DP(BNX2X_MSG_SP,
  3942. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  3943. elem->message.data.vif_list_event.func_bit_map);
  3944. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  3945. elem->message.data.vif_list_event.func_bit_map);
  3946. } else if (elem->message.data.vif_list_event.echo ==
  3947. VIF_LIST_RULE_SET) {
  3948. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  3949. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  3950. }
  3951. }
  3952. /* called with rtnl_lock */
  3953. static void bnx2x_after_function_update(struct bnx2x *bp)
  3954. {
  3955. int q, rc;
  3956. struct bnx2x_fastpath *fp;
  3957. struct bnx2x_queue_state_params queue_params = {NULL};
  3958. struct bnx2x_queue_update_params *q_update_params =
  3959. &queue_params.params.update;
  3960. /* Send Q update command with afex vlan removal values for all Qs */
  3961. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  3962. /* set silent vlan removal values according to vlan mode */
  3963. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  3964. &q_update_params->update_flags);
  3965. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  3966. &q_update_params->update_flags);
  3967. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3968. /* in access mode mark mask and value are 0 to strip all vlans */
  3969. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  3970. q_update_params->silent_removal_value = 0;
  3971. q_update_params->silent_removal_mask = 0;
  3972. } else {
  3973. q_update_params->silent_removal_value =
  3974. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  3975. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  3976. }
  3977. for_each_eth_queue(bp, q) {
  3978. /* Set the appropriate Queue object */
  3979. fp = &bp->fp[q];
  3980. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3981. /* send the ramrod */
  3982. rc = bnx2x_queue_state_change(bp, &queue_params);
  3983. if (rc < 0)
  3984. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  3985. q);
  3986. }
  3987. if (!NO_FCOE(bp)) {
  3988. fp = &bp->fp[FCOE_IDX(bp)];
  3989. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  3990. /* clear pending completion bit */
  3991. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  3992. /* mark latest Q bit */
  3993. smp_mb__before_clear_bit();
  3994. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  3995. smp_mb__after_clear_bit();
  3996. /* send Q update ramrod for FCoE Q */
  3997. rc = bnx2x_queue_state_change(bp, &queue_params);
  3998. if (rc < 0)
  3999. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4000. q);
  4001. } else {
  4002. /* If no FCoE ring - ACK MCP now */
  4003. bnx2x_link_report(bp);
  4004. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4005. }
  4006. }
  4007. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4008. struct bnx2x *bp, u32 cid)
  4009. {
  4010. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4011. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4012. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4013. else
  4014. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4015. }
  4016. static void bnx2x_eq_int(struct bnx2x *bp)
  4017. {
  4018. u16 hw_cons, sw_cons, sw_prod;
  4019. union event_ring_elem *elem;
  4020. u8 echo;
  4021. u32 cid;
  4022. u8 opcode;
  4023. int spqe_cnt = 0;
  4024. struct bnx2x_queue_sp_obj *q_obj;
  4025. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4026. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4027. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4028. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4029. * when we get the the next-page we nned to adjust so the loop
  4030. * condition below will be met. The next element is the size of a
  4031. * regular element and hence incrementing by 1
  4032. */
  4033. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4034. hw_cons++;
  4035. /* This function may never run in parallel with itself for a
  4036. * specific bp, thus there is no need in "paired" read memory
  4037. * barrier here.
  4038. */
  4039. sw_cons = bp->eq_cons;
  4040. sw_prod = bp->eq_prod;
  4041. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4042. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4043. for (; sw_cons != hw_cons;
  4044. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4045. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4046. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4047. opcode = elem->message.opcode;
  4048. /* handle eq element */
  4049. switch (opcode) {
  4050. case EVENT_RING_OPCODE_STAT_QUERY:
  4051. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4052. "got statistics comp event %d\n",
  4053. bp->stats_comp++);
  4054. /* nothing to do with stats comp */
  4055. goto next_spqe;
  4056. case EVENT_RING_OPCODE_CFC_DEL:
  4057. /* handle according to cid range */
  4058. /*
  4059. * we may want to verify here that the bp state is
  4060. * HALTING
  4061. */
  4062. DP(BNX2X_MSG_SP,
  4063. "got delete ramrod for MULTI[%d]\n", cid);
  4064. if (CNIC_LOADED(bp) &&
  4065. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4066. goto next_spqe;
  4067. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4068. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4069. break;
  4070. goto next_spqe;
  4071. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4072. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4073. if (f_obj->complete_cmd(bp, f_obj,
  4074. BNX2X_F_CMD_TX_STOP))
  4075. break;
  4076. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4077. goto next_spqe;
  4078. case EVENT_RING_OPCODE_START_TRAFFIC:
  4079. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4080. if (f_obj->complete_cmd(bp, f_obj,
  4081. BNX2X_F_CMD_TX_START))
  4082. break;
  4083. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4084. goto next_spqe;
  4085. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4086. echo = elem->message.data.function_update_event.echo;
  4087. if (echo == SWITCH_UPDATE) {
  4088. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4089. "got FUNC_SWITCH_UPDATE ramrod\n");
  4090. if (f_obj->complete_cmd(
  4091. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4092. break;
  4093. } else {
  4094. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4095. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4096. f_obj->complete_cmd(bp, f_obj,
  4097. BNX2X_F_CMD_AFEX_UPDATE);
  4098. /* We will perform the Queues update from
  4099. * sp_rtnl task as all Queue SP operations
  4100. * should run under rtnl_lock.
  4101. */
  4102. smp_mb__before_clear_bit();
  4103. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4104. &bp->sp_rtnl_state);
  4105. smp_mb__after_clear_bit();
  4106. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4107. }
  4108. goto next_spqe;
  4109. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4110. f_obj->complete_cmd(bp, f_obj,
  4111. BNX2X_F_CMD_AFEX_VIFLISTS);
  4112. bnx2x_after_afex_vif_lists(bp, elem);
  4113. goto next_spqe;
  4114. case EVENT_RING_OPCODE_FUNCTION_START:
  4115. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4116. "got FUNC_START ramrod\n");
  4117. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4118. break;
  4119. goto next_spqe;
  4120. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4121. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4122. "got FUNC_STOP ramrod\n");
  4123. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4124. break;
  4125. goto next_spqe;
  4126. }
  4127. switch (opcode | bp->state) {
  4128. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4129. BNX2X_STATE_OPEN):
  4130. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4131. BNX2X_STATE_OPENING_WAIT4_PORT):
  4132. cid = elem->message.data.eth_event.echo &
  4133. BNX2X_SWCID_MASK;
  4134. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4135. cid);
  4136. rss_raw->clear_pending(rss_raw);
  4137. break;
  4138. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4139. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4140. case (EVENT_RING_OPCODE_SET_MAC |
  4141. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4142. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4143. BNX2X_STATE_OPEN):
  4144. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4145. BNX2X_STATE_DIAG):
  4146. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4147. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4148. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4149. bnx2x_handle_classification_eqe(bp, elem);
  4150. break;
  4151. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4152. BNX2X_STATE_OPEN):
  4153. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4154. BNX2X_STATE_DIAG):
  4155. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4156. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4157. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4158. bnx2x_handle_mcast_eqe(bp);
  4159. break;
  4160. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4161. BNX2X_STATE_OPEN):
  4162. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4163. BNX2X_STATE_DIAG):
  4164. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4165. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4166. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4167. bnx2x_handle_rx_mode_eqe(bp);
  4168. break;
  4169. default:
  4170. /* unknown event log error and continue */
  4171. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4172. elem->message.opcode, bp->state);
  4173. }
  4174. next_spqe:
  4175. spqe_cnt++;
  4176. } /* for */
  4177. smp_mb__before_atomic_inc();
  4178. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4179. bp->eq_cons = sw_cons;
  4180. bp->eq_prod = sw_prod;
  4181. /* Make sure that above mem writes were issued towards the memory */
  4182. smp_wmb();
  4183. /* update producer */
  4184. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4185. }
  4186. static void bnx2x_sp_task(struct work_struct *work)
  4187. {
  4188. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4189. u16 status;
  4190. status = bnx2x_update_dsb_idx(bp);
  4191. /* if (status == 0) */
  4192. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  4193. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  4194. /* HW attentions */
  4195. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4196. bnx2x_attn_int(bp);
  4197. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4198. }
  4199. /* SP events: STAT_QUERY and others */
  4200. if (status & BNX2X_DEF_SB_IDX) {
  4201. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4202. if (FCOE_INIT(bp) &&
  4203. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4204. /*
  4205. * Prevent local bottom-halves from running as
  4206. * we are going to change the local NAPI list.
  4207. */
  4208. local_bh_disable();
  4209. napi_schedule(&bnx2x_fcoe(bp, napi));
  4210. local_bh_enable();
  4211. }
  4212. /* Handle EQ completions */
  4213. bnx2x_eq_int(bp);
  4214. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4215. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4216. status &= ~BNX2X_DEF_SB_IDX;
  4217. }
  4218. if (unlikely(status))
  4219. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  4220. status);
  4221. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4222. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4223. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4224. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4225. &bp->sp_state)) {
  4226. bnx2x_link_report(bp);
  4227. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4228. }
  4229. }
  4230. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4231. {
  4232. struct net_device *dev = dev_instance;
  4233. struct bnx2x *bp = netdev_priv(dev);
  4234. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4235. IGU_INT_DISABLE, 0);
  4236. #ifdef BNX2X_STOP_ON_ERROR
  4237. if (unlikely(bp->panic))
  4238. return IRQ_HANDLED;
  4239. #endif
  4240. if (CNIC_LOADED(bp)) {
  4241. struct cnic_ops *c_ops;
  4242. rcu_read_lock();
  4243. c_ops = rcu_dereference(bp->cnic_ops);
  4244. if (c_ops)
  4245. c_ops->cnic_handler(bp->cnic_data, NULL);
  4246. rcu_read_unlock();
  4247. }
  4248. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  4249. return IRQ_HANDLED;
  4250. }
  4251. /* end of slow path */
  4252. void bnx2x_drv_pulse(struct bnx2x *bp)
  4253. {
  4254. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4255. bp->fw_drv_pulse_wr_seq);
  4256. }
  4257. static void bnx2x_timer(unsigned long data)
  4258. {
  4259. struct bnx2x *bp = (struct bnx2x *) data;
  4260. if (!netif_running(bp->dev))
  4261. return;
  4262. if (!BP_NOMCP(bp)) {
  4263. int mb_idx = BP_FW_MB_IDX(bp);
  4264. u32 drv_pulse;
  4265. u32 mcp_pulse;
  4266. ++bp->fw_drv_pulse_wr_seq;
  4267. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4268. /* TBD - add SYSTEM_TIME */
  4269. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4270. bnx2x_drv_pulse(bp);
  4271. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4272. MCP_PULSE_SEQ_MASK);
  4273. /* The delta between driver pulse and mcp response
  4274. * should be 1 (before mcp response) or 0 (after mcp response)
  4275. */
  4276. if ((drv_pulse != mcp_pulse) &&
  4277. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4278. /* someone lost a heartbeat... */
  4279. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4280. drv_pulse, mcp_pulse);
  4281. }
  4282. }
  4283. if (bp->state == BNX2X_STATE_OPEN)
  4284. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4285. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4286. }
  4287. /* end of Statistics */
  4288. /* nic init */
  4289. /*
  4290. * nic init service functions
  4291. */
  4292. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4293. {
  4294. u32 i;
  4295. if (!(len%4) && !(addr%4))
  4296. for (i = 0; i < len; i += 4)
  4297. REG_WR(bp, addr + i, fill);
  4298. else
  4299. for (i = 0; i < len; i++)
  4300. REG_WR8(bp, addr + i, fill);
  4301. }
  4302. /* helper: writes FP SP data to FW - data_size in dwords */
  4303. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4304. int fw_sb_id,
  4305. u32 *sb_data_p,
  4306. u32 data_size)
  4307. {
  4308. int index;
  4309. for (index = 0; index < data_size; index++)
  4310. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4311. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4312. sizeof(u32)*index,
  4313. *(sb_data_p + index));
  4314. }
  4315. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4316. {
  4317. u32 *sb_data_p;
  4318. u32 data_size = 0;
  4319. struct hc_status_block_data_e2 sb_data_e2;
  4320. struct hc_status_block_data_e1x sb_data_e1x;
  4321. /* disable the function first */
  4322. if (!CHIP_IS_E1x(bp)) {
  4323. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4324. sb_data_e2.common.state = SB_DISABLED;
  4325. sb_data_e2.common.p_func.vf_valid = false;
  4326. sb_data_p = (u32 *)&sb_data_e2;
  4327. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4328. } else {
  4329. memset(&sb_data_e1x, 0,
  4330. sizeof(struct hc_status_block_data_e1x));
  4331. sb_data_e1x.common.state = SB_DISABLED;
  4332. sb_data_e1x.common.p_func.vf_valid = false;
  4333. sb_data_p = (u32 *)&sb_data_e1x;
  4334. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4335. }
  4336. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4337. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4338. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4339. CSTORM_STATUS_BLOCK_SIZE);
  4340. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4341. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4342. CSTORM_SYNC_BLOCK_SIZE);
  4343. }
  4344. /* helper: writes SP SB data to FW */
  4345. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4346. struct hc_sp_status_block_data *sp_sb_data)
  4347. {
  4348. int func = BP_FUNC(bp);
  4349. int i;
  4350. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4351. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4352. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4353. i*sizeof(u32),
  4354. *((u32 *)sp_sb_data + i));
  4355. }
  4356. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4357. {
  4358. int func = BP_FUNC(bp);
  4359. struct hc_sp_status_block_data sp_sb_data;
  4360. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4361. sp_sb_data.state = SB_DISABLED;
  4362. sp_sb_data.p_func.vf_valid = false;
  4363. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4364. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4365. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4366. CSTORM_SP_STATUS_BLOCK_SIZE);
  4367. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4368. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4369. CSTORM_SP_SYNC_BLOCK_SIZE);
  4370. }
  4371. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4372. int igu_sb_id, int igu_seg_id)
  4373. {
  4374. hc_sm->igu_sb_id = igu_sb_id;
  4375. hc_sm->igu_seg_id = igu_seg_id;
  4376. hc_sm->timer_value = 0xFF;
  4377. hc_sm->time_to_expire = 0xFFFFFFFF;
  4378. }
  4379. /* allocates state machine ids. */
  4380. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4381. {
  4382. /* zero out state machine indices */
  4383. /* rx indices */
  4384. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4385. /* tx indices */
  4386. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4387. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4388. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4389. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4390. /* map indices */
  4391. /* rx indices */
  4392. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4393. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4394. /* tx indices */
  4395. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4396. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4397. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4398. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4399. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4400. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4401. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4402. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4403. }
  4404. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4405. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4406. {
  4407. int igu_seg_id;
  4408. struct hc_status_block_data_e2 sb_data_e2;
  4409. struct hc_status_block_data_e1x sb_data_e1x;
  4410. struct hc_status_block_sm *hc_sm_p;
  4411. int data_size;
  4412. u32 *sb_data_p;
  4413. if (CHIP_INT_MODE_IS_BC(bp))
  4414. igu_seg_id = HC_SEG_ACCESS_NORM;
  4415. else
  4416. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4417. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4418. if (!CHIP_IS_E1x(bp)) {
  4419. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4420. sb_data_e2.common.state = SB_ENABLED;
  4421. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4422. sb_data_e2.common.p_func.vf_id = vfid;
  4423. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4424. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4425. sb_data_e2.common.same_igu_sb_1b = true;
  4426. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4427. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4428. hc_sm_p = sb_data_e2.common.state_machine;
  4429. sb_data_p = (u32 *)&sb_data_e2;
  4430. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4431. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4432. } else {
  4433. memset(&sb_data_e1x, 0,
  4434. sizeof(struct hc_status_block_data_e1x));
  4435. sb_data_e1x.common.state = SB_ENABLED;
  4436. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4437. sb_data_e1x.common.p_func.vf_id = 0xff;
  4438. sb_data_e1x.common.p_func.vf_valid = false;
  4439. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4440. sb_data_e1x.common.same_igu_sb_1b = true;
  4441. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4442. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4443. hc_sm_p = sb_data_e1x.common.state_machine;
  4444. sb_data_p = (u32 *)&sb_data_e1x;
  4445. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4446. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4447. }
  4448. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4449. igu_sb_id, igu_seg_id);
  4450. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4451. igu_sb_id, igu_seg_id);
  4452. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4453. /* write indecies to HW */
  4454. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4455. }
  4456. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4457. u16 tx_usec, u16 rx_usec)
  4458. {
  4459. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4460. false, rx_usec);
  4461. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4462. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4463. tx_usec);
  4464. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4465. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4466. tx_usec);
  4467. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4468. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4469. tx_usec);
  4470. }
  4471. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4472. {
  4473. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4474. dma_addr_t mapping = bp->def_status_blk_mapping;
  4475. int igu_sp_sb_index;
  4476. int igu_seg_id;
  4477. int port = BP_PORT(bp);
  4478. int func = BP_FUNC(bp);
  4479. int reg_offset, reg_offset_en5;
  4480. u64 section;
  4481. int index;
  4482. struct hc_sp_status_block_data sp_sb_data;
  4483. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4484. if (CHIP_INT_MODE_IS_BC(bp)) {
  4485. igu_sp_sb_index = DEF_SB_IGU_ID;
  4486. igu_seg_id = HC_SEG_ACCESS_DEF;
  4487. } else {
  4488. igu_sp_sb_index = bp->igu_dsb_id;
  4489. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4490. }
  4491. /* ATTN */
  4492. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4493. atten_status_block);
  4494. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4495. bp->attn_state = 0;
  4496. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4497. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4498. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4499. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4500. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4501. int sindex;
  4502. /* take care of sig[0]..sig[4] */
  4503. for (sindex = 0; sindex < 4; sindex++)
  4504. bp->attn_group[index].sig[sindex] =
  4505. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4506. if (!CHIP_IS_E1x(bp))
  4507. /*
  4508. * enable5 is separate from the rest of the registers,
  4509. * and therefore the address skip is 4
  4510. * and not 16 between the different groups
  4511. */
  4512. bp->attn_group[index].sig[4] = REG_RD(bp,
  4513. reg_offset_en5 + 0x4*index);
  4514. else
  4515. bp->attn_group[index].sig[4] = 0;
  4516. }
  4517. if (bp->common.int_block == INT_BLOCK_HC) {
  4518. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4519. HC_REG_ATTN_MSG0_ADDR_L);
  4520. REG_WR(bp, reg_offset, U64_LO(section));
  4521. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4522. } else if (!CHIP_IS_E1x(bp)) {
  4523. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4524. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4525. }
  4526. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4527. sp_sb);
  4528. bnx2x_zero_sp_sb(bp);
  4529. sp_sb_data.state = SB_ENABLED;
  4530. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4531. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4532. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4533. sp_sb_data.igu_seg_id = igu_seg_id;
  4534. sp_sb_data.p_func.pf_id = func;
  4535. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4536. sp_sb_data.p_func.vf_id = 0xff;
  4537. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4538. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4539. }
  4540. void bnx2x_update_coalesce(struct bnx2x *bp)
  4541. {
  4542. int i;
  4543. for_each_eth_queue(bp, i)
  4544. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4545. bp->tx_ticks, bp->rx_ticks);
  4546. }
  4547. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4548. {
  4549. spin_lock_init(&bp->spq_lock);
  4550. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4551. bp->spq_prod_idx = 0;
  4552. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4553. bp->spq_prod_bd = bp->spq;
  4554. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4555. }
  4556. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4557. {
  4558. int i;
  4559. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4560. union event_ring_elem *elem =
  4561. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4562. elem->next_page.addr.hi =
  4563. cpu_to_le32(U64_HI(bp->eq_mapping +
  4564. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4565. elem->next_page.addr.lo =
  4566. cpu_to_le32(U64_LO(bp->eq_mapping +
  4567. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4568. }
  4569. bp->eq_cons = 0;
  4570. bp->eq_prod = NUM_EQ_DESC;
  4571. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4572. /* we want a warning message before it gets rought... */
  4573. atomic_set(&bp->eq_spq_left,
  4574. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4575. }
  4576. /* called with netif_addr_lock_bh() */
  4577. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4578. unsigned long rx_mode_flags,
  4579. unsigned long rx_accept_flags,
  4580. unsigned long tx_accept_flags,
  4581. unsigned long ramrod_flags)
  4582. {
  4583. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4584. int rc;
  4585. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4586. /* Prepare ramrod parameters */
  4587. ramrod_param.cid = 0;
  4588. ramrod_param.cl_id = cl_id;
  4589. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4590. ramrod_param.func_id = BP_FUNC(bp);
  4591. ramrod_param.pstate = &bp->sp_state;
  4592. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4593. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4594. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4595. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4596. ramrod_param.ramrod_flags = ramrod_flags;
  4597. ramrod_param.rx_mode_flags = rx_mode_flags;
  4598. ramrod_param.rx_accept_flags = rx_accept_flags;
  4599. ramrod_param.tx_accept_flags = tx_accept_flags;
  4600. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4601. if (rc < 0) {
  4602. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4603. return;
  4604. }
  4605. }
  4606. /* called with netif_addr_lock_bh() */
  4607. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4608. {
  4609. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4610. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4611. if (!NO_FCOE(bp))
  4612. /* Configure rx_mode of FCoE Queue */
  4613. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4614. switch (bp->rx_mode) {
  4615. case BNX2X_RX_MODE_NONE:
  4616. /*
  4617. * 'drop all' supersedes any accept flags that may have been
  4618. * passed to the function.
  4619. */
  4620. break;
  4621. case BNX2X_RX_MODE_NORMAL:
  4622. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4623. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4624. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4625. /* internal switching mode */
  4626. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4627. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4628. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4629. break;
  4630. case BNX2X_RX_MODE_ALLMULTI:
  4631. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4632. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4633. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4634. /* internal switching mode */
  4635. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4636. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4637. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4638. break;
  4639. case BNX2X_RX_MODE_PROMISC:
  4640. /* According to deffinition of SI mode, iface in promisc mode
  4641. * should receive matched and unmatched (in resolution of port)
  4642. * unicast packets.
  4643. */
  4644. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4645. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4646. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4647. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4648. /* internal switching mode */
  4649. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4650. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4651. if (IS_MF_SI(bp))
  4652. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4653. else
  4654. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4655. break;
  4656. default:
  4657. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4658. return;
  4659. }
  4660. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4661. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4662. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4663. }
  4664. __set_bit(RAMROD_RX, &ramrod_flags);
  4665. __set_bit(RAMROD_TX, &ramrod_flags);
  4666. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4667. tx_accept_flags, ramrod_flags);
  4668. }
  4669. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4670. {
  4671. int i;
  4672. if (IS_MF_SI(bp))
  4673. /*
  4674. * In switch independent mode, the TSTORM needs to accept
  4675. * packets that failed classification, since approximate match
  4676. * mac addresses aren't written to NIG LLH
  4677. */
  4678. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4679. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4680. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4681. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4682. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4683. /* Zero this manually as its initialization is
  4684. currently missing in the initTool */
  4685. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4686. REG_WR(bp, BAR_USTRORM_INTMEM +
  4687. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4688. if (!CHIP_IS_E1x(bp)) {
  4689. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4690. CHIP_INT_MODE_IS_BC(bp) ?
  4691. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4692. }
  4693. }
  4694. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4695. {
  4696. switch (load_code) {
  4697. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4698. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4699. bnx2x_init_internal_common(bp);
  4700. /* no break */
  4701. case FW_MSG_CODE_DRV_LOAD_PORT:
  4702. /* nothing to do */
  4703. /* no break */
  4704. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4705. /* internal memory per function is
  4706. initialized inside bnx2x_pf_init */
  4707. break;
  4708. default:
  4709. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4710. break;
  4711. }
  4712. }
  4713. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4714. {
  4715. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4716. }
  4717. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4718. {
  4719. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4720. }
  4721. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4722. {
  4723. if (CHIP_IS_E1x(fp->bp))
  4724. return BP_L_ID(fp->bp) + fp->index;
  4725. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4726. return bnx2x_fp_igu_sb_id(fp);
  4727. }
  4728. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4729. {
  4730. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4731. u8 cos;
  4732. unsigned long q_type = 0;
  4733. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4734. fp->rx_queue = fp_idx;
  4735. fp->cid = fp_idx;
  4736. fp->cl_id = bnx2x_fp_cl_id(fp);
  4737. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4738. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4739. /* qZone id equals to FW (per path) client id */
  4740. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4741. /* init shortcut */
  4742. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4743. /* Setup SB indicies */
  4744. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4745. /* Configure Queue State object */
  4746. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4747. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4748. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4749. /* init tx data */
  4750. for_each_cos_in_tx_queue(fp, cos) {
  4751. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4752. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4753. FP_COS_TO_TXQ(fp, cos, bp),
  4754. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4755. cids[cos] = fp->txdata_ptr[cos]->cid;
  4756. }
  4757. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4758. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4759. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4760. /**
  4761. * Configure classification DBs: Always enable Tx switching
  4762. */
  4763. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4764. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4765. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4766. fp->igu_sb_id);
  4767. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4768. fp->fw_sb_id, fp->igu_sb_id);
  4769. bnx2x_update_fpsb_idx(fp);
  4770. }
  4771. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4772. {
  4773. int i;
  4774. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4775. struct eth_tx_next_bd *tx_next_bd =
  4776. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4777. tx_next_bd->addr_hi =
  4778. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4779. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4780. tx_next_bd->addr_lo =
  4781. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4782. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4783. }
  4784. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4785. txdata->tx_db.data.zero_fill1 = 0;
  4786. txdata->tx_db.data.prod = 0;
  4787. txdata->tx_pkt_prod = 0;
  4788. txdata->tx_pkt_cons = 0;
  4789. txdata->tx_bd_prod = 0;
  4790. txdata->tx_bd_cons = 0;
  4791. txdata->tx_pkt = 0;
  4792. }
  4793. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  4794. {
  4795. int i;
  4796. for_each_tx_queue_cnic(bp, i)
  4797. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  4798. }
  4799. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4800. {
  4801. int i;
  4802. u8 cos;
  4803. for_each_eth_queue(bp, i)
  4804. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4805. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4806. }
  4807. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  4808. {
  4809. if (!NO_FCOE(bp))
  4810. bnx2x_init_fcoe_fp(bp);
  4811. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4812. BNX2X_VF_ID_INVALID, false,
  4813. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4814. /* ensure status block indices were read */
  4815. rmb();
  4816. bnx2x_init_rx_rings_cnic(bp);
  4817. bnx2x_init_tx_rings_cnic(bp);
  4818. /* flush all */
  4819. mb();
  4820. mmiowb();
  4821. }
  4822. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4823. {
  4824. int i;
  4825. for_each_eth_queue(bp, i)
  4826. bnx2x_init_eth_fp(bp, i);
  4827. /* Initialize MOD_ABS interrupts */
  4828. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4829. bp->common.shmem_base, bp->common.shmem2_base,
  4830. BP_PORT(bp));
  4831. /* ensure status block indices were read */
  4832. rmb();
  4833. bnx2x_init_def_sb(bp);
  4834. bnx2x_update_dsb_idx(bp);
  4835. bnx2x_init_rx_rings(bp);
  4836. bnx2x_init_tx_rings(bp);
  4837. bnx2x_init_sp_ring(bp);
  4838. bnx2x_init_eq_ring(bp);
  4839. bnx2x_init_internal(bp, load_code);
  4840. bnx2x_pf_init(bp);
  4841. bnx2x_stats_init(bp);
  4842. /* flush all before enabling interrupts */
  4843. mb();
  4844. mmiowb();
  4845. bnx2x_int_enable(bp);
  4846. /* Check for SPIO5 */
  4847. bnx2x_attn_int_deasserted0(bp,
  4848. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4849. AEU_INPUTS_ATTN_BITS_SPIO5);
  4850. }
  4851. /* end of nic init */
  4852. /*
  4853. * gzip service functions
  4854. */
  4855. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4856. {
  4857. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4858. &bp->gunzip_mapping, GFP_KERNEL);
  4859. if (bp->gunzip_buf == NULL)
  4860. goto gunzip_nomem1;
  4861. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4862. if (bp->strm == NULL)
  4863. goto gunzip_nomem2;
  4864. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4865. if (bp->strm->workspace == NULL)
  4866. goto gunzip_nomem3;
  4867. return 0;
  4868. gunzip_nomem3:
  4869. kfree(bp->strm);
  4870. bp->strm = NULL;
  4871. gunzip_nomem2:
  4872. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4873. bp->gunzip_mapping);
  4874. bp->gunzip_buf = NULL;
  4875. gunzip_nomem1:
  4876. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4877. return -ENOMEM;
  4878. }
  4879. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4880. {
  4881. if (bp->strm) {
  4882. vfree(bp->strm->workspace);
  4883. kfree(bp->strm);
  4884. bp->strm = NULL;
  4885. }
  4886. if (bp->gunzip_buf) {
  4887. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4888. bp->gunzip_mapping);
  4889. bp->gunzip_buf = NULL;
  4890. }
  4891. }
  4892. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4893. {
  4894. int n, rc;
  4895. /* check gzip header */
  4896. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4897. BNX2X_ERR("Bad gzip header\n");
  4898. return -EINVAL;
  4899. }
  4900. n = 10;
  4901. #define FNAME 0x8
  4902. if (zbuf[3] & FNAME)
  4903. while ((zbuf[n++] != 0) && (n < len));
  4904. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4905. bp->strm->avail_in = len - n;
  4906. bp->strm->next_out = bp->gunzip_buf;
  4907. bp->strm->avail_out = FW_BUF_SIZE;
  4908. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4909. if (rc != Z_OK)
  4910. return rc;
  4911. rc = zlib_inflate(bp->strm, Z_FINISH);
  4912. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4913. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4914. bp->strm->msg);
  4915. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4916. if (bp->gunzip_outlen & 0x3)
  4917. netdev_err(bp->dev,
  4918. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4919. bp->gunzip_outlen);
  4920. bp->gunzip_outlen >>= 2;
  4921. zlib_inflateEnd(bp->strm);
  4922. if (rc == Z_STREAM_END)
  4923. return 0;
  4924. return rc;
  4925. }
  4926. /* nic load/unload */
  4927. /*
  4928. * General service functions
  4929. */
  4930. /* send a NIG loopback debug packet */
  4931. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4932. {
  4933. u32 wb_write[3];
  4934. /* Ethernet source and destination addresses */
  4935. wb_write[0] = 0x55555555;
  4936. wb_write[1] = 0x55555555;
  4937. wb_write[2] = 0x20; /* SOP */
  4938. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4939. /* NON-IP protocol */
  4940. wb_write[0] = 0x09000000;
  4941. wb_write[1] = 0x55555555;
  4942. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4943. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4944. }
  4945. /* some of the internal memories
  4946. * are not directly readable from the driver
  4947. * to test them we send debug packets
  4948. */
  4949. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4950. {
  4951. int factor;
  4952. int count, i;
  4953. u32 val = 0;
  4954. if (CHIP_REV_IS_FPGA(bp))
  4955. factor = 120;
  4956. else if (CHIP_REV_IS_EMUL(bp))
  4957. factor = 200;
  4958. else
  4959. factor = 1;
  4960. /* Disable inputs of parser neighbor blocks */
  4961. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4962. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4963. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4964. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4965. /* Write 0 to parser credits for CFC search request */
  4966. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4967. /* send Ethernet packet */
  4968. bnx2x_lb_pckt(bp);
  4969. /* TODO do i reset NIG statistic? */
  4970. /* Wait until NIG register shows 1 packet of size 0x10 */
  4971. count = 1000 * factor;
  4972. while (count) {
  4973. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4974. val = *bnx2x_sp(bp, wb_data[0]);
  4975. if (val == 0x10)
  4976. break;
  4977. msleep(10);
  4978. count--;
  4979. }
  4980. if (val != 0x10) {
  4981. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4982. return -1;
  4983. }
  4984. /* Wait until PRS register shows 1 packet */
  4985. count = 1000 * factor;
  4986. while (count) {
  4987. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4988. if (val == 1)
  4989. break;
  4990. msleep(10);
  4991. count--;
  4992. }
  4993. if (val != 0x1) {
  4994. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4995. return -2;
  4996. }
  4997. /* Reset and init BRB, PRS */
  4998. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4999. msleep(50);
  5000. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5001. msleep(50);
  5002. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5003. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5004. DP(NETIF_MSG_HW, "part2\n");
  5005. /* Disable inputs of parser neighbor blocks */
  5006. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5007. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5008. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5009. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5010. /* Write 0 to parser credits for CFC search request */
  5011. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5012. /* send 10 Ethernet packets */
  5013. for (i = 0; i < 10; i++)
  5014. bnx2x_lb_pckt(bp);
  5015. /* Wait until NIG register shows 10 + 1
  5016. packets of size 11*0x10 = 0xb0 */
  5017. count = 1000 * factor;
  5018. while (count) {
  5019. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5020. val = *bnx2x_sp(bp, wb_data[0]);
  5021. if (val == 0xb0)
  5022. break;
  5023. msleep(10);
  5024. count--;
  5025. }
  5026. if (val != 0xb0) {
  5027. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5028. return -3;
  5029. }
  5030. /* Wait until PRS register shows 2 packets */
  5031. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5032. if (val != 2)
  5033. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5034. /* Write 1 to parser credits for CFC search request */
  5035. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5036. /* Wait until PRS register shows 3 packets */
  5037. msleep(10 * factor);
  5038. /* Wait until NIG register shows 1 packet of size 0x10 */
  5039. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5040. if (val != 3)
  5041. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5042. /* clear NIG EOP FIFO */
  5043. for (i = 0; i < 11; i++)
  5044. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5045. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5046. if (val != 1) {
  5047. BNX2X_ERR("clear of NIG failed\n");
  5048. return -4;
  5049. }
  5050. /* Reset and init BRB, PRS, NIG */
  5051. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5052. msleep(50);
  5053. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5054. msleep(50);
  5055. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5056. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5057. if (!CNIC_SUPPORT(bp))
  5058. /* set NIC mode */
  5059. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5060. /* Enable inputs of parser neighbor blocks */
  5061. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5062. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5063. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5064. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5065. DP(NETIF_MSG_HW, "done\n");
  5066. return 0; /* OK */
  5067. }
  5068. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5069. {
  5070. u32 val;
  5071. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5072. if (!CHIP_IS_E1x(bp))
  5073. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5074. else
  5075. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5076. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5077. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5078. /*
  5079. * mask read length error interrupts in brb for parser
  5080. * (parsing unit and 'checksum and crc' unit)
  5081. * these errors are legal (PU reads fixed length and CAC can cause
  5082. * read length error on truncated packets)
  5083. */
  5084. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5085. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5086. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5087. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5088. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5089. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5090. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5091. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5092. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5093. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5094. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5095. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5096. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5097. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5098. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5099. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5100. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5101. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5102. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5103. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5104. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5105. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5106. if (!CHIP_IS_E1x(bp))
  5107. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5108. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5109. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5110. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5111. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5112. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5113. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5114. if (!CHIP_IS_E1x(bp))
  5115. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5116. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5117. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5118. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5119. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5120. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5121. }
  5122. static void bnx2x_reset_common(struct bnx2x *bp)
  5123. {
  5124. u32 val = 0x1400;
  5125. /* reset_common */
  5126. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5127. 0xd3ffff7f);
  5128. if (CHIP_IS_E3(bp)) {
  5129. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5130. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5131. }
  5132. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5133. }
  5134. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5135. {
  5136. bp->dmae_ready = 0;
  5137. spin_lock_init(&bp->dmae_lock);
  5138. }
  5139. static void bnx2x_init_pxp(struct bnx2x *bp)
  5140. {
  5141. u16 devctl;
  5142. int r_order, w_order;
  5143. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5144. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5145. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5146. if (bp->mrrs == -1)
  5147. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5148. else {
  5149. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5150. r_order = bp->mrrs;
  5151. }
  5152. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5153. }
  5154. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5155. {
  5156. int is_required;
  5157. u32 val;
  5158. int port;
  5159. if (BP_NOMCP(bp))
  5160. return;
  5161. is_required = 0;
  5162. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5163. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5164. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5165. is_required = 1;
  5166. /*
  5167. * The fan failure mechanism is usually related to the PHY type since
  5168. * the power consumption of the board is affected by the PHY. Currently,
  5169. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5170. */
  5171. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5172. for (port = PORT_0; port < PORT_MAX; port++) {
  5173. is_required |=
  5174. bnx2x_fan_failure_det_req(
  5175. bp,
  5176. bp->common.shmem_base,
  5177. bp->common.shmem2_base,
  5178. port);
  5179. }
  5180. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5181. if (is_required == 0)
  5182. return;
  5183. /* Fan failure is indicated by SPIO 5 */
  5184. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5185. /* set to active low mode */
  5186. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5187. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5188. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5189. /* enable interrupt to signal the IGU */
  5190. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5191. val |= MISC_SPIO_SPIO5;
  5192. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5193. }
  5194. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  5195. {
  5196. u32 offset = 0;
  5197. if (CHIP_IS_E1(bp))
  5198. return;
  5199. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  5200. return;
  5201. switch (BP_ABS_FUNC(bp)) {
  5202. case 0:
  5203. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  5204. break;
  5205. case 1:
  5206. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  5207. break;
  5208. case 2:
  5209. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  5210. break;
  5211. case 3:
  5212. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  5213. break;
  5214. case 4:
  5215. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  5216. break;
  5217. case 5:
  5218. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  5219. break;
  5220. case 6:
  5221. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  5222. break;
  5223. case 7:
  5224. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  5225. break;
  5226. default:
  5227. return;
  5228. }
  5229. REG_WR(bp, offset, pretend_func_num);
  5230. REG_RD(bp, offset);
  5231. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  5232. }
  5233. void bnx2x_pf_disable(struct bnx2x *bp)
  5234. {
  5235. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5236. val &= ~IGU_PF_CONF_FUNC_EN;
  5237. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5238. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5239. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5240. }
  5241. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5242. {
  5243. u32 shmem_base[2], shmem2_base[2];
  5244. /* Avoid common init in case MFW supports LFA */
  5245. if (SHMEM2_RD(bp, size) >
  5246. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5247. return;
  5248. shmem_base[0] = bp->common.shmem_base;
  5249. shmem2_base[0] = bp->common.shmem2_base;
  5250. if (!CHIP_IS_E1x(bp)) {
  5251. shmem_base[1] =
  5252. SHMEM2_RD(bp, other_shmem_base_addr);
  5253. shmem2_base[1] =
  5254. SHMEM2_RD(bp, other_shmem2_base_addr);
  5255. }
  5256. bnx2x_acquire_phy_lock(bp);
  5257. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5258. bp->common.chip_id);
  5259. bnx2x_release_phy_lock(bp);
  5260. }
  5261. /**
  5262. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5263. *
  5264. * @bp: driver handle
  5265. */
  5266. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5267. {
  5268. u32 val;
  5269. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5270. /*
  5271. * take the UNDI lock to protect undi_unload flow from accessing
  5272. * registers while we're resetting the chip
  5273. */
  5274. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5275. bnx2x_reset_common(bp);
  5276. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5277. val = 0xfffc;
  5278. if (CHIP_IS_E3(bp)) {
  5279. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5280. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5281. }
  5282. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5283. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5284. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5285. if (!CHIP_IS_E1x(bp)) {
  5286. u8 abs_func_id;
  5287. /**
  5288. * 4-port mode or 2-port mode we need to turn of master-enable
  5289. * for everyone, after that, turn it back on for self.
  5290. * so, we disregard multi-function or not, and always disable
  5291. * for all functions on the given path, this means 0,2,4,6 for
  5292. * path 0 and 1,3,5,7 for path 1
  5293. */
  5294. for (abs_func_id = BP_PATH(bp);
  5295. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5296. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5297. REG_WR(bp,
  5298. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5299. 1);
  5300. continue;
  5301. }
  5302. bnx2x_pretend_func(bp, abs_func_id);
  5303. /* clear pf enable */
  5304. bnx2x_pf_disable(bp);
  5305. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5306. }
  5307. }
  5308. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5309. if (CHIP_IS_E1(bp)) {
  5310. /* enable HW interrupt from PXP on USDM overflow
  5311. bit 16 on INT_MASK_0 */
  5312. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5313. }
  5314. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5315. bnx2x_init_pxp(bp);
  5316. #ifdef __BIG_ENDIAN
  5317. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5318. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5319. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5320. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5321. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5322. /* make sure this value is 0 */
  5323. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5324. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5325. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5326. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5327. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5328. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5329. #endif
  5330. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5331. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5332. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5333. /* let the HW do it's magic ... */
  5334. msleep(100);
  5335. /* finish PXP init */
  5336. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5337. if (val != 1) {
  5338. BNX2X_ERR("PXP2 CFG failed\n");
  5339. return -EBUSY;
  5340. }
  5341. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5342. if (val != 1) {
  5343. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5344. return -EBUSY;
  5345. }
  5346. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5347. * have entries with value "0" and valid bit on.
  5348. * This needs to be done by the first PF that is loaded in a path
  5349. * (i.e. common phase)
  5350. */
  5351. if (!CHIP_IS_E1x(bp)) {
  5352. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5353. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5354. * This occurs when a different function (func2,3) is being marked
  5355. * as "scan-off". Real-life scenario for example: if a driver is being
  5356. * load-unloaded while func6,7 are down. This will cause the timer to access
  5357. * the ilt, translate to a logical address and send a request to read/write.
  5358. * Since the ilt for the function that is down is not valid, this will cause
  5359. * a translation error which is unrecoverable.
  5360. * The Workaround is intended to make sure that when this happens nothing fatal
  5361. * will occur. The workaround:
  5362. * 1. First PF driver which loads on a path will:
  5363. * a. After taking the chip out of reset, by using pretend,
  5364. * it will write "0" to the following registers of
  5365. * the other vnics.
  5366. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5367. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5368. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5369. * And for itself it will write '1' to
  5370. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5371. * dmae-operations (writing to pram for example.)
  5372. * note: can be done for only function 6,7 but cleaner this
  5373. * way.
  5374. * b. Write zero+valid to the entire ILT.
  5375. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5376. * VNIC3 (of that port). The range allocated will be the
  5377. * entire ILT. This is needed to prevent ILT range error.
  5378. * 2. Any PF driver load flow:
  5379. * a. ILT update with the physical addresses of the allocated
  5380. * logical pages.
  5381. * b. Wait 20msec. - note that this timeout is needed to make
  5382. * sure there are no requests in one of the PXP internal
  5383. * queues with "old" ILT addresses.
  5384. * c. PF enable in the PGLC.
  5385. * d. Clear the was_error of the PF in the PGLC. (could have
  5386. * occured while driver was down)
  5387. * e. PF enable in the CFC (WEAK + STRONG)
  5388. * f. Timers scan enable
  5389. * 3. PF driver unload flow:
  5390. * a. Clear the Timers scan_en.
  5391. * b. Polling for scan_on=0 for that PF.
  5392. * c. Clear the PF enable bit in the PXP.
  5393. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5394. * e. Write zero+valid to all ILT entries (The valid bit must
  5395. * stay set)
  5396. * f. If this is VNIC 3 of a port then also init
  5397. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5398. * to the last enrty in the ILT.
  5399. *
  5400. * Notes:
  5401. * Currently the PF error in the PGLC is non recoverable.
  5402. * In the future the there will be a recovery routine for this error.
  5403. * Currently attention is masked.
  5404. * Having an MCP lock on the load/unload process does not guarantee that
  5405. * there is no Timer disable during Func6/7 enable. This is because the
  5406. * Timers scan is currently being cleared by the MCP on FLR.
  5407. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5408. * there is error before clearing it. But the flow above is simpler and
  5409. * more general.
  5410. * All ILT entries are written by zero+valid and not just PF6/7
  5411. * ILT entries since in the future the ILT entries allocation for
  5412. * PF-s might be dynamic.
  5413. */
  5414. struct ilt_client_info ilt_cli;
  5415. struct bnx2x_ilt ilt;
  5416. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5417. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5418. /* initialize dummy TM client */
  5419. ilt_cli.start = 0;
  5420. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5421. ilt_cli.client_num = ILT_CLIENT_TM;
  5422. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5423. * Step 2: set the timers first/last ilt entry to point
  5424. * to the entire range to prevent ILT range error for 3rd/4th
  5425. * vnic (this code assumes existance of the vnic)
  5426. *
  5427. * both steps performed by call to bnx2x_ilt_client_init_op()
  5428. * with dummy TM client
  5429. *
  5430. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5431. * and his brother are split registers
  5432. */
  5433. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5434. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5435. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5436. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5437. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5438. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5439. }
  5440. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5441. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5442. if (!CHIP_IS_E1x(bp)) {
  5443. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5444. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5445. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5446. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5447. /* let the HW do it's magic ... */
  5448. do {
  5449. msleep(200);
  5450. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5451. } while (factor-- && (val != 1));
  5452. if (val != 1) {
  5453. BNX2X_ERR("ATC_INIT failed\n");
  5454. return -EBUSY;
  5455. }
  5456. }
  5457. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5458. /* clean the DMAE memory */
  5459. bp->dmae_ready = 1;
  5460. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5461. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5462. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5463. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5464. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5465. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5466. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5467. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5468. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5469. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5470. /* QM queues pointers table */
  5471. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5472. /* soft reset pulse */
  5473. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5474. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5475. if (CNIC_SUPPORT(bp))
  5476. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5477. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5478. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5479. if (!CHIP_REV_IS_SLOW(bp))
  5480. /* enable hw interrupt from doorbell Q */
  5481. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5482. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5483. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5484. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5485. if (!CHIP_IS_E1(bp))
  5486. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5487. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5488. if (IS_MF_AFEX(bp)) {
  5489. /* configure that VNTag and VLAN headers must be
  5490. * received in afex mode
  5491. */
  5492. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5493. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5494. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5495. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5496. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5497. } else {
  5498. /* Bit-map indicating which L2 hdrs may appear
  5499. * after the basic Ethernet header
  5500. */
  5501. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5502. bp->path_has_ovlan ? 7 : 6);
  5503. }
  5504. }
  5505. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5506. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5507. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5508. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5509. if (!CHIP_IS_E1x(bp)) {
  5510. /* reset VFC memories */
  5511. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5512. VFC_MEMORIES_RST_REG_CAM_RST |
  5513. VFC_MEMORIES_RST_REG_RAM_RST);
  5514. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5515. VFC_MEMORIES_RST_REG_CAM_RST |
  5516. VFC_MEMORIES_RST_REG_RAM_RST);
  5517. msleep(20);
  5518. }
  5519. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5520. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5521. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5522. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5523. /* sync semi rtc */
  5524. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5525. 0x80000000);
  5526. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5527. 0x80000000);
  5528. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5529. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5530. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5531. if (!CHIP_IS_E1x(bp)) {
  5532. if (IS_MF_AFEX(bp)) {
  5533. /* configure that VNTag and VLAN headers must be
  5534. * sent in afex mode
  5535. */
  5536. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5537. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5538. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5539. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5540. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5541. } else {
  5542. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5543. bp->path_has_ovlan ? 7 : 6);
  5544. }
  5545. }
  5546. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5547. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5548. if (CNIC_SUPPORT(bp)) {
  5549. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5550. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5551. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5552. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5553. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5554. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5555. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5556. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5557. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5558. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5559. }
  5560. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5561. if (sizeof(union cdu_context) != 1024)
  5562. /* we currently assume that a context is 1024 bytes */
  5563. dev_alert(&bp->pdev->dev,
  5564. "please adjust the size of cdu_context(%ld)\n",
  5565. (long)sizeof(union cdu_context));
  5566. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5567. val = (4 << 24) + (0 << 12) + 1024;
  5568. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5569. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5570. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5571. /* enable context validation interrupt from CFC */
  5572. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5573. /* set the thresholds to prevent CFC/CDU race */
  5574. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5575. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5576. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5577. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5578. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5579. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5580. /* Reset PCIE errors for debug */
  5581. REG_WR(bp, 0x2814, 0xffffffff);
  5582. REG_WR(bp, 0x3820, 0xffffffff);
  5583. if (!CHIP_IS_E1x(bp)) {
  5584. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5585. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5586. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5587. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5588. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5589. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5590. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5591. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5592. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5593. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5594. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5595. }
  5596. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5597. if (!CHIP_IS_E1(bp)) {
  5598. /* in E3 this done in per-port section */
  5599. if (!CHIP_IS_E3(bp))
  5600. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5601. }
  5602. if (CHIP_IS_E1H(bp))
  5603. /* not applicable for E2 (and above ...) */
  5604. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5605. if (CHIP_REV_IS_SLOW(bp))
  5606. msleep(200);
  5607. /* finish CFC init */
  5608. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5609. if (val != 1) {
  5610. BNX2X_ERR("CFC LL_INIT failed\n");
  5611. return -EBUSY;
  5612. }
  5613. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5614. if (val != 1) {
  5615. BNX2X_ERR("CFC AC_INIT failed\n");
  5616. return -EBUSY;
  5617. }
  5618. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5619. if (val != 1) {
  5620. BNX2X_ERR("CFC CAM_INIT failed\n");
  5621. return -EBUSY;
  5622. }
  5623. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5624. if (CHIP_IS_E1(bp)) {
  5625. /* read NIG statistic
  5626. to see if this is our first up since powerup */
  5627. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5628. val = *bnx2x_sp(bp, wb_data[0]);
  5629. /* do internal memory self test */
  5630. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5631. BNX2X_ERR("internal mem self test failed\n");
  5632. return -EBUSY;
  5633. }
  5634. }
  5635. bnx2x_setup_fan_failure_detection(bp);
  5636. /* clear PXP2 attentions */
  5637. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5638. bnx2x_enable_blocks_attention(bp);
  5639. bnx2x_enable_blocks_parity(bp);
  5640. if (!BP_NOMCP(bp)) {
  5641. if (CHIP_IS_E1x(bp))
  5642. bnx2x__common_init_phy(bp);
  5643. } else
  5644. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5645. return 0;
  5646. }
  5647. /**
  5648. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5649. *
  5650. * @bp: driver handle
  5651. */
  5652. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5653. {
  5654. int rc = bnx2x_init_hw_common(bp);
  5655. if (rc)
  5656. return rc;
  5657. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5658. if (!BP_NOMCP(bp))
  5659. bnx2x__common_init_phy(bp);
  5660. return 0;
  5661. }
  5662. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5663. {
  5664. int port = BP_PORT(bp);
  5665. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5666. u32 low, high;
  5667. u32 val;
  5668. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5669. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5670. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5671. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5672. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5673. /* Timers bug workaround: disables the pf_master bit in pglue at
  5674. * common phase, we need to enable it here before any dmae access are
  5675. * attempted. Therefore we manually added the enable-master to the
  5676. * port phase (it also happens in the function phase)
  5677. */
  5678. if (!CHIP_IS_E1x(bp))
  5679. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5680. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5681. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5682. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5683. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5684. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5685. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5686. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5687. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5688. /* QM cid (connection) count */
  5689. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5690. if (CNIC_SUPPORT(bp)) {
  5691. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5692. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5693. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5694. }
  5695. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5696. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5697. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5698. if (IS_MF(bp))
  5699. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5700. else if (bp->dev->mtu > 4096) {
  5701. if (bp->flags & ONE_PORT_FLAG)
  5702. low = 160;
  5703. else {
  5704. val = bp->dev->mtu;
  5705. /* (24*1024 + val*4)/256 */
  5706. low = 96 + (val/64) +
  5707. ((val % 64) ? 1 : 0);
  5708. }
  5709. } else
  5710. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5711. high = low + 56; /* 14*1024/256 */
  5712. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5713. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5714. }
  5715. if (CHIP_MODE_IS_4_PORT(bp))
  5716. REG_WR(bp, (BP_PORT(bp) ?
  5717. BRB1_REG_MAC_GUARANTIED_1 :
  5718. BRB1_REG_MAC_GUARANTIED_0), 40);
  5719. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5720. if (CHIP_IS_E3B0(bp)) {
  5721. if (IS_MF_AFEX(bp)) {
  5722. /* configure headers for AFEX mode */
  5723. REG_WR(bp, BP_PORT(bp) ?
  5724. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5725. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5726. REG_WR(bp, BP_PORT(bp) ?
  5727. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5728. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5729. REG_WR(bp, BP_PORT(bp) ?
  5730. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5731. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5732. } else {
  5733. /* Ovlan exists only if we are in multi-function +
  5734. * switch-dependent mode, in switch-independent there
  5735. * is no ovlan headers
  5736. */
  5737. REG_WR(bp, BP_PORT(bp) ?
  5738. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5739. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5740. (bp->path_has_ovlan ? 7 : 6));
  5741. }
  5742. }
  5743. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5744. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5745. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5746. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5747. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5748. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5749. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5750. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5751. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5752. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5753. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5754. if (CHIP_IS_E1x(bp)) {
  5755. /* configure PBF to work without PAUSE mtu 9000 */
  5756. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5757. /* update threshold */
  5758. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5759. /* update init credit */
  5760. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5761. /* probe changes */
  5762. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5763. udelay(50);
  5764. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5765. }
  5766. if (CNIC_SUPPORT(bp))
  5767. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5768. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5769. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5770. if (CHIP_IS_E1(bp)) {
  5771. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5772. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5773. }
  5774. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5775. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5776. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5777. /* init aeu_mask_attn_func_0/1:
  5778. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5779. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5780. * bits 4-7 are used for "per vn group attention" */
  5781. val = IS_MF(bp) ? 0xF7 : 0x7;
  5782. /* Enable DCBX attention for all but E1 */
  5783. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5784. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5785. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5786. if (!CHIP_IS_E1x(bp)) {
  5787. /* Bit-map indicating which L2 hdrs may appear after the
  5788. * basic Ethernet header
  5789. */
  5790. if (IS_MF_AFEX(bp))
  5791. REG_WR(bp, BP_PORT(bp) ?
  5792. NIG_REG_P1_HDRS_AFTER_BASIC :
  5793. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5794. else
  5795. REG_WR(bp, BP_PORT(bp) ?
  5796. NIG_REG_P1_HDRS_AFTER_BASIC :
  5797. NIG_REG_P0_HDRS_AFTER_BASIC,
  5798. IS_MF_SD(bp) ? 7 : 6);
  5799. if (CHIP_IS_E3(bp))
  5800. REG_WR(bp, BP_PORT(bp) ?
  5801. NIG_REG_LLH1_MF_MODE :
  5802. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5803. }
  5804. if (!CHIP_IS_E3(bp))
  5805. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5806. if (!CHIP_IS_E1(bp)) {
  5807. /* 0x2 disable mf_ov, 0x1 enable */
  5808. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5809. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5810. if (!CHIP_IS_E1x(bp)) {
  5811. val = 0;
  5812. switch (bp->mf_mode) {
  5813. case MULTI_FUNCTION_SD:
  5814. val = 1;
  5815. break;
  5816. case MULTI_FUNCTION_SI:
  5817. case MULTI_FUNCTION_AFEX:
  5818. val = 2;
  5819. break;
  5820. }
  5821. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5822. NIG_REG_LLH0_CLS_TYPE), val);
  5823. }
  5824. {
  5825. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5826. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5827. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5828. }
  5829. }
  5830. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5831. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5832. if (val & MISC_SPIO_SPIO5) {
  5833. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5834. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5835. val = REG_RD(bp, reg_addr);
  5836. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5837. REG_WR(bp, reg_addr, val);
  5838. }
  5839. return 0;
  5840. }
  5841. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5842. {
  5843. int reg;
  5844. u32 wb_write[2];
  5845. if (CHIP_IS_E1(bp))
  5846. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5847. else
  5848. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5849. wb_write[0] = ONCHIP_ADDR1(addr);
  5850. wb_write[1] = ONCHIP_ADDR2(addr);
  5851. REG_WR_DMAE(bp, reg, wb_write, 2);
  5852. }
  5853. static void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func,
  5854. u8 idu_sb_id, bool is_Pf)
  5855. {
  5856. u32 data, ctl, cnt = 100;
  5857. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  5858. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  5859. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  5860. u32 sb_bit = 1 << (idu_sb_id%32);
  5861. u32 func_encode = func | (is_Pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  5862. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  5863. /* Not supported in BC mode */
  5864. if (CHIP_INT_MODE_IS_BC(bp))
  5865. return;
  5866. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  5867. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  5868. IGU_REGULAR_CLEANUP_SET |
  5869. IGU_REGULAR_BCLEANUP;
  5870. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  5871. func_encode << IGU_CTRL_REG_FID_SHIFT |
  5872. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  5873. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5874. data, igu_addr_data);
  5875. REG_WR(bp, igu_addr_data, data);
  5876. mmiowb();
  5877. barrier();
  5878. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  5879. ctl, igu_addr_ctl);
  5880. REG_WR(bp, igu_addr_ctl, ctl);
  5881. mmiowb();
  5882. barrier();
  5883. /* wait for clean up to finish */
  5884. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  5885. msleep(20);
  5886. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  5887. DP(NETIF_MSG_HW,
  5888. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  5889. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  5890. }
  5891. }
  5892. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5893. {
  5894. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5895. }
  5896. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5897. {
  5898. u32 i, base = FUNC_ILT_BASE(func);
  5899. for (i = base; i < base + ILT_PER_FUNC; i++)
  5900. bnx2x_ilt_wr(bp, i, 0);
  5901. }
  5902. static void bnx2x_init_searcher(struct bnx2x *bp)
  5903. {
  5904. int port = BP_PORT(bp);
  5905. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5906. /* T1 hash bits value determines the T1 number of entries */
  5907. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5908. }
  5909. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  5910. {
  5911. int rc;
  5912. struct bnx2x_func_state_params func_params = {NULL};
  5913. struct bnx2x_func_switch_update_params *switch_update_params =
  5914. &func_params.params.switch_update;
  5915. /* Prepare parameters for function state transitions */
  5916. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  5917. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  5918. func_params.f_obj = &bp->func_obj;
  5919. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  5920. /* Function parameters */
  5921. switch_update_params->suspend = suspend;
  5922. rc = bnx2x_func_state_change(bp, &func_params);
  5923. return rc;
  5924. }
  5925. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  5926. {
  5927. int rc, i, port = BP_PORT(bp);
  5928. int vlan_en = 0, mac_en[NUM_MACS];
  5929. /* Close input from network */
  5930. if (bp->mf_mode == SINGLE_FUNCTION) {
  5931. bnx2x_set_rx_filter(&bp->link_params, 0);
  5932. } else {
  5933. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5934. NIG_REG_LLH0_FUNC_EN);
  5935. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5936. NIG_REG_LLH0_FUNC_EN, 0);
  5937. for (i = 0; i < NUM_MACS; i++) {
  5938. mac_en[i] = REG_RD(bp, port ?
  5939. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5940. 4 * i) :
  5941. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  5942. 4 * i));
  5943. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5944. 4 * i) :
  5945. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  5946. }
  5947. }
  5948. /* Close BMC to host */
  5949. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  5950. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  5951. /* Suspend Tx switching to the PF. Completion of this ramrod
  5952. * further guarantees that all the packets of that PF / child
  5953. * VFs in BRB were processed by the Parser, so it is safe to
  5954. * change the NIC_MODE register.
  5955. */
  5956. rc = bnx2x_func_switch_update(bp, 1);
  5957. if (rc) {
  5958. BNX2X_ERR("Can't suspend tx-switching!\n");
  5959. return rc;
  5960. }
  5961. /* Change NIC_MODE register */
  5962. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  5963. /* Open input from network */
  5964. if (bp->mf_mode == SINGLE_FUNCTION) {
  5965. bnx2x_set_rx_filter(&bp->link_params, 1);
  5966. } else {
  5967. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  5968. NIG_REG_LLH0_FUNC_EN, vlan_en);
  5969. for (i = 0; i < NUM_MACS; i++) {
  5970. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  5971. 4 * i) :
  5972. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  5973. mac_en[i]);
  5974. }
  5975. }
  5976. /* Enable BMC to host */
  5977. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  5978. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  5979. /* Resume Tx switching to the PF */
  5980. rc = bnx2x_func_switch_update(bp, 0);
  5981. if (rc) {
  5982. BNX2X_ERR("Can't resume tx-switching!\n");
  5983. return rc;
  5984. }
  5985. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  5986. return 0;
  5987. }
  5988. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  5989. {
  5990. int rc;
  5991. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  5992. if (CONFIGURE_NIC_MODE(bp)) {
  5993. /* Configrue searcher as part of function hw init */
  5994. bnx2x_init_searcher(bp);
  5995. /* Reset NIC mode */
  5996. rc = bnx2x_reset_nic_mode(bp);
  5997. if (rc)
  5998. BNX2X_ERR("Can't change NIC mode!\n");
  5999. return rc;
  6000. }
  6001. return 0;
  6002. }
  6003. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6004. {
  6005. int port = BP_PORT(bp);
  6006. int func = BP_FUNC(bp);
  6007. int init_phase = PHASE_PF0 + func;
  6008. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6009. u16 cdu_ilt_start;
  6010. u32 addr, val;
  6011. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6012. int i, main_mem_width, rc;
  6013. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6014. /* FLR cleanup - hmmm */
  6015. if (!CHIP_IS_E1x(bp)) {
  6016. rc = bnx2x_pf_flr_clnup(bp);
  6017. if (rc)
  6018. return rc;
  6019. }
  6020. /* set MSI reconfigure capability */
  6021. if (bp->common.int_block == INT_BLOCK_HC) {
  6022. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6023. val = REG_RD(bp, addr);
  6024. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6025. REG_WR(bp, addr, val);
  6026. }
  6027. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6028. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6029. ilt = BP_ILT(bp);
  6030. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6031. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6032. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6033. ilt->lines[cdu_ilt_start + i].page_mapping =
  6034. bp->context[i].cxt_mapping;
  6035. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6036. }
  6037. bnx2x_ilt_init_op(bp, INITOP_SET);
  6038. if (!CONFIGURE_NIC_MODE(bp)) {
  6039. bnx2x_init_searcher(bp);
  6040. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6041. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6042. } else {
  6043. /* Set NIC mode */
  6044. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6045. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6046. }
  6047. if (!CHIP_IS_E1x(bp)) {
  6048. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6049. /* Turn on a single ISR mode in IGU if driver is going to use
  6050. * INT#x or MSI
  6051. */
  6052. if (!(bp->flags & USING_MSIX_FLAG))
  6053. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6054. /*
  6055. * Timers workaround bug: function init part.
  6056. * Need to wait 20msec after initializing ILT,
  6057. * needed to make sure there are no requests in
  6058. * one of the PXP internal queues with "old" ILT addresses
  6059. */
  6060. msleep(20);
  6061. /*
  6062. * Master enable - Due to WB DMAE writes performed before this
  6063. * register is re-initialized as part of the regular function
  6064. * init
  6065. */
  6066. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6067. /* Enable the function in IGU */
  6068. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6069. }
  6070. bp->dmae_ready = 1;
  6071. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6072. if (!CHIP_IS_E1x(bp))
  6073. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6074. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6075. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6076. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6077. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6078. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6079. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6080. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6081. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6082. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6083. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6084. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6085. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6086. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6087. if (!CHIP_IS_E1x(bp))
  6088. REG_WR(bp, QM_REG_PF_EN, 1);
  6089. if (!CHIP_IS_E1x(bp)) {
  6090. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6091. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6092. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6093. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6094. }
  6095. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6096. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6097. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6098. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6099. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6100. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6101. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6102. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6103. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6104. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6105. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6106. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6107. if (!CHIP_IS_E1x(bp))
  6108. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6109. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6110. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6111. if (!CHIP_IS_E1x(bp))
  6112. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6113. if (IS_MF(bp)) {
  6114. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6115. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6116. }
  6117. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6118. /* HC init per function */
  6119. if (bp->common.int_block == INT_BLOCK_HC) {
  6120. if (CHIP_IS_E1H(bp)) {
  6121. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6122. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6123. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6124. }
  6125. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6126. } else {
  6127. int num_segs, sb_idx, prod_offset;
  6128. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6129. if (!CHIP_IS_E1x(bp)) {
  6130. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6131. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6132. }
  6133. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6134. if (!CHIP_IS_E1x(bp)) {
  6135. int dsb_idx = 0;
  6136. /**
  6137. * Producer memory:
  6138. * E2 mode: address 0-135 match to the mapping memory;
  6139. * 136 - PF0 default prod; 137 - PF1 default prod;
  6140. * 138 - PF2 default prod; 139 - PF3 default prod;
  6141. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6142. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6143. * 144-147 reserved.
  6144. *
  6145. * E1.5 mode - In backward compatible mode;
  6146. * for non default SB; each even line in the memory
  6147. * holds the U producer and each odd line hold
  6148. * the C producer. The first 128 producers are for
  6149. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6150. * producers are for the DSB for each PF.
  6151. * Each PF has five segments: (the order inside each
  6152. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6153. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6154. * 144-147 attn prods;
  6155. */
  6156. /* non-default-status-blocks */
  6157. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6158. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6159. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6160. prod_offset = (bp->igu_base_sb + sb_idx) *
  6161. num_segs;
  6162. for (i = 0; i < num_segs; i++) {
  6163. addr = IGU_REG_PROD_CONS_MEMORY +
  6164. (prod_offset + i) * 4;
  6165. REG_WR(bp, addr, 0);
  6166. }
  6167. /* send consumer update with value 0 */
  6168. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6169. USTORM_ID, 0, IGU_INT_NOP, 1);
  6170. bnx2x_igu_clear_sb(bp,
  6171. bp->igu_base_sb + sb_idx);
  6172. }
  6173. /* default-status-blocks */
  6174. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6175. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6176. if (CHIP_MODE_IS_4_PORT(bp))
  6177. dsb_idx = BP_FUNC(bp);
  6178. else
  6179. dsb_idx = BP_VN(bp);
  6180. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6181. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6182. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6183. /*
  6184. * igu prods come in chunks of E1HVN_MAX (4) -
  6185. * does not matters what is the current chip mode
  6186. */
  6187. for (i = 0; i < (num_segs * E1HVN_MAX);
  6188. i += E1HVN_MAX) {
  6189. addr = IGU_REG_PROD_CONS_MEMORY +
  6190. (prod_offset + i)*4;
  6191. REG_WR(bp, addr, 0);
  6192. }
  6193. /* send consumer update with 0 */
  6194. if (CHIP_INT_MODE_IS_BC(bp)) {
  6195. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6196. USTORM_ID, 0, IGU_INT_NOP, 1);
  6197. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6198. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6199. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6200. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6201. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6202. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6203. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6204. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6205. } else {
  6206. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6207. USTORM_ID, 0, IGU_INT_NOP, 1);
  6208. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6209. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6210. }
  6211. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6212. /* !!! these should become driver const once
  6213. rf-tool supports split-68 const */
  6214. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6215. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6216. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6217. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6218. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6219. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6220. }
  6221. }
  6222. /* Reset PCIE errors for debug */
  6223. REG_WR(bp, 0x2114, 0xffffffff);
  6224. REG_WR(bp, 0x2120, 0xffffffff);
  6225. if (CHIP_IS_E1x(bp)) {
  6226. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6227. main_mem_base = HC_REG_MAIN_MEMORY +
  6228. BP_PORT(bp) * (main_mem_size * 4);
  6229. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6230. main_mem_width = 8;
  6231. val = REG_RD(bp, main_mem_prty_clr);
  6232. if (val)
  6233. DP(NETIF_MSG_HW,
  6234. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6235. val);
  6236. /* Clear "false" parity errors in MSI-X table */
  6237. for (i = main_mem_base;
  6238. i < main_mem_base + main_mem_size * 4;
  6239. i += main_mem_width) {
  6240. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6241. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6242. i, main_mem_width / 4);
  6243. }
  6244. /* Clear HC parity attention */
  6245. REG_RD(bp, main_mem_prty_clr);
  6246. }
  6247. #ifdef BNX2X_STOP_ON_ERROR
  6248. /* Enable STORMs SP logging */
  6249. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6250. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6251. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6252. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6253. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6254. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6255. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6256. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6257. #endif
  6258. bnx2x_phy_probe(&bp->link_params);
  6259. return 0;
  6260. }
  6261. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6262. {
  6263. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6264. if (!CHIP_IS_E1x(bp))
  6265. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6266. sizeof(struct host_hc_status_block_e2));
  6267. else
  6268. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6269. sizeof(struct host_hc_status_block_e1x));
  6270. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6271. }
  6272. void bnx2x_free_mem(struct bnx2x *bp)
  6273. {
  6274. int i;
  6275. /* fastpath */
  6276. bnx2x_free_fp_mem(bp);
  6277. /* end of fastpath */
  6278. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6279. sizeof(struct host_sp_status_block));
  6280. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6281. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6282. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6283. sizeof(struct bnx2x_slowpath));
  6284. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6285. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6286. bp->context[i].size);
  6287. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6288. BNX2X_FREE(bp->ilt->lines);
  6289. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6290. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6291. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6292. }
  6293. static int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  6294. {
  6295. int num_groups;
  6296. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  6297. /* number of queues for statistics is number of eth queues + FCoE */
  6298. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  6299. /* Total number of FW statistics requests =
  6300. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  6301. * num of queues
  6302. */
  6303. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  6304. /* Request is built from stats_query_header and an array of
  6305. * stats_query_cmd_group each of which contains
  6306. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  6307. * configured in the stats_query_header.
  6308. */
  6309. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  6310. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  6311. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  6312. num_groups * sizeof(struct stats_query_cmd_group);
  6313. /* Data for statistics requests + stats_conter
  6314. *
  6315. * stats_counter holds per-STORM counters that are incremented
  6316. * when STORM has finished with the current request.
  6317. *
  6318. * memory for FCoE offloaded statistics are counted anyway,
  6319. * even if they will not be sent.
  6320. */
  6321. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  6322. sizeof(struct per_pf_stats) +
  6323. sizeof(struct fcoe_statistics_params) +
  6324. sizeof(struct per_queue_stats) * num_queue_stats +
  6325. sizeof(struct stats_counter);
  6326. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  6327. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6328. /* Set shortcuts */
  6329. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  6330. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  6331. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  6332. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  6333. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  6334. bp->fw_stats_req_sz;
  6335. return 0;
  6336. alloc_mem_err:
  6337. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6338. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6339. BNX2X_ERR("Can't allocate memory\n");
  6340. return -ENOMEM;
  6341. }
  6342. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6343. {
  6344. if (!CHIP_IS_E1x(bp))
  6345. /* size = the status block + ramrod buffers */
  6346. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6347. sizeof(struct host_hc_status_block_e2));
  6348. else
  6349. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6350. &bp->cnic_sb_mapping,
  6351. sizeof(struct
  6352. host_hc_status_block_e1x));
  6353. if (CONFIGURE_NIC_MODE(bp))
  6354. /* allocate searcher T2 table, as it wan't allocated before */
  6355. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6356. /* write address to which L5 should insert its values */
  6357. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6358. &bp->slowpath->drv_info_to_mcp;
  6359. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6360. goto alloc_mem_err;
  6361. return 0;
  6362. alloc_mem_err:
  6363. bnx2x_free_mem_cnic(bp);
  6364. BNX2X_ERR("Can't allocate memory\n");
  6365. return -ENOMEM;
  6366. }
  6367. int bnx2x_alloc_mem(struct bnx2x *bp)
  6368. {
  6369. int i, allocated, context_size;
  6370. if (!CONFIGURE_NIC_MODE(bp))
  6371. /* allocate searcher T2 table */
  6372. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6373. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6374. sizeof(struct host_sp_status_block));
  6375. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6376. sizeof(struct bnx2x_slowpath));
  6377. /* Allocated memory for FW statistics */
  6378. if (bnx2x_alloc_fw_stats_mem(bp))
  6379. goto alloc_mem_err;
  6380. /* Allocate memory for CDU context:
  6381. * This memory is allocated separately and not in the generic ILT
  6382. * functions because CDU differs in few aspects:
  6383. * 1. There are multiple entities allocating memory for context -
  6384. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6385. * its own ILT lines.
  6386. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6387. * for the other ILT clients), to be efficient we want to support
  6388. * allocation of sub-page-size in the last entry.
  6389. * 3. Context pointers are used by the driver to pass to FW / update
  6390. * the context (for the other ILT clients the pointers are used just to
  6391. * free the memory during unload).
  6392. */
  6393. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6394. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6395. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6396. (context_size - allocated));
  6397. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6398. &bp->context[i].cxt_mapping,
  6399. bp->context[i].size);
  6400. allocated += bp->context[i].size;
  6401. }
  6402. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6403. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6404. goto alloc_mem_err;
  6405. /* Slow path ring */
  6406. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6407. /* EQ */
  6408. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6409. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6410. /* fastpath */
  6411. /* need to be done at the end, since it's self adjusting to amount
  6412. * of memory available for RSS queues
  6413. */
  6414. if (bnx2x_alloc_fp_mem(bp))
  6415. goto alloc_mem_err;
  6416. return 0;
  6417. alloc_mem_err:
  6418. bnx2x_free_mem(bp);
  6419. BNX2X_ERR("Can't allocate memory\n");
  6420. return -ENOMEM;
  6421. }
  6422. /*
  6423. * Init service functions
  6424. */
  6425. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6426. struct bnx2x_vlan_mac_obj *obj, bool set,
  6427. int mac_type, unsigned long *ramrod_flags)
  6428. {
  6429. int rc;
  6430. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6431. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6432. /* Fill general parameters */
  6433. ramrod_param.vlan_mac_obj = obj;
  6434. ramrod_param.ramrod_flags = *ramrod_flags;
  6435. /* Fill a user request section if needed */
  6436. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6437. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6438. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6439. /* Set the command: ADD or DEL */
  6440. if (set)
  6441. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6442. else
  6443. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6444. }
  6445. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6446. if (rc == -EEXIST) {
  6447. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6448. /* do not treat adding same MAC as error */
  6449. rc = 0;
  6450. } else if (rc < 0)
  6451. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6452. return rc;
  6453. }
  6454. int bnx2x_del_all_macs(struct bnx2x *bp,
  6455. struct bnx2x_vlan_mac_obj *mac_obj,
  6456. int mac_type, bool wait_for_comp)
  6457. {
  6458. int rc;
  6459. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6460. /* Wait for completion of requested */
  6461. if (wait_for_comp)
  6462. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6463. /* Set the mac type of addresses we want to clear */
  6464. __set_bit(mac_type, &vlan_mac_flags);
  6465. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6466. if (rc < 0)
  6467. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6468. return rc;
  6469. }
  6470. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6471. {
  6472. unsigned long ramrod_flags = 0;
  6473. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6474. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6475. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6476. "Ignoring Zero MAC for STORAGE SD mode\n");
  6477. return 0;
  6478. }
  6479. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6480. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6481. /* Eth MAC is set on RSS leading client (fp[0]) */
  6482. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6483. set, BNX2X_ETH_MAC, &ramrod_flags);
  6484. }
  6485. int bnx2x_setup_leading(struct bnx2x *bp)
  6486. {
  6487. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6488. }
  6489. /**
  6490. * bnx2x_set_int_mode - configure interrupt mode
  6491. *
  6492. * @bp: driver handle
  6493. *
  6494. * In case of MSI-X it will also try to enable MSI-X.
  6495. */
  6496. void bnx2x_set_int_mode(struct bnx2x *bp)
  6497. {
  6498. switch (int_mode) {
  6499. case INT_MODE_MSI:
  6500. bnx2x_enable_msi(bp);
  6501. /* falling through... */
  6502. case INT_MODE_INTx:
  6503. bp->num_ethernet_queues = 1;
  6504. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6505. BNX2X_DEV_INFO("set number of queues to 1\n");
  6506. break;
  6507. default:
  6508. /* if we can't use MSI-X we only need one fp,
  6509. * so try to enable MSI-X with the requested number of fp's
  6510. * and fallback to MSI or legacy INTx with one fp
  6511. */
  6512. if (bnx2x_enable_msix(bp) ||
  6513. bp->flags & USING_SINGLE_MSIX_FLAG) {
  6514. /* failed to enable multiple MSI-X */
  6515. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6516. bp->num_queues,
  6517. 1 + bp->num_cnic_queues);
  6518. bp->num_queues = 1 + bp->num_cnic_queues;
  6519. /* Try to enable MSI */
  6520. if (!(bp->flags & USING_SINGLE_MSIX_FLAG) &&
  6521. !(bp->flags & DISABLE_MSI_FLAG))
  6522. bnx2x_enable_msi(bp);
  6523. }
  6524. break;
  6525. }
  6526. }
  6527. /* must be called prioir to any HW initializations */
  6528. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6529. {
  6530. return L2_ILT_LINES(bp);
  6531. }
  6532. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6533. {
  6534. struct ilt_client_info *ilt_client;
  6535. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6536. u16 line = 0;
  6537. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6538. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6539. /* CDU */
  6540. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6541. ilt_client->client_num = ILT_CLIENT_CDU;
  6542. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6543. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6544. ilt_client->start = line;
  6545. line += bnx2x_cid_ilt_lines(bp);
  6546. if (CNIC_SUPPORT(bp))
  6547. line += CNIC_ILT_LINES;
  6548. ilt_client->end = line - 1;
  6549. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6550. ilt_client->start,
  6551. ilt_client->end,
  6552. ilt_client->page_size,
  6553. ilt_client->flags,
  6554. ilog2(ilt_client->page_size >> 12));
  6555. /* QM */
  6556. if (QM_INIT(bp->qm_cid_count)) {
  6557. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6558. ilt_client->client_num = ILT_CLIENT_QM;
  6559. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6560. ilt_client->flags = 0;
  6561. ilt_client->start = line;
  6562. /* 4 bytes for each cid */
  6563. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6564. QM_ILT_PAGE_SZ);
  6565. ilt_client->end = line - 1;
  6566. DP(NETIF_MSG_IFUP,
  6567. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6568. ilt_client->start,
  6569. ilt_client->end,
  6570. ilt_client->page_size,
  6571. ilt_client->flags,
  6572. ilog2(ilt_client->page_size >> 12));
  6573. }
  6574. if (CNIC_SUPPORT(bp)) {
  6575. /* SRC */
  6576. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6577. ilt_client->client_num = ILT_CLIENT_SRC;
  6578. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6579. ilt_client->flags = 0;
  6580. ilt_client->start = line;
  6581. line += SRC_ILT_LINES;
  6582. ilt_client->end = line - 1;
  6583. DP(NETIF_MSG_IFUP,
  6584. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6585. ilt_client->start,
  6586. ilt_client->end,
  6587. ilt_client->page_size,
  6588. ilt_client->flags,
  6589. ilog2(ilt_client->page_size >> 12));
  6590. /* TM */
  6591. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6592. ilt_client->client_num = ILT_CLIENT_TM;
  6593. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6594. ilt_client->flags = 0;
  6595. ilt_client->start = line;
  6596. line += TM_ILT_LINES;
  6597. ilt_client->end = line - 1;
  6598. DP(NETIF_MSG_IFUP,
  6599. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6600. ilt_client->start,
  6601. ilt_client->end,
  6602. ilt_client->page_size,
  6603. ilt_client->flags,
  6604. ilog2(ilt_client->page_size >> 12));
  6605. }
  6606. BUG_ON(line > ILT_MAX_LINES);
  6607. }
  6608. /**
  6609. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6610. *
  6611. * @bp: driver handle
  6612. * @fp: pointer to fastpath
  6613. * @init_params: pointer to parameters structure
  6614. *
  6615. * parameters configured:
  6616. * - HC configuration
  6617. * - Queue's CDU context
  6618. */
  6619. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6620. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6621. {
  6622. u8 cos;
  6623. int cxt_index, cxt_offset;
  6624. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6625. if (!IS_FCOE_FP(fp)) {
  6626. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6627. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6628. /* If HC is supporterd, enable host coalescing in the transition
  6629. * to INIT state.
  6630. */
  6631. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6632. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6633. /* HC rate */
  6634. init_params->rx.hc_rate = bp->rx_ticks ?
  6635. (1000000 / bp->rx_ticks) : 0;
  6636. init_params->tx.hc_rate = bp->tx_ticks ?
  6637. (1000000 / bp->tx_ticks) : 0;
  6638. /* FW SB ID */
  6639. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6640. fp->fw_sb_id;
  6641. /*
  6642. * CQ index among the SB indices: FCoE clients uses the default
  6643. * SB, therefore it's different.
  6644. */
  6645. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6646. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6647. }
  6648. /* set maximum number of COSs supported by this queue */
  6649. init_params->max_cos = fp->max_cos;
  6650. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6651. fp->index, init_params->max_cos);
  6652. /* set the context pointers queue object */
  6653. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6654. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6655. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6656. ILT_PAGE_CIDS);
  6657. init_params->cxts[cos] =
  6658. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6659. }
  6660. }
  6661. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6662. struct bnx2x_queue_state_params *q_params,
  6663. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6664. int tx_index, bool leading)
  6665. {
  6666. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6667. /* Set the command */
  6668. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6669. /* Set tx-only QUEUE flags: don't zero statistics */
  6670. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6671. /* choose the index of the cid to send the slow path on */
  6672. tx_only_params->cid_index = tx_index;
  6673. /* Set general TX_ONLY_SETUP parameters */
  6674. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6675. /* Set Tx TX_ONLY_SETUP parameters */
  6676. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6677. DP(NETIF_MSG_IFUP,
  6678. "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",
  6679. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6680. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6681. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6682. /* send the ramrod */
  6683. return bnx2x_queue_state_change(bp, q_params);
  6684. }
  6685. /**
  6686. * bnx2x_setup_queue - setup queue
  6687. *
  6688. * @bp: driver handle
  6689. * @fp: pointer to fastpath
  6690. * @leading: is leading
  6691. *
  6692. * This function performs 2 steps in a Queue state machine
  6693. * actually: 1) RESET->INIT 2) INIT->SETUP
  6694. */
  6695. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6696. bool leading)
  6697. {
  6698. struct bnx2x_queue_state_params q_params = {NULL};
  6699. struct bnx2x_queue_setup_params *setup_params =
  6700. &q_params.params.setup;
  6701. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6702. &q_params.params.tx_only;
  6703. int rc;
  6704. u8 tx_index;
  6705. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6706. /* reset IGU state skip FCoE L2 queue */
  6707. if (!IS_FCOE_FP(fp))
  6708. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6709. IGU_INT_ENABLE, 0);
  6710. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6711. /* We want to wait for completion in this context */
  6712. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6713. /* Prepare the INIT parameters */
  6714. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6715. /* Set the command */
  6716. q_params.cmd = BNX2X_Q_CMD_INIT;
  6717. /* Change the state to INIT */
  6718. rc = bnx2x_queue_state_change(bp, &q_params);
  6719. if (rc) {
  6720. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6721. return rc;
  6722. }
  6723. DP(NETIF_MSG_IFUP, "init complete\n");
  6724. /* Now move the Queue to the SETUP state... */
  6725. memset(setup_params, 0, sizeof(*setup_params));
  6726. /* Set QUEUE flags */
  6727. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6728. /* Set general SETUP parameters */
  6729. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6730. FIRST_TX_COS_INDEX);
  6731. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6732. &setup_params->rxq_params);
  6733. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6734. FIRST_TX_COS_INDEX);
  6735. /* Set the command */
  6736. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6737. if (IS_FCOE_FP(fp))
  6738. bp->fcoe_init = true;
  6739. /* Change the state to SETUP */
  6740. rc = bnx2x_queue_state_change(bp, &q_params);
  6741. if (rc) {
  6742. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6743. return rc;
  6744. }
  6745. /* loop through the relevant tx-only indices */
  6746. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6747. tx_index < fp->max_cos;
  6748. tx_index++) {
  6749. /* prepare and send tx-only ramrod*/
  6750. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6751. tx_only_params, tx_index, leading);
  6752. if (rc) {
  6753. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6754. fp->index, tx_index);
  6755. return rc;
  6756. }
  6757. }
  6758. return rc;
  6759. }
  6760. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6761. {
  6762. struct bnx2x_fastpath *fp = &bp->fp[index];
  6763. struct bnx2x_fp_txdata *txdata;
  6764. struct bnx2x_queue_state_params q_params = {NULL};
  6765. int rc, tx_index;
  6766. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6767. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6768. /* We want to wait for completion in this context */
  6769. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6770. /* close tx-only connections */
  6771. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6772. tx_index < fp->max_cos;
  6773. tx_index++){
  6774. /* ascertain this is a normal queue*/
  6775. txdata = fp->txdata_ptr[tx_index];
  6776. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6777. txdata->txq_index);
  6778. /* send halt terminate on tx-only connection */
  6779. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6780. memset(&q_params.params.terminate, 0,
  6781. sizeof(q_params.params.terminate));
  6782. q_params.params.terminate.cid_index = tx_index;
  6783. rc = bnx2x_queue_state_change(bp, &q_params);
  6784. if (rc)
  6785. return rc;
  6786. /* send halt terminate on tx-only connection */
  6787. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6788. memset(&q_params.params.cfc_del, 0,
  6789. sizeof(q_params.params.cfc_del));
  6790. q_params.params.cfc_del.cid_index = tx_index;
  6791. rc = bnx2x_queue_state_change(bp, &q_params);
  6792. if (rc)
  6793. return rc;
  6794. }
  6795. /* Stop the primary connection: */
  6796. /* ...halt the connection */
  6797. q_params.cmd = BNX2X_Q_CMD_HALT;
  6798. rc = bnx2x_queue_state_change(bp, &q_params);
  6799. if (rc)
  6800. return rc;
  6801. /* ...terminate the connection */
  6802. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6803. memset(&q_params.params.terminate, 0,
  6804. sizeof(q_params.params.terminate));
  6805. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6806. rc = bnx2x_queue_state_change(bp, &q_params);
  6807. if (rc)
  6808. return rc;
  6809. /* ...delete cfc entry */
  6810. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6811. memset(&q_params.params.cfc_del, 0,
  6812. sizeof(q_params.params.cfc_del));
  6813. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6814. return bnx2x_queue_state_change(bp, &q_params);
  6815. }
  6816. static void bnx2x_reset_func(struct bnx2x *bp)
  6817. {
  6818. int port = BP_PORT(bp);
  6819. int func = BP_FUNC(bp);
  6820. int i;
  6821. /* Disable the function in the FW */
  6822. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6823. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6824. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6825. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6826. /* FP SBs */
  6827. for_each_eth_queue(bp, i) {
  6828. struct bnx2x_fastpath *fp = &bp->fp[i];
  6829. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6830. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6831. SB_DISABLED);
  6832. }
  6833. if (CNIC_LOADED(bp))
  6834. /* CNIC SB */
  6835. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6836. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6837. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6838. /* SP SB */
  6839. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6840. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6841. SB_DISABLED);
  6842. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6843. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6844. 0);
  6845. /* Configure IGU */
  6846. if (bp->common.int_block == INT_BLOCK_HC) {
  6847. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6848. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6849. } else {
  6850. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6851. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6852. }
  6853. if (CNIC_LOADED(bp)) {
  6854. /* Disable Timer scan */
  6855. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6856. /*
  6857. * Wait for at least 10ms and up to 2 second for the timers
  6858. * scan to complete
  6859. */
  6860. for (i = 0; i < 200; i++) {
  6861. msleep(10);
  6862. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6863. break;
  6864. }
  6865. }
  6866. /* Clear ILT */
  6867. bnx2x_clear_func_ilt(bp, func);
  6868. /* Timers workaround bug for E2: if this is vnic-3,
  6869. * we need to set the entire ilt range for this timers.
  6870. */
  6871. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6872. struct ilt_client_info ilt_cli;
  6873. /* use dummy TM client */
  6874. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6875. ilt_cli.start = 0;
  6876. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6877. ilt_cli.client_num = ILT_CLIENT_TM;
  6878. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6879. }
  6880. /* this assumes that reset_port() called before reset_func()*/
  6881. if (!CHIP_IS_E1x(bp))
  6882. bnx2x_pf_disable(bp);
  6883. bp->dmae_ready = 0;
  6884. }
  6885. static void bnx2x_reset_port(struct bnx2x *bp)
  6886. {
  6887. int port = BP_PORT(bp);
  6888. u32 val;
  6889. /* Reset physical Link */
  6890. bnx2x__link_reset(bp);
  6891. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6892. /* Do not rcv packets to BRB */
  6893. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6894. /* Do not direct rcv packets that are not for MCP to the BRB */
  6895. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6896. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6897. /* Configure AEU */
  6898. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6899. msleep(100);
  6900. /* Check for BRB port occupancy */
  6901. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6902. if (val)
  6903. DP(NETIF_MSG_IFDOWN,
  6904. "BRB1 is not empty %d blocks are occupied\n", val);
  6905. /* TODO: Close Doorbell port? */
  6906. }
  6907. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6908. {
  6909. struct bnx2x_func_state_params func_params = {NULL};
  6910. /* Prepare parameters for function state transitions */
  6911. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6912. func_params.f_obj = &bp->func_obj;
  6913. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6914. func_params.params.hw_init.load_phase = load_code;
  6915. return bnx2x_func_state_change(bp, &func_params);
  6916. }
  6917. static int bnx2x_func_stop(struct bnx2x *bp)
  6918. {
  6919. struct bnx2x_func_state_params func_params = {NULL};
  6920. int rc;
  6921. /* Prepare parameters for function state transitions */
  6922. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6923. func_params.f_obj = &bp->func_obj;
  6924. func_params.cmd = BNX2X_F_CMD_STOP;
  6925. /*
  6926. * Try to stop the function the 'good way'. If fails (in case
  6927. * of a parity error during bnx2x_chip_cleanup()) and we are
  6928. * not in a debug mode, perform a state transaction in order to
  6929. * enable further HW_RESET transaction.
  6930. */
  6931. rc = bnx2x_func_state_change(bp, &func_params);
  6932. if (rc) {
  6933. #ifdef BNX2X_STOP_ON_ERROR
  6934. return rc;
  6935. #else
  6936. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6937. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6938. return bnx2x_func_state_change(bp, &func_params);
  6939. #endif
  6940. }
  6941. return 0;
  6942. }
  6943. /**
  6944. * bnx2x_send_unload_req - request unload mode from the MCP.
  6945. *
  6946. * @bp: driver handle
  6947. * @unload_mode: requested function's unload mode
  6948. *
  6949. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6950. */
  6951. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6952. {
  6953. u32 reset_code = 0;
  6954. int port = BP_PORT(bp);
  6955. /* Select the UNLOAD request mode */
  6956. if (unload_mode == UNLOAD_NORMAL)
  6957. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6958. else if (bp->flags & NO_WOL_FLAG)
  6959. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6960. else if (bp->wol) {
  6961. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6962. u8 *mac_addr = bp->dev->dev_addr;
  6963. u32 val;
  6964. u16 pmc;
  6965. /* The mac address is written to entries 1-4 to
  6966. * preserve entry 0 which is used by the PMF
  6967. */
  6968. u8 entry = (BP_VN(bp) + 1)*8;
  6969. val = (mac_addr[0] << 8) | mac_addr[1];
  6970. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6971. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6972. (mac_addr[4] << 8) | mac_addr[5];
  6973. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6974. /* Enable the PME and clear the status */
  6975. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6976. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6977. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6978. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6979. } else
  6980. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6981. /* Send the request to the MCP */
  6982. if (!BP_NOMCP(bp))
  6983. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6984. else {
  6985. int path = BP_PATH(bp);
  6986. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  6987. path, load_count[path][0], load_count[path][1],
  6988. load_count[path][2]);
  6989. load_count[path][0]--;
  6990. load_count[path][1 + port]--;
  6991. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  6992. path, load_count[path][0], load_count[path][1],
  6993. load_count[path][2]);
  6994. if (load_count[path][0] == 0)
  6995. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6996. else if (load_count[path][1 + port] == 0)
  6997. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6998. else
  6999. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7000. }
  7001. return reset_code;
  7002. }
  7003. /**
  7004. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7005. *
  7006. * @bp: driver handle
  7007. * @keep_link: true iff link should be kept up
  7008. */
  7009. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7010. {
  7011. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7012. /* Report UNLOAD_DONE to MCP */
  7013. if (!BP_NOMCP(bp))
  7014. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7015. }
  7016. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7017. {
  7018. int tout = 50;
  7019. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7020. if (!bp->port.pmf)
  7021. return 0;
  7022. /*
  7023. * (assumption: No Attention from MCP at this stage)
  7024. * PMF probably in the middle of TXdisable/enable transaction
  7025. * 1. Sync IRS for default SB
  7026. * 2. Sync SP queue - this guarantes us that attention handling started
  7027. * 3. Wait, that TXdisable/enable transaction completes
  7028. *
  7029. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7030. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7031. * received complettion for the transaction the state is TX_STOPPED.
  7032. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7033. * transaction.
  7034. */
  7035. /* make sure default SB ISR is done */
  7036. if (msix)
  7037. synchronize_irq(bp->msix_table[0].vector);
  7038. else
  7039. synchronize_irq(bp->pdev->irq);
  7040. flush_workqueue(bnx2x_wq);
  7041. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7042. BNX2X_F_STATE_STARTED && tout--)
  7043. msleep(20);
  7044. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7045. BNX2X_F_STATE_STARTED) {
  7046. #ifdef BNX2X_STOP_ON_ERROR
  7047. BNX2X_ERR("Wrong function state\n");
  7048. return -EBUSY;
  7049. #else
  7050. /*
  7051. * Failed to complete the transaction in a "good way"
  7052. * Force both transactions with CLR bit
  7053. */
  7054. struct bnx2x_func_state_params func_params = {NULL};
  7055. DP(NETIF_MSG_IFDOWN,
  7056. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7057. func_params.f_obj = &bp->func_obj;
  7058. __set_bit(RAMROD_DRV_CLR_ONLY,
  7059. &func_params.ramrod_flags);
  7060. /* STARTED-->TX_ST0PPED */
  7061. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7062. bnx2x_func_state_change(bp, &func_params);
  7063. /* TX_ST0PPED-->STARTED */
  7064. func_params.cmd = BNX2X_F_CMD_TX_START;
  7065. return bnx2x_func_state_change(bp, &func_params);
  7066. #endif
  7067. }
  7068. return 0;
  7069. }
  7070. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7071. {
  7072. int port = BP_PORT(bp);
  7073. int i, rc = 0;
  7074. u8 cos;
  7075. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7076. u32 reset_code;
  7077. /* Wait until tx fastpath tasks complete */
  7078. for_each_tx_queue(bp, i) {
  7079. struct bnx2x_fastpath *fp = &bp->fp[i];
  7080. for_each_cos_in_tx_queue(fp, cos)
  7081. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7082. #ifdef BNX2X_STOP_ON_ERROR
  7083. if (rc)
  7084. return;
  7085. #endif
  7086. }
  7087. /* Give HW time to discard old tx messages */
  7088. usleep_range(1000, 1000);
  7089. /* Clean all ETH MACs */
  7090. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7091. false);
  7092. if (rc < 0)
  7093. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7094. /* Clean up UC list */
  7095. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7096. true);
  7097. if (rc < 0)
  7098. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7099. rc);
  7100. /* Disable LLH */
  7101. if (!CHIP_IS_E1(bp))
  7102. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7103. /* Set "drop all" (stop Rx).
  7104. * We need to take a netif_addr_lock() here in order to prevent
  7105. * a race between the completion code and this code.
  7106. */
  7107. netif_addr_lock_bh(bp->dev);
  7108. /* Schedule the rx_mode command */
  7109. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7110. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7111. else
  7112. bnx2x_set_storm_rx_mode(bp);
  7113. /* Cleanup multicast configuration */
  7114. rparam.mcast_obj = &bp->mcast_obj;
  7115. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7116. if (rc < 0)
  7117. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7118. netif_addr_unlock_bh(bp->dev);
  7119. /*
  7120. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7121. * this function should perform FUNC, PORT or COMMON HW
  7122. * reset.
  7123. */
  7124. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7125. /*
  7126. * (assumption: No Attention from MCP at this stage)
  7127. * PMF probably in the middle of TXdisable/enable transaction
  7128. */
  7129. rc = bnx2x_func_wait_started(bp);
  7130. if (rc) {
  7131. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7132. #ifdef BNX2X_STOP_ON_ERROR
  7133. return;
  7134. #endif
  7135. }
  7136. /* Close multi and leading connections
  7137. * Completions for ramrods are collected in a synchronous way
  7138. */
  7139. for_each_eth_queue(bp, i)
  7140. if (bnx2x_stop_queue(bp, i))
  7141. #ifdef BNX2X_STOP_ON_ERROR
  7142. return;
  7143. #else
  7144. goto unload_error;
  7145. #endif
  7146. if (CNIC_LOADED(bp)) {
  7147. for_each_cnic_queue(bp, i)
  7148. if (bnx2x_stop_queue(bp, i))
  7149. #ifdef BNX2X_STOP_ON_ERROR
  7150. return;
  7151. #else
  7152. goto unload_error;
  7153. #endif
  7154. }
  7155. /* If SP settings didn't get completed so far - something
  7156. * very wrong has happen.
  7157. */
  7158. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7159. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7160. #ifndef BNX2X_STOP_ON_ERROR
  7161. unload_error:
  7162. #endif
  7163. rc = bnx2x_func_stop(bp);
  7164. if (rc) {
  7165. BNX2X_ERR("Function stop failed!\n");
  7166. #ifdef BNX2X_STOP_ON_ERROR
  7167. return;
  7168. #endif
  7169. }
  7170. /* Disable HW interrupts, NAPI */
  7171. bnx2x_netif_stop(bp, 1);
  7172. /* Delete all NAPI objects */
  7173. bnx2x_del_all_napi(bp);
  7174. if (CNIC_LOADED(bp))
  7175. bnx2x_del_all_napi_cnic(bp);
  7176. /* Release IRQs */
  7177. bnx2x_free_irq(bp);
  7178. /* Reset the chip */
  7179. rc = bnx2x_reset_hw(bp, reset_code);
  7180. if (rc)
  7181. BNX2X_ERR("HW_RESET failed\n");
  7182. /* Report UNLOAD_DONE to MCP */
  7183. bnx2x_send_unload_done(bp, keep_link);
  7184. }
  7185. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7186. {
  7187. u32 val;
  7188. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7189. if (CHIP_IS_E1(bp)) {
  7190. int port = BP_PORT(bp);
  7191. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7192. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7193. val = REG_RD(bp, addr);
  7194. val &= ~(0x300);
  7195. REG_WR(bp, addr, val);
  7196. } else {
  7197. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7198. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7199. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7200. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7201. }
  7202. }
  7203. /* Close gates #2, #3 and #4: */
  7204. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7205. {
  7206. u32 val;
  7207. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7208. if (!CHIP_IS_E1(bp)) {
  7209. /* #4 */
  7210. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7211. /* #2 */
  7212. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7213. }
  7214. /* #3 */
  7215. if (CHIP_IS_E1x(bp)) {
  7216. /* Prevent interrupts from HC on both ports */
  7217. val = REG_RD(bp, HC_REG_CONFIG_1);
  7218. REG_WR(bp, HC_REG_CONFIG_1,
  7219. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7220. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7221. val = REG_RD(bp, HC_REG_CONFIG_0);
  7222. REG_WR(bp, HC_REG_CONFIG_0,
  7223. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7224. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7225. } else {
  7226. /* Prevent incomming interrupts in IGU */
  7227. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7228. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7229. (!close) ?
  7230. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7231. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7232. }
  7233. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7234. close ? "closing" : "opening");
  7235. mmiowb();
  7236. }
  7237. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7238. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7239. {
  7240. /* Do some magic... */
  7241. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7242. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7243. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7244. }
  7245. /**
  7246. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7247. *
  7248. * @bp: driver handle
  7249. * @magic_val: old value of the `magic' bit.
  7250. */
  7251. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7252. {
  7253. /* Restore the `magic' bit value... */
  7254. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7255. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7256. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7257. }
  7258. /**
  7259. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7260. *
  7261. * @bp: driver handle
  7262. * @magic_val: old value of 'magic' bit.
  7263. *
  7264. * Takes care of CLP configurations.
  7265. */
  7266. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7267. {
  7268. u32 shmem;
  7269. u32 validity_offset;
  7270. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7271. /* Set `magic' bit in order to save MF config */
  7272. if (!CHIP_IS_E1(bp))
  7273. bnx2x_clp_reset_prep(bp, magic_val);
  7274. /* Get shmem offset */
  7275. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7276. validity_offset =
  7277. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7278. /* Clear validity map flags */
  7279. if (shmem > 0)
  7280. REG_WR(bp, shmem + validity_offset, 0);
  7281. }
  7282. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7283. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7284. /**
  7285. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7286. *
  7287. * @bp: driver handle
  7288. */
  7289. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7290. {
  7291. /* special handling for emulation and FPGA,
  7292. wait 10 times longer */
  7293. if (CHIP_REV_IS_SLOW(bp))
  7294. msleep(MCP_ONE_TIMEOUT*10);
  7295. else
  7296. msleep(MCP_ONE_TIMEOUT);
  7297. }
  7298. /*
  7299. * initializes bp->common.shmem_base and waits for validity signature to appear
  7300. */
  7301. static int bnx2x_init_shmem(struct bnx2x *bp)
  7302. {
  7303. int cnt = 0;
  7304. u32 val = 0;
  7305. do {
  7306. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7307. if (bp->common.shmem_base) {
  7308. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7309. if (val & SHR_MEM_VALIDITY_MB)
  7310. return 0;
  7311. }
  7312. bnx2x_mcp_wait_one(bp);
  7313. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7314. BNX2X_ERR("BAD MCP validity signature\n");
  7315. return -ENODEV;
  7316. }
  7317. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7318. {
  7319. int rc = bnx2x_init_shmem(bp);
  7320. /* Restore the `magic' bit value */
  7321. if (!CHIP_IS_E1(bp))
  7322. bnx2x_clp_reset_done(bp, magic_val);
  7323. return rc;
  7324. }
  7325. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7326. {
  7327. if (!CHIP_IS_E1(bp)) {
  7328. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7329. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7330. mmiowb();
  7331. }
  7332. }
  7333. /*
  7334. * Reset the whole chip except for:
  7335. * - PCIE core
  7336. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7337. * one reset bit)
  7338. * - IGU
  7339. * - MISC (including AEU)
  7340. * - GRC
  7341. * - RBCN, RBCP
  7342. */
  7343. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7344. {
  7345. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7346. u32 global_bits2, stay_reset2;
  7347. /*
  7348. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7349. * (per chip) blocks.
  7350. */
  7351. global_bits2 =
  7352. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7353. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7354. /* Don't reset the following blocks.
  7355. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7356. * reset, as in 4 port device they might still be owned
  7357. * by the MCP (there is only one leader per path).
  7358. */
  7359. not_reset_mask1 =
  7360. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7361. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7362. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7363. not_reset_mask2 =
  7364. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7365. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7366. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7367. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7368. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7369. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7370. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7371. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7372. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7373. MISC_REGISTERS_RESET_REG_2_PGLC |
  7374. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7375. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7376. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7377. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7378. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7379. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7380. /*
  7381. * Keep the following blocks in reset:
  7382. * - all xxMACs are handled by the bnx2x_link code.
  7383. */
  7384. stay_reset2 =
  7385. MISC_REGISTERS_RESET_REG_2_XMAC |
  7386. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7387. /* Full reset masks according to the chip */
  7388. reset_mask1 = 0xffffffff;
  7389. if (CHIP_IS_E1(bp))
  7390. reset_mask2 = 0xffff;
  7391. else if (CHIP_IS_E1H(bp))
  7392. reset_mask2 = 0x1ffff;
  7393. else if (CHIP_IS_E2(bp))
  7394. reset_mask2 = 0xfffff;
  7395. else /* CHIP_IS_E3 */
  7396. reset_mask2 = 0x3ffffff;
  7397. /* Don't reset global blocks unless we need to */
  7398. if (!global)
  7399. reset_mask2 &= ~global_bits2;
  7400. /*
  7401. * In case of attention in the QM, we need to reset PXP
  7402. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7403. * because otherwise QM reset would release 'close the gates' shortly
  7404. * before resetting the PXP, then the PSWRQ would send a write
  7405. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7406. * read the payload data from PSWWR, but PSWWR would not
  7407. * respond. The write queue in PGLUE would stuck, dmae commands
  7408. * would not return. Therefore it's important to reset the second
  7409. * reset register (containing the
  7410. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7411. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7412. * bit).
  7413. */
  7414. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7415. reset_mask2 & (~not_reset_mask2));
  7416. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7417. reset_mask1 & (~not_reset_mask1));
  7418. barrier();
  7419. mmiowb();
  7420. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7421. reset_mask2 & (~stay_reset2));
  7422. barrier();
  7423. mmiowb();
  7424. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7425. mmiowb();
  7426. }
  7427. /**
  7428. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7429. * It should get cleared in no more than 1s.
  7430. *
  7431. * @bp: driver handle
  7432. *
  7433. * It should get cleared in no more than 1s. Returns 0 if
  7434. * pending writes bit gets cleared.
  7435. */
  7436. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7437. {
  7438. u32 cnt = 1000;
  7439. u32 pend_bits = 0;
  7440. do {
  7441. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7442. if (pend_bits == 0)
  7443. break;
  7444. usleep_range(1000, 1000);
  7445. } while (cnt-- > 0);
  7446. if (cnt <= 0) {
  7447. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7448. pend_bits);
  7449. return -EBUSY;
  7450. }
  7451. return 0;
  7452. }
  7453. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7454. {
  7455. int cnt = 1000;
  7456. u32 val = 0;
  7457. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7458. u32 tags_63_32 = 0;
  7459. /* Empty the Tetris buffer, wait for 1s */
  7460. do {
  7461. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7462. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7463. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7464. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7465. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7466. if (CHIP_IS_E3(bp))
  7467. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7468. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7469. ((port_is_idle_0 & 0x1) == 0x1) &&
  7470. ((port_is_idle_1 & 0x1) == 0x1) &&
  7471. (pgl_exp_rom2 == 0xffffffff) &&
  7472. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7473. break;
  7474. usleep_range(1000, 1000);
  7475. } while (cnt-- > 0);
  7476. if (cnt <= 0) {
  7477. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7478. 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",
  7479. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7480. pgl_exp_rom2);
  7481. return -EAGAIN;
  7482. }
  7483. barrier();
  7484. /* Close gates #2, #3 and #4 */
  7485. bnx2x_set_234_gates(bp, true);
  7486. /* Poll for IGU VQs for 57712 and newer chips */
  7487. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7488. return -EAGAIN;
  7489. /* TBD: Indicate that "process kill" is in progress to MCP */
  7490. /* Clear "unprepared" bit */
  7491. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7492. barrier();
  7493. /* Make sure all is written to the chip before the reset */
  7494. mmiowb();
  7495. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7496. * PSWHST, GRC and PSWRD Tetris buffer.
  7497. */
  7498. usleep_range(1000, 1000);
  7499. /* Prepare to chip reset: */
  7500. /* MCP */
  7501. if (global)
  7502. bnx2x_reset_mcp_prep(bp, &val);
  7503. /* PXP */
  7504. bnx2x_pxp_prep(bp);
  7505. barrier();
  7506. /* reset the chip */
  7507. bnx2x_process_kill_chip_reset(bp, global);
  7508. barrier();
  7509. /* Recover after reset: */
  7510. /* MCP */
  7511. if (global && bnx2x_reset_mcp_comp(bp, val))
  7512. return -EAGAIN;
  7513. /* TBD: Add resetting the NO_MCP mode DB here */
  7514. /* Open the gates #2, #3 and #4 */
  7515. bnx2x_set_234_gates(bp, false);
  7516. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7517. * reset state, re-enable attentions. */
  7518. return 0;
  7519. }
  7520. static int bnx2x_leader_reset(struct bnx2x *bp)
  7521. {
  7522. int rc = 0;
  7523. bool global = bnx2x_reset_is_global(bp);
  7524. u32 load_code;
  7525. /* if not going to reset MCP - load "fake" driver to reset HW while
  7526. * driver is owner of the HW
  7527. */
  7528. if (!global && !BP_NOMCP(bp)) {
  7529. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7530. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7531. if (!load_code) {
  7532. BNX2X_ERR("MCP response failure, aborting\n");
  7533. rc = -EAGAIN;
  7534. goto exit_leader_reset;
  7535. }
  7536. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7537. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7538. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7539. rc = -EAGAIN;
  7540. goto exit_leader_reset2;
  7541. }
  7542. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7543. if (!load_code) {
  7544. BNX2X_ERR("MCP response failure, aborting\n");
  7545. rc = -EAGAIN;
  7546. goto exit_leader_reset2;
  7547. }
  7548. }
  7549. /* Try to recover after the failure */
  7550. if (bnx2x_process_kill(bp, global)) {
  7551. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7552. BP_PATH(bp));
  7553. rc = -EAGAIN;
  7554. goto exit_leader_reset2;
  7555. }
  7556. /*
  7557. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7558. * state.
  7559. */
  7560. bnx2x_set_reset_done(bp);
  7561. if (global)
  7562. bnx2x_clear_reset_global(bp);
  7563. exit_leader_reset2:
  7564. /* unload "fake driver" if it was loaded */
  7565. if (!global && !BP_NOMCP(bp)) {
  7566. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7567. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7568. }
  7569. exit_leader_reset:
  7570. bp->is_leader = 0;
  7571. bnx2x_release_leader_lock(bp);
  7572. smp_mb();
  7573. return rc;
  7574. }
  7575. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7576. {
  7577. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7578. /* Disconnect this device */
  7579. netif_device_detach(bp->dev);
  7580. /*
  7581. * Block ifup for all function on this engine until "process kill"
  7582. * or power cycle.
  7583. */
  7584. bnx2x_set_reset_in_progress(bp);
  7585. /* Shut down the power */
  7586. bnx2x_set_power_state(bp, PCI_D3hot);
  7587. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7588. smp_mb();
  7589. }
  7590. /*
  7591. * Assumption: runs under rtnl lock. This together with the fact
  7592. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7593. * will never be called when netif_running(bp->dev) is false.
  7594. */
  7595. static void bnx2x_parity_recover(struct bnx2x *bp)
  7596. {
  7597. bool global = false;
  7598. u32 error_recovered, error_unrecovered;
  7599. bool is_parity;
  7600. DP(NETIF_MSG_HW, "Handling parity\n");
  7601. while (1) {
  7602. switch (bp->recovery_state) {
  7603. case BNX2X_RECOVERY_INIT:
  7604. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7605. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7606. WARN_ON(!is_parity);
  7607. /* Try to get a LEADER_LOCK HW lock */
  7608. if (bnx2x_trylock_leader_lock(bp)) {
  7609. bnx2x_set_reset_in_progress(bp);
  7610. /*
  7611. * Check if there is a global attention and if
  7612. * there was a global attention, set the global
  7613. * reset bit.
  7614. */
  7615. if (global)
  7616. bnx2x_set_reset_global(bp);
  7617. bp->is_leader = 1;
  7618. }
  7619. /* Stop the driver */
  7620. /* If interface has been removed - break */
  7621. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7622. return;
  7623. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7624. /* Ensure "is_leader", MCP command sequence and
  7625. * "recovery_state" update values are seen on other
  7626. * CPUs.
  7627. */
  7628. smp_mb();
  7629. break;
  7630. case BNX2X_RECOVERY_WAIT:
  7631. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7632. if (bp->is_leader) {
  7633. int other_engine = BP_PATH(bp) ? 0 : 1;
  7634. bool other_load_status =
  7635. bnx2x_get_load_status(bp, other_engine);
  7636. bool load_status =
  7637. bnx2x_get_load_status(bp, BP_PATH(bp));
  7638. global = bnx2x_reset_is_global(bp);
  7639. /*
  7640. * In case of a parity in a global block, let
  7641. * the first leader that performs a
  7642. * leader_reset() reset the global blocks in
  7643. * order to clear global attentions. Otherwise
  7644. * the the gates will remain closed for that
  7645. * engine.
  7646. */
  7647. if (load_status ||
  7648. (global && other_load_status)) {
  7649. /* Wait until all other functions get
  7650. * down.
  7651. */
  7652. schedule_delayed_work(&bp->sp_rtnl_task,
  7653. HZ/10);
  7654. return;
  7655. } else {
  7656. /* If all other functions got down -
  7657. * try to bring the chip back to
  7658. * normal. In any case it's an exit
  7659. * point for a leader.
  7660. */
  7661. if (bnx2x_leader_reset(bp)) {
  7662. bnx2x_recovery_failed(bp);
  7663. return;
  7664. }
  7665. /* If we are here, means that the
  7666. * leader has succeeded and doesn't
  7667. * want to be a leader any more. Try
  7668. * to continue as a none-leader.
  7669. */
  7670. break;
  7671. }
  7672. } else { /* non-leader */
  7673. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7674. /* Try to get a LEADER_LOCK HW lock as
  7675. * long as a former leader may have
  7676. * been unloaded by the user or
  7677. * released a leadership by another
  7678. * reason.
  7679. */
  7680. if (bnx2x_trylock_leader_lock(bp)) {
  7681. /* I'm a leader now! Restart a
  7682. * switch case.
  7683. */
  7684. bp->is_leader = 1;
  7685. break;
  7686. }
  7687. schedule_delayed_work(&bp->sp_rtnl_task,
  7688. HZ/10);
  7689. return;
  7690. } else {
  7691. /*
  7692. * If there was a global attention, wait
  7693. * for it to be cleared.
  7694. */
  7695. if (bnx2x_reset_is_global(bp)) {
  7696. schedule_delayed_work(
  7697. &bp->sp_rtnl_task,
  7698. HZ/10);
  7699. return;
  7700. }
  7701. error_recovered =
  7702. bp->eth_stats.recoverable_error;
  7703. error_unrecovered =
  7704. bp->eth_stats.unrecoverable_error;
  7705. bp->recovery_state =
  7706. BNX2X_RECOVERY_NIC_LOADING;
  7707. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7708. error_unrecovered++;
  7709. netdev_err(bp->dev,
  7710. "Recovery failed. Power cycle needed\n");
  7711. /* Disconnect this device */
  7712. netif_device_detach(bp->dev);
  7713. /* Shut down the power */
  7714. bnx2x_set_power_state(
  7715. bp, PCI_D3hot);
  7716. smp_mb();
  7717. } else {
  7718. bp->recovery_state =
  7719. BNX2X_RECOVERY_DONE;
  7720. error_recovered++;
  7721. smp_mb();
  7722. }
  7723. bp->eth_stats.recoverable_error =
  7724. error_recovered;
  7725. bp->eth_stats.unrecoverable_error =
  7726. error_unrecovered;
  7727. return;
  7728. }
  7729. }
  7730. default:
  7731. return;
  7732. }
  7733. }
  7734. }
  7735. static int bnx2x_close(struct net_device *dev);
  7736. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7737. * scheduled on a general queue in order to prevent a dead lock.
  7738. */
  7739. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7740. {
  7741. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7742. rtnl_lock();
  7743. if (!netif_running(bp->dev))
  7744. goto sp_rtnl_exit;
  7745. /* if stop on error is defined no recovery flows should be executed */
  7746. #ifdef BNX2X_STOP_ON_ERROR
  7747. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7748. "you will need to reboot when done\n");
  7749. goto sp_rtnl_not_reset;
  7750. #endif
  7751. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7752. /*
  7753. * Clear all pending SP commands as we are going to reset the
  7754. * function anyway.
  7755. */
  7756. bp->sp_rtnl_state = 0;
  7757. smp_mb();
  7758. bnx2x_parity_recover(bp);
  7759. goto sp_rtnl_exit;
  7760. }
  7761. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7762. /*
  7763. * Clear all pending SP commands as we are going to reset the
  7764. * function anyway.
  7765. */
  7766. bp->sp_rtnl_state = 0;
  7767. smp_mb();
  7768. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7769. bnx2x_nic_load(bp, LOAD_NORMAL);
  7770. goto sp_rtnl_exit;
  7771. }
  7772. #ifdef BNX2X_STOP_ON_ERROR
  7773. sp_rtnl_not_reset:
  7774. #endif
  7775. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7776. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7777. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7778. bnx2x_after_function_update(bp);
  7779. /*
  7780. * in case of fan failure we need to reset id if the "stop on error"
  7781. * debug flag is set, since we trying to prevent permanent overheating
  7782. * damage
  7783. */
  7784. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7785. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7786. netif_device_detach(bp->dev);
  7787. bnx2x_close(bp->dev);
  7788. }
  7789. sp_rtnl_exit:
  7790. rtnl_unlock();
  7791. }
  7792. /* end of nic load/unload */
  7793. static void bnx2x_period_task(struct work_struct *work)
  7794. {
  7795. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7796. if (!netif_running(bp->dev))
  7797. goto period_task_exit;
  7798. if (CHIP_REV_IS_SLOW(bp)) {
  7799. BNX2X_ERR("period task called on emulation, ignoring\n");
  7800. goto period_task_exit;
  7801. }
  7802. bnx2x_acquire_phy_lock(bp);
  7803. /*
  7804. * The barrier is needed to ensure the ordering between the writing to
  7805. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7806. * the reading here.
  7807. */
  7808. smp_mb();
  7809. if (bp->port.pmf) {
  7810. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7811. /* Re-queue task in 1 sec */
  7812. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7813. }
  7814. bnx2x_release_phy_lock(bp);
  7815. period_task_exit:
  7816. return;
  7817. }
  7818. /*
  7819. * Init service functions
  7820. */
  7821. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7822. {
  7823. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7824. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7825. return base + (BP_ABS_FUNC(bp)) * stride;
  7826. }
  7827. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7828. {
  7829. u32 reg = bnx2x_get_pretend_reg(bp);
  7830. /* Flush all outstanding writes */
  7831. mmiowb();
  7832. /* Pretend to be function 0 */
  7833. REG_WR(bp, reg, 0);
  7834. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7835. /* From now we are in the "like-E1" mode */
  7836. bnx2x_int_disable(bp);
  7837. /* Flush all outstanding writes */
  7838. mmiowb();
  7839. /* Restore the original function */
  7840. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7841. REG_RD(bp, reg);
  7842. }
  7843. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7844. {
  7845. if (CHIP_IS_E1(bp))
  7846. bnx2x_int_disable(bp);
  7847. else
  7848. bnx2x_undi_int_disable_e1h(bp);
  7849. }
  7850. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  7851. struct bnx2x_mac_vals *vals)
  7852. {
  7853. u32 val, base_addr, offset, mask, reset_reg;
  7854. bool mac_stopped = false;
  7855. u8 port = BP_PORT(bp);
  7856. /* reset addresses as they also mark which values were changed */
  7857. vals->bmac_addr = 0;
  7858. vals->umac_addr = 0;
  7859. vals->xmac_addr = 0;
  7860. vals->emac_addr = 0;
  7861. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7862. if (!CHIP_IS_E3(bp)) {
  7863. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7864. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7865. if ((mask & reset_reg) && val) {
  7866. u32 wb_data[2];
  7867. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7868. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7869. : NIG_REG_INGRESS_BMAC0_MEM;
  7870. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7871. : BIGMAC_REGISTER_BMAC_CONTROL;
  7872. /*
  7873. * use rd/wr since we cannot use dmae. This is safe
  7874. * since MCP won't access the bus due to the request
  7875. * to unload, and no function on the path can be
  7876. * loaded at this time.
  7877. */
  7878. wb_data[0] = REG_RD(bp, base_addr + offset);
  7879. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  7880. vals->bmac_addr = base_addr + offset;
  7881. vals->bmac_val[0] = wb_data[0];
  7882. vals->bmac_val[1] = wb_data[1];
  7883. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  7884. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  7885. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  7886. }
  7887. BNX2X_DEV_INFO("Disable emac Rx\n");
  7888. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  7889. vals->emac_val = REG_RD(bp, vals->emac_addr);
  7890. REG_WR(bp, vals->emac_addr, 0);
  7891. mac_stopped = true;
  7892. } else {
  7893. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  7894. BNX2X_DEV_INFO("Disable xmac Rx\n");
  7895. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  7896. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  7897. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7898. val & ~(1 << 1));
  7899. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  7900. val | (1 << 1));
  7901. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  7902. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  7903. REG_WR(bp, vals->xmac_addr, 0);
  7904. mac_stopped = true;
  7905. }
  7906. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  7907. if (mask & reset_reg) {
  7908. BNX2X_DEV_INFO("Disable umac Rx\n");
  7909. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  7910. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  7911. vals->umac_val = REG_RD(bp, vals->umac_addr);
  7912. REG_WR(bp, vals->umac_addr, 0);
  7913. mac_stopped = true;
  7914. }
  7915. }
  7916. if (mac_stopped)
  7917. msleep(20);
  7918. }
  7919. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  7920. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  7921. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  7922. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  7923. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  7924. {
  7925. u16 rcq, bd;
  7926. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  7927. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  7928. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  7929. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  7930. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  7931. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  7932. port, bd, rcq);
  7933. }
  7934. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  7935. {
  7936. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  7937. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  7938. if (!rc) {
  7939. BNX2X_ERR("MCP response failure, aborting\n");
  7940. return -EBUSY;
  7941. }
  7942. return 0;
  7943. }
  7944. static struct bnx2x_prev_path_list *
  7945. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  7946. {
  7947. struct bnx2x_prev_path_list *tmp_list;
  7948. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  7949. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7950. bp->pdev->bus->number == tmp_list->bus &&
  7951. BP_PATH(bp) == tmp_list->path)
  7952. return tmp_list;
  7953. return NULL;
  7954. }
  7955. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  7956. {
  7957. struct bnx2x_prev_path_list *tmp_list;
  7958. int rc = false;
  7959. if (down_trylock(&bnx2x_prev_sem))
  7960. return false;
  7961. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  7962. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  7963. bp->pdev->bus->number == tmp_list->bus &&
  7964. BP_PATH(bp) == tmp_list->path) {
  7965. rc = true;
  7966. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  7967. BP_PATH(bp));
  7968. break;
  7969. }
  7970. }
  7971. up(&bnx2x_prev_sem);
  7972. return rc;
  7973. }
  7974. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  7975. {
  7976. struct bnx2x_prev_path_list *tmp_list;
  7977. int rc;
  7978. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  7979. if (!tmp_list) {
  7980. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  7981. return -ENOMEM;
  7982. }
  7983. tmp_list->bus = bp->pdev->bus->number;
  7984. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  7985. tmp_list->path = BP_PATH(bp);
  7986. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  7987. rc = down_interruptible(&bnx2x_prev_sem);
  7988. if (rc) {
  7989. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  7990. kfree(tmp_list);
  7991. } else {
  7992. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  7993. BP_PATH(bp));
  7994. list_add(&tmp_list->list, &bnx2x_prev_list);
  7995. up(&bnx2x_prev_sem);
  7996. }
  7997. return rc;
  7998. }
  7999. static int bnx2x_do_flr(struct bnx2x *bp)
  8000. {
  8001. int i;
  8002. u16 status;
  8003. struct pci_dev *dev = bp->pdev;
  8004. if (CHIP_IS_E1x(bp)) {
  8005. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8006. return -EINVAL;
  8007. }
  8008. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8009. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8010. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8011. bp->common.bc_ver);
  8012. return -EINVAL;
  8013. }
  8014. /* Wait for Transaction Pending bit clean */
  8015. for (i = 0; i < 4; i++) {
  8016. if (i)
  8017. msleep((1 << (i - 1)) * 100);
  8018. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8019. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8020. goto clear;
  8021. }
  8022. dev_err(&dev->dev,
  8023. "transaction is not cleared; proceeding with reset anyway\n");
  8024. clear:
  8025. BNX2X_DEV_INFO("Initiating FLR\n");
  8026. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8027. return 0;
  8028. }
  8029. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8030. {
  8031. int rc;
  8032. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8033. /* Test if previous unload process was already finished for this path */
  8034. if (bnx2x_prev_is_path_marked(bp))
  8035. return bnx2x_prev_mcp_done(bp);
  8036. /* If function has FLR capabilities, and existing FW version matches
  8037. * the one required, then FLR will be sufficient to clean any residue
  8038. * left by previous driver
  8039. */
  8040. rc = bnx2x_test_firmware_version(bp, false);
  8041. if (!rc) {
  8042. /* fw version is good */
  8043. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8044. rc = bnx2x_do_flr(bp);
  8045. }
  8046. if (!rc) {
  8047. /* FLR was performed */
  8048. BNX2X_DEV_INFO("FLR successful\n");
  8049. return 0;
  8050. }
  8051. BNX2X_DEV_INFO("Could not FLR\n");
  8052. /* Close the MCP request, return failure*/
  8053. rc = bnx2x_prev_mcp_done(bp);
  8054. if (!rc)
  8055. rc = BNX2X_PREV_WAIT_NEEDED;
  8056. return rc;
  8057. }
  8058. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8059. {
  8060. u32 reset_reg, tmp_reg = 0, rc;
  8061. bool prev_undi = false;
  8062. struct bnx2x_mac_vals mac_vals;
  8063. /* It is possible a previous function received 'common' answer,
  8064. * but hasn't loaded yet, therefore creating a scenario of
  8065. * multiple functions receiving 'common' on the same path.
  8066. */
  8067. BNX2X_DEV_INFO("Common unload Flow\n");
  8068. memset(&mac_vals, 0, sizeof(mac_vals));
  8069. if (bnx2x_prev_is_path_marked(bp))
  8070. return bnx2x_prev_mcp_done(bp);
  8071. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8072. /* Reset should be performed after BRB is emptied */
  8073. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8074. u32 timer_count = 1000;
  8075. /* Close the MAC Rx to prevent BRB from filling up */
  8076. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8077. /* close LLH filters towards the BRB */
  8078. bnx2x_set_rx_filter(&bp->link_params, 0);
  8079. /* Check if the UNDI driver was previously loaded
  8080. * UNDI driver initializes CID offset for normal bell to 0x7
  8081. */
  8082. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8083. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8084. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8085. if (tmp_reg == 0x7) {
  8086. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8087. prev_undi = true;
  8088. /* clear the UNDI indication */
  8089. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8090. }
  8091. }
  8092. /* wait until BRB is empty */
  8093. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8094. while (timer_count) {
  8095. u32 prev_brb = tmp_reg;
  8096. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8097. if (!tmp_reg)
  8098. break;
  8099. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8100. /* reset timer as long as BRB actually gets emptied */
  8101. if (prev_brb > tmp_reg)
  8102. timer_count = 1000;
  8103. else
  8104. timer_count--;
  8105. /* If UNDI resides in memory, manually increment it */
  8106. if (prev_undi)
  8107. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8108. udelay(10);
  8109. }
  8110. if (!timer_count)
  8111. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8112. }
  8113. /* No packets are in the pipeline, path is ready for reset */
  8114. bnx2x_reset_common(bp);
  8115. if (mac_vals.xmac_addr)
  8116. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8117. if (mac_vals.umac_addr)
  8118. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8119. if (mac_vals.emac_addr)
  8120. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8121. if (mac_vals.bmac_addr) {
  8122. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8123. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8124. }
  8125. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8126. if (rc) {
  8127. bnx2x_prev_mcp_done(bp);
  8128. return rc;
  8129. }
  8130. return bnx2x_prev_mcp_done(bp);
  8131. }
  8132. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8133. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8134. * the addresses of the transaction, resulting in was-error bit set in the pci
  8135. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8136. * to clear the interrupt which detected this from the pglueb and the was done
  8137. * bit
  8138. */
  8139. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8140. {
  8141. if (!CHIP_IS_E1x(bp)) {
  8142. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8143. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8144. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  8145. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8146. 1 << BP_FUNC(bp));
  8147. }
  8148. }
  8149. }
  8150. static int bnx2x_prev_unload(struct bnx2x *bp)
  8151. {
  8152. int time_counter = 10;
  8153. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8154. struct bnx2x_prev_path_list *prev_list;
  8155. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8156. /* clear hw from errors which may have resulted from an interrupted
  8157. * dmae transaction.
  8158. */
  8159. bnx2x_prev_interrupted_dmae(bp);
  8160. /* Release previously held locks */
  8161. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8162. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8163. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8164. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8165. if (hw_lock_val) {
  8166. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8167. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8168. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8169. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8170. }
  8171. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8172. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8173. } else
  8174. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8175. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8176. BNX2X_DEV_INFO("Release previously held alr\n");
  8177. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8178. }
  8179. do {
  8180. /* Lock MCP using an unload request */
  8181. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8182. if (!fw) {
  8183. BNX2X_ERR("MCP response failure, aborting\n");
  8184. rc = -EBUSY;
  8185. break;
  8186. }
  8187. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8188. rc = bnx2x_prev_unload_common(bp);
  8189. break;
  8190. }
  8191. /* non-common reply from MCP night require looping */
  8192. rc = bnx2x_prev_unload_uncommon(bp);
  8193. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8194. break;
  8195. msleep(20);
  8196. } while (--time_counter);
  8197. if (!time_counter || rc) {
  8198. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8199. rc = -EBUSY;
  8200. }
  8201. /* Mark function if its port was used to boot from SAN */
  8202. prev_list = bnx2x_prev_path_get_entry(bp);
  8203. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8204. bp->link_params.feature_config_flags |=
  8205. FEATURE_CONFIG_BOOT_FROM_SAN;
  8206. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8207. return rc;
  8208. }
  8209. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8210. {
  8211. u32 val, val2, val3, val4, id, boot_mode;
  8212. u16 pmc;
  8213. /* Get the chip revision id and number. */
  8214. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8215. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8216. id = ((val & 0xffff) << 16);
  8217. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8218. id |= ((val & 0xf) << 12);
  8219. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8220. id |= ((val & 0xff) << 4);
  8221. val = REG_RD(bp, MISC_REG_BOND_ID);
  8222. id |= (val & 0xf);
  8223. bp->common.chip_id = id;
  8224. /* force 57811 according to MISC register */
  8225. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8226. if (CHIP_IS_57810(bp))
  8227. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8228. (bp->common.chip_id & 0x0000FFFF);
  8229. else if (CHIP_IS_57810_MF(bp))
  8230. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8231. (bp->common.chip_id & 0x0000FFFF);
  8232. bp->common.chip_id |= 0x1;
  8233. }
  8234. /* Set doorbell size */
  8235. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8236. if (!CHIP_IS_E1x(bp)) {
  8237. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8238. if ((val & 1) == 0)
  8239. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8240. else
  8241. val = (val >> 1) & 1;
  8242. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8243. "2_PORT_MODE");
  8244. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8245. CHIP_2_PORT_MODE;
  8246. if (CHIP_MODE_IS_4_PORT(bp))
  8247. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8248. else
  8249. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8250. } else {
  8251. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8252. bp->pfid = bp->pf_num; /* 0..7 */
  8253. }
  8254. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8255. bp->link_params.chip_id = bp->common.chip_id;
  8256. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8257. val = (REG_RD(bp, 0x2874) & 0x55);
  8258. if ((bp->common.chip_id & 0x1) ||
  8259. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8260. bp->flags |= ONE_PORT_FLAG;
  8261. BNX2X_DEV_INFO("single port device\n");
  8262. }
  8263. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8264. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8265. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8266. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8267. bp->common.flash_size, bp->common.flash_size);
  8268. bnx2x_init_shmem(bp);
  8269. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8270. MISC_REG_GENERIC_CR_1 :
  8271. MISC_REG_GENERIC_CR_0));
  8272. bp->link_params.shmem_base = bp->common.shmem_base;
  8273. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8274. if (SHMEM2_RD(bp, size) >
  8275. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8276. bp->link_params.lfa_base =
  8277. REG_RD(bp, bp->common.shmem2_base +
  8278. (u32)offsetof(struct shmem2_region,
  8279. lfa_host_addr[BP_PORT(bp)]));
  8280. else
  8281. bp->link_params.lfa_base = 0;
  8282. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8283. bp->common.shmem_base, bp->common.shmem2_base);
  8284. if (!bp->common.shmem_base) {
  8285. BNX2X_DEV_INFO("MCP not active\n");
  8286. bp->flags |= NO_MCP_FLAG;
  8287. return;
  8288. }
  8289. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8290. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8291. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8292. SHARED_HW_CFG_LED_MODE_MASK) >>
  8293. SHARED_HW_CFG_LED_MODE_SHIFT);
  8294. bp->link_params.feature_config_flags = 0;
  8295. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8296. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8297. bp->link_params.feature_config_flags |=
  8298. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8299. else
  8300. bp->link_params.feature_config_flags &=
  8301. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8302. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8303. bp->common.bc_ver = val;
  8304. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8305. if (val < BNX2X_BC_VER) {
  8306. /* for now only warn
  8307. * later we might need to enforce this */
  8308. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8309. BNX2X_BC_VER, val);
  8310. }
  8311. bp->link_params.feature_config_flags |=
  8312. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8313. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8314. bp->link_params.feature_config_flags |=
  8315. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8316. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8317. bp->link_params.feature_config_flags |=
  8318. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8319. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8320. bp->link_params.feature_config_flags |=
  8321. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8322. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8323. bp->link_params.feature_config_flags |=
  8324. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8325. FEATURE_CONFIG_MT_SUPPORT : 0;
  8326. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8327. BC_SUPPORTS_PFC_STATS : 0;
  8328. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8329. BC_SUPPORTS_FCOE_FEATURES : 0;
  8330. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8331. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8332. boot_mode = SHMEM_RD(bp,
  8333. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8334. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8335. switch (boot_mode) {
  8336. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8337. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8338. break;
  8339. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8340. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8341. break;
  8342. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8343. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8344. break;
  8345. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8346. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8347. break;
  8348. }
  8349. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8350. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8351. BNX2X_DEV_INFO("%sWoL capable\n",
  8352. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8353. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8354. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8355. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8356. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8357. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8358. val, val2, val3, val4);
  8359. }
  8360. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8361. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8362. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8363. {
  8364. int pfid = BP_FUNC(bp);
  8365. int igu_sb_id;
  8366. u32 val;
  8367. u8 fid, igu_sb_cnt = 0;
  8368. bp->igu_base_sb = 0xff;
  8369. if (CHIP_INT_MODE_IS_BC(bp)) {
  8370. int vn = BP_VN(bp);
  8371. igu_sb_cnt = bp->igu_sb_cnt;
  8372. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8373. FP_SB_MAX_E1x;
  8374. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8375. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8376. return 0;
  8377. }
  8378. /* IGU in normal mode - read CAM */
  8379. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8380. igu_sb_id++) {
  8381. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8382. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8383. continue;
  8384. fid = IGU_FID(val);
  8385. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8386. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8387. continue;
  8388. if (IGU_VEC(val) == 0)
  8389. /* default status block */
  8390. bp->igu_dsb_id = igu_sb_id;
  8391. else {
  8392. if (bp->igu_base_sb == 0xff)
  8393. bp->igu_base_sb = igu_sb_id;
  8394. igu_sb_cnt++;
  8395. }
  8396. }
  8397. }
  8398. #ifdef CONFIG_PCI_MSI
  8399. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8400. * optional that number of CAM entries will not be equal to the value
  8401. * advertised in PCI.
  8402. * Driver should use the minimal value of both as the actual status
  8403. * block count
  8404. */
  8405. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8406. #endif
  8407. if (igu_sb_cnt == 0) {
  8408. BNX2X_ERR("CAM configuration error\n");
  8409. return -EINVAL;
  8410. }
  8411. return 0;
  8412. }
  8413. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8414. {
  8415. int cfg_size = 0, idx, port = BP_PORT(bp);
  8416. /* Aggregation of supported attributes of all external phys */
  8417. bp->port.supported[0] = 0;
  8418. bp->port.supported[1] = 0;
  8419. switch (bp->link_params.num_phys) {
  8420. case 1:
  8421. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8422. cfg_size = 1;
  8423. break;
  8424. case 2:
  8425. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8426. cfg_size = 1;
  8427. break;
  8428. case 3:
  8429. if (bp->link_params.multi_phy_config &
  8430. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8431. bp->port.supported[1] =
  8432. bp->link_params.phy[EXT_PHY1].supported;
  8433. bp->port.supported[0] =
  8434. bp->link_params.phy[EXT_PHY2].supported;
  8435. } else {
  8436. bp->port.supported[0] =
  8437. bp->link_params.phy[EXT_PHY1].supported;
  8438. bp->port.supported[1] =
  8439. bp->link_params.phy[EXT_PHY2].supported;
  8440. }
  8441. cfg_size = 2;
  8442. break;
  8443. }
  8444. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8445. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8446. SHMEM_RD(bp,
  8447. dev_info.port_hw_config[port].external_phy_config),
  8448. SHMEM_RD(bp,
  8449. dev_info.port_hw_config[port].external_phy_config2));
  8450. return;
  8451. }
  8452. if (CHIP_IS_E3(bp))
  8453. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8454. else {
  8455. switch (switch_cfg) {
  8456. case SWITCH_CFG_1G:
  8457. bp->port.phy_addr = REG_RD(
  8458. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8459. break;
  8460. case SWITCH_CFG_10G:
  8461. bp->port.phy_addr = REG_RD(
  8462. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8463. break;
  8464. default:
  8465. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8466. bp->port.link_config[0]);
  8467. return;
  8468. }
  8469. }
  8470. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8471. /* mask what we support according to speed_cap_mask per configuration */
  8472. for (idx = 0; idx < cfg_size; idx++) {
  8473. if (!(bp->link_params.speed_cap_mask[idx] &
  8474. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8475. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8476. if (!(bp->link_params.speed_cap_mask[idx] &
  8477. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8478. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8479. if (!(bp->link_params.speed_cap_mask[idx] &
  8480. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8481. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8482. if (!(bp->link_params.speed_cap_mask[idx] &
  8483. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8484. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8485. if (!(bp->link_params.speed_cap_mask[idx] &
  8486. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8487. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8488. SUPPORTED_1000baseT_Full);
  8489. if (!(bp->link_params.speed_cap_mask[idx] &
  8490. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8491. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8492. if (!(bp->link_params.speed_cap_mask[idx] &
  8493. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8494. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8495. }
  8496. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8497. bp->port.supported[1]);
  8498. }
  8499. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8500. {
  8501. u32 link_config, idx, cfg_size = 0;
  8502. bp->port.advertising[0] = 0;
  8503. bp->port.advertising[1] = 0;
  8504. switch (bp->link_params.num_phys) {
  8505. case 1:
  8506. case 2:
  8507. cfg_size = 1;
  8508. break;
  8509. case 3:
  8510. cfg_size = 2;
  8511. break;
  8512. }
  8513. for (idx = 0; idx < cfg_size; idx++) {
  8514. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8515. link_config = bp->port.link_config[idx];
  8516. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8517. case PORT_FEATURE_LINK_SPEED_AUTO:
  8518. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8519. bp->link_params.req_line_speed[idx] =
  8520. SPEED_AUTO_NEG;
  8521. bp->port.advertising[idx] |=
  8522. bp->port.supported[idx];
  8523. if (bp->link_params.phy[EXT_PHY1].type ==
  8524. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8525. bp->port.advertising[idx] |=
  8526. (SUPPORTED_100baseT_Half |
  8527. SUPPORTED_100baseT_Full);
  8528. } else {
  8529. /* force 10G, no AN */
  8530. bp->link_params.req_line_speed[idx] =
  8531. SPEED_10000;
  8532. bp->port.advertising[idx] |=
  8533. (ADVERTISED_10000baseT_Full |
  8534. ADVERTISED_FIBRE);
  8535. continue;
  8536. }
  8537. break;
  8538. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8539. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8540. bp->link_params.req_line_speed[idx] =
  8541. SPEED_10;
  8542. bp->port.advertising[idx] |=
  8543. (ADVERTISED_10baseT_Full |
  8544. ADVERTISED_TP);
  8545. } else {
  8546. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8547. link_config,
  8548. bp->link_params.speed_cap_mask[idx]);
  8549. return;
  8550. }
  8551. break;
  8552. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8553. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8554. bp->link_params.req_line_speed[idx] =
  8555. SPEED_10;
  8556. bp->link_params.req_duplex[idx] =
  8557. DUPLEX_HALF;
  8558. bp->port.advertising[idx] |=
  8559. (ADVERTISED_10baseT_Half |
  8560. ADVERTISED_TP);
  8561. } else {
  8562. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8563. link_config,
  8564. bp->link_params.speed_cap_mask[idx]);
  8565. return;
  8566. }
  8567. break;
  8568. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8569. if (bp->port.supported[idx] &
  8570. SUPPORTED_100baseT_Full) {
  8571. bp->link_params.req_line_speed[idx] =
  8572. SPEED_100;
  8573. bp->port.advertising[idx] |=
  8574. (ADVERTISED_100baseT_Full |
  8575. ADVERTISED_TP);
  8576. } else {
  8577. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8578. link_config,
  8579. bp->link_params.speed_cap_mask[idx]);
  8580. return;
  8581. }
  8582. break;
  8583. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8584. if (bp->port.supported[idx] &
  8585. SUPPORTED_100baseT_Half) {
  8586. bp->link_params.req_line_speed[idx] =
  8587. SPEED_100;
  8588. bp->link_params.req_duplex[idx] =
  8589. DUPLEX_HALF;
  8590. bp->port.advertising[idx] |=
  8591. (ADVERTISED_100baseT_Half |
  8592. ADVERTISED_TP);
  8593. } else {
  8594. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8595. link_config,
  8596. bp->link_params.speed_cap_mask[idx]);
  8597. return;
  8598. }
  8599. break;
  8600. case PORT_FEATURE_LINK_SPEED_1G:
  8601. if (bp->port.supported[idx] &
  8602. SUPPORTED_1000baseT_Full) {
  8603. bp->link_params.req_line_speed[idx] =
  8604. SPEED_1000;
  8605. bp->port.advertising[idx] |=
  8606. (ADVERTISED_1000baseT_Full |
  8607. ADVERTISED_TP);
  8608. } else {
  8609. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8610. link_config,
  8611. bp->link_params.speed_cap_mask[idx]);
  8612. return;
  8613. }
  8614. break;
  8615. case PORT_FEATURE_LINK_SPEED_2_5G:
  8616. if (bp->port.supported[idx] &
  8617. SUPPORTED_2500baseX_Full) {
  8618. bp->link_params.req_line_speed[idx] =
  8619. SPEED_2500;
  8620. bp->port.advertising[idx] |=
  8621. (ADVERTISED_2500baseX_Full |
  8622. ADVERTISED_TP);
  8623. } else {
  8624. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8625. link_config,
  8626. bp->link_params.speed_cap_mask[idx]);
  8627. return;
  8628. }
  8629. break;
  8630. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8631. if (bp->port.supported[idx] &
  8632. SUPPORTED_10000baseT_Full) {
  8633. bp->link_params.req_line_speed[idx] =
  8634. SPEED_10000;
  8635. bp->port.advertising[idx] |=
  8636. (ADVERTISED_10000baseT_Full |
  8637. ADVERTISED_FIBRE);
  8638. } else {
  8639. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8640. link_config,
  8641. bp->link_params.speed_cap_mask[idx]);
  8642. return;
  8643. }
  8644. break;
  8645. case PORT_FEATURE_LINK_SPEED_20G:
  8646. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8647. break;
  8648. default:
  8649. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8650. link_config);
  8651. bp->link_params.req_line_speed[idx] =
  8652. SPEED_AUTO_NEG;
  8653. bp->port.advertising[idx] =
  8654. bp->port.supported[idx];
  8655. break;
  8656. }
  8657. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8658. PORT_FEATURE_FLOW_CONTROL_MASK);
  8659. if (bp->link_params.req_flow_ctrl[idx] ==
  8660. BNX2X_FLOW_CTRL_AUTO) {
  8661. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8662. bp->link_params.req_flow_ctrl[idx] =
  8663. BNX2X_FLOW_CTRL_NONE;
  8664. else
  8665. bnx2x_set_requested_fc(bp);
  8666. }
  8667. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8668. bp->link_params.req_line_speed[idx],
  8669. bp->link_params.req_duplex[idx],
  8670. bp->link_params.req_flow_ctrl[idx],
  8671. bp->port.advertising[idx]);
  8672. }
  8673. }
  8674. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8675. {
  8676. mac_hi = cpu_to_be16(mac_hi);
  8677. mac_lo = cpu_to_be32(mac_lo);
  8678. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8679. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8680. }
  8681. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8682. {
  8683. int port = BP_PORT(bp);
  8684. u32 config;
  8685. u32 ext_phy_type, ext_phy_config, eee_mode;
  8686. bp->link_params.bp = bp;
  8687. bp->link_params.port = port;
  8688. bp->link_params.lane_config =
  8689. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8690. bp->link_params.speed_cap_mask[0] =
  8691. SHMEM_RD(bp,
  8692. dev_info.port_hw_config[port].speed_capability_mask);
  8693. bp->link_params.speed_cap_mask[1] =
  8694. SHMEM_RD(bp,
  8695. dev_info.port_hw_config[port].speed_capability_mask2);
  8696. bp->port.link_config[0] =
  8697. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8698. bp->port.link_config[1] =
  8699. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8700. bp->link_params.multi_phy_config =
  8701. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8702. /* If the device is capable of WoL, set the default state according
  8703. * to the HW
  8704. */
  8705. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8706. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8707. (config & PORT_FEATURE_WOL_ENABLED));
  8708. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8709. bp->link_params.lane_config,
  8710. bp->link_params.speed_cap_mask[0],
  8711. bp->port.link_config[0]);
  8712. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8713. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8714. bnx2x_phy_probe(&bp->link_params);
  8715. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8716. bnx2x_link_settings_requested(bp);
  8717. /*
  8718. * If connected directly, work with the internal PHY, otherwise, work
  8719. * with the external PHY
  8720. */
  8721. ext_phy_config =
  8722. SHMEM_RD(bp,
  8723. dev_info.port_hw_config[port].external_phy_config);
  8724. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8725. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8726. bp->mdio.prtad = bp->port.phy_addr;
  8727. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8728. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8729. bp->mdio.prtad =
  8730. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8731. /* Configure link feature according to nvram value */
  8732. eee_mode = (((SHMEM_RD(bp, dev_info.
  8733. port_feature_config[port].eee_power_mode)) &
  8734. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8735. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8736. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8737. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8738. EEE_MODE_ENABLE_LPI |
  8739. EEE_MODE_OUTPUT_TIME;
  8740. } else {
  8741. bp->link_params.eee_mode = 0;
  8742. }
  8743. }
  8744. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8745. {
  8746. u32 no_flags = NO_ISCSI_FLAG;
  8747. int port = BP_PORT(bp);
  8748. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8749. drv_lic_key[port].max_iscsi_conn);
  8750. if (!CNIC_SUPPORT(bp)) {
  8751. bp->flags |= no_flags;
  8752. return;
  8753. }
  8754. /* Get the number of maximum allowed iSCSI connections */
  8755. bp->cnic_eth_dev.max_iscsi_conn =
  8756. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8757. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8758. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8759. bp->cnic_eth_dev.max_iscsi_conn);
  8760. /*
  8761. * If maximum allowed number of connections is zero -
  8762. * disable the feature.
  8763. */
  8764. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8765. bp->flags |= no_flags;
  8766. }
  8767. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8768. {
  8769. /* Port info */
  8770. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8771. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8772. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8773. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8774. /* Node info */
  8775. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8776. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8777. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8778. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8779. }
  8780. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8781. {
  8782. int port = BP_PORT(bp);
  8783. int func = BP_ABS_FUNC(bp);
  8784. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8785. drv_lic_key[port].max_fcoe_conn);
  8786. if (!CNIC_SUPPORT(bp)) {
  8787. bp->flags |= NO_FCOE_FLAG;
  8788. return;
  8789. }
  8790. /* Get the number of maximum allowed FCoE connections */
  8791. bp->cnic_eth_dev.max_fcoe_conn =
  8792. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8793. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8794. /* Read the WWN: */
  8795. if (!IS_MF(bp)) {
  8796. /* Port info */
  8797. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8798. SHMEM_RD(bp,
  8799. dev_info.port_hw_config[port].
  8800. fcoe_wwn_port_name_upper);
  8801. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8802. SHMEM_RD(bp,
  8803. dev_info.port_hw_config[port].
  8804. fcoe_wwn_port_name_lower);
  8805. /* Node info */
  8806. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8807. SHMEM_RD(bp,
  8808. dev_info.port_hw_config[port].
  8809. fcoe_wwn_node_name_upper);
  8810. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8811. SHMEM_RD(bp,
  8812. dev_info.port_hw_config[port].
  8813. fcoe_wwn_node_name_lower);
  8814. } else if (!IS_MF_SD(bp)) {
  8815. /*
  8816. * Read the WWN info only if the FCoE feature is enabled for
  8817. * this function.
  8818. */
  8819. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8820. bnx2x_get_ext_wwn_info(bp, func);
  8821. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8822. bnx2x_get_ext_wwn_info(bp, func);
  8823. }
  8824. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8825. /*
  8826. * If maximum allowed number of connections is zero -
  8827. * disable the feature.
  8828. */
  8829. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8830. bp->flags |= NO_FCOE_FLAG;
  8831. }
  8832. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  8833. {
  8834. /*
  8835. * iSCSI may be dynamically disabled but reading
  8836. * info here we will decrease memory usage by driver
  8837. * if the feature is disabled for good
  8838. */
  8839. bnx2x_get_iscsi_info(bp);
  8840. bnx2x_get_fcoe_info(bp);
  8841. }
  8842. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8843. {
  8844. u32 val, val2;
  8845. int func = BP_ABS_FUNC(bp);
  8846. int port = BP_PORT(bp);
  8847. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8848. u8 *fip_mac = bp->fip_mac;
  8849. if (IS_MF(bp)) {
  8850. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8851. * FCoE MAC then the appropriate feature should be disabled.
  8852. * In non SD mode features configuration comes from struct
  8853. * func_ext_config.
  8854. */
  8855. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  8856. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8857. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8858. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8859. iscsi_mac_addr_upper);
  8860. val = MF_CFG_RD(bp, func_ext_config[func].
  8861. iscsi_mac_addr_lower);
  8862. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8863. BNX2X_DEV_INFO
  8864. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8865. } else {
  8866. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8867. }
  8868. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8869. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8870. fcoe_mac_addr_upper);
  8871. val = MF_CFG_RD(bp, func_ext_config[func].
  8872. fcoe_mac_addr_lower);
  8873. bnx2x_set_mac_buf(fip_mac, val, val2);
  8874. BNX2X_DEV_INFO
  8875. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  8876. } else {
  8877. bp->flags |= NO_FCOE_FLAG;
  8878. }
  8879. bp->mf_ext_config = cfg;
  8880. } else { /* SD MODE */
  8881. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8882. /* use primary mac as iscsi mac */
  8883. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  8884. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8885. BNX2X_DEV_INFO
  8886. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  8887. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  8888. /* use primary mac as fip mac */
  8889. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  8890. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8891. BNX2X_DEV_INFO
  8892. ("Read FIP MAC: %pM\n", fip_mac);
  8893. }
  8894. }
  8895. if (IS_MF_STORAGE_SD(bp))
  8896. /* Zero primary MAC configuration */
  8897. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8898. if (IS_MF_FCOE_AFEX(bp))
  8899. /* use FIP MAC as primary MAC */
  8900. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  8901. } else {
  8902. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8903. iscsi_mac_upper);
  8904. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8905. iscsi_mac_lower);
  8906. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8907. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8908. fcoe_fip_mac_upper);
  8909. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8910. fcoe_fip_mac_lower);
  8911. bnx2x_set_mac_buf(fip_mac, val, val2);
  8912. }
  8913. /* Disable iSCSI OOO if MAC configuration is invalid. */
  8914. if (!is_valid_ether_addr(iscsi_mac)) {
  8915. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8916. memset(iscsi_mac, 0, ETH_ALEN);
  8917. }
  8918. /* Disable FCoE if MAC configuration is invalid. */
  8919. if (!is_valid_ether_addr(fip_mac)) {
  8920. bp->flags |= NO_FCOE_FLAG;
  8921. memset(bp->fip_mac, 0, ETH_ALEN);
  8922. }
  8923. }
  8924. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8925. {
  8926. u32 val, val2;
  8927. int func = BP_ABS_FUNC(bp);
  8928. int port = BP_PORT(bp);
  8929. /* Zero primary MAC configuration */
  8930. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8931. if (BP_NOMCP(bp)) {
  8932. BNX2X_ERROR("warning: random MAC workaround active\n");
  8933. eth_hw_addr_random(bp->dev);
  8934. } else if (IS_MF(bp)) {
  8935. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8936. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8937. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8938. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8939. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8940. if (CNIC_SUPPORT(bp))
  8941. bnx2x_get_cnic_mac_hwinfo(bp);
  8942. } else {
  8943. /* in SF read MACs from port configuration */
  8944. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8945. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8946. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8947. if (CNIC_SUPPORT(bp))
  8948. bnx2x_get_cnic_mac_hwinfo(bp);
  8949. }
  8950. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8951. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8952. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8953. dev_err(&bp->pdev->dev,
  8954. "bad Ethernet MAC address configuration: %pM\n"
  8955. "change it manually before bringing up the appropriate network interface\n",
  8956. bp->dev->dev_addr);
  8957. }
  8958. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  8959. {
  8960. int tmp;
  8961. u32 cfg;
  8962. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  8963. /* Take function: tmp = func */
  8964. tmp = BP_ABS_FUNC(bp);
  8965. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  8966. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  8967. } else {
  8968. /* Take port: tmp = port */
  8969. tmp = BP_PORT(bp);
  8970. cfg = SHMEM_RD(bp,
  8971. dev_info.port_hw_config[tmp].generic_features);
  8972. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  8973. }
  8974. return cfg;
  8975. }
  8976. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  8977. {
  8978. int /*abs*/func = BP_ABS_FUNC(bp);
  8979. int vn;
  8980. u32 val = 0;
  8981. int rc = 0;
  8982. bnx2x_get_common_hwinfo(bp);
  8983. /*
  8984. * initialize IGU parameters
  8985. */
  8986. if (CHIP_IS_E1x(bp)) {
  8987. bp->common.int_block = INT_BLOCK_HC;
  8988. bp->igu_dsb_id = DEF_SB_IGU_ID;
  8989. bp->igu_base_sb = 0;
  8990. } else {
  8991. bp->common.int_block = INT_BLOCK_IGU;
  8992. /* do not allow device reset during IGU info preocessing */
  8993. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8994. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  8995. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8996. int tout = 5000;
  8997. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  8998. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  8999. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9000. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9001. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9002. tout--;
  9003. usleep_range(1000, 1000);
  9004. }
  9005. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9006. dev_err(&bp->pdev->dev,
  9007. "FORCING Normal Mode failed!!!\n");
  9008. bnx2x_release_hw_lock(bp,
  9009. HW_LOCK_RESOURCE_RESET);
  9010. return -EPERM;
  9011. }
  9012. }
  9013. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9014. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9015. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9016. } else
  9017. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9018. rc = bnx2x_get_igu_cam_info(bp);
  9019. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9020. if (rc)
  9021. return rc;
  9022. }
  9023. /*
  9024. * set base FW non-default (fast path) status block id, this value is
  9025. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9026. * determine the id used by the FW.
  9027. */
  9028. if (CHIP_IS_E1x(bp))
  9029. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9030. else /*
  9031. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9032. * the same queue are indicated on the same IGU SB). So we prefer
  9033. * FW and IGU SBs to be the same value.
  9034. */
  9035. bp->base_fw_ndsb = bp->igu_base_sb;
  9036. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9037. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9038. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9039. /*
  9040. * Initialize MF configuration
  9041. */
  9042. bp->mf_ov = 0;
  9043. bp->mf_mode = 0;
  9044. vn = BP_VN(bp);
  9045. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9046. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9047. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9048. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9049. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9050. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9051. else
  9052. bp->common.mf_cfg_base = bp->common.shmem_base +
  9053. offsetof(struct shmem_region, func_mb) +
  9054. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9055. /*
  9056. * get mf configuration:
  9057. * 1. existence of MF configuration
  9058. * 2. MAC address must be legal (check only upper bytes)
  9059. * for Switch-Independent mode;
  9060. * OVLAN must be legal for Switch-Dependent mode
  9061. * 3. SF_MODE configures specific MF mode
  9062. */
  9063. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9064. /* get mf configuration */
  9065. val = SHMEM_RD(bp,
  9066. dev_info.shared_feature_config.config);
  9067. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9068. switch (val) {
  9069. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9070. val = MF_CFG_RD(bp, func_mf_config[func].
  9071. mac_upper);
  9072. /* check for legal mac (upper bytes)*/
  9073. if (val != 0xffff) {
  9074. bp->mf_mode = MULTI_FUNCTION_SI;
  9075. bp->mf_config[vn] = MF_CFG_RD(bp,
  9076. func_mf_config[func].config);
  9077. } else
  9078. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9079. break;
  9080. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9081. if ((!CHIP_IS_E1x(bp)) &&
  9082. (MF_CFG_RD(bp, func_mf_config[func].
  9083. mac_upper) != 0xffff) &&
  9084. (SHMEM2_HAS(bp,
  9085. afex_driver_support))) {
  9086. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9087. bp->mf_config[vn] = MF_CFG_RD(bp,
  9088. func_mf_config[func].config);
  9089. } else {
  9090. BNX2X_DEV_INFO("can not configure afex mode\n");
  9091. }
  9092. break;
  9093. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9094. /* get OV configuration */
  9095. val = MF_CFG_RD(bp,
  9096. func_mf_config[FUNC_0].e1hov_tag);
  9097. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9098. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9099. bp->mf_mode = MULTI_FUNCTION_SD;
  9100. bp->mf_config[vn] = MF_CFG_RD(bp,
  9101. func_mf_config[func].config);
  9102. } else
  9103. BNX2X_DEV_INFO("illegal OV for SD\n");
  9104. break;
  9105. default:
  9106. /* Unknown configuration: reset mf_config */
  9107. bp->mf_config[vn] = 0;
  9108. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9109. }
  9110. }
  9111. BNX2X_DEV_INFO("%s function mode\n",
  9112. IS_MF(bp) ? "multi" : "single");
  9113. switch (bp->mf_mode) {
  9114. case MULTI_FUNCTION_SD:
  9115. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9116. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9117. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9118. bp->mf_ov = val;
  9119. bp->path_has_ovlan = true;
  9120. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9121. func, bp->mf_ov, bp->mf_ov);
  9122. } else {
  9123. dev_err(&bp->pdev->dev,
  9124. "No valid MF OV for func %d, aborting\n",
  9125. func);
  9126. return -EPERM;
  9127. }
  9128. break;
  9129. case MULTI_FUNCTION_AFEX:
  9130. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9131. break;
  9132. case MULTI_FUNCTION_SI:
  9133. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9134. func);
  9135. break;
  9136. default:
  9137. if (vn) {
  9138. dev_err(&bp->pdev->dev,
  9139. "VN %d is in a single function mode, aborting\n",
  9140. vn);
  9141. return -EPERM;
  9142. }
  9143. break;
  9144. }
  9145. /* check if other port on the path needs ovlan:
  9146. * Since MF configuration is shared between ports
  9147. * Possible mixed modes are only
  9148. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9149. */
  9150. if (CHIP_MODE_IS_4_PORT(bp) &&
  9151. !bp->path_has_ovlan &&
  9152. !IS_MF(bp) &&
  9153. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9154. u8 other_port = !BP_PORT(bp);
  9155. u8 other_func = BP_PATH(bp) + 2*other_port;
  9156. val = MF_CFG_RD(bp,
  9157. func_mf_config[other_func].e1hov_tag);
  9158. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9159. bp->path_has_ovlan = true;
  9160. }
  9161. }
  9162. /* adjust igu_sb_cnt to MF for E1x */
  9163. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9164. bp->igu_sb_cnt /= E1HVN_MAX;
  9165. /* port info */
  9166. bnx2x_get_port_hwinfo(bp);
  9167. /* Get MAC addresses */
  9168. bnx2x_get_mac_hwinfo(bp);
  9169. bnx2x_get_cnic_info(bp);
  9170. return rc;
  9171. }
  9172. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9173. {
  9174. int cnt, i, block_end, rodi;
  9175. char vpd_start[BNX2X_VPD_LEN+1];
  9176. char str_id_reg[VENDOR_ID_LEN+1];
  9177. char str_id_cap[VENDOR_ID_LEN+1];
  9178. char *vpd_data;
  9179. char *vpd_extended_data = NULL;
  9180. u8 len;
  9181. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9182. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9183. if (cnt < BNX2X_VPD_LEN)
  9184. goto out_not_found;
  9185. /* VPD RO tag should be first tag after identifier string, hence
  9186. * we should be able to find it in first BNX2X_VPD_LEN chars
  9187. */
  9188. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9189. PCI_VPD_LRDT_RO_DATA);
  9190. if (i < 0)
  9191. goto out_not_found;
  9192. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9193. pci_vpd_lrdt_size(&vpd_start[i]);
  9194. i += PCI_VPD_LRDT_TAG_SIZE;
  9195. if (block_end > BNX2X_VPD_LEN) {
  9196. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9197. if (vpd_extended_data == NULL)
  9198. goto out_not_found;
  9199. /* read rest of vpd image into vpd_extended_data */
  9200. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9201. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9202. block_end - BNX2X_VPD_LEN,
  9203. vpd_extended_data + BNX2X_VPD_LEN);
  9204. if (cnt < (block_end - BNX2X_VPD_LEN))
  9205. goto out_not_found;
  9206. vpd_data = vpd_extended_data;
  9207. } else
  9208. vpd_data = vpd_start;
  9209. /* now vpd_data holds full vpd content in both cases */
  9210. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9211. PCI_VPD_RO_KEYWORD_MFR_ID);
  9212. if (rodi < 0)
  9213. goto out_not_found;
  9214. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9215. if (len != VENDOR_ID_LEN)
  9216. goto out_not_found;
  9217. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9218. /* vendor specific info */
  9219. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9220. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9221. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9222. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9223. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9224. PCI_VPD_RO_KEYWORD_VENDOR0);
  9225. if (rodi >= 0) {
  9226. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9227. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9228. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9229. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9230. bp->fw_ver[len] = ' ';
  9231. }
  9232. }
  9233. kfree(vpd_extended_data);
  9234. return;
  9235. }
  9236. out_not_found:
  9237. kfree(vpd_extended_data);
  9238. return;
  9239. }
  9240. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9241. {
  9242. u32 flags = 0;
  9243. if (CHIP_REV_IS_FPGA(bp))
  9244. SET_FLAGS(flags, MODE_FPGA);
  9245. else if (CHIP_REV_IS_EMUL(bp))
  9246. SET_FLAGS(flags, MODE_EMUL);
  9247. else
  9248. SET_FLAGS(flags, MODE_ASIC);
  9249. if (CHIP_MODE_IS_4_PORT(bp))
  9250. SET_FLAGS(flags, MODE_PORT4);
  9251. else
  9252. SET_FLAGS(flags, MODE_PORT2);
  9253. if (CHIP_IS_E2(bp))
  9254. SET_FLAGS(flags, MODE_E2);
  9255. else if (CHIP_IS_E3(bp)) {
  9256. SET_FLAGS(flags, MODE_E3);
  9257. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9258. SET_FLAGS(flags, MODE_E3_A0);
  9259. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9260. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9261. }
  9262. if (IS_MF(bp)) {
  9263. SET_FLAGS(flags, MODE_MF);
  9264. switch (bp->mf_mode) {
  9265. case MULTI_FUNCTION_SD:
  9266. SET_FLAGS(flags, MODE_MF_SD);
  9267. break;
  9268. case MULTI_FUNCTION_SI:
  9269. SET_FLAGS(flags, MODE_MF_SI);
  9270. break;
  9271. case MULTI_FUNCTION_AFEX:
  9272. SET_FLAGS(flags, MODE_MF_AFEX);
  9273. break;
  9274. }
  9275. } else
  9276. SET_FLAGS(flags, MODE_SF);
  9277. #if defined(__LITTLE_ENDIAN)
  9278. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9279. #else /*(__BIG_ENDIAN)*/
  9280. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9281. #endif
  9282. INIT_MODE_FLAGS(bp) = flags;
  9283. }
  9284. static int bnx2x_init_bp(struct bnx2x *bp)
  9285. {
  9286. int func;
  9287. int rc;
  9288. mutex_init(&bp->port.phy_mutex);
  9289. mutex_init(&bp->fw_mb_mutex);
  9290. spin_lock_init(&bp->stats_lock);
  9291. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9292. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9293. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9294. rc = bnx2x_get_hwinfo(bp);
  9295. if (rc)
  9296. return rc;
  9297. bnx2x_set_modes_bitmap(bp);
  9298. rc = bnx2x_alloc_mem_bp(bp);
  9299. if (rc)
  9300. return rc;
  9301. bnx2x_read_fwinfo(bp);
  9302. func = BP_FUNC(bp);
  9303. /* need to reset chip if undi was active */
  9304. if (!BP_NOMCP(bp)) {
  9305. /* init fw_seq */
  9306. bp->fw_seq =
  9307. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9308. DRV_MSG_SEQ_NUMBER_MASK;
  9309. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9310. bnx2x_prev_unload(bp);
  9311. }
  9312. if (CHIP_REV_IS_FPGA(bp))
  9313. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9314. if (BP_NOMCP(bp) && (func == 0))
  9315. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9316. bp->disable_tpa = disable_tpa;
  9317. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9318. /* Set TPA flags */
  9319. if (bp->disable_tpa) {
  9320. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9321. bp->dev->features &= ~NETIF_F_LRO;
  9322. } else {
  9323. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9324. bp->dev->features |= NETIF_F_LRO;
  9325. }
  9326. if (CHIP_IS_E1(bp))
  9327. bp->dropless_fc = 0;
  9328. else
  9329. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9330. bp->mrrs = mrrs;
  9331. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9332. /* make sure that the numbers are in the right granularity */
  9333. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9334. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9335. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9336. init_timer(&bp->timer);
  9337. bp->timer.expires = jiffies + bp->current_interval;
  9338. bp->timer.data = (unsigned long) bp;
  9339. bp->timer.function = bnx2x_timer;
  9340. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9341. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9342. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9343. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9344. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9345. bnx2x_dcbx_init_params(bp);
  9346. } else {
  9347. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9348. }
  9349. if (CHIP_IS_E1x(bp))
  9350. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9351. else
  9352. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9353. /* multiple tx priority */
  9354. if (CHIP_IS_E1x(bp))
  9355. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9356. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9357. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9358. if (CHIP_IS_E3B0(bp))
  9359. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9360. /* We need at least one default status block for slow-path events,
  9361. * second status block for the L2 queue, and a third status block for
  9362. * CNIC if supproted.
  9363. */
  9364. if (CNIC_SUPPORT(bp))
  9365. bp->min_msix_vec_cnt = 3;
  9366. else
  9367. bp->min_msix_vec_cnt = 2;
  9368. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9369. return rc;
  9370. }
  9371. /****************************************************************************
  9372. * General service functions
  9373. ****************************************************************************/
  9374. /*
  9375. * net_device service functions
  9376. */
  9377. /* called with rtnl_lock */
  9378. static int bnx2x_open(struct net_device *dev)
  9379. {
  9380. struct bnx2x *bp = netdev_priv(dev);
  9381. bool global = false;
  9382. int other_engine = BP_PATH(bp) ? 0 : 1;
  9383. bool other_load_status, load_status;
  9384. bp->stats_init = true;
  9385. netif_carrier_off(dev);
  9386. bnx2x_set_power_state(bp, PCI_D0);
  9387. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9388. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9389. /*
  9390. * If parity had happen during the unload, then attentions
  9391. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9392. * want the first function loaded on the current engine to
  9393. * complete the recovery.
  9394. */
  9395. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9396. bnx2x_chk_parity_attn(bp, &global, true))
  9397. do {
  9398. /*
  9399. * If there are attentions and they are in a global
  9400. * blocks, set the GLOBAL_RESET bit regardless whether
  9401. * it will be this function that will complete the
  9402. * recovery or not.
  9403. */
  9404. if (global)
  9405. bnx2x_set_reset_global(bp);
  9406. /*
  9407. * Only the first function on the current engine should
  9408. * try to recover in open. In case of attentions in
  9409. * global blocks only the first in the chip should try
  9410. * to recover.
  9411. */
  9412. if ((!load_status &&
  9413. (!global || !other_load_status)) &&
  9414. bnx2x_trylock_leader_lock(bp) &&
  9415. !bnx2x_leader_reset(bp)) {
  9416. netdev_info(bp->dev, "Recovered in open\n");
  9417. break;
  9418. }
  9419. /* recovery has failed... */
  9420. bnx2x_set_power_state(bp, PCI_D3hot);
  9421. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9422. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9423. "If you still see this message after a few retries then power cycle is required.\n");
  9424. return -EAGAIN;
  9425. } while (0);
  9426. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9427. return bnx2x_nic_load(bp, LOAD_OPEN);
  9428. }
  9429. /* called with rtnl_lock */
  9430. static int bnx2x_close(struct net_device *dev)
  9431. {
  9432. struct bnx2x *bp = netdev_priv(dev);
  9433. /* Unload the driver, release IRQs */
  9434. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9435. /* Power off */
  9436. bnx2x_set_power_state(bp, PCI_D3hot);
  9437. return 0;
  9438. }
  9439. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9440. struct bnx2x_mcast_ramrod_params *p)
  9441. {
  9442. int mc_count = netdev_mc_count(bp->dev);
  9443. struct bnx2x_mcast_list_elem *mc_mac =
  9444. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9445. struct netdev_hw_addr *ha;
  9446. if (!mc_mac)
  9447. return -ENOMEM;
  9448. INIT_LIST_HEAD(&p->mcast_list);
  9449. netdev_for_each_mc_addr(ha, bp->dev) {
  9450. mc_mac->mac = bnx2x_mc_addr(ha);
  9451. list_add_tail(&mc_mac->link, &p->mcast_list);
  9452. mc_mac++;
  9453. }
  9454. p->mcast_list_len = mc_count;
  9455. return 0;
  9456. }
  9457. static void bnx2x_free_mcast_macs_list(
  9458. struct bnx2x_mcast_ramrod_params *p)
  9459. {
  9460. struct bnx2x_mcast_list_elem *mc_mac =
  9461. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9462. link);
  9463. WARN_ON(!mc_mac);
  9464. kfree(mc_mac);
  9465. }
  9466. /**
  9467. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9468. *
  9469. * @bp: driver handle
  9470. *
  9471. * We will use zero (0) as a MAC type for these MACs.
  9472. */
  9473. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9474. {
  9475. int rc;
  9476. struct net_device *dev = bp->dev;
  9477. struct netdev_hw_addr *ha;
  9478. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9479. unsigned long ramrod_flags = 0;
  9480. /* First schedule a cleanup up of old configuration */
  9481. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9482. if (rc < 0) {
  9483. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9484. return rc;
  9485. }
  9486. netdev_for_each_uc_addr(ha, dev) {
  9487. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9488. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9489. if (rc == -EEXIST) {
  9490. DP(BNX2X_MSG_SP,
  9491. "Failed to schedule ADD operations: %d\n", rc);
  9492. /* do not treat adding same MAC as error */
  9493. rc = 0;
  9494. } else if (rc < 0) {
  9495. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9496. rc);
  9497. return rc;
  9498. }
  9499. }
  9500. /* Execute the pending commands */
  9501. __set_bit(RAMROD_CONT, &ramrod_flags);
  9502. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9503. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9504. }
  9505. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9506. {
  9507. struct net_device *dev = bp->dev;
  9508. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9509. int rc = 0;
  9510. rparam.mcast_obj = &bp->mcast_obj;
  9511. /* first, clear all configured multicast MACs */
  9512. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9513. if (rc < 0) {
  9514. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9515. return rc;
  9516. }
  9517. /* then, configure a new MACs list */
  9518. if (netdev_mc_count(dev)) {
  9519. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9520. if (rc) {
  9521. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9522. rc);
  9523. return rc;
  9524. }
  9525. /* Now add the new MACs */
  9526. rc = bnx2x_config_mcast(bp, &rparam,
  9527. BNX2X_MCAST_CMD_ADD);
  9528. if (rc < 0)
  9529. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9530. rc);
  9531. bnx2x_free_mcast_macs_list(&rparam);
  9532. }
  9533. return rc;
  9534. }
  9535. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9536. void bnx2x_set_rx_mode(struct net_device *dev)
  9537. {
  9538. struct bnx2x *bp = netdev_priv(dev);
  9539. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9540. if (bp->state != BNX2X_STATE_OPEN) {
  9541. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9542. return;
  9543. }
  9544. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9545. if (dev->flags & IFF_PROMISC)
  9546. rx_mode = BNX2X_RX_MODE_PROMISC;
  9547. else if ((dev->flags & IFF_ALLMULTI) ||
  9548. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9549. CHIP_IS_E1(bp)))
  9550. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9551. else {
  9552. /* some multicasts */
  9553. if (bnx2x_set_mc_list(bp) < 0)
  9554. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9555. if (bnx2x_set_uc_list(bp) < 0)
  9556. rx_mode = BNX2X_RX_MODE_PROMISC;
  9557. }
  9558. bp->rx_mode = rx_mode;
  9559. /* handle ISCSI SD mode */
  9560. if (IS_MF_ISCSI_SD(bp))
  9561. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9562. /* Schedule the rx_mode command */
  9563. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9564. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9565. return;
  9566. }
  9567. bnx2x_set_storm_rx_mode(bp);
  9568. }
  9569. /* called with rtnl_lock */
  9570. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9571. int devad, u16 addr)
  9572. {
  9573. struct bnx2x *bp = netdev_priv(netdev);
  9574. u16 value;
  9575. int rc;
  9576. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9577. prtad, devad, addr);
  9578. /* The HW expects different devad if CL22 is used */
  9579. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9580. bnx2x_acquire_phy_lock(bp);
  9581. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9582. bnx2x_release_phy_lock(bp);
  9583. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9584. if (!rc)
  9585. rc = value;
  9586. return rc;
  9587. }
  9588. /* called with rtnl_lock */
  9589. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9590. u16 addr, u16 value)
  9591. {
  9592. struct bnx2x *bp = netdev_priv(netdev);
  9593. int rc;
  9594. DP(NETIF_MSG_LINK,
  9595. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9596. prtad, devad, addr, value);
  9597. /* The HW expects different devad if CL22 is used */
  9598. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9599. bnx2x_acquire_phy_lock(bp);
  9600. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9601. bnx2x_release_phy_lock(bp);
  9602. return rc;
  9603. }
  9604. /* called with rtnl_lock */
  9605. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9606. {
  9607. struct bnx2x *bp = netdev_priv(dev);
  9608. struct mii_ioctl_data *mdio = if_mii(ifr);
  9609. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9610. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9611. if (!netif_running(dev))
  9612. return -EAGAIN;
  9613. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9614. }
  9615. #ifdef CONFIG_NET_POLL_CONTROLLER
  9616. static void poll_bnx2x(struct net_device *dev)
  9617. {
  9618. struct bnx2x *bp = netdev_priv(dev);
  9619. int i;
  9620. for_each_eth_queue(bp, i) {
  9621. struct bnx2x_fastpath *fp = &bp->fp[i];
  9622. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9623. }
  9624. }
  9625. #endif
  9626. static int bnx2x_validate_addr(struct net_device *dev)
  9627. {
  9628. struct bnx2x *bp = netdev_priv(dev);
  9629. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9630. BNX2X_ERR("Non-valid Ethernet address\n");
  9631. return -EADDRNOTAVAIL;
  9632. }
  9633. return 0;
  9634. }
  9635. static const struct net_device_ops bnx2x_netdev_ops = {
  9636. .ndo_open = bnx2x_open,
  9637. .ndo_stop = bnx2x_close,
  9638. .ndo_start_xmit = bnx2x_start_xmit,
  9639. .ndo_select_queue = bnx2x_select_queue,
  9640. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9641. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9642. .ndo_validate_addr = bnx2x_validate_addr,
  9643. .ndo_do_ioctl = bnx2x_ioctl,
  9644. .ndo_change_mtu = bnx2x_change_mtu,
  9645. .ndo_fix_features = bnx2x_fix_features,
  9646. .ndo_set_features = bnx2x_set_features,
  9647. .ndo_tx_timeout = bnx2x_tx_timeout,
  9648. #ifdef CONFIG_NET_POLL_CONTROLLER
  9649. .ndo_poll_controller = poll_bnx2x,
  9650. #endif
  9651. .ndo_setup_tc = bnx2x_setup_tc,
  9652. #ifdef NETDEV_FCOE_WWNN
  9653. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9654. #endif
  9655. };
  9656. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9657. {
  9658. struct device *dev = &bp->pdev->dev;
  9659. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9660. bp->flags |= USING_DAC_FLAG;
  9661. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9662. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9663. return -EIO;
  9664. }
  9665. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9666. dev_err(dev, "System does not support DMA, aborting\n");
  9667. return -EIO;
  9668. }
  9669. return 0;
  9670. }
  9671. static int bnx2x_init_dev(struct pci_dev *pdev, struct net_device *dev,
  9672. unsigned long board_type)
  9673. {
  9674. struct bnx2x *bp;
  9675. int rc;
  9676. u32 pci_cfg_dword;
  9677. bool chip_is_e1x = (board_type == BCM57710 ||
  9678. board_type == BCM57711 ||
  9679. board_type == BCM57711E);
  9680. SET_NETDEV_DEV(dev, &pdev->dev);
  9681. bp = netdev_priv(dev);
  9682. bp->dev = dev;
  9683. bp->pdev = pdev;
  9684. bp->flags = 0;
  9685. rc = pci_enable_device(pdev);
  9686. if (rc) {
  9687. dev_err(&bp->pdev->dev,
  9688. "Cannot enable PCI device, aborting\n");
  9689. goto err_out;
  9690. }
  9691. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9692. dev_err(&bp->pdev->dev,
  9693. "Cannot find PCI device base address, aborting\n");
  9694. rc = -ENODEV;
  9695. goto err_out_disable;
  9696. }
  9697. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9698. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  9699. " base address, aborting\n");
  9700. rc = -ENODEV;
  9701. goto err_out_disable;
  9702. }
  9703. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9704. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9705. PCICFG_REVESION_ID_ERROR_VAL) {
  9706. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9707. rc = -ENODEV;
  9708. goto err_out_disable;
  9709. }
  9710. if (atomic_read(&pdev->enable_cnt) == 1) {
  9711. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9712. if (rc) {
  9713. dev_err(&bp->pdev->dev,
  9714. "Cannot obtain PCI resources, aborting\n");
  9715. goto err_out_disable;
  9716. }
  9717. pci_set_master(pdev);
  9718. pci_save_state(pdev);
  9719. }
  9720. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9721. if (bp->pm_cap == 0) {
  9722. dev_err(&bp->pdev->dev,
  9723. "Cannot find power management capability, aborting\n");
  9724. rc = -EIO;
  9725. goto err_out_release;
  9726. }
  9727. if (!pci_is_pcie(pdev)) {
  9728. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9729. rc = -EIO;
  9730. goto err_out_release;
  9731. }
  9732. rc = bnx2x_set_coherency_mask(bp);
  9733. if (rc)
  9734. goto err_out_release;
  9735. dev->mem_start = pci_resource_start(pdev, 0);
  9736. dev->base_addr = dev->mem_start;
  9737. dev->mem_end = pci_resource_end(pdev, 0);
  9738. dev->irq = pdev->irq;
  9739. bp->regview = pci_ioremap_bar(pdev, 0);
  9740. if (!bp->regview) {
  9741. dev_err(&bp->pdev->dev,
  9742. "Cannot map register space, aborting\n");
  9743. rc = -ENOMEM;
  9744. goto err_out_release;
  9745. }
  9746. /* In E1/E1H use pci device function given by kernel.
  9747. * In E2/E3 read physical function from ME register since these chips
  9748. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9749. * (depending on hypervisor).
  9750. */
  9751. if (chip_is_e1x)
  9752. bp->pf_num = PCI_FUNC(pdev->devfn);
  9753. else {/* chip is E2/3*/
  9754. pci_read_config_dword(bp->pdev,
  9755. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9756. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9757. ME_REG_ABS_PF_NUM_SHIFT);
  9758. }
  9759. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9760. bnx2x_set_power_state(bp, PCI_D0);
  9761. /* clean indirect addresses */
  9762. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9763. PCICFG_VENDOR_ID_OFFSET);
  9764. /*
  9765. * Clean the following indirect addresses for all functions since it
  9766. * is not used by the driver.
  9767. */
  9768. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9769. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9770. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9771. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9772. if (chip_is_e1x) {
  9773. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9774. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9775. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9776. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9777. }
  9778. /*
  9779. * Enable internal target-read (in case we are probed after PF FLR).
  9780. * Must be done prior to any BAR read access. Only for 57712 and up
  9781. */
  9782. if (!chip_is_e1x)
  9783. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9784. dev->watchdog_timeo = TX_TIMEOUT;
  9785. dev->netdev_ops = &bnx2x_netdev_ops;
  9786. bnx2x_set_ethtool_ops(dev);
  9787. dev->priv_flags |= IFF_UNICAST_FLT;
  9788. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9789. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9790. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9791. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9792. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9793. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9794. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9795. if (bp->flags & USING_DAC_FLAG)
  9796. dev->features |= NETIF_F_HIGHDMA;
  9797. /* Add Loopback capability to the device */
  9798. dev->hw_features |= NETIF_F_LOOPBACK;
  9799. #ifdef BCM_DCBNL
  9800. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  9801. #endif
  9802. /* get_port_hwinfo() will set prtad and mmds properly */
  9803. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9804. bp->mdio.mmds = 0;
  9805. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9806. bp->mdio.dev = dev;
  9807. bp->mdio.mdio_read = bnx2x_mdio_read;
  9808. bp->mdio.mdio_write = bnx2x_mdio_write;
  9809. return 0;
  9810. err_out_release:
  9811. if (atomic_read(&pdev->enable_cnt) == 1)
  9812. pci_release_regions(pdev);
  9813. err_out_disable:
  9814. pci_disable_device(pdev);
  9815. pci_set_drvdata(pdev, NULL);
  9816. err_out:
  9817. return rc;
  9818. }
  9819. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  9820. {
  9821. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9822. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9823. /* return value of 1=2.5GHz 2=5GHz */
  9824. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9825. }
  9826. static int bnx2x_check_firmware(struct bnx2x *bp)
  9827. {
  9828. const struct firmware *firmware = bp->firmware;
  9829. struct bnx2x_fw_file_hdr *fw_hdr;
  9830. struct bnx2x_fw_file_section *sections;
  9831. u32 offset, len, num_ops;
  9832. u16 *ops_offsets;
  9833. int i;
  9834. const u8 *fw_ver;
  9835. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  9836. BNX2X_ERR("Wrong FW size\n");
  9837. return -EINVAL;
  9838. }
  9839. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9840. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9841. /* Make sure none of the offsets and sizes make us read beyond
  9842. * the end of the firmware data */
  9843. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9844. offset = be32_to_cpu(sections[i].offset);
  9845. len = be32_to_cpu(sections[i].len);
  9846. if (offset + len > firmware->size) {
  9847. BNX2X_ERR("Section %d length is out of bounds\n", i);
  9848. return -EINVAL;
  9849. }
  9850. }
  9851. /* Likewise for the init_ops offsets */
  9852. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9853. ops_offsets = (u16 *)(firmware->data + offset);
  9854. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9855. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9856. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9857. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  9858. return -EINVAL;
  9859. }
  9860. }
  9861. /* Check FW version */
  9862. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9863. fw_ver = firmware->data + offset;
  9864. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9865. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9866. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9867. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9868. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  9869. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  9870. BCM_5710_FW_MAJOR_VERSION,
  9871. BCM_5710_FW_MINOR_VERSION,
  9872. BCM_5710_FW_REVISION_VERSION,
  9873. BCM_5710_FW_ENGINEERING_VERSION);
  9874. return -EINVAL;
  9875. }
  9876. return 0;
  9877. }
  9878. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9879. {
  9880. const __be32 *source = (const __be32 *)_source;
  9881. u32 *target = (u32 *)_target;
  9882. u32 i;
  9883. for (i = 0; i < n/4; i++)
  9884. target[i] = be32_to_cpu(source[i]);
  9885. }
  9886. /*
  9887. Ops array is stored in the following format:
  9888. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9889. */
  9890. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9891. {
  9892. const __be32 *source = (const __be32 *)_source;
  9893. struct raw_op *target = (struct raw_op *)_target;
  9894. u32 i, j, tmp;
  9895. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9896. tmp = be32_to_cpu(source[j]);
  9897. target[i].op = (tmp >> 24) & 0xff;
  9898. target[i].offset = tmp & 0xffffff;
  9899. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9900. }
  9901. }
  9902. /* IRO array is stored in the following format:
  9903. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9904. */
  9905. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9906. {
  9907. const __be32 *source = (const __be32 *)_source;
  9908. struct iro *target = (struct iro *)_target;
  9909. u32 i, j, tmp;
  9910. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9911. target[i].base = be32_to_cpu(source[j]);
  9912. j++;
  9913. tmp = be32_to_cpu(source[j]);
  9914. target[i].m1 = (tmp >> 16) & 0xffff;
  9915. target[i].m2 = tmp & 0xffff;
  9916. j++;
  9917. tmp = be32_to_cpu(source[j]);
  9918. target[i].m3 = (tmp >> 16) & 0xffff;
  9919. target[i].size = tmp & 0xffff;
  9920. j++;
  9921. }
  9922. }
  9923. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9924. {
  9925. const __be16 *source = (const __be16 *)_source;
  9926. u16 *target = (u16 *)_target;
  9927. u32 i;
  9928. for (i = 0; i < n/2; i++)
  9929. target[i] = be16_to_cpu(source[i]);
  9930. }
  9931. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9932. do { \
  9933. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9934. bp->arr = kmalloc(len, GFP_KERNEL); \
  9935. if (!bp->arr) \
  9936. goto lbl; \
  9937. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9938. (u8 *)bp->arr, len); \
  9939. } while (0)
  9940. static int bnx2x_init_firmware(struct bnx2x *bp)
  9941. {
  9942. const char *fw_file_name;
  9943. struct bnx2x_fw_file_hdr *fw_hdr;
  9944. int rc;
  9945. if (bp->firmware)
  9946. return 0;
  9947. if (CHIP_IS_E1(bp))
  9948. fw_file_name = FW_FILE_NAME_E1;
  9949. else if (CHIP_IS_E1H(bp))
  9950. fw_file_name = FW_FILE_NAME_E1H;
  9951. else if (!CHIP_IS_E1x(bp))
  9952. fw_file_name = FW_FILE_NAME_E2;
  9953. else {
  9954. BNX2X_ERR("Unsupported chip revision\n");
  9955. return -EINVAL;
  9956. }
  9957. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9958. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9959. if (rc) {
  9960. BNX2X_ERR("Can't load firmware file %s\n",
  9961. fw_file_name);
  9962. goto request_firmware_exit;
  9963. }
  9964. rc = bnx2x_check_firmware(bp);
  9965. if (rc) {
  9966. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9967. goto request_firmware_exit;
  9968. }
  9969. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  9970. /* Initialize the pointers to the init arrays */
  9971. /* Blob */
  9972. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  9973. /* Opcodes */
  9974. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  9975. /* Offsets */
  9976. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  9977. be16_to_cpu_n);
  9978. /* STORMs firmware */
  9979. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9980. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  9981. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  9982. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  9983. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9984. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  9985. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  9986. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  9987. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9988. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  9989. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  9990. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  9991. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9992. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  9993. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  9994. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  9995. /* IRO */
  9996. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  9997. return 0;
  9998. iro_alloc_err:
  9999. kfree(bp->init_ops_offsets);
  10000. init_offsets_alloc_err:
  10001. kfree(bp->init_ops);
  10002. init_ops_alloc_err:
  10003. kfree(bp->init_data);
  10004. request_firmware_exit:
  10005. release_firmware(bp->firmware);
  10006. bp->firmware = NULL;
  10007. return rc;
  10008. }
  10009. static void bnx2x_release_firmware(struct bnx2x *bp)
  10010. {
  10011. kfree(bp->init_ops_offsets);
  10012. kfree(bp->init_ops);
  10013. kfree(bp->init_data);
  10014. release_firmware(bp->firmware);
  10015. bp->firmware = NULL;
  10016. }
  10017. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10018. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10019. .init_hw_cmn = bnx2x_init_hw_common,
  10020. .init_hw_port = bnx2x_init_hw_port,
  10021. .init_hw_func = bnx2x_init_hw_func,
  10022. .reset_hw_cmn = bnx2x_reset_common,
  10023. .reset_hw_port = bnx2x_reset_port,
  10024. .reset_hw_func = bnx2x_reset_func,
  10025. .gunzip_init = bnx2x_gunzip_init,
  10026. .gunzip_end = bnx2x_gunzip_end,
  10027. .init_fw = bnx2x_init_firmware,
  10028. .release_fw = bnx2x_release_firmware,
  10029. };
  10030. void bnx2x__init_func_obj(struct bnx2x *bp)
  10031. {
  10032. /* Prepare DMAE related driver resources */
  10033. bnx2x_setup_dmae(bp);
  10034. bnx2x_init_func_obj(bp, &bp->func_obj,
  10035. bnx2x_sp(bp, func_rdata),
  10036. bnx2x_sp_mapping(bp, func_rdata),
  10037. bnx2x_sp(bp, func_afex_rdata),
  10038. bnx2x_sp_mapping(bp, func_afex_rdata),
  10039. &bnx2x_func_sp_drv);
  10040. }
  10041. /* must be called after sriov-enable */
  10042. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10043. {
  10044. int cid_count = BNX2X_L2_MAX_CID(bp);
  10045. if (CNIC_SUPPORT(bp))
  10046. cid_count += CNIC_CID_MAX;
  10047. return roundup(cid_count, QM_CID_ROUND);
  10048. }
  10049. /**
  10050. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10051. *
  10052. * @dev: pci device
  10053. *
  10054. */
  10055. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10056. int cnic_cnt)
  10057. {
  10058. int pos;
  10059. u16 control;
  10060. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10061. /*
  10062. * If MSI-X is not supported - return number of SBs needed to support
  10063. * one fast path queue: one FP queue + SB for CNIC
  10064. */
  10065. if (!pos)
  10066. return 1 + cnic_cnt;
  10067. /*
  10068. * The value in the PCI configuration space is the index of the last
  10069. * entry, namely one less than the actual size of the table, which is
  10070. * exactly what we want to return from this function: number of all SBs
  10071. * without the default SB.
  10072. */
  10073. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10074. return control & PCI_MSIX_FLAGS_QSIZE;
  10075. }
  10076. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *);
  10077. static int bnx2x_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  10078. {
  10079. struct net_device *dev = NULL;
  10080. struct bnx2x *bp;
  10081. int pcie_width, pcie_speed;
  10082. int rc, max_non_def_sbs;
  10083. int rx_count, tx_count, rss_count, doorbell_size;
  10084. int cnic_cnt;
  10085. /*
  10086. * An estimated maximum supported CoS number according to the chip
  10087. * version.
  10088. * We will try to roughly estimate the maximum number of CoSes this chip
  10089. * may support in order to minimize the memory allocated for Tx
  10090. * netdev_queue's. This number will be accurately calculated during the
  10091. * initialization of bp->max_cos based on the chip versions AND chip
  10092. * revision in the bnx2x_init_bp().
  10093. */
  10094. u8 max_cos_est = 0;
  10095. switch (ent->driver_data) {
  10096. case BCM57710:
  10097. case BCM57711:
  10098. case BCM57711E:
  10099. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  10100. break;
  10101. case BCM57712:
  10102. case BCM57712_MF:
  10103. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  10104. break;
  10105. case BCM57800:
  10106. case BCM57800_MF:
  10107. case BCM57810:
  10108. case BCM57810_MF:
  10109. case BCM57840_O:
  10110. case BCM57840_4_10:
  10111. case BCM57840_2_20:
  10112. case BCM57840_MFO:
  10113. case BCM57840_MF:
  10114. case BCM57811:
  10115. case BCM57811_MF:
  10116. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  10117. break;
  10118. default:
  10119. pr_err("Unknown board_type (%ld), aborting\n",
  10120. ent->driver_data);
  10121. return -ENODEV;
  10122. }
  10123. cnic_cnt = 1;
  10124. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  10125. WARN_ON(!max_non_def_sbs);
  10126. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10127. rss_count = max_non_def_sbs - cnic_cnt;
  10128. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10129. rx_count = rss_count + cnic_cnt;
  10130. /*
  10131. * Maximum number of netdev Tx queues:
  10132. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10133. */
  10134. tx_count = rss_count * max_cos_est + cnic_cnt;
  10135. /* dev zeroed in init_etherdev */
  10136. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10137. if (!dev)
  10138. return -ENOMEM;
  10139. bp = netdev_priv(dev);
  10140. bp->igu_sb_cnt = max_non_def_sbs;
  10141. bp->msg_enable = debug;
  10142. bp->cnic_support = cnic_cnt;
  10143. bp->cnic_probe = bnx2x_cnic_probe;
  10144. pci_set_drvdata(pdev, dev);
  10145. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  10146. if (rc < 0) {
  10147. free_netdev(dev);
  10148. return rc;
  10149. }
  10150. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10151. BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
  10152. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10153. tx_count, rx_count);
  10154. rc = bnx2x_init_bp(bp);
  10155. if (rc)
  10156. goto init_one_exit;
  10157. /*
  10158. * Map doorbels here as we need the real value of bp->max_cos which
  10159. * is initialized in bnx2x_init_bp().
  10160. */
  10161. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10162. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10163. dev_err(&bp->pdev->dev,
  10164. "Cannot map doorbells, bar size too small, aborting\n");
  10165. rc = -ENOMEM;
  10166. goto init_one_exit;
  10167. }
  10168. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10169. doorbell_size);
  10170. if (!bp->doorbells) {
  10171. dev_err(&bp->pdev->dev,
  10172. "Cannot map doorbell space, aborting\n");
  10173. rc = -ENOMEM;
  10174. goto init_one_exit;
  10175. }
  10176. /* calc qm_cid_count */
  10177. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10178. /* disable FCOE L2 queue for E1x*/
  10179. if (CHIP_IS_E1x(bp))
  10180. bp->flags |= NO_FCOE_FLAG;
  10181. /* disable FCOE for 57840 device, until FW supports it */
  10182. switch (ent->driver_data) {
  10183. case BCM57840_O:
  10184. case BCM57840_4_10:
  10185. case BCM57840_2_20:
  10186. case BCM57840_MFO:
  10187. case BCM57840_MF:
  10188. bp->flags |= NO_FCOE_FLAG;
  10189. }
  10190. /* Set bp->num_queues for MSI-X mode*/
  10191. bnx2x_set_num_queues(bp);
  10192. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10193. * needed.
  10194. */
  10195. bnx2x_set_int_mode(bp);
  10196. rc = register_netdev(dev);
  10197. if (rc) {
  10198. dev_err(&pdev->dev, "Cannot register net device\n");
  10199. goto init_one_exit;
  10200. }
  10201. if (!NO_FCOE(bp)) {
  10202. /* Add storage MAC address */
  10203. rtnl_lock();
  10204. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10205. rtnl_unlock();
  10206. }
  10207. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10208. BNX2X_DEV_INFO(
  10209. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10210. board_info[ent->driver_data].name,
  10211. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10212. pcie_width,
  10213. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10214. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10215. "5GHz (Gen2)" : "2.5GHz",
  10216. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10217. return 0;
  10218. init_one_exit:
  10219. if (bp->regview)
  10220. iounmap(bp->regview);
  10221. if (bp->doorbells)
  10222. iounmap(bp->doorbells);
  10223. free_netdev(dev);
  10224. if (atomic_read(&pdev->enable_cnt) == 1)
  10225. pci_release_regions(pdev);
  10226. pci_disable_device(pdev);
  10227. pci_set_drvdata(pdev, NULL);
  10228. return rc;
  10229. }
  10230. static void bnx2x_remove_one(struct pci_dev *pdev)
  10231. {
  10232. struct net_device *dev = pci_get_drvdata(pdev);
  10233. struct bnx2x *bp;
  10234. if (!dev) {
  10235. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10236. return;
  10237. }
  10238. bp = netdev_priv(dev);
  10239. /* Delete storage MAC address */
  10240. if (!NO_FCOE(bp)) {
  10241. rtnl_lock();
  10242. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10243. rtnl_unlock();
  10244. }
  10245. #ifdef BCM_DCBNL
  10246. /* Delete app tlvs from dcbnl */
  10247. bnx2x_dcbnl_update_applist(bp, true);
  10248. #endif
  10249. unregister_netdev(dev);
  10250. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10251. bnx2x_set_power_state(bp, PCI_D0);
  10252. /* Disable MSI/MSI-X */
  10253. bnx2x_disable_msi(bp);
  10254. /* Power off */
  10255. bnx2x_set_power_state(bp, PCI_D3hot);
  10256. /* Make sure RESET task is not scheduled before continuing */
  10257. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10258. if (bp->regview)
  10259. iounmap(bp->regview);
  10260. if (bp->doorbells)
  10261. iounmap(bp->doorbells);
  10262. bnx2x_release_firmware(bp);
  10263. bnx2x_free_mem_bp(bp);
  10264. free_netdev(dev);
  10265. if (atomic_read(&pdev->enable_cnt) == 1)
  10266. pci_release_regions(pdev);
  10267. pci_disable_device(pdev);
  10268. pci_set_drvdata(pdev, NULL);
  10269. }
  10270. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10271. {
  10272. int i;
  10273. bp->state = BNX2X_STATE_ERROR;
  10274. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10275. if (CNIC_LOADED(bp))
  10276. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10277. /* Stop Tx */
  10278. bnx2x_tx_disable(bp);
  10279. bnx2x_netif_stop(bp, 0);
  10280. /* Delete all NAPI objects */
  10281. bnx2x_del_all_napi(bp);
  10282. if (CNIC_LOADED(bp))
  10283. bnx2x_del_all_napi_cnic(bp);
  10284. del_timer_sync(&bp->timer);
  10285. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10286. /* Release IRQs */
  10287. bnx2x_free_irq(bp);
  10288. /* Free SKBs, SGEs, TPA pool and driver internals */
  10289. bnx2x_free_skbs(bp);
  10290. for_each_rx_queue(bp, i)
  10291. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10292. bnx2x_free_mem(bp);
  10293. bp->state = BNX2X_STATE_CLOSED;
  10294. netif_carrier_off(bp->dev);
  10295. return 0;
  10296. }
  10297. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10298. {
  10299. u32 val;
  10300. mutex_init(&bp->port.phy_mutex);
  10301. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10302. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10303. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10304. BNX2X_ERR("BAD MCP validity signature\n");
  10305. }
  10306. /**
  10307. * bnx2x_io_error_detected - called when PCI error is detected
  10308. * @pdev: Pointer to PCI device
  10309. * @state: The current pci connection state
  10310. *
  10311. * This function is called after a PCI bus error affecting
  10312. * this device has been detected.
  10313. */
  10314. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10315. pci_channel_state_t state)
  10316. {
  10317. struct net_device *dev = pci_get_drvdata(pdev);
  10318. struct bnx2x *bp = netdev_priv(dev);
  10319. rtnl_lock();
  10320. netif_device_detach(dev);
  10321. if (state == pci_channel_io_perm_failure) {
  10322. rtnl_unlock();
  10323. return PCI_ERS_RESULT_DISCONNECT;
  10324. }
  10325. if (netif_running(dev))
  10326. bnx2x_eeh_nic_unload(bp);
  10327. pci_disable_device(pdev);
  10328. rtnl_unlock();
  10329. /* Request a slot reset */
  10330. return PCI_ERS_RESULT_NEED_RESET;
  10331. }
  10332. /**
  10333. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10334. * @pdev: Pointer to PCI device
  10335. *
  10336. * Restart the card from scratch, as if from a cold-boot.
  10337. */
  10338. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10339. {
  10340. struct net_device *dev = pci_get_drvdata(pdev);
  10341. struct bnx2x *bp = netdev_priv(dev);
  10342. rtnl_lock();
  10343. if (pci_enable_device(pdev)) {
  10344. dev_err(&pdev->dev,
  10345. "Cannot re-enable PCI device after reset\n");
  10346. rtnl_unlock();
  10347. return PCI_ERS_RESULT_DISCONNECT;
  10348. }
  10349. pci_set_master(pdev);
  10350. pci_restore_state(pdev);
  10351. if (netif_running(dev))
  10352. bnx2x_set_power_state(bp, PCI_D0);
  10353. rtnl_unlock();
  10354. return PCI_ERS_RESULT_RECOVERED;
  10355. }
  10356. /**
  10357. * bnx2x_io_resume - called when traffic can start flowing again
  10358. * @pdev: Pointer to PCI device
  10359. *
  10360. * This callback is called when the error recovery driver tells us that
  10361. * its OK to resume normal operation.
  10362. */
  10363. static void bnx2x_io_resume(struct pci_dev *pdev)
  10364. {
  10365. struct net_device *dev = pci_get_drvdata(pdev);
  10366. struct bnx2x *bp = netdev_priv(dev);
  10367. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10368. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10369. return;
  10370. }
  10371. rtnl_lock();
  10372. bnx2x_eeh_recover(bp);
  10373. if (netif_running(dev))
  10374. bnx2x_nic_load(bp, LOAD_NORMAL);
  10375. netif_device_attach(dev);
  10376. rtnl_unlock();
  10377. }
  10378. static const struct pci_error_handlers bnx2x_err_handler = {
  10379. .error_detected = bnx2x_io_error_detected,
  10380. .slot_reset = bnx2x_io_slot_reset,
  10381. .resume = bnx2x_io_resume,
  10382. };
  10383. static struct pci_driver bnx2x_pci_driver = {
  10384. .name = DRV_MODULE_NAME,
  10385. .id_table = bnx2x_pci_tbl,
  10386. .probe = bnx2x_init_one,
  10387. .remove = bnx2x_remove_one,
  10388. .suspend = bnx2x_suspend,
  10389. .resume = bnx2x_resume,
  10390. .err_handler = &bnx2x_err_handler,
  10391. };
  10392. static int __init bnx2x_init(void)
  10393. {
  10394. int ret;
  10395. pr_info("%s", version);
  10396. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10397. if (bnx2x_wq == NULL) {
  10398. pr_err("Cannot create workqueue\n");
  10399. return -ENOMEM;
  10400. }
  10401. ret = pci_register_driver(&bnx2x_pci_driver);
  10402. if (ret) {
  10403. pr_err("Cannot register driver\n");
  10404. destroy_workqueue(bnx2x_wq);
  10405. }
  10406. return ret;
  10407. }
  10408. static void __exit bnx2x_cleanup(void)
  10409. {
  10410. struct list_head *pos, *q;
  10411. pci_unregister_driver(&bnx2x_pci_driver);
  10412. destroy_workqueue(bnx2x_wq);
  10413. /* Free globablly allocated resources */
  10414. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10415. struct bnx2x_prev_path_list *tmp =
  10416. list_entry(pos, struct bnx2x_prev_path_list, list);
  10417. list_del(pos);
  10418. kfree(tmp);
  10419. }
  10420. }
  10421. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10422. {
  10423. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10424. }
  10425. module_init(bnx2x_init);
  10426. module_exit(bnx2x_cleanup);
  10427. /**
  10428. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10429. *
  10430. * @bp: driver handle
  10431. * @set: set or clear the CAM entry
  10432. *
  10433. * This function will wait until the ramdord completion returns.
  10434. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10435. */
  10436. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10437. {
  10438. unsigned long ramrod_flags = 0;
  10439. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10440. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10441. &bp->iscsi_l2_mac_obj, true,
  10442. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10443. }
  10444. /* count denotes the number of new completions we have seen */
  10445. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10446. {
  10447. struct eth_spe *spe;
  10448. int cxt_index, cxt_offset;
  10449. #ifdef BNX2X_STOP_ON_ERROR
  10450. if (unlikely(bp->panic))
  10451. return;
  10452. #endif
  10453. spin_lock_bh(&bp->spq_lock);
  10454. BUG_ON(bp->cnic_spq_pending < count);
  10455. bp->cnic_spq_pending -= count;
  10456. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10457. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10458. & SPE_HDR_CONN_TYPE) >>
  10459. SPE_HDR_CONN_TYPE_SHIFT;
  10460. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10461. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10462. /* Set validation for iSCSI L2 client before sending SETUP
  10463. * ramrod
  10464. */
  10465. if (type == ETH_CONNECTION_TYPE) {
  10466. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10467. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10468. ILT_PAGE_CIDS;
  10469. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10470. (cxt_index * ILT_PAGE_CIDS);
  10471. bnx2x_set_ctx_validation(bp,
  10472. &bp->context[cxt_index].
  10473. vcxt[cxt_offset].eth,
  10474. BNX2X_ISCSI_ETH_CID(bp));
  10475. }
  10476. }
  10477. /*
  10478. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10479. * and in the air. We also check that number of outstanding
  10480. * COMMON ramrods is not more than the EQ and SPQ can
  10481. * accommodate.
  10482. */
  10483. if (type == ETH_CONNECTION_TYPE) {
  10484. if (!atomic_read(&bp->cq_spq_left))
  10485. break;
  10486. else
  10487. atomic_dec(&bp->cq_spq_left);
  10488. } else if (type == NONE_CONNECTION_TYPE) {
  10489. if (!atomic_read(&bp->eq_spq_left))
  10490. break;
  10491. else
  10492. atomic_dec(&bp->eq_spq_left);
  10493. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10494. (type == FCOE_CONNECTION_TYPE)) {
  10495. if (bp->cnic_spq_pending >=
  10496. bp->cnic_eth_dev.max_kwqe_pending)
  10497. break;
  10498. else
  10499. bp->cnic_spq_pending++;
  10500. } else {
  10501. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10502. bnx2x_panic();
  10503. break;
  10504. }
  10505. spe = bnx2x_sp_get_next(bp);
  10506. *spe = *bp->cnic_kwq_cons;
  10507. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10508. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10509. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10510. bp->cnic_kwq_cons = bp->cnic_kwq;
  10511. else
  10512. bp->cnic_kwq_cons++;
  10513. }
  10514. bnx2x_sp_prod_update(bp);
  10515. spin_unlock_bh(&bp->spq_lock);
  10516. }
  10517. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10518. struct kwqe_16 *kwqes[], u32 count)
  10519. {
  10520. struct bnx2x *bp = netdev_priv(dev);
  10521. int i;
  10522. #ifdef BNX2X_STOP_ON_ERROR
  10523. if (unlikely(bp->panic)) {
  10524. BNX2X_ERR("Can't post to SP queue while panic\n");
  10525. return -EIO;
  10526. }
  10527. #endif
  10528. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10529. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10530. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10531. return -EAGAIN;
  10532. }
  10533. spin_lock_bh(&bp->spq_lock);
  10534. for (i = 0; i < count; i++) {
  10535. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10536. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10537. break;
  10538. *bp->cnic_kwq_prod = *spe;
  10539. bp->cnic_kwq_pending++;
  10540. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10541. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10542. spe->data.update_data_addr.hi,
  10543. spe->data.update_data_addr.lo,
  10544. bp->cnic_kwq_pending);
  10545. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10546. bp->cnic_kwq_prod = bp->cnic_kwq;
  10547. else
  10548. bp->cnic_kwq_prod++;
  10549. }
  10550. spin_unlock_bh(&bp->spq_lock);
  10551. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10552. bnx2x_cnic_sp_post(bp, 0);
  10553. return i;
  10554. }
  10555. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10556. {
  10557. struct cnic_ops *c_ops;
  10558. int rc = 0;
  10559. mutex_lock(&bp->cnic_mutex);
  10560. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10561. lockdep_is_held(&bp->cnic_mutex));
  10562. if (c_ops)
  10563. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10564. mutex_unlock(&bp->cnic_mutex);
  10565. return rc;
  10566. }
  10567. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10568. {
  10569. struct cnic_ops *c_ops;
  10570. int rc = 0;
  10571. rcu_read_lock();
  10572. c_ops = rcu_dereference(bp->cnic_ops);
  10573. if (c_ops)
  10574. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10575. rcu_read_unlock();
  10576. return rc;
  10577. }
  10578. /*
  10579. * for commands that have no data
  10580. */
  10581. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10582. {
  10583. struct cnic_ctl_info ctl = {0};
  10584. ctl.cmd = cmd;
  10585. return bnx2x_cnic_ctl_send(bp, &ctl);
  10586. }
  10587. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10588. {
  10589. struct cnic_ctl_info ctl = {0};
  10590. /* first we tell CNIC and only then we count this as a completion */
  10591. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10592. ctl.data.comp.cid = cid;
  10593. ctl.data.comp.error = err;
  10594. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10595. bnx2x_cnic_sp_post(bp, 0);
  10596. }
  10597. /* Called with netif_addr_lock_bh() taken.
  10598. * Sets an rx_mode config for an iSCSI ETH client.
  10599. * Doesn't block.
  10600. * Completion should be checked outside.
  10601. */
  10602. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10603. {
  10604. unsigned long accept_flags = 0, ramrod_flags = 0;
  10605. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10606. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10607. if (start) {
  10608. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10609. * because it's the only way for UIO Queue to accept
  10610. * multicasts (in non-promiscuous mode only one Queue per
  10611. * function will receive multicast packets (leading in our
  10612. * case).
  10613. */
  10614. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10615. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10616. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10617. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10618. /* Clear STOP_PENDING bit if START is requested */
  10619. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10620. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10621. } else
  10622. /* Clear START_PENDING bit if STOP is requested */
  10623. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10624. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10625. set_bit(sched_state, &bp->sp_state);
  10626. else {
  10627. __set_bit(RAMROD_RX, &ramrod_flags);
  10628. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10629. ramrod_flags);
  10630. }
  10631. }
  10632. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10633. {
  10634. struct bnx2x *bp = netdev_priv(dev);
  10635. int rc = 0;
  10636. switch (ctl->cmd) {
  10637. case DRV_CTL_CTXTBL_WR_CMD: {
  10638. u32 index = ctl->data.io.offset;
  10639. dma_addr_t addr = ctl->data.io.dma_addr;
  10640. bnx2x_ilt_wr(bp, index, addr);
  10641. break;
  10642. }
  10643. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10644. int count = ctl->data.credit.credit_count;
  10645. bnx2x_cnic_sp_post(bp, count);
  10646. break;
  10647. }
  10648. /* rtnl_lock is held. */
  10649. case DRV_CTL_START_L2_CMD: {
  10650. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10651. unsigned long sp_bits = 0;
  10652. /* Configure the iSCSI classification object */
  10653. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10654. cp->iscsi_l2_client_id,
  10655. cp->iscsi_l2_cid, BP_FUNC(bp),
  10656. bnx2x_sp(bp, mac_rdata),
  10657. bnx2x_sp_mapping(bp, mac_rdata),
  10658. BNX2X_FILTER_MAC_PENDING,
  10659. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10660. &bp->macs_pool);
  10661. /* Set iSCSI MAC address */
  10662. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10663. if (rc)
  10664. break;
  10665. mmiowb();
  10666. barrier();
  10667. /* Start accepting on iSCSI L2 ring */
  10668. netif_addr_lock_bh(dev);
  10669. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10670. netif_addr_unlock_bh(dev);
  10671. /* bits to wait on */
  10672. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10673. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10674. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10675. BNX2X_ERR("rx_mode completion timed out!\n");
  10676. break;
  10677. }
  10678. /* rtnl_lock is held. */
  10679. case DRV_CTL_STOP_L2_CMD: {
  10680. unsigned long sp_bits = 0;
  10681. /* Stop accepting on iSCSI L2 ring */
  10682. netif_addr_lock_bh(dev);
  10683. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10684. netif_addr_unlock_bh(dev);
  10685. /* bits to wait on */
  10686. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10687. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10688. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10689. BNX2X_ERR("rx_mode completion timed out!\n");
  10690. mmiowb();
  10691. barrier();
  10692. /* Unset iSCSI L2 MAC */
  10693. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10694. BNX2X_ISCSI_ETH_MAC, true);
  10695. break;
  10696. }
  10697. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10698. int count = ctl->data.credit.credit_count;
  10699. smp_mb__before_atomic_inc();
  10700. atomic_add(count, &bp->cq_spq_left);
  10701. smp_mb__after_atomic_inc();
  10702. break;
  10703. }
  10704. case DRV_CTL_ULP_REGISTER_CMD: {
  10705. int ulp_type = ctl->data.register_data.ulp_type;
  10706. if (CHIP_IS_E3(bp)) {
  10707. int idx = BP_FW_MB_IDX(bp);
  10708. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10709. int path = BP_PATH(bp);
  10710. int port = BP_PORT(bp);
  10711. int i;
  10712. u32 scratch_offset;
  10713. u32 *host_addr;
  10714. /* first write capability to shmem2 */
  10715. if (ulp_type == CNIC_ULP_ISCSI)
  10716. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10717. else if (ulp_type == CNIC_ULP_FCOE)
  10718. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10719. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10720. if ((ulp_type != CNIC_ULP_FCOE) ||
  10721. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  10722. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  10723. break;
  10724. /* if reached here - should write fcoe capabilities */
  10725. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  10726. if (!scratch_offset)
  10727. break;
  10728. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  10729. fcoe_features[path][port]);
  10730. host_addr = (u32 *) &(ctl->data.register_data.
  10731. fcoe_features);
  10732. for (i = 0; i < sizeof(struct fcoe_capabilities);
  10733. i += 4)
  10734. REG_WR(bp, scratch_offset + i,
  10735. *(host_addr + i/4));
  10736. }
  10737. break;
  10738. }
  10739. case DRV_CTL_ULP_UNREGISTER_CMD: {
  10740. int ulp_type = ctl->data.ulp_type;
  10741. if (CHIP_IS_E3(bp)) {
  10742. int idx = BP_FW_MB_IDX(bp);
  10743. u32 cap;
  10744. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10745. if (ulp_type == CNIC_ULP_ISCSI)
  10746. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10747. else if (ulp_type == CNIC_ULP_FCOE)
  10748. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10749. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10750. }
  10751. break;
  10752. }
  10753. default:
  10754. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10755. rc = -EINVAL;
  10756. }
  10757. return rc;
  10758. }
  10759. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10760. {
  10761. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10762. if (bp->flags & USING_MSIX_FLAG) {
  10763. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10764. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10765. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10766. } else {
  10767. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10768. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10769. }
  10770. if (!CHIP_IS_E1x(bp))
  10771. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  10772. else
  10773. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  10774. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  10775. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  10776. cp->irq_arr[1].status_blk = bp->def_status_blk;
  10777. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  10778. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  10779. cp->num_irq = 2;
  10780. }
  10781. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  10782. {
  10783. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10784. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10785. bnx2x_cid_ilt_lines(bp);
  10786. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10787. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10788. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10789. if (NO_ISCSI_OOO(bp))
  10790. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10791. }
  10792. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  10793. void *data)
  10794. {
  10795. struct bnx2x *bp = netdev_priv(dev);
  10796. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10797. int rc;
  10798. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  10799. if (ops == NULL) {
  10800. BNX2X_ERR("NULL ops received\n");
  10801. return -EINVAL;
  10802. }
  10803. if (!CNIC_SUPPORT(bp)) {
  10804. BNX2X_ERR("Can't register CNIC when not supported\n");
  10805. return -EOPNOTSUPP;
  10806. }
  10807. if (!CNIC_LOADED(bp)) {
  10808. rc = bnx2x_load_cnic(bp);
  10809. if (rc) {
  10810. BNX2X_ERR("CNIC-related load failed\n");
  10811. return rc;
  10812. }
  10813. }
  10814. bp->cnic_enabled = true;
  10815. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  10816. if (!bp->cnic_kwq)
  10817. return -ENOMEM;
  10818. bp->cnic_kwq_cons = bp->cnic_kwq;
  10819. bp->cnic_kwq_prod = bp->cnic_kwq;
  10820. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  10821. bp->cnic_spq_pending = 0;
  10822. bp->cnic_kwq_pending = 0;
  10823. bp->cnic_data = data;
  10824. cp->num_irq = 0;
  10825. cp->drv_state |= CNIC_DRV_STATE_REGD;
  10826. cp->iro_arr = bp->iro_arr;
  10827. bnx2x_setup_cnic_irq_info(bp);
  10828. rcu_assign_pointer(bp->cnic_ops, ops);
  10829. return 0;
  10830. }
  10831. static int bnx2x_unregister_cnic(struct net_device *dev)
  10832. {
  10833. struct bnx2x *bp = netdev_priv(dev);
  10834. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10835. mutex_lock(&bp->cnic_mutex);
  10836. cp->drv_state = 0;
  10837. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  10838. mutex_unlock(&bp->cnic_mutex);
  10839. synchronize_rcu();
  10840. kfree(bp->cnic_kwq);
  10841. bp->cnic_kwq = NULL;
  10842. return 0;
  10843. }
  10844. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  10845. {
  10846. struct bnx2x *bp = netdev_priv(dev);
  10847. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10848. /* If both iSCSI and FCoE are disabled - return NULL in
  10849. * order to indicate CNIC that it should not try to work
  10850. * with this device.
  10851. */
  10852. if (NO_ISCSI(bp) && NO_FCOE(bp))
  10853. return NULL;
  10854. cp->drv_owner = THIS_MODULE;
  10855. cp->chip_id = CHIP_ID(bp);
  10856. cp->pdev = bp->pdev;
  10857. cp->io_base = bp->regview;
  10858. cp->io_base2 = bp->doorbells;
  10859. cp->max_kwqe_pending = 8;
  10860. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  10861. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  10862. bnx2x_cid_ilt_lines(bp);
  10863. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10864. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  10865. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10866. cp->drv_ctl = bnx2x_drv_ctl;
  10867. cp->drv_register_cnic = bnx2x_register_cnic;
  10868. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10869. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  10870. cp->iscsi_l2_client_id =
  10871. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10872. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  10873. if (NO_ISCSI_OOO(bp))
  10874. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  10875. if (NO_ISCSI(bp))
  10876. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  10877. if (NO_FCOE(bp))
  10878. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  10879. BNX2X_DEV_INFO(
  10880. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  10881. cp->ctx_blk_size,
  10882. cp->ctx_tbl_offset,
  10883. cp->ctx_tbl_len,
  10884. cp->starting_cid);
  10885. return cp;
  10886. }