bnx2x_main.c 375 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 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_vfpf.h"
  60. #include "bnx2x_dcb.h"
  61. #include "bnx2x_sp.h"
  62. #include <linux/firmware.h>
  63. #include "bnx2x_fw_file_hdr.h"
  64. /* FW files */
  65. #define FW_FILE_VERSION \
  66. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  69. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  70. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  73. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] =
  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. int int_mode;
  96. module_param(int_mode, int, 0);
  97. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  98. "(1 INT#x; 2 MSI)");
  99. static int dropless_fc;
  100. module_param(dropless_fc, int, 0);
  101. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  102. static int mrrs = -1;
  103. module_param(mrrs, int, 0);
  104. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  105. static int debug;
  106. module_param(debug, int, 0);
  107. MODULE_PARM_DESC(debug, " Default debug msglevel");
  108. struct workqueue_struct *bnx2x_wq;
  109. struct bnx2x_mac_vals {
  110. u32 xmac_addr;
  111. u32 xmac_val;
  112. u32 emac_addr;
  113. u32 emac_val;
  114. u32 umac_addr;
  115. u32 umac_val;
  116. u32 bmac_addr;
  117. u32 bmac_val[2];
  118. };
  119. enum bnx2x_board_type {
  120. BCM57710 = 0,
  121. BCM57711,
  122. BCM57711E,
  123. BCM57712,
  124. BCM57712_MF,
  125. BCM57712_VF,
  126. BCM57800,
  127. BCM57800_MF,
  128. BCM57800_VF,
  129. BCM57810,
  130. BCM57810_MF,
  131. BCM57810_VF,
  132. BCM57840_4_10,
  133. BCM57840_2_20,
  134. BCM57840_MF,
  135. BCM57840_VF,
  136. BCM57811,
  137. BCM57811_MF,
  138. BCM57840_O,
  139. BCM57840_MFO,
  140. BCM57811_VF
  141. };
  142. /* indexed by board_type, above */
  143. static struct {
  144. char *name;
  145. } board_info[] = {
  146. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  147. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  148. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  149. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  150. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  151. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  152. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  153. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  154. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  156. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  157. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  159. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  160. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  161. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  162. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  163. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  164. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  165. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  166. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  167. };
  168. #ifndef PCI_DEVICE_ID_NX2_57710
  169. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57711
  172. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711E
  175. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57712
  178. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  181. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  184. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57800
  187. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  190. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  193. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57810
  196. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  199. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57840_O
  202. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  205. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  208. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  211. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  214. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  217. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  220. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57811
  223. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  226. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  229. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  230. #endif
  231. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  232. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  233. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  253. { 0 }
  254. };
  255. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  256. /* Global resources for unloading a previously loaded device */
  257. #define BNX2X_PREV_WAIT_NEEDED 1
  258. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  259. static LIST_HEAD(bnx2x_prev_list);
  260. /****************************************************************************
  261. * General service functions
  262. ****************************************************************************/
  263. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  264. u32 addr, dma_addr_t mapping)
  265. {
  266. REG_WR(bp, addr, U64_LO(mapping));
  267. REG_WR(bp, addr + 4, U64_HI(mapping));
  268. }
  269. static void storm_memset_spq_addr(struct bnx2x *bp,
  270. dma_addr_t mapping, u16 abs_fid)
  271. {
  272. u32 addr = XSEM_REG_FAST_MEMORY +
  273. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  274. __storm_memset_dma_mapping(bp, addr, mapping);
  275. }
  276. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  277. u16 pf_id)
  278. {
  279. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  280. pf_id);
  281. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  282. pf_id);
  283. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  284. pf_id);
  285. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. }
  288. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  289. u8 enable)
  290. {
  291. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  292. enable);
  293. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  294. enable);
  295. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  296. enable);
  297. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. }
  300. static void storm_memset_eq_data(struct bnx2x *bp,
  301. struct event_ring_data *eq_data,
  302. u16 pfid)
  303. {
  304. size_t size = sizeof(struct event_ring_data);
  305. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  306. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  307. }
  308. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  309. u16 pfid)
  310. {
  311. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  312. REG_WR16(bp, addr, eq_prod);
  313. }
  314. /* used only at init
  315. * locking is done by mcp
  316. */
  317. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  318. {
  319. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  320. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  321. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  322. PCICFG_VENDOR_ID_OFFSET);
  323. }
  324. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  325. {
  326. u32 val;
  327. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  328. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  330. PCICFG_VENDOR_ID_OFFSET);
  331. return val;
  332. }
  333. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  334. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  335. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  336. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  337. #define DMAE_DP_DST_NONE "dst_addr [none]"
  338. static void bnx2x_dp_dmae(struct bnx2x *bp,
  339. struct dmae_command *dmae, int msglvl)
  340. {
  341. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  342. int i;
  343. switch (dmae->opcode & DMAE_COMMAND_DST) {
  344. case DMAE_CMD_DST_PCI:
  345. if (src_type == DMAE_CMD_SRC_PCI)
  346. DP(msglvl, "DMAE: opcode 0x%08x\n"
  347. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  348. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  349. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  350. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  351. dmae->comp_addr_hi, dmae->comp_addr_lo,
  352. dmae->comp_val);
  353. else
  354. DP(msglvl, "DMAE: opcode 0x%08x\n"
  355. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  356. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  357. dmae->opcode, dmae->src_addr_lo >> 2,
  358. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  359. dmae->comp_addr_hi, dmae->comp_addr_lo,
  360. dmae->comp_val);
  361. break;
  362. case DMAE_CMD_DST_GRC:
  363. if (src_type == DMAE_CMD_SRC_PCI)
  364. DP(msglvl, "DMAE: opcode 0x%08x\n"
  365. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  366. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  367. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  368. dmae->len, dmae->dst_addr_lo >> 2,
  369. dmae->comp_addr_hi, dmae->comp_addr_lo,
  370. dmae->comp_val);
  371. else
  372. DP(msglvl, "DMAE: opcode 0x%08x\n"
  373. "src [%08x], len [%d*4], dst [%08x]\n"
  374. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  375. dmae->opcode, dmae->src_addr_lo >> 2,
  376. dmae->len, dmae->dst_addr_lo >> 2,
  377. dmae->comp_addr_hi, dmae->comp_addr_lo,
  378. dmae->comp_val);
  379. break;
  380. default:
  381. if (src_type == DMAE_CMD_SRC_PCI)
  382. DP(msglvl, "DMAE: opcode 0x%08x\n"
  383. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  384. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  385. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  386. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  387. dmae->comp_val);
  388. else
  389. DP(msglvl, "DMAE: opcode 0x%08x\n"
  390. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  391. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  392. dmae->opcode, dmae->src_addr_lo >> 2,
  393. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  394. dmae->comp_val);
  395. break;
  396. }
  397. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  398. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  399. i, *(((u32 *)dmae) + i));
  400. }
  401. /* copy command into DMAE command memory and set DMAE command go */
  402. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  403. {
  404. u32 cmd_offset;
  405. int i;
  406. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  407. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  408. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  409. }
  410. REG_WR(bp, dmae_reg_go_c[idx], 1);
  411. }
  412. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  413. {
  414. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  415. DMAE_CMD_C_ENABLE);
  416. }
  417. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  418. {
  419. return opcode & ~DMAE_CMD_SRC_RESET;
  420. }
  421. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  422. bool with_comp, u8 comp_type)
  423. {
  424. u32 opcode = 0;
  425. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  426. (dst_type << DMAE_COMMAND_DST_SHIFT));
  427. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  428. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  429. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  430. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  431. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  432. #ifdef __BIG_ENDIAN
  433. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  434. #else
  435. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  436. #endif
  437. if (with_comp)
  438. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  439. return opcode;
  440. }
  441. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  442. struct dmae_command *dmae,
  443. u8 src_type, u8 dst_type)
  444. {
  445. memset(dmae, 0, sizeof(struct dmae_command));
  446. /* set the opcode */
  447. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  448. true, DMAE_COMP_PCI);
  449. /* fill in the completion parameters */
  450. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  451. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  452. dmae->comp_val = DMAE_COMP_VAL;
  453. }
  454. /* issue a dmae command over the init-channel and wait for completion */
  455. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae,
  456. u32 *comp)
  457. {
  458. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  459. int rc = 0;
  460. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  461. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  462. * as long as this code is called both from syscall context and
  463. * from ndo_set_rx_mode() flow that may be called from BH.
  464. */
  465. spin_lock_bh(&bp->dmae_lock);
  466. /* reset completion */
  467. *comp = 0;
  468. /* post the command on the channel used for initializations */
  469. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  470. /* wait for completion */
  471. udelay(5);
  472. while ((*comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  473. if (!cnt ||
  474. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  475. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  476. BNX2X_ERR("DMAE timeout!\n");
  477. rc = DMAE_TIMEOUT;
  478. goto unlock;
  479. }
  480. cnt--;
  481. udelay(50);
  482. }
  483. if (*comp & DMAE_PCI_ERR_FLAG) {
  484. BNX2X_ERR("DMAE PCI error!\n");
  485. rc = DMAE_PCI_ERROR;
  486. }
  487. unlock:
  488. spin_unlock_bh(&bp->dmae_lock);
  489. return rc;
  490. }
  491. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  492. u32 len32)
  493. {
  494. int rc;
  495. struct dmae_command dmae;
  496. if (!bp->dmae_ready) {
  497. u32 *data = bnx2x_sp(bp, wb_data[0]);
  498. if (CHIP_IS_E1(bp))
  499. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  500. else
  501. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  502. return;
  503. }
  504. /* set opcode and fixed command fields */
  505. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  506. /* fill in addresses and len */
  507. dmae.src_addr_lo = U64_LO(dma_addr);
  508. dmae.src_addr_hi = U64_HI(dma_addr);
  509. dmae.dst_addr_lo = dst_addr >> 2;
  510. dmae.dst_addr_hi = 0;
  511. dmae.len = len32;
  512. /* issue the command and wait for completion */
  513. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  514. if (rc) {
  515. BNX2X_ERR("DMAE returned failure %d\n", rc);
  516. bnx2x_panic();
  517. }
  518. }
  519. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  520. {
  521. int rc;
  522. struct dmae_command dmae;
  523. if (!bp->dmae_ready) {
  524. u32 *data = bnx2x_sp(bp, wb_data[0]);
  525. int i;
  526. if (CHIP_IS_E1(bp))
  527. for (i = 0; i < len32; i++)
  528. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  529. else
  530. for (i = 0; i < len32; i++)
  531. data[i] = REG_RD(bp, src_addr + i*4);
  532. return;
  533. }
  534. /* set opcode and fixed command fields */
  535. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  536. /* fill in addresses and len */
  537. dmae.src_addr_lo = src_addr >> 2;
  538. dmae.src_addr_hi = 0;
  539. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  540. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  541. dmae.len = len32;
  542. /* issue the command and wait for completion */
  543. rc = bnx2x_issue_dmae_with_comp(bp, &dmae, bnx2x_sp(bp, wb_comp));
  544. if (rc) {
  545. BNX2X_ERR("DMAE returned failure %d\n", rc);
  546. bnx2x_panic();
  547. }
  548. }
  549. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  550. u32 addr, u32 len)
  551. {
  552. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  553. int offset = 0;
  554. while (len > dmae_wr_max) {
  555. bnx2x_write_dmae(bp, phys_addr + offset,
  556. addr + offset, dmae_wr_max);
  557. offset += dmae_wr_max * 4;
  558. len -= dmae_wr_max;
  559. }
  560. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  561. }
  562. static int bnx2x_mc_assert(struct bnx2x *bp)
  563. {
  564. char last_idx;
  565. int i, rc = 0;
  566. u32 row0, row1, row2, row3;
  567. /* XSTORM */
  568. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  569. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  570. if (last_idx)
  571. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  572. /* print the asserts */
  573. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  574. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  575. XSTORM_ASSERT_LIST_OFFSET(i));
  576. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  577. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  578. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  579. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  580. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  581. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  582. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  583. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  584. i, row3, row2, row1, row0);
  585. rc++;
  586. } else {
  587. break;
  588. }
  589. }
  590. /* TSTORM */
  591. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  592. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  593. if (last_idx)
  594. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  595. /* print the asserts */
  596. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  597. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  598. TSTORM_ASSERT_LIST_OFFSET(i));
  599. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  600. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  601. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  602. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  603. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  604. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  605. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  606. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  607. i, row3, row2, row1, row0);
  608. rc++;
  609. } else {
  610. break;
  611. }
  612. }
  613. /* CSTORM */
  614. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  615. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  616. if (last_idx)
  617. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  618. /* print the asserts */
  619. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  620. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  621. CSTORM_ASSERT_LIST_OFFSET(i));
  622. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  623. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  624. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  625. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  626. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  627. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  628. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  629. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  630. i, row3, row2, row1, row0);
  631. rc++;
  632. } else {
  633. break;
  634. }
  635. }
  636. /* USTORM */
  637. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  638. USTORM_ASSERT_LIST_INDEX_OFFSET);
  639. if (last_idx)
  640. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  641. /* print the asserts */
  642. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  643. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  644. USTORM_ASSERT_LIST_OFFSET(i));
  645. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  646. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  647. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  648. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  649. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  650. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  651. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  652. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  653. i, row3, row2, row1, row0);
  654. rc++;
  655. } else {
  656. break;
  657. }
  658. }
  659. return rc;
  660. }
  661. #define MCPR_TRACE_BUFFER_SIZE (0x800)
  662. #define SCRATCH_BUFFER_SIZE(bp) \
  663. (CHIP_IS_E1(bp) ? 0x10000 : (CHIP_IS_E1H(bp) ? 0x20000 : 0x28000))
  664. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  665. {
  666. u32 addr, val;
  667. u32 mark, offset;
  668. __be32 data[9];
  669. int word;
  670. u32 trace_shmem_base;
  671. if (BP_NOMCP(bp)) {
  672. BNX2X_ERR("NO MCP - can not dump\n");
  673. return;
  674. }
  675. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  676. (bp->common.bc_ver & 0xff0000) >> 16,
  677. (bp->common.bc_ver & 0xff00) >> 8,
  678. (bp->common.bc_ver & 0xff));
  679. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  680. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  681. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  682. if (BP_PATH(bp) == 0)
  683. trace_shmem_base = bp->common.shmem_base;
  684. else
  685. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  686. /* sanity */
  687. if (trace_shmem_base < MCPR_SCRATCH_BASE(bp) + MCPR_TRACE_BUFFER_SIZE ||
  688. trace_shmem_base >= MCPR_SCRATCH_BASE(bp) +
  689. SCRATCH_BUFFER_SIZE(bp)) {
  690. BNX2X_ERR("Unable to dump trace buffer (mark %x)\n",
  691. trace_shmem_base);
  692. return;
  693. }
  694. addr = trace_shmem_base - MCPR_TRACE_BUFFER_SIZE;
  695. /* validate TRCB signature */
  696. mark = REG_RD(bp, addr);
  697. if (mark != MFW_TRACE_SIGNATURE) {
  698. BNX2X_ERR("Trace buffer signature is missing.");
  699. return ;
  700. }
  701. /* read cyclic buffer pointer */
  702. addr += 4;
  703. mark = REG_RD(bp, addr);
  704. mark = MCPR_SCRATCH_BASE(bp) + ((mark + 0x3) & ~0x3) - 0x08000000;
  705. if (mark >= trace_shmem_base || mark < addr + 4) {
  706. BNX2X_ERR("Mark doesn't fall inside Trace Buffer\n");
  707. return;
  708. }
  709. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  710. printk("%s", lvl);
  711. /* dump buffer after the mark */
  712. for (offset = mark; offset < trace_shmem_base; offset += 0x8*4) {
  713. for (word = 0; word < 8; word++)
  714. data[word] = htonl(REG_RD(bp, offset + 4*word));
  715. data[8] = 0x0;
  716. pr_cont("%s", (char *)data);
  717. }
  718. /* dump buffer before the mark */
  719. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  720. for (word = 0; word < 8; word++)
  721. data[word] = htonl(REG_RD(bp, offset + 4*word));
  722. data[8] = 0x0;
  723. pr_cont("%s", (char *)data);
  724. }
  725. printk("%s" "end of fw dump\n", lvl);
  726. }
  727. static void bnx2x_fw_dump(struct bnx2x *bp)
  728. {
  729. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  730. }
  731. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  732. {
  733. int port = BP_PORT(bp);
  734. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  735. u32 val = REG_RD(bp, addr);
  736. /* in E1 we must use only PCI configuration space to disable
  737. * MSI/MSIX capability
  738. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  739. */
  740. if (CHIP_IS_E1(bp)) {
  741. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  742. * Use mask register to prevent from HC sending interrupts
  743. * after we exit the function
  744. */
  745. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  746. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  747. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  748. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  749. } else
  750. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  751. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  752. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  753. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  754. DP(NETIF_MSG_IFDOWN,
  755. "write %x to HC %d (addr 0x%x)\n",
  756. val, port, addr);
  757. /* flush all outstanding writes */
  758. mmiowb();
  759. REG_WR(bp, addr, val);
  760. if (REG_RD(bp, addr) != val)
  761. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  762. }
  763. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  764. {
  765. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  766. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  767. IGU_PF_CONF_INT_LINE_EN |
  768. IGU_PF_CONF_ATTN_BIT_EN);
  769. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  770. /* flush all outstanding writes */
  771. mmiowb();
  772. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  773. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  774. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  775. }
  776. static void bnx2x_int_disable(struct bnx2x *bp)
  777. {
  778. if (bp->common.int_block == INT_BLOCK_HC)
  779. bnx2x_hc_int_disable(bp);
  780. else
  781. bnx2x_igu_int_disable(bp);
  782. }
  783. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  784. {
  785. int i;
  786. u16 j;
  787. struct hc_sp_status_block_data sp_sb_data;
  788. int func = BP_FUNC(bp);
  789. #ifdef BNX2X_STOP_ON_ERROR
  790. u16 start = 0, end = 0;
  791. u8 cos;
  792. #endif
  793. if (disable_int)
  794. bnx2x_int_disable(bp);
  795. bp->stats_state = STATS_STATE_DISABLED;
  796. bp->eth_stats.unrecoverable_error++;
  797. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  798. BNX2X_ERR("begin crash dump -----------------\n");
  799. /* Indices */
  800. /* Common */
  801. 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",
  802. bp->def_idx, bp->def_att_idx, bp->attn_state,
  803. bp->spq_prod_idx, bp->stats_counter);
  804. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  805. bp->def_status_blk->atten_status_block.attn_bits,
  806. bp->def_status_blk->atten_status_block.attn_bits_ack,
  807. bp->def_status_blk->atten_status_block.status_block_id,
  808. bp->def_status_blk->atten_status_block.attn_bits_index);
  809. BNX2X_ERR(" def (");
  810. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  811. pr_cont("0x%x%s",
  812. bp->def_status_blk->sp_sb.index_values[i],
  813. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  814. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  815. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  816. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  817. i*sizeof(u32));
  818. 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",
  819. sp_sb_data.igu_sb_id,
  820. sp_sb_data.igu_seg_id,
  821. sp_sb_data.p_func.pf_id,
  822. sp_sb_data.p_func.vnic_id,
  823. sp_sb_data.p_func.vf_id,
  824. sp_sb_data.p_func.vf_valid,
  825. sp_sb_data.state);
  826. for_each_eth_queue(bp, i) {
  827. struct bnx2x_fastpath *fp = &bp->fp[i];
  828. int loop;
  829. struct hc_status_block_data_e2 sb_data_e2;
  830. struct hc_status_block_data_e1x sb_data_e1x;
  831. struct hc_status_block_sm *hc_sm_p =
  832. CHIP_IS_E1x(bp) ?
  833. sb_data_e1x.common.state_machine :
  834. sb_data_e2.common.state_machine;
  835. struct hc_index_data *hc_index_p =
  836. CHIP_IS_E1x(bp) ?
  837. sb_data_e1x.index_data :
  838. sb_data_e2.index_data;
  839. u8 data_size, cos;
  840. u32 *sb_data_p;
  841. struct bnx2x_fp_txdata txdata;
  842. /* Rx */
  843. 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",
  844. i, fp->rx_bd_prod, fp->rx_bd_cons,
  845. fp->rx_comp_prod,
  846. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  847. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  848. fp->rx_sge_prod, fp->last_max_sge,
  849. le16_to_cpu(fp->fp_hc_idx));
  850. /* Tx */
  851. for_each_cos_in_tx_queue(fp, cos)
  852. {
  853. txdata = *fp->txdata_ptr[cos];
  854. 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",
  855. i, txdata.tx_pkt_prod,
  856. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  857. txdata.tx_bd_cons,
  858. le16_to_cpu(*txdata.tx_cons_sb));
  859. }
  860. loop = CHIP_IS_E1x(bp) ?
  861. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  862. /* host sb data */
  863. if (IS_FCOE_FP(fp))
  864. continue;
  865. BNX2X_ERR(" run indexes (");
  866. for (j = 0; j < HC_SB_MAX_SM; j++)
  867. pr_cont("0x%x%s",
  868. fp->sb_running_index[j],
  869. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  870. BNX2X_ERR(" indexes (");
  871. for (j = 0; j < loop; j++)
  872. pr_cont("0x%x%s",
  873. fp->sb_index_values[j],
  874. (j == loop - 1) ? ")" : " ");
  875. /* fw sb data */
  876. data_size = CHIP_IS_E1x(bp) ?
  877. sizeof(struct hc_status_block_data_e1x) :
  878. sizeof(struct hc_status_block_data_e2);
  879. data_size /= sizeof(u32);
  880. sb_data_p = CHIP_IS_E1x(bp) ?
  881. (u32 *)&sb_data_e1x :
  882. (u32 *)&sb_data_e2;
  883. /* copy sb data in here */
  884. for (j = 0; j < data_size; j++)
  885. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  886. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  887. j * sizeof(u32));
  888. if (!CHIP_IS_E1x(bp)) {
  889. 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",
  890. sb_data_e2.common.p_func.pf_id,
  891. sb_data_e2.common.p_func.vf_id,
  892. sb_data_e2.common.p_func.vf_valid,
  893. sb_data_e2.common.p_func.vnic_id,
  894. sb_data_e2.common.same_igu_sb_1b,
  895. sb_data_e2.common.state);
  896. } else {
  897. 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",
  898. sb_data_e1x.common.p_func.pf_id,
  899. sb_data_e1x.common.p_func.vf_id,
  900. sb_data_e1x.common.p_func.vf_valid,
  901. sb_data_e1x.common.p_func.vnic_id,
  902. sb_data_e1x.common.same_igu_sb_1b,
  903. sb_data_e1x.common.state);
  904. }
  905. /* SB_SMs data */
  906. for (j = 0; j < HC_SB_MAX_SM; j++) {
  907. 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",
  908. j, hc_sm_p[j].__flags,
  909. hc_sm_p[j].igu_sb_id,
  910. hc_sm_p[j].igu_seg_id,
  911. hc_sm_p[j].time_to_expire,
  912. hc_sm_p[j].timer_value);
  913. }
  914. /* Indices data */
  915. for (j = 0; j < loop; j++) {
  916. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  917. hc_index_p[j].flags,
  918. hc_index_p[j].timeout);
  919. }
  920. }
  921. #ifdef BNX2X_STOP_ON_ERROR
  922. /* event queue */
  923. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  924. for (i = 0; i < NUM_EQ_DESC; i++) {
  925. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  926. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  927. i, bp->eq_ring[i].message.opcode,
  928. bp->eq_ring[i].message.error);
  929. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  930. }
  931. /* Rings */
  932. /* Rx */
  933. for_each_valid_rx_queue(bp, i) {
  934. struct bnx2x_fastpath *fp = &bp->fp[i];
  935. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  936. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  937. for (j = start; j != end; j = RX_BD(j + 1)) {
  938. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  939. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  940. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  941. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  942. }
  943. start = RX_SGE(fp->rx_sge_prod);
  944. end = RX_SGE(fp->last_max_sge);
  945. for (j = start; j != end; j = RX_SGE(j + 1)) {
  946. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  947. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  948. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  949. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  950. }
  951. start = RCQ_BD(fp->rx_comp_cons - 10);
  952. end = RCQ_BD(fp->rx_comp_cons + 503);
  953. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  954. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  955. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  956. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  957. }
  958. }
  959. /* Tx */
  960. for_each_valid_tx_queue(bp, i) {
  961. struct bnx2x_fastpath *fp = &bp->fp[i];
  962. for_each_cos_in_tx_queue(fp, cos) {
  963. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  964. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  965. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  966. for (j = start; j != end; j = TX_BD(j + 1)) {
  967. struct sw_tx_bd *sw_bd =
  968. &txdata->tx_buf_ring[j];
  969. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  970. i, cos, j, sw_bd->skb,
  971. sw_bd->first_bd);
  972. }
  973. start = TX_BD(txdata->tx_bd_cons - 10);
  974. end = TX_BD(txdata->tx_bd_cons + 254);
  975. for (j = start; j != end; j = TX_BD(j + 1)) {
  976. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  977. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  978. i, cos, j, tx_bd[0], tx_bd[1],
  979. tx_bd[2], tx_bd[3]);
  980. }
  981. }
  982. }
  983. #endif
  984. bnx2x_fw_dump(bp);
  985. bnx2x_mc_assert(bp);
  986. BNX2X_ERR("end crash dump -----------------\n");
  987. }
  988. /*
  989. * FLR Support for E2
  990. *
  991. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  992. * initialization.
  993. */
  994. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  995. #define FLR_WAIT_INTERVAL 50 /* usec */
  996. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  997. struct pbf_pN_buf_regs {
  998. int pN;
  999. u32 init_crd;
  1000. u32 crd;
  1001. u32 crd_freed;
  1002. };
  1003. struct pbf_pN_cmd_regs {
  1004. int pN;
  1005. u32 lines_occup;
  1006. u32 lines_freed;
  1007. };
  1008. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  1009. struct pbf_pN_buf_regs *regs,
  1010. u32 poll_count)
  1011. {
  1012. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  1013. u32 cur_cnt = poll_count;
  1014. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1015. crd = crd_start = REG_RD(bp, regs->crd);
  1016. init_crd = REG_RD(bp, regs->init_crd);
  1017. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1018. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1019. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1020. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1021. (init_crd - crd_start))) {
  1022. if (cur_cnt--) {
  1023. udelay(FLR_WAIT_INTERVAL);
  1024. crd = REG_RD(bp, regs->crd);
  1025. crd_freed = REG_RD(bp, regs->crd_freed);
  1026. } else {
  1027. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1028. regs->pN);
  1029. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1030. regs->pN, crd);
  1031. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1032. regs->pN, crd_freed);
  1033. break;
  1034. }
  1035. }
  1036. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1037. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1038. }
  1039. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1040. struct pbf_pN_cmd_regs *regs,
  1041. u32 poll_count)
  1042. {
  1043. u32 occup, to_free, freed, freed_start;
  1044. u32 cur_cnt = poll_count;
  1045. occup = to_free = REG_RD(bp, regs->lines_occup);
  1046. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1047. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1048. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1049. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1050. if (cur_cnt--) {
  1051. udelay(FLR_WAIT_INTERVAL);
  1052. occup = REG_RD(bp, regs->lines_occup);
  1053. freed = REG_RD(bp, regs->lines_freed);
  1054. } else {
  1055. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1056. regs->pN);
  1057. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1058. regs->pN, occup);
  1059. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1060. regs->pN, freed);
  1061. break;
  1062. }
  1063. }
  1064. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1065. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1066. }
  1067. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1068. u32 expected, u32 poll_count)
  1069. {
  1070. u32 cur_cnt = poll_count;
  1071. u32 val;
  1072. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1073. udelay(FLR_WAIT_INTERVAL);
  1074. return val;
  1075. }
  1076. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1077. char *msg, u32 poll_cnt)
  1078. {
  1079. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1080. if (val != 0) {
  1081. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1082. return 1;
  1083. }
  1084. return 0;
  1085. }
  1086. /* Common routines with VF FLR cleanup */
  1087. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1088. {
  1089. /* adjust polling timeout */
  1090. if (CHIP_REV_IS_EMUL(bp))
  1091. return FLR_POLL_CNT * 2000;
  1092. if (CHIP_REV_IS_FPGA(bp))
  1093. return FLR_POLL_CNT * 120;
  1094. return FLR_POLL_CNT;
  1095. }
  1096. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1097. {
  1098. struct pbf_pN_cmd_regs cmd_regs[] = {
  1099. {0, (CHIP_IS_E3B0(bp)) ?
  1100. PBF_REG_TQ_OCCUPANCY_Q0 :
  1101. PBF_REG_P0_TQ_OCCUPANCY,
  1102. (CHIP_IS_E3B0(bp)) ?
  1103. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1104. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1105. {1, (CHIP_IS_E3B0(bp)) ?
  1106. PBF_REG_TQ_OCCUPANCY_Q1 :
  1107. PBF_REG_P1_TQ_OCCUPANCY,
  1108. (CHIP_IS_E3B0(bp)) ?
  1109. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1110. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1111. {4, (CHIP_IS_E3B0(bp)) ?
  1112. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1113. PBF_REG_P4_TQ_OCCUPANCY,
  1114. (CHIP_IS_E3B0(bp)) ?
  1115. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1116. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1117. };
  1118. struct pbf_pN_buf_regs buf_regs[] = {
  1119. {0, (CHIP_IS_E3B0(bp)) ?
  1120. PBF_REG_INIT_CRD_Q0 :
  1121. PBF_REG_P0_INIT_CRD ,
  1122. (CHIP_IS_E3B0(bp)) ?
  1123. PBF_REG_CREDIT_Q0 :
  1124. PBF_REG_P0_CREDIT,
  1125. (CHIP_IS_E3B0(bp)) ?
  1126. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1127. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1128. {1, (CHIP_IS_E3B0(bp)) ?
  1129. PBF_REG_INIT_CRD_Q1 :
  1130. PBF_REG_P1_INIT_CRD,
  1131. (CHIP_IS_E3B0(bp)) ?
  1132. PBF_REG_CREDIT_Q1 :
  1133. PBF_REG_P1_CREDIT,
  1134. (CHIP_IS_E3B0(bp)) ?
  1135. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1136. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1137. {4, (CHIP_IS_E3B0(bp)) ?
  1138. PBF_REG_INIT_CRD_LB_Q :
  1139. PBF_REG_P4_INIT_CRD,
  1140. (CHIP_IS_E3B0(bp)) ?
  1141. PBF_REG_CREDIT_LB_Q :
  1142. PBF_REG_P4_CREDIT,
  1143. (CHIP_IS_E3B0(bp)) ?
  1144. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1145. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1146. };
  1147. int i;
  1148. /* Verify the command queues are flushed P0, P1, P4 */
  1149. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1150. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1151. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1152. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1153. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1154. }
  1155. #define OP_GEN_PARAM(param) \
  1156. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1157. #define OP_GEN_TYPE(type) \
  1158. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1159. #define OP_GEN_AGG_VECT(index) \
  1160. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1161. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1162. {
  1163. u32 op_gen_command = 0;
  1164. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1165. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1166. int ret = 0;
  1167. if (REG_RD(bp, comp_addr)) {
  1168. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1169. return 1;
  1170. }
  1171. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1172. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1173. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1174. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1175. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1176. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1177. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1178. BNX2X_ERR("FW final cleanup did not succeed\n");
  1179. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1180. (REG_RD(bp, comp_addr)));
  1181. bnx2x_panic();
  1182. return 1;
  1183. }
  1184. /* Zero completion for next FLR */
  1185. REG_WR(bp, comp_addr, 0);
  1186. return ret;
  1187. }
  1188. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1189. {
  1190. u16 status;
  1191. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1192. return status & PCI_EXP_DEVSTA_TRPND;
  1193. }
  1194. /* PF FLR specific routines
  1195. */
  1196. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1197. {
  1198. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1199. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1200. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1201. "CFC PF usage counter timed out",
  1202. poll_cnt))
  1203. return 1;
  1204. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1205. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1206. DORQ_REG_PF_USAGE_CNT,
  1207. "DQ PF usage counter timed out",
  1208. poll_cnt))
  1209. return 1;
  1210. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1211. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1212. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1213. "QM PF usage counter timed out",
  1214. poll_cnt))
  1215. return 1;
  1216. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1217. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1218. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1219. "Timers VNIC usage counter timed out",
  1220. poll_cnt))
  1221. return 1;
  1222. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1223. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1224. "Timers NUM_SCANS usage counter timed out",
  1225. poll_cnt))
  1226. return 1;
  1227. /* Wait DMAE PF usage counter to zero */
  1228. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1229. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1230. "DMAE command register timed out",
  1231. poll_cnt))
  1232. return 1;
  1233. return 0;
  1234. }
  1235. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1236. {
  1237. u32 val;
  1238. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1239. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1240. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1241. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1242. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1243. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1244. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1245. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1246. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1247. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1248. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1249. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1250. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1251. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1252. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1253. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1254. val);
  1255. }
  1256. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1257. {
  1258. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1259. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1260. /* Re-enable PF target read access */
  1261. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1262. /* Poll HW usage counters */
  1263. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1264. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1265. return -EBUSY;
  1266. /* Zero the igu 'trailing edge' and 'leading edge' */
  1267. /* Send the FW cleanup command */
  1268. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1269. return -EBUSY;
  1270. /* ATC cleanup */
  1271. /* Verify TX hw is flushed */
  1272. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1273. /* Wait 100ms (not adjusted according to platform) */
  1274. msleep(100);
  1275. /* Verify no pending pci transactions */
  1276. if (bnx2x_is_pcie_pending(bp->pdev))
  1277. BNX2X_ERR("PCIE Transactions still pending\n");
  1278. /* Debug */
  1279. bnx2x_hw_enable_status(bp);
  1280. /*
  1281. * Master enable - Due to WB DMAE writes performed before this
  1282. * register is re-initialized as part of the regular function init
  1283. */
  1284. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1285. return 0;
  1286. }
  1287. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1288. {
  1289. int port = BP_PORT(bp);
  1290. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1291. u32 val = REG_RD(bp, addr);
  1292. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1293. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1294. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1295. if (msix) {
  1296. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1297. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1298. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1299. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1300. if (single_msix)
  1301. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1302. } else if (msi) {
  1303. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1304. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1305. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1306. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1307. } else {
  1308. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1309. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1310. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1311. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1312. if (!CHIP_IS_E1(bp)) {
  1313. DP(NETIF_MSG_IFUP,
  1314. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1315. REG_WR(bp, addr, val);
  1316. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1317. }
  1318. }
  1319. if (CHIP_IS_E1(bp))
  1320. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1321. DP(NETIF_MSG_IFUP,
  1322. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1323. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1324. REG_WR(bp, addr, val);
  1325. /*
  1326. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1327. */
  1328. mmiowb();
  1329. barrier();
  1330. if (!CHIP_IS_E1(bp)) {
  1331. /* init leading/trailing edge */
  1332. if (IS_MF(bp)) {
  1333. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1334. if (bp->port.pmf)
  1335. /* enable nig and gpio3 attention */
  1336. val |= 0x1100;
  1337. } else
  1338. val = 0xffff;
  1339. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1340. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1341. }
  1342. /* Make sure that interrupts are indeed enabled from here on */
  1343. mmiowb();
  1344. }
  1345. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1346. {
  1347. u32 val;
  1348. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1349. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1350. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1351. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1352. if (msix) {
  1353. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1354. IGU_PF_CONF_SINGLE_ISR_EN);
  1355. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1356. IGU_PF_CONF_ATTN_BIT_EN);
  1357. if (single_msix)
  1358. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1359. } else if (msi) {
  1360. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1361. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1362. IGU_PF_CONF_ATTN_BIT_EN |
  1363. IGU_PF_CONF_SINGLE_ISR_EN);
  1364. } else {
  1365. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1366. val |= (IGU_PF_CONF_INT_LINE_EN |
  1367. IGU_PF_CONF_ATTN_BIT_EN |
  1368. IGU_PF_CONF_SINGLE_ISR_EN);
  1369. }
  1370. /* Clean previous status - need to configure igu prior to ack*/
  1371. if ((!msix) || single_msix) {
  1372. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1373. bnx2x_ack_int(bp);
  1374. }
  1375. val |= IGU_PF_CONF_FUNC_EN;
  1376. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1377. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1378. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1379. if (val & IGU_PF_CONF_INT_LINE_EN)
  1380. pci_intx(bp->pdev, true);
  1381. barrier();
  1382. /* init leading/trailing edge */
  1383. if (IS_MF(bp)) {
  1384. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1385. if (bp->port.pmf)
  1386. /* enable nig and gpio3 attention */
  1387. val |= 0x1100;
  1388. } else
  1389. val = 0xffff;
  1390. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1391. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1392. /* Make sure that interrupts are indeed enabled from here on */
  1393. mmiowb();
  1394. }
  1395. void bnx2x_int_enable(struct bnx2x *bp)
  1396. {
  1397. if (bp->common.int_block == INT_BLOCK_HC)
  1398. bnx2x_hc_int_enable(bp);
  1399. else
  1400. bnx2x_igu_int_enable(bp);
  1401. }
  1402. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1403. {
  1404. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1405. int i, offset;
  1406. if (disable_hw)
  1407. /* prevent the HW from sending interrupts */
  1408. bnx2x_int_disable(bp);
  1409. /* make sure all ISRs are done */
  1410. if (msix) {
  1411. synchronize_irq(bp->msix_table[0].vector);
  1412. offset = 1;
  1413. if (CNIC_SUPPORT(bp))
  1414. offset++;
  1415. for_each_eth_queue(bp, i)
  1416. synchronize_irq(bp->msix_table[offset++].vector);
  1417. } else
  1418. synchronize_irq(bp->pdev->irq);
  1419. /* make sure sp_task is not running */
  1420. cancel_delayed_work(&bp->sp_task);
  1421. cancel_delayed_work(&bp->period_task);
  1422. flush_workqueue(bnx2x_wq);
  1423. }
  1424. /* fast path */
  1425. /*
  1426. * General service functions
  1427. */
  1428. /* Return true if succeeded to acquire the lock */
  1429. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1430. {
  1431. u32 lock_status;
  1432. u32 resource_bit = (1 << resource);
  1433. int func = BP_FUNC(bp);
  1434. u32 hw_lock_control_reg;
  1435. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1436. "Trying to take a lock on resource %d\n", resource);
  1437. /* Validating that the resource is within range */
  1438. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1439. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1440. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1441. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1442. return false;
  1443. }
  1444. if (func <= 5)
  1445. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1446. else
  1447. hw_lock_control_reg =
  1448. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1449. /* Try to acquire the lock */
  1450. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1451. lock_status = REG_RD(bp, hw_lock_control_reg);
  1452. if (lock_status & resource_bit)
  1453. return true;
  1454. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1455. "Failed to get a lock on resource %d\n", resource);
  1456. return false;
  1457. }
  1458. /**
  1459. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1460. *
  1461. * @bp: driver handle
  1462. *
  1463. * Returns the recovery leader resource id according to the engine this function
  1464. * belongs to. Currently only only 2 engines is supported.
  1465. */
  1466. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1467. {
  1468. if (BP_PATH(bp))
  1469. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1470. else
  1471. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1472. }
  1473. /**
  1474. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1475. *
  1476. * @bp: driver handle
  1477. *
  1478. * Tries to acquire a leader lock for current engine.
  1479. */
  1480. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1481. {
  1482. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1483. }
  1484. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1485. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1486. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1487. {
  1488. /* Set the interrupt occurred bit for the sp-task to recognize it
  1489. * must ack the interrupt and transition according to the IGU
  1490. * state machine.
  1491. */
  1492. atomic_set(&bp->interrupt_occurred, 1);
  1493. /* The sp_task must execute only after this bit
  1494. * is set, otherwise we will get out of sync and miss all
  1495. * further interrupts. Hence, the barrier.
  1496. */
  1497. smp_wmb();
  1498. /* schedule sp_task to workqueue */
  1499. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1500. }
  1501. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1502. {
  1503. struct bnx2x *bp = fp->bp;
  1504. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1505. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1506. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1507. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1508. DP(BNX2X_MSG_SP,
  1509. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1510. fp->index, cid, command, bp->state,
  1511. rr_cqe->ramrod_cqe.ramrod_type);
  1512. /* If cid is within VF range, replace the slowpath object with the
  1513. * one corresponding to this VF
  1514. */
  1515. if (cid >= BNX2X_FIRST_VF_CID &&
  1516. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1517. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1518. switch (command) {
  1519. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1520. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1521. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1522. break;
  1523. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1524. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1525. drv_cmd = BNX2X_Q_CMD_SETUP;
  1526. break;
  1527. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1528. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1529. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1530. break;
  1531. case (RAMROD_CMD_ID_ETH_HALT):
  1532. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1533. drv_cmd = BNX2X_Q_CMD_HALT;
  1534. break;
  1535. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1536. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1537. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1538. break;
  1539. case (RAMROD_CMD_ID_ETH_EMPTY):
  1540. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1541. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1542. break;
  1543. default:
  1544. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1545. command, fp->index);
  1546. return;
  1547. }
  1548. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1549. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1550. /* q_obj->complete_cmd() failure means that this was
  1551. * an unexpected completion.
  1552. *
  1553. * In this case we don't want to increase the bp->spq_left
  1554. * because apparently we haven't sent this command the first
  1555. * place.
  1556. */
  1557. #ifdef BNX2X_STOP_ON_ERROR
  1558. bnx2x_panic();
  1559. #else
  1560. return;
  1561. #endif
  1562. /* SRIOV: reschedule any 'in_progress' operations */
  1563. bnx2x_iov_sp_event(bp, cid, true);
  1564. smp_mb__before_atomic_inc();
  1565. atomic_inc(&bp->cq_spq_left);
  1566. /* push the change in bp->spq_left and towards the memory */
  1567. smp_mb__after_atomic_inc();
  1568. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1569. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1570. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1571. /* if Q update ramrod is completed for last Q in AFEX vif set
  1572. * flow, then ACK MCP at the end
  1573. *
  1574. * mark pending ACK to MCP bit.
  1575. * prevent case that both bits are cleared.
  1576. * At the end of load/unload driver checks that
  1577. * sp_state is cleared, and this order prevents
  1578. * races
  1579. */
  1580. smp_mb__before_clear_bit();
  1581. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1582. wmb();
  1583. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1584. smp_mb__after_clear_bit();
  1585. /* schedule the sp task as mcp ack is required */
  1586. bnx2x_schedule_sp_task(bp);
  1587. }
  1588. return;
  1589. }
  1590. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1591. {
  1592. struct bnx2x *bp = netdev_priv(dev_instance);
  1593. u16 status = bnx2x_ack_int(bp);
  1594. u16 mask;
  1595. int i;
  1596. u8 cos;
  1597. /* Return here if interrupt is shared and it's not for us */
  1598. if (unlikely(status == 0)) {
  1599. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1600. return IRQ_NONE;
  1601. }
  1602. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1603. #ifdef BNX2X_STOP_ON_ERROR
  1604. if (unlikely(bp->panic))
  1605. return IRQ_HANDLED;
  1606. #endif
  1607. for_each_eth_queue(bp, i) {
  1608. struct bnx2x_fastpath *fp = &bp->fp[i];
  1609. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1610. if (status & mask) {
  1611. /* Handle Rx or Tx according to SB id */
  1612. for_each_cos_in_tx_queue(fp, cos)
  1613. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1614. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1615. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1616. status &= ~mask;
  1617. }
  1618. }
  1619. if (CNIC_SUPPORT(bp)) {
  1620. mask = 0x2;
  1621. if (status & (mask | 0x1)) {
  1622. struct cnic_ops *c_ops = NULL;
  1623. rcu_read_lock();
  1624. c_ops = rcu_dereference(bp->cnic_ops);
  1625. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1626. CNIC_DRV_STATE_HANDLES_IRQ))
  1627. c_ops->cnic_handler(bp->cnic_data, NULL);
  1628. rcu_read_unlock();
  1629. status &= ~mask;
  1630. }
  1631. }
  1632. if (unlikely(status & 0x1)) {
  1633. /* schedule sp task to perform default status block work, ack
  1634. * attentions and enable interrupts.
  1635. */
  1636. bnx2x_schedule_sp_task(bp);
  1637. status &= ~0x1;
  1638. if (!status)
  1639. return IRQ_HANDLED;
  1640. }
  1641. if (unlikely(status))
  1642. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1643. status);
  1644. return IRQ_HANDLED;
  1645. }
  1646. /* Link */
  1647. /*
  1648. * General service functions
  1649. */
  1650. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1651. {
  1652. u32 lock_status;
  1653. u32 resource_bit = (1 << resource);
  1654. int func = BP_FUNC(bp);
  1655. u32 hw_lock_control_reg;
  1656. int cnt;
  1657. /* Validating that the resource is within range */
  1658. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1659. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1660. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1661. return -EINVAL;
  1662. }
  1663. if (func <= 5) {
  1664. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1665. } else {
  1666. hw_lock_control_reg =
  1667. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1668. }
  1669. /* Validating that the resource is not already taken */
  1670. lock_status = REG_RD(bp, hw_lock_control_reg);
  1671. if (lock_status & resource_bit) {
  1672. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1673. lock_status, resource_bit);
  1674. return -EEXIST;
  1675. }
  1676. /* Try for 5 second every 5ms */
  1677. for (cnt = 0; cnt < 1000; cnt++) {
  1678. /* Try to acquire the lock */
  1679. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1680. lock_status = REG_RD(bp, hw_lock_control_reg);
  1681. if (lock_status & resource_bit)
  1682. return 0;
  1683. usleep_range(5000, 10000);
  1684. }
  1685. BNX2X_ERR("Timeout\n");
  1686. return -EAGAIN;
  1687. }
  1688. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1689. {
  1690. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1691. }
  1692. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1693. {
  1694. u32 lock_status;
  1695. u32 resource_bit = (1 << resource);
  1696. int func = BP_FUNC(bp);
  1697. u32 hw_lock_control_reg;
  1698. /* Validating that the resource is within range */
  1699. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1700. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1701. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1702. return -EINVAL;
  1703. }
  1704. if (func <= 5) {
  1705. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1706. } else {
  1707. hw_lock_control_reg =
  1708. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1709. }
  1710. /* Validating that the resource is currently taken */
  1711. lock_status = REG_RD(bp, hw_lock_control_reg);
  1712. if (!(lock_status & resource_bit)) {
  1713. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1714. lock_status, resource_bit);
  1715. return -EFAULT;
  1716. }
  1717. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1718. return 0;
  1719. }
  1720. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1721. {
  1722. /* The GPIO should be swapped if swap register is set and active */
  1723. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1724. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1725. int gpio_shift = gpio_num +
  1726. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1727. u32 gpio_mask = (1 << gpio_shift);
  1728. u32 gpio_reg;
  1729. int value;
  1730. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1731. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1732. return -EINVAL;
  1733. }
  1734. /* read GPIO value */
  1735. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1736. /* get the requested pin value */
  1737. if ((gpio_reg & gpio_mask) == gpio_mask)
  1738. value = 1;
  1739. else
  1740. value = 0;
  1741. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1742. return value;
  1743. }
  1744. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1745. {
  1746. /* The GPIO should be swapped if swap register is set and active */
  1747. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1748. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1749. int gpio_shift = gpio_num +
  1750. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1751. u32 gpio_mask = (1 << gpio_shift);
  1752. u32 gpio_reg;
  1753. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1754. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1755. return -EINVAL;
  1756. }
  1757. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1758. /* read GPIO and mask except the float bits */
  1759. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1760. switch (mode) {
  1761. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1762. DP(NETIF_MSG_LINK,
  1763. "Set GPIO %d (shift %d) -> output low\n",
  1764. gpio_num, gpio_shift);
  1765. /* clear FLOAT and set CLR */
  1766. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1767. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1768. break;
  1769. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1770. DP(NETIF_MSG_LINK,
  1771. "Set GPIO %d (shift %d) -> output high\n",
  1772. gpio_num, gpio_shift);
  1773. /* clear FLOAT and set SET */
  1774. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1775. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1776. break;
  1777. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1778. DP(NETIF_MSG_LINK,
  1779. "Set GPIO %d (shift %d) -> input\n",
  1780. gpio_num, gpio_shift);
  1781. /* set FLOAT */
  1782. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1783. break;
  1784. default:
  1785. break;
  1786. }
  1787. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1788. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1789. return 0;
  1790. }
  1791. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1792. {
  1793. u32 gpio_reg = 0;
  1794. int rc = 0;
  1795. /* Any port swapping should be handled by caller. */
  1796. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1797. /* read GPIO and mask except the float bits */
  1798. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1799. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1800. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1801. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1802. switch (mode) {
  1803. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1804. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1805. /* set CLR */
  1806. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1807. break;
  1808. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1809. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1810. /* set SET */
  1811. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1812. break;
  1813. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1814. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1815. /* set FLOAT */
  1816. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1817. break;
  1818. default:
  1819. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1820. rc = -EINVAL;
  1821. break;
  1822. }
  1823. if (rc == 0)
  1824. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1825. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1826. return rc;
  1827. }
  1828. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1829. {
  1830. /* The GPIO should be swapped if swap register is set and active */
  1831. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1832. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1833. int gpio_shift = gpio_num +
  1834. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1835. u32 gpio_mask = (1 << gpio_shift);
  1836. u32 gpio_reg;
  1837. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1838. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1839. return -EINVAL;
  1840. }
  1841. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1842. /* read GPIO int */
  1843. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1844. switch (mode) {
  1845. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1846. DP(NETIF_MSG_LINK,
  1847. "Clear GPIO INT %d (shift %d) -> output low\n",
  1848. gpio_num, gpio_shift);
  1849. /* clear SET and set CLR */
  1850. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1851. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1852. break;
  1853. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1854. DP(NETIF_MSG_LINK,
  1855. "Set GPIO INT %d (shift %d) -> output high\n",
  1856. gpio_num, gpio_shift);
  1857. /* clear CLR and set SET */
  1858. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1859. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1860. break;
  1861. default:
  1862. break;
  1863. }
  1864. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1865. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1866. return 0;
  1867. }
  1868. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1869. {
  1870. u32 spio_reg;
  1871. /* Only 2 SPIOs are configurable */
  1872. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1873. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1874. return -EINVAL;
  1875. }
  1876. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1877. /* read SPIO and mask except the float bits */
  1878. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1879. switch (mode) {
  1880. case MISC_SPIO_OUTPUT_LOW:
  1881. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1882. /* clear FLOAT and set CLR */
  1883. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1884. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1885. break;
  1886. case MISC_SPIO_OUTPUT_HIGH:
  1887. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1888. /* clear FLOAT and set SET */
  1889. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1890. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1891. break;
  1892. case MISC_SPIO_INPUT_HI_Z:
  1893. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1894. /* set FLOAT */
  1895. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1896. break;
  1897. default:
  1898. break;
  1899. }
  1900. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1901. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1902. return 0;
  1903. }
  1904. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1905. {
  1906. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1907. switch (bp->link_vars.ieee_fc &
  1908. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1909. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1910. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1911. ADVERTISED_Pause);
  1912. break;
  1913. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1914. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1915. ADVERTISED_Pause);
  1916. break;
  1917. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1918. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1919. break;
  1920. default:
  1921. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1922. ADVERTISED_Pause);
  1923. break;
  1924. }
  1925. }
  1926. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1927. {
  1928. /* Initialize link parameters structure variables
  1929. * It is recommended to turn off RX FC for jumbo frames
  1930. * for better performance
  1931. */
  1932. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1933. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1934. else
  1935. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1936. }
  1937. static void bnx2x_init_dropless_fc(struct bnx2x *bp)
  1938. {
  1939. u32 pause_enabled = 0;
  1940. if (!CHIP_IS_E1(bp) && bp->dropless_fc && bp->link_vars.link_up) {
  1941. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1942. pause_enabled = 1;
  1943. REG_WR(bp, BAR_USTRORM_INTMEM +
  1944. USTORM_ETH_PAUSE_ENABLED_OFFSET(BP_PORT(bp)),
  1945. pause_enabled);
  1946. }
  1947. DP(NETIF_MSG_IFUP | NETIF_MSG_LINK, "dropless_fc is %s\n",
  1948. pause_enabled ? "enabled" : "disabled");
  1949. }
  1950. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1951. {
  1952. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1953. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1954. if (!BP_NOMCP(bp)) {
  1955. bnx2x_set_requested_fc(bp);
  1956. bnx2x_acquire_phy_lock(bp);
  1957. if (load_mode == LOAD_DIAG) {
  1958. struct link_params *lp = &bp->link_params;
  1959. lp->loopback_mode = LOOPBACK_XGXS;
  1960. /* do PHY loopback at 10G speed, if possible */
  1961. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1962. if (lp->speed_cap_mask[cfx_idx] &
  1963. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1964. lp->req_line_speed[cfx_idx] =
  1965. SPEED_10000;
  1966. else
  1967. lp->req_line_speed[cfx_idx] =
  1968. SPEED_1000;
  1969. }
  1970. }
  1971. if (load_mode == LOAD_LOOPBACK_EXT) {
  1972. struct link_params *lp = &bp->link_params;
  1973. lp->loopback_mode = LOOPBACK_EXT;
  1974. }
  1975. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1976. bnx2x_release_phy_lock(bp);
  1977. bnx2x_init_dropless_fc(bp);
  1978. bnx2x_calc_fc_adv(bp);
  1979. if (bp->link_vars.link_up) {
  1980. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1981. bnx2x_link_report(bp);
  1982. }
  1983. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1984. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1985. return rc;
  1986. }
  1987. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1988. return -EINVAL;
  1989. }
  1990. void bnx2x_link_set(struct bnx2x *bp)
  1991. {
  1992. if (!BP_NOMCP(bp)) {
  1993. bnx2x_acquire_phy_lock(bp);
  1994. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1995. bnx2x_release_phy_lock(bp);
  1996. bnx2x_init_dropless_fc(bp);
  1997. bnx2x_calc_fc_adv(bp);
  1998. } else
  1999. BNX2X_ERR("Bootcode is missing - can not set link\n");
  2000. }
  2001. static void bnx2x__link_reset(struct bnx2x *bp)
  2002. {
  2003. if (!BP_NOMCP(bp)) {
  2004. bnx2x_acquire_phy_lock(bp);
  2005. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  2006. bnx2x_release_phy_lock(bp);
  2007. } else
  2008. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  2009. }
  2010. void bnx2x_force_link_reset(struct bnx2x *bp)
  2011. {
  2012. bnx2x_acquire_phy_lock(bp);
  2013. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  2014. bnx2x_release_phy_lock(bp);
  2015. }
  2016. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  2017. {
  2018. u8 rc = 0;
  2019. if (!BP_NOMCP(bp)) {
  2020. bnx2x_acquire_phy_lock(bp);
  2021. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  2022. is_serdes);
  2023. bnx2x_release_phy_lock(bp);
  2024. } else
  2025. BNX2X_ERR("Bootcode is missing - can not test link\n");
  2026. return rc;
  2027. }
  2028. /* Calculates the sum of vn_min_rates.
  2029. It's needed for further normalizing of the min_rates.
  2030. Returns:
  2031. sum of vn_min_rates.
  2032. or
  2033. 0 - if all the min_rates are 0.
  2034. In the later case fairness algorithm should be deactivated.
  2035. If not all min_rates are zero then those that are zeroes will be set to 1.
  2036. */
  2037. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2038. struct cmng_init_input *input)
  2039. {
  2040. int all_zero = 1;
  2041. int vn;
  2042. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2043. u32 vn_cfg = bp->mf_config[vn];
  2044. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2045. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2046. /* Skip hidden vns */
  2047. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2048. vn_min_rate = 0;
  2049. /* If min rate is zero - set it to 1 */
  2050. else if (!vn_min_rate)
  2051. vn_min_rate = DEF_MIN_RATE;
  2052. else
  2053. all_zero = 0;
  2054. input->vnic_min_rate[vn] = vn_min_rate;
  2055. }
  2056. /* if ETS or all min rates are zeros - disable fairness */
  2057. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2058. input->flags.cmng_enables &=
  2059. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2060. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2061. } else if (all_zero) {
  2062. input->flags.cmng_enables &=
  2063. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2064. DP(NETIF_MSG_IFUP,
  2065. "All MIN values are zeroes fairness will be disabled\n");
  2066. } else
  2067. input->flags.cmng_enables |=
  2068. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2069. }
  2070. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2071. struct cmng_init_input *input)
  2072. {
  2073. u16 vn_max_rate;
  2074. u32 vn_cfg = bp->mf_config[vn];
  2075. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2076. vn_max_rate = 0;
  2077. else {
  2078. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2079. if (IS_MF_SI(bp)) {
  2080. /* maxCfg in percents of linkspeed */
  2081. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2082. } else /* SD modes */
  2083. /* maxCfg is absolute in 100Mb units */
  2084. vn_max_rate = maxCfg * 100;
  2085. }
  2086. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2087. input->vnic_max_rate[vn] = vn_max_rate;
  2088. }
  2089. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2090. {
  2091. if (CHIP_REV_IS_SLOW(bp))
  2092. return CMNG_FNS_NONE;
  2093. if (IS_MF(bp))
  2094. return CMNG_FNS_MINMAX;
  2095. return CMNG_FNS_NONE;
  2096. }
  2097. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2098. {
  2099. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2100. if (BP_NOMCP(bp))
  2101. return; /* what should be the default value in this case */
  2102. /* For 2 port configuration the absolute function number formula
  2103. * is:
  2104. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2105. *
  2106. * and there are 4 functions per port
  2107. *
  2108. * For 4 port configuration it is
  2109. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2110. *
  2111. * and there are 2 functions per port
  2112. */
  2113. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2114. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2115. if (func >= E1H_FUNC_MAX)
  2116. break;
  2117. bp->mf_config[vn] =
  2118. MF_CFG_RD(bp, func_mf_config[func].config);
  2119. }
  2120. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2121. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2122. bp->flags |= MF_FUNC_DIS;
  2123. } else {
  2124. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2125. bp->flags &= ~MF_FUNC_DIS;
  2126. }
  2127. }
  2128. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2129. {
  2130. struct cmng_init_input input;
  2131. memset(&input, 0, sizeof(struct cmng_init_input));
  2132. input.port_rate = bp->link_vars.line_speed;
  2133. if (cmng_type == CMNG_FNS_MINMAX && input.port_rate) {
  2134. int vn;
  2135. /* read mf conf from shmem */
  2136. if (read_cfg)
  2137. bnx2x_read_mf_cfg(bp);
  2138. /* vn_weight_sum and enable fairness if not 0 */
  2139. bnx2x_calc_vn_min(bp, &input);
  2140. /* calculate and set min-max rate for each vn */
  2141. if (bp->port.pmf)
  2142. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2143. bnx2x_calc_vn_max(bp, vn, &input);
  2144. /* always enable rate shaping and fairness */
  2145. input.flags.cmng_enables |=
  2146. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2147. bnx2x_init_cmng(&input, &bp->cmng);
  2148. return;
  2149. }
  2150. /* rate shaping and fairness are disabled */
  2151. DP(NETIF_MSG_IFUP,
  2152. "rate shaping and fairness are disabled\n");
  2153. }
  2154. static void storm_memset_cmng(struct bnx2x *bp,
  2155. struct cmng_init *cmng,
  2156. u8 port)
  2157. {
  2158. int vn;
  2159. size_t size = sizeof(struct cmng_struct_per_port);
  2160. u32 addr = BAR_XSTRORM_INTMEM +
  2161. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2162. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2163. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2164. int func = func_by_vn(bp, vn);
  2165. addr = BAR_XSTRORM_INTMEM +
  2166. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2167. size = sizeof(struct rate_shaping_vars_per_vn);
  2168. __storm_memset_struct(bp, addr, size,
  2169. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2170. addr = BAR_XSTRORM_INTMEM +
  2171. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2172. size = sizeof(struct fairness_vars_per_vn);
  2173. __storm_memset_struct(bp, addr, size,
  2174. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2175. }
  2176. }
  2177. /* init cmng mode in HW according to local configuration */
  2178. void bnx2x_set_local_cmng(struct bnx2x *bp)
  2179. {
  2180. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2181. if (cmng_fns != CMNG_FNS_NONE) {
  2182. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2183. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2184. } else {
  2185. /* rate shaping and fairness are disabled */
  2186. DP(NETIF_MSG_IFUP,
  2187. "single function mode without fairness\n");
  2188. }
  2189. }
  2190. /* This function is called upon link interrupt */
  2191. static void bnx2x_link_attn(struct bnx2x *bp)
  2192. {
  2193. /* Make sure that we are synced with the current statistics */
  2194. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2195. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2196. bnx2x_init_dropless_fc(bp);
  2197. if (bp->link_vars.link_up) {
  2198. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2199. struct host_port_stats *pstats;
  2200. pstats = bnx2x_sp(bp, port_stats);
  2201. /* reset old mac stats */
  2202. memset(&(pstats->mac_stx[0]), 0,
  2203. sizeof(struct mac_stx));
  2204. }
  2205. if (bp->state == BNX2X_STATE_OPEN)
  2206. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2207. }
  2208. if (bp->link_vars.link_up && bp->link_vars.line_speed)
  2209. bnx2x_set_local_cmng(bp);
  2210. __bnx2x_link_report(bp);
  2211. if (IS_MF(bp))
  2212. bnx2x_link_sync_notify(bp);
  2213. }
  2214. void bnx2x__link_status_update(struct bnx2x *bp)
  2215. {
  2216. if (bp->state != BNX2X_STATE_OPEN)
  2217. return;
  2218. /* read updated dcb configuration */
  2219. if (IS_PF(bp)) {
  2220. bnx2x_dcbx_pmf_update(bp);
  2221. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2222. if (bp->link_vars.link_up)
  2223. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2224. else
  2225. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2226. /* indicate link status */
  2227. bnx2x_link_report(bp);
  2228. } else { /* VF */
  2229. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2230. SUPPORTED_10baseT_Full |
  2231. SUPPORTED_100baseT_Half |
  2232. SUPPORTED_100baseT_Full |
  2233. SUPPORTED_1000baseT_Full |
  2234. SUPPORTED_2500baseX_Full |
  2235. SUPPORTED_10000baseT_Full |
  2236. SUPPORTED_TP |
  2237. SUPPORTED_FIBRE |
  2238. SUPPORTED_Autoneg |
  2239. SUPPORTED_Pause |
  2240. SUPPORTED_Asym_Pause);
  2241. bp->port.advertising[0] = bp->port.supported[0];
  2242. bp->link_params.bp = bp;
  2243. bp->link_params.port = BP_PORT(bp);
  2244. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2245. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2246. bp->link_params.req_line_speed[0] = SPEED_10000;
  2247. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2248. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2249. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2250. bp->link_vars.line_speed = SPEED_10000;
  2251. bp->link_vars.link_status =
  2252. (LINK_STATUS_LINK_UP |
  2253. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2254. bp->link_vars.link_up = 1;
  2255. bp->link_vars.duplex = DUPLEX_FULL;
  2256. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2257. __bnx2x_link_report(bp);
  2258. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2259. }
  2260. }
  2261. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2262. u16 vlan_val, u8 allowed_prio)
  2263. {
  2264. struct bnx2x_func_state_params func_params = {NULL};
  2265. struct bnx2x_func_afex_update_params *f_update_params =
  2266. &func_params.params.afex_update;
  2267. func_params.f_obj = &bp->func_obj;
  2268. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2269. /* no need to wait for RAMROD completion, so don't
  2270. * set RAMROD_COMP_WAIT flag
  2271. */
  2272. f_update_params->vif_id = vifid;
  2273. f_update_params->afex_default_vlan = vlan_val;
  2274. f_update_params->allowed_priorities = allowed_prio;
  2275. /* if ramrod can not be sent, response to MCP immediately */
  2276. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2277. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2278. return 0;
  2279. }
  2280. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2281. u16 vif_index, u8 func_bit_map)
  2282. {
  2283. struct bnx2x_func_state_params func_params = {NULL};
  2284. struct bnx2x_func_afex_viflists_params *update_params =
  2285. &func_params.params.afex_viflists;
  2286. int rc;
  2287. u32 drv_msg_code;
  2288. /* validate only LIST_SET and LIST_GET are received from switch */
  2289. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2290. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2291. cmd_type);
  2292. func_params.f_obj = &bp->func_obj;
  2293. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2294. /* set parameters according to cmd_type */
  2295. update_params->afex_vif_list_command = cmd_type;
  2296. update_params->vif_list_index = vif_index;
  2297. update_params->func_bit_map =
  2298. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2299. update_params->func_to_clear = 0;
  2300. drv_msg_code =
  2301. (cmd_type == VIF_LIST_RULE_GET) ?
  2302. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2303. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2304. /* if ramrod can not be sent, respond to MCP immediately for
  2305. * SET and GET requests (other are not triggered from MCP)
  2306. */
  2307. rc = bnx2x_func_state_change(bp, &func_params);
  2308. if (rc < 0)
  2309. bnx2x_fw_command(bp, drv_msg_code, 0);
  2310. return 0;
  2311. }
  2312. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2313. {
  2314. struct afex_stats afex_stats;
  2315. u32 func = BP_ABS_FUNC(bp);
  2316. u32 mf_config;
  2317. u16 vlan_val;
  2318. u32 vlan_prio;
  2319. u16 vif_id;
  2320. u8 allowed_prio;
  2321. u8 vlan_mode;
  2322. u32 addr_to_write, vifid, addrs, stats_type, i;
  2323. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2324. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2325. DP(BNX2X_MSG_MCP,
  2326. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2327. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2328. }
  2329. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2330. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2331. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2332. DP(BNX2X_MSG_MCP,
  2333. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2334. vifid, addrs);
  2335. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2336. addrs);
  2337. }
  2338. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2339. addr_to_write = SHMEM2_RD(bp,
  2340. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2341. stats_type = SHMEM2_RD(bp,
  2342. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2343. DP(BNX2X_MSG_MCP,
  2344. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2345. addr_to_write);
  2346. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2347. /* write response to scratchpad, for MCP */
  2348. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2349. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2350. *(((u32 *)(&afex_stats))+i));
  2351. /* send ack message to MCP */
  2352. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2353. }
  2354. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2355. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2356. bp->mf_config[BP_VN(bp)] = mf_config;
  2357. DP(BNX2X_MSG_MCP,
  2358. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2359. mf_config);
  2360. /* if VIF_SET is "enabled" */
  2361. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2362. /* set rate limit directly to internal RAM */
  2363. struct cmng_init_input cmng_input;
  2364. struct rate_shaping_vars_per_vn m_rs_vn;
  2365. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2366. u32 addr = BAR_XSTRORM_INTMEM +
  2367. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2368. bp->mf_config[BP_VN(bp)] = mf_config;
  2369. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2370. m_rs_vn.vn_counter.rate =
  2371. cmng_input.vnic_max_rate[BP_VN(bp)];
  2372. m_rs_vn.vn_counter.quota =
  2373. (m_rs_vn.vn_counter.rate *
  2374. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2375. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2376. /* read relevant values from mf_cfg struct in shmem */
  2377. vif_id =
  2378. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2379. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2380. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2381. vlan_val =
  2382. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2383. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2384. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2385. vlan_prio = (mf_config &
  2386. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2387. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2388. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2389. vlan_mode =
  2390. (MF_CFG_RD(bp,
  2391. func_mf_config[func].afex_config) &
  2392. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2393. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2394. allowed_prio =
  2395. (MF_CFG_RD(bp,
  2396. func_mf_config[func].afex_config) &
  2397. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2398. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2399. /* send ramrod to FW, return in case of failure */
  2400. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2401. allowed_prio))
  2402. return;
  2403. bp->afex_def_vlan_tag = vlan_val;
  2404. bp->afex_vlan_mode = vlan_mode;
  2405. } else {
  2406. /* notify link down because BP->flags is disabled */
  2407. bnx2x_link_report(bp);
  2408. /* send INVALID VIF ramrod to FW */
  2409. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2410. /* Reset the default afex VLAN */
  2411. bp->afex_def_vlan_tag = -1;
  2412. }
  2413. }
  2414. }
  2415. static void bnx2x_pmf_update(struct bnx2x *bp)
  2416. {
  2417. int port = BP_PORT(bp);
  2418. u32 val;
  2419. bp->port.pmf = 1;
  2420. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2421. /*
  2422. * We need the mb() to ensure the ordering between the writing to
  2423. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2424. */
  2425. smp_mb();
  2426. /* queue a periodic task */
  2427. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2428. bnx2x_dcbx_pmf_update(bp);
  2429. /* enable nig attention */
  2430. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2431. if (bp->common.int_block == INT_BLOCK_HC) {
  2432. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2433. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2434. } else if (!CHIP_IS_E1x(bp)) {
  2435. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2436. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2437. }
  2438. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2439. }
  2440. /* end of Link */
  2441. /* slow path */
  2442. /*
  2443. * General service functions
  2444. */
  2445. /* send the MCP a request, block until there is a reply */
  2446. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2447. {
  2448. int mb_idx = BP_FW_MB_IDX(bp);
  2449. u32 seq;
  2450. u32 rc = 0;
  2451. u32 cnt = 1;
  2452. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2453. mutex_lock(&bp->fw_mb_mutex);
  2454. seq = ++bp->fw_seq;
  2455. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2456. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2457. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2458. (command | seq), param);
  2459. do {
  2460. /* let the FW do it's magic ... */
  2461. msleep(delay);
  2462. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2463. /* Give the FW up to 5 second (500*10ms) */
  2464. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2465. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2466. cnt*delay, rc, seq);
  2467. /* is this a reply to our command? */
  2468. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2469. rc &= FW_MSG_CODE_MASK;
  2470. else {
  2471. /* FW BUG! */
  2472. BNX2X_ERR("FW failed to respond!\n");
  2473. bnx2x_fw_dump(bp);
  2474. rc = 0;
  2475. }
  2476. mutex_unlock(&bp->fw_mb_mutex);
  2477. return rc;
  2478. }
  2479. static void storm_memset_func_cfg(struct bnx2x *bp,
  2480. struct tstorm_eth_function_common_config *tcfg,
  2481. u16 abs_fid)
  2482. {
  2483. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2484. u32 addr = BAR_TSTRORM_INTMEM +
  2485. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2486. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2487. }
  2488. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2489. {
  2490. if (CHIP_IS_E1x(bp)) {
  2491. struct tstorm_eth_function_common_config tcfg = {0};
  2492. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2493. }
  2494. /* Enable the function in the FW */
  2495. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2496. storm_memset_func_en(bp, p->func_id, 1);
  2497. /* spq */
  2498. if (p->func_flgs & FUNC_FLG_SPQ) {
  2499. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2500. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2501. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2502. }
  2503. }
  2504. /**
  2505. * bnx2x_get_common_flags - Return common flags
  2506. *
  2507. * @bp device handle
  2508. * @fp queue handle
  2509. * @zero_stats TRUE if statistics zeroing is needed
  2510. *
  2511. * Return the flags that are common for the Tx-only and not normal connections.
  2512. */
  2513. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2514. struct bnx2x_fastpath *fp,
  2515. bool zero_stats)
  2516. {
  2517. unsigned long flags = 0;
  2518. /* PF driver will always initialize the Queue to an ACTIVE state */
  2519. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2520. /* tx only connections collect statistics (on the same index as the
  2521. * parent connection). The statistics are zeroed when the parent
  2522. * connection is initialized.
  2523. */
  2524. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2525. if (zero_stats)
  2526. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2527. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2528. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2529. #ifdef BNX2X_STOP_ON_ERROR
  2530. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2531. #endif
  2532. return flags;
  2533. }
  2534. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2535. struct bnx2x_fastpath *fp,
  2536. bool leading)
  2537. {
  2538. unsigned long flags = 0;
  2539. /* calculate other queue flags */
  2540. if (IS_MF_SD(bp))
  2541. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2542. if (IS_FCOE_FP(fp)) {
  2543. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2544. /* For FCoE - force usage of default priority (for afex) */
  2545. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2546. }
  2547. if (!fp->disable_tpa) {
  2548. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2549. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2550. if (fp->mode == TPA_MODE_GRO)
  2551. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2552. }
  2553. if (leading) {
  2554. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2555. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2556. }
  2557. /* Always set HW VLAN stripping */
  2558. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2559. /* configure silent vlan removal */
  2560. if (IS_MF_AFEX(bp))
  2561. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2562. return flags | bnx2x_get_common_flags(bp, fp, true);
  2563. }
  2564. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2565. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2566. u8 cos)
  2567. {
  2568. gen_init->stat_id = bnx2x_stats_id(fp);
  2569. gen_init->spcl_id = fp->cl_id;
  2570. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2571. if (IS_FCOE_FP(fp))
  2572. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2573. else
  2574. gen_init->mtu = bp->dev->mtu;
  2575. gen_init->cos = cos;
  2576. }
  2577. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2578. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2579. struct bnx2x_rxq_setup_params *rxq_init)
  2580. {
  2581. u8 max_sge = 0;
  2582. u16 sge_sz = 0;
  2583. u16 tpa_agg_size = 0;
  2584. if (!fp->disable_tpa) {
  2585. pause->sge_th_lo = SGE_TH_LO(bp);
  2586. pause->sge_th_hi = SGE_TH_HI(bp);
  2587. /* validate SGE ring has enough to cross high threshold */
  2588. WARN_ON(bp->dropless_fc &&
  2589. pause->sge_th_hi + FW_PREFETCH_CNT >
  2590. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2591. tpa_agg_size = TPA_AGG_SIZE;
  2592. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2593. SGE_PAGE_SHIFT;
  2594. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2595. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2596. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2597. }
  2598. /* pause - not for e1 */
  2599. if (!CHIP_IS_E1(bp)) {
  2600. pause->bd_th_lo = BD_TH_LO(bp);
  2601. pause->bd_th_hi = BD_TH_HI(bp);
  2602. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2603. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2604. /*
  2605. * validate that rings have enough entries to cross
  2606. * high thresholds
  2607. */
  2608. WARN_ON(bp->dropless_fc &&
  2609. pause->bd_th_hi + FW_PREFETCH_CNT >
  2610. bp->rx_ring_size);
  2611. WARN_ON(bp->dropless_fc &&
  2612. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2613. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2614. pause->pri_map = 1;
  2615. }
  2616. /* rxq setup */
  2617. rxq_init->dscr_map = fp->rx_desc_mapping;
  2618. rxq_init->sge_map = fp->rx_sge_mapping;
  2619. rxq_init->rcq_map = fp->rx_comp_mapping;
  2620. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2621. /* This should be a maximum number of data bytes that may be
  2622. * placed on the BD (not including paddings).
  2623. */
  2624. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2625. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2626. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2627. rxq_init->tpa_agg_sz = tpa_agg_size;
  2628. rxq_init->sge_buf_sz = sge_sz;
  2629. rxq_init->max_sges_pkt = max_sge;
  2630. rxq_init->rss_engine_id = BP_FUNC(bp);
  2631. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2632. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2633. *
  2634. * For PF Clients it should be the maximum available number.
  2635. * VF driver(s) may want to define it to a smaller value.
  2636. */
  2637. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2638. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2639. rxq_init->fw_sb_id = fp->fw_sb_id;
  2640. if (IS_FCOE_FP(fp))
  2641. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2642. else
  2643. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2644. /* configure silent vlan removal
  2645. * if multi function mode is afex, then mask default vlan
  2646. */
  2647. if (IS_MF_AFEX(bp)) {
  2648. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2649. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2650. }
  2651. }
  2652. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2653. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2654. u8 cos)
  2655. {
  2656. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2657. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2658. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2659. txq_init->fw_sb_id = fp->fw_sb_id;
  2660. /*
  2661. * set the tss leading client id for TX classification ==
  2662. * leading RSS client id
  2663. */
  2664. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2665. if (IS_FCOE_FP(fp)) {
  2666. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2667. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2668. }
  2669. }
  2670. static void bnx2x_pf_init(struct bnx2x *bp)
  2671. {
  2672. struct bnx2x_func_init_params func_init = {0};
  2673. struct event_ring_data eq_data = { {0} };
  2674. u16 flags;
  2675. if (!CHIP_IS_E1x(bp)) {
  2676. /* reset IGU PF statistics: MSIX + ATTN */
  2677. /* PF */
  2678. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2679. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2680. (CHIP_MODE_IS_4_PORT(bp) ?
  2681. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2682. /* ATTN */
  2683. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2684. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2685. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2686. (CHIP_MODE_IS_4_PORT(bp) ?
  2687. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2688. }
  2689. /* function setup flags */
  2690. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2691. /* This flag is relevant for E1x only.
  2692. * E2 doesn't have a TPA configuration in a function level.
  2693. */
  2694. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2695. func_init.func_flgs = flags;
  2696. func_init.pf_id = BP_FUNC(bp);
  2697. func_init.func_id = BP_FUNC(bp);
  2698. func_init.spq_map = bp->spq_mapping;
  2699. func_init.spq_prod = bp->spq_prod_idx;
  2700. bnx2x_func_init(bp, &func_init);
  2701. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2702. /*
  2703. * Congestion management values depend on the link rate
  2704. * There is no active link so initial link rate is set to 10 Gbps.
  2705. * When the link comes up The congestion management values are
  2706. * re-calculated according to the actual link rate.
  2707. */
  2708. bp->link_vars.line_speed = SPEED_10000;
  2709. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2710. /* Only the PMF sets the HW */
  2711. if (bp->port.pmf)
  2712. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2713. /* init Event Queue - PCI bus guarantees correct endianity*/
  2714. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2715. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2716. eq_data.producer = bp->eq_prod;
  2717. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2718. eq_data.sb_id = DEF_SB_ID;
  2719. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2720. }
  2721. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2722. {
  2723. int port = BP_PORT(bp);
  2724. bnx2x_tx_disable(bp);
  2725. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2726. }
  2727. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2728. {
  2729. int port = BP_PORT(bp);
  2730. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2731. /* Tx queue should be only re-enabled */
  2732. netif_tx_wake_all_queues(bp->dev);
  2733. /*
  2734. * Should not call netif_carrier_on since it will be called if the link
  2735. * is up when checking for link state
  2736. */
  2737. }
  2738. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2739. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2740. {
  2741. struct eth_stats_info *ether_stat =
  2742. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2743. struct bnx2x_vlan_mac_obj *mac_obj =
  2744. &bp->sp_objs->mac_obj;
  2745. int i;
  2746. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2747. ETH_STAT_INFO_VERSION_LEN);
  2748. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2749. * mac_local field in ether_stat struct. The base address is offset by 2
  2750. * bytes to account for the field being 8 bytes but a mac address is
  2751. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2752. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2753. * allocated by the ether_stat struct, so the macs will land in their
  2754. * proper positions.
  2755. */
  2756. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2757. memset(ether_stat->mac_local + i, 0,
  2758. sizeof(ether_stat->mac_local[0]));
  2759. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2760. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2761. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2762. ETH_ALEN);
  2763. ether_stat->mtu_size = bp->dev->mtu;
  2764. if (bp->dev->features & NETIF_F_RXCSUM)
  2765. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2766. if (bp->dev->features & NETIF_F_TSO)
  2767. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2768. ether_stat->feature_flags |= bp->common.boot_mode;
  2769. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2770. ether_stat->txq_size = bp->tx_ring_size;
  2771. ether_stat->rxq_size = bp->rx_ring_size;
  2772. }
  2773. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2774. {
  2775. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2776. struct fcoe_stats_info *fcoe_stat =
  2777. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2778. if (!CNIC_LOADED(bp))
  2779. return;
  2780. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2781. fcoe_stat->qos_priority =
  2782. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2783. /* insert FCoE stats from ramrod response */
  2784. if (!NO_FCOE(bp)) {
  2785. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2786. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2787. tstorm_queue_statistics;
  2788. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2789. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2790. xstorm_queue_statistics;
  2791. struct fcoe_statistics_params *fw_fcoe_stat =
  2792. &bp->fw_stats_data->fcoe;
  2793. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2794. fcoe_stat->rx_bytes_lo,
  2795. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2796. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2797. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2798. fcoe_stat->rx_bytes_lo,
  2799. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2800. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2801. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2802. fcoe_stat->rx_bytes_lo,
  2803. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2804. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2805. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2806. fcoe_stat->rx_bytes_lo,
  2807. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2808. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2809. fcoe_stat->rx_frames_lo,
  2810. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2811. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2812. fcoe_stat->rx_frames_lo,
  2813. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2814. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2815. fcoe_stat->rx_frames_lo,
  2816. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2817. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2818. fcoe_stat->rx_frames_lo,
  2819. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2820. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2821. fcoe_stat->tx_bytes_lo,
  2822. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2823. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2824. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2825. fcoe_stat->tx_bytes_lo,
  2826. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2827. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2828. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2829. fcoe_stat->tx_bytes_lo,
  2830. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2831. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2832. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2833. fcoe_stat->tx_bytes_lo,
  2834. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2835. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2836. fcoe_stat->tx_frames_lo,
  2837. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2838. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2839. fcoe_stat->tx_frames_lo,
  2840. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2841. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2842. fcoe_stat->tx_frames_lo,
  2843. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2844. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2845. fcoe_stat->tx_frames_lo,
  2846. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2847. }
  2848. /* ask L5 driver to add data to the struct */
  2849. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2850. }
  2851. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2852. {
  2853. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2854. struct iscsi_stats_info *iscsi_stat =
  2855. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2856. if (!CNIC_LOADED(bp))
  2857. return;
  2858. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2859. ETH_ALEN);
  2860. iscsi_stat->qos_priority =
  2861. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2862. /* ask L5 driver to add data to the struct */
  2863. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2864. }
  2865. /* called due to MCP event (on pmf):
  2866. * reread new bandwidth configuration
  2867. * configure FW
  2868. * notify others function about the change
  2869. */
  2870. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2871. {
  2872. if (bp->link_vars.link_up) {
  2873. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2874. bnx2x_link_sync_notify(bp);
  2875. }
  2876. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2877. }
  2878. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2879. {
  2880. bnx2x_config_mf_bw(bp);
  2881. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2882. }
  2883. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2884. {
  2885. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2886. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2887. }
  2888. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2889. {
  2890. enum drv_info_opcode op_code;
  2891. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2892. /* if drv_info version supported by MFW doesn't match - send NACK */
  2893. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2894. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2895. return;
  2896. }
  2897. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2898. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2899. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2900. sizeof(union drv_info_to_mcp));
  2901. switch (op_code) {
  2902. case ETH_STATS_OPCODE:
  2903. bnx2x_drv_info_ether_stat(bp);
  2904. break;
  2905. case FCOE_STATS_OPCODE:
  2906. bnx2x_drv_info_fcoe_stat(bp);
  2907. break;
  2908. case ISCSI_STATS_OPCODE:
  2909. bnx2x_drv_info_iscsi_stat(bp);
  2910. break;
  2911. default:
  2912. /* if op code isn't supported - send NACK */
  2913. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2914. return;
  2915. }
  2916. /* if we got drv_info attn from MFW then these fields are defined in
  2917. * shmem2 for sure
  2918. */
  2919. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2920. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2921. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2922. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2923. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2924. }
  2925. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2926. {
  2927. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2928. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2929. /*
  2930. * This is the only place besides the function initialization
  2931. * where the bp->flags can change so it is done without any
  2932. * locks
  2933. */
  2934. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2935. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2936. bp->flags |= MF_FUNC_DIS;
  2937. bnx2x_e1h_disable(bp);
  2938. } else {
  2939. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2940. bp->flags &= ~MF_FUNC_DIS;
  2941. bnx2x_e1h_enable(bp);
  2942. }
  2943. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2944. }
  2945. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2946. bnx2x_config_mf_bw(bp);
  2947. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2948. }
  2949. /* Report results to MCP */
  2950. if (dcc_event)
  2951. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2952. else
  2953. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2954. }
  2955. /* must be called under the spq lock */
  2956. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2957. {
  2958. struct eth_spe *next_spe = bp->spq_prod_bd;
  2959. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2960. bp->spq_prod_bd = bp->spq;
  2961. bp->spq_prod_idx = 0;
  2962. DP(BNX2X_MSG_SP, "end of spq\n");
  2963. } else {
  2964. bp->spq_prod_bd++;
  2965. bp->spq_prod_idx++;
  2966. }
  2967. return next_spe;
  2968. }
  2969. /* must be called under the spq lock */
  2970. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2971. {
  2972. int func = BP_FUNC(bp);
  2973. /*
  2974. * Make sure that BD data is updated before writing the producer:
  2975. * BD data is written to the memory, the producer is read from the
  2976. * memory, thus we need a full memory barrier to ensure the ordering.
  2977. */
  2978. mb();
  2979. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2980. bp->spq_prod_idx);
  2981. mmiowb();
  2982. }
  2983. /**
  2984. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2985. *
  2986. * @cmd: command to check
  2987. * @cmd_type: command type
  2988. */
  2989. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2990. {
  2991. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2992. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2993. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2994. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2995. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2996. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2997. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2998. return true;
  2999. else
  3000. return false;
  3001. }
  3002. /**
  3003. * bnx2x_sp_post - place a single command on an SP ring
  3004. *
  3005. * @bp: driver handle
  3006. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  3007. * @cid: SW CID the command is related to
  3008. * @data_hi: command private data address (high 32 bits)
  3009. * @data_lo: command private data address (low 32 bits)
  3010. * @cmd_type: command type (e.g. NONE, ETH)
  3011. *
  3012. * SP data is handled as if it's always an address pair, thus data fields are
  3013. * not swapped to little endian in upper functions. Instead this function swaps
  3014. * data as if it's two u32 fields.
  3015. */
  3016. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  3017. u32 data_hi, u32 data_lo, int cmd_type)
  3018. {
  3019. struct eth_spe *spe;
  3020. u16 type;
  3021. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  3022. #ifdef BNX2X_STOP_ON_ERROR
  3023. if (unlikely(bp->panic)) {
  3024. BNX2X_ERR("Can't post SP when there is panic\n");
  3025. return -EIO;
  3026. }
  3027. #endif
  3028. spin_lock_bh(&bp->spq_lock);
  3029. if (common) {
  3030. if (!atomic_read(&bp->eq_spq_left)) {
  3031. BNX2X_ERR("BUG! EQ ring full!\n");
  3032. spin_unlock_bh(&bp->spq_lock);
  3033. bnx2x_panic();
  3034. return -EBUSY;
  3035. }
  3036. } else if (!atomic_read(&bp->cq_spq_left)) {
  3037. BNX2X_ERR("BUG! SPQ ring full!\n");
  3038. spin_unlock_bh(&bp->spq_lock);
  3039. bnx2x_panic();
  3040. return -EBUSY;
  3041. }
  3042. spe = bnx2x_sp_get_next(bp);
  3043. /* CID needs port number to be encoded int it */
  3044. spe->hdr.conn_and_cmd_data =
  3045. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3046. HW_CID(bp, cid));
  3047. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  3048. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3049. SPE_HDR_FUNCTION_ID);
  3050. spe->hdr.type = cpu_to_le16(type);
  3051. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3052. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3053. /*
  3054. * It's ok if the actual decrement is issued towards the memory
  3055. * somewhere between the spin_lock and spin_unlock. Thus no
  3056. * more explicit memory barrier is needed.
  3057. */
  3058. if (common)
  3059. atomic_dec(&bp->eq_spq_left);
  3060. else
  3061. atomic_dec(&bp->cq_spq_left);
  3062. DP(BNX2X_MSG_SP,
  3063. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3064. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3065. (u32)(U64_LO(bp->spq_mapping) +
  3066. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3067. HW_CID(bp, cid), data_hi, data_lo, type,
  3068. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3069. bnx2x_sp_prod_update(bp);
  3070. spin_unlock_bh(&bp->spq_lock);
  3071. return 0;
  3072. }
  3073. /* acquire split MCP access lock register */
  3074. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3075. {
  3076. u32 j, val;
  3077. int rc = 0;
  3078. might_sleep();
  3079. for (j = 0; j < 1000; j++) {
  3080. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3081. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3082. if (val & MCPR_ACCESS_LOCK_LOCK)
  3083. break;
  3084. usleep_range(5000, 10000);
  3085. }
  3086. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3087. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3088. rc = -EBUSY;
  3089. }
  3090. return rc;
  3091. }
  3092. /* release split MCP access lock register */
  3093. static void bnx2x_release_alr(struct bnx2x *bp)
  3094. {
  3095. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3096. }
  3097. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3098. #define BNX2X_DEF_SB_IDX 0x0002
  3099. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3100. {
  3101. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3102. u16 rc = 0;
  3103. barrier(); /* status block is written to by the chip */
  3104. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3105. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3106. rc |= BNX2X_DEF_SB_ATT_IDX;
  3107. }
  3108. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3109. bp->def_idx = def_sb->sp_sb.running_index;
  3110. rc |= BNX2X_DEF_SB_IDX;
  3111. }
  3112. /* Do not reorder: indices reading should complete before handling */
  3113. barrier();
  3114. return rc;
  3115. }
  3116. /*
  3117. * slow path service functions
  3118. */
  3119. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3120. {
  3121. int port = BP_PORT(bp);
  3122. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3123. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3124. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3125. NIG_REG_MASK_INTERRUPT_PORT0;
  3126. u32 aeu_mask;
  3127. u32 nig_mask = 0;
  3128. u32 reg_addr;
  3129. if (bp->attn_state & asserted)
  3130. BNX2X_ERR("IGU ERROR\n");
  3131. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3132. aeu_mask = REG_RD(bp, aeu_addr);
  3133. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3134. aeu_mask, asserted);
  3135. aeu_mask &= ~(asserted & 0x3ff);
  3136. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3137. REG_WR(bp, aeu_addr, aeu_mask);
  3138. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3139. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3140. bp->attn_state |= asserted;
  3141. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3142. if (asserted & ATTN_HARD_WIRED_MASK) {
  3143. if (asserted & ATTN_NIG_FOR_FUNC) {
  3144. bnx2x_acquire_phy_lock(bp);
  3145. /* save nig interrupt mask */
  3146. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3147. /* If nig_mask is not set, no need to call the update
  3148. * function.
  3149. */
  3150. if (nig_mask) {
  3151. REG_WR(bp, nig_int_mask_addr, 0);
  3152. bnx2x_link_attn(bp);
  3153. }
  3154. /* handle unicore attn? */
  3155. }
  3156. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3157. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3158. if (asserted & GPIO_2_FUNC)
  3159. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3160. if (asserted & GPIO_3_FUNC)
  3161. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3162. if (asserted & GPIO_4_FUNC)
  3163. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3164. if (port == 0) {
  3165. if (asserted & ATTN_GENERAL_ATTN_1) {
  3166. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3167. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3168. }
  3169. if (asserted & ATTN_GENERAL_ATTN_2) {
  3170. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3171. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3172. }
  3173. if (asserted & ATTN_GENERAL_ATTN_3) {
  3174. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3175. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3176. }
  3177. } else {
  3178. if (asserted & ATTN_GENERAL_ATTN_4) {
  3179. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3180. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3181. }
  3182. if (asserted & ATTN_GENERAL_ATTN_5) {
  3183. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3184. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3185. }
  3186. if (asserted & ATTN_GENERAL_ATTN_6) {
  3187. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3188. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3189. }
  3190. }
  3191. } /* if hardwired */
  3192. if (bp->common.int_block == INT_BLOCK_HC)
  3193. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3194. COMMAND_REG_ATTN_BITS_SET);
  3195. else
  3196. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3197. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3198. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3199. REG_WR(bp, reg_addr, asserted);
  3200. /* now set back the mask */
  3201. if (asserted & ATTN_NIG_FOR_FUNC) {
  3202. /* Verify that IGU ack through BAR was written before restoring
  3203. * NIG mask. This loop should exit after 2-3 iterations max.
  3204. */
  3205. if (bp->common.int_block != INT_BLOCK_HC) {
  3206. u32 cnt = 0, igu_acked;
  3207. do {
  3208. igu_acked = REG_RD(bp,
  3209. IGU_REG_ATTENTION_ACK_BITS);
  3210. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3211. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3212. if (!igu_acked)
  3213. DP(NETIF_MSG_HW,
  3214. "Failed to verify IGU ack on time\n");
  3215. barrier();
  3216. }
  3217. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3218. bnx2x_release_phy_lock(bp);
  3219. }
  3220. }
  3221. static void bnx2x_fan_failure(struct bnx2x *bp)
  3222. {
  3223. int port = BP_PORT(bp);
  3224. u32 ext_phy_config;
  3225. /* mark the failure */
  3226. ext_phy_config =
  3227. SHMEM_RD(bp,
  3228. dev_info.port_hw_config[port].external_phy_config);
  3229. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3230. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3231. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3232. ext_phy_config);
  3233. /* log the failure */
  3234. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3235. "Please contact OEM Support for assistance\n");
  3236. /* Schedule device reset (unload)
  3237. * This is due to some boards consuming sufficient power when driver is
  3238. * up to overheat if fan fails.
  3239. */
  3240. smp_mb__before_clear_bit();
  3241. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3242. smp_mb__after_clear_bit();
  3243. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3244. }
  3245. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3246. {
  3247. int port = BP_PORT(bp);
  3248. int reg_offset;
  3249. u32 val;
  3250. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3251. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3252. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3253. val = REG_RD(bp, reg_offset);
  3254. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3255. REG_WR(bp, reg_offset, val);
  3256. BNX2X_ERR("SPIO5 hw attention\n");
  3257. /* Fan failure attention */
  3258. bnx2x_hw_reset_phy(&bp->link_params);
  3259. bnx2x_fan_failure(bp);
  3260. }
  3261. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3262. bnx2x_acquire_phy_lock(bp);
  3263. bnx2x_handle_module_detect_int(&bp->link_params);
  3264. bnx2x_release_phy_lock(bp);
  3265. }
  3266. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3267. val = REG_RD(bp, reg_offset);
  3268. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3269. REG_WR(bp, reg_offset, val);
  3270. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3271. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3272. bnx2x_panic();
  3273. }
  3274. }
  3275. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3276. {
  3277. u32 val;
  3278. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3279. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3280. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3281. /* DORQ discard attention */
  3282. if (val & 0x2)
  3283. BNX2X_ERR("FATAL error from DORQ\n");
  3284. }
  3285. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3286. int port = BP_PORT(bp);
  3287. int reg_offset;
  3288. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3289. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3290. val = REG_RD(bp, reg_offset);
  3291. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3292. REG_WR(bp, reg_offset, val);
  3293. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3294. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3295. bnx2x_panic();
  3296. }
  3297. }
  3298. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3299. {
  3300. u32 val;
  3301. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3302. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3303. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3304. /* CFC error attention */
  3305. if (val & 0x2)
  3306. BNX2X_ERR("FATAL error from CFC\n");
  3307. }
  3308. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3309. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3310. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3311. /* RQ_USDMDP_FIFO_OVERFLOW */
  3312. if (val & 0x18000)
  3313. BNX2X_ERR("FATAL error from PXP\n");
  3314. if (!CHIP_IS_E1x(bp)) {
  3315. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3316. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3317. }
  3318. }
  3319. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3320. int port = BP_PORT(bp);
  3321. int reg_offset;
  3322. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3323. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3324. val = REG_RD(bp, reg_offset);
  3325. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3326. REG_WR(bp, reg_offset, val);
  3327. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3328. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3329. bnx2x_panic();
  3330. }
  3331. }
  3332. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3333. {
  3334. u32 val;
  3335. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3336. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3337. int func = BP_FUNC(bp);
  3338. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3339. bnx2x_read_mf_cfg(bp);
  3340. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3341. func_mf_config[BP_ABS_FUNC(bp)].config);
  3342. val = SHMEM_RD(bp,
  3343. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3344. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3345. bnx2x_dcc_event(bp,
  3346. (val & DRV_STATUS_DCC_EVENT_MASK));
  3347. if (val & DRV_STATUS_SET_MF_BW)
  3348. bnx2x_set_mf_bw(bp);
  3349. if (val & DRV_STATUS_DRV_INFO_REQ)
  3350. bnx2x_handle_drv_info_req(bp);
  3351. if (val & DRV_STATUS_VF_DISABLED)
  3352. bnx2x_vf_handle_flr_event(bp);
  3353. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3354. bnx2x_pmf_update(bp);
  3355. if (bp->port.pmf &&
  3356. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3357. bp->dcbx_enabled > 0)
  3358. /* start dcbx state machine */
  3359. bnx2x_dcbx_set_params(bp,
  3360. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3361. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3362. bnx2x_handle_afex_cmd(bp,
  3363. val & DRV_STATUS_AFEX_EVENT_MASK);
  3364. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3365. bnx2x_handle_eee_event(bp);
  3366. if (bp->link_vars.periodic_flags &
  3367. PERIODIC_FLAGS_LINK_EVENT) {
  3368. /* sync with link */
  3369. bnx2x_acquire_phy_lock(bp);
  3370. bp->link_vars.periodic_flags &=
  3371. ~PERIODIC_FLAGS_LINK_EVENT;
  3372. bnx2x_release_phy_lock(bp);
  3373. if (IS_MF(bp))
  3374. bnx2x_link_sync_notify(bp);
  3375. bnx2x_link_report(bp);
  3376. }
  3377. /* Always call it here: bnx2x_link_report() will
  3378. * prevent the link indication duplication.
  3379. */
  3380. bnx2x__link_status_update(bp);
  3381. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3382. BNX2X_ERR("MC assert!\n");
  3383. bnx2x_mc_assert(bp);
  3384. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3385. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3386. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3387. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3388. bnx2x_panic();
  3389. } else if (attn & BNX2X_MCP_ASSERT) {
  3390. BNX2X_ERR("MCP assert!\n");
  3391. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3392. bnx2x_fw_dump(bp);
  3393. } else
  3394. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3395. }
  3396. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3397. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3398. if (attn & BNX2X_GRC_TIMEOUT) {
  3399. val = CHIP_IS_E1(bp) ? 0 :
  3400. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3401. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3402. }
  3403. if (attn & BNX2X_GRC_RSV) {
  3404. val = CHIP_IS_E1(bp) ? 0 :
  3405. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3406. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3407. }
  3408. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3409. }
  3410. }
  3411. /*
  3412. * Bits map:
  3413. * 0-7 - Engine0 load counter.
  3414. * 8-15 - Engine1 load counter.
  3415. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3416. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3417. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3418. * on the engine
  3419. * 19 - Engine1 ONE_IS_LOADED.
  3420. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3421. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3422. * just the one belonging to its engine).
  3423. *
  3424. */
  3425. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3426. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3427. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3428. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3429. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3430. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3431. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3432. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3433. /*
  3434. * Set the GLOBAL_RESET bit.
  3435. *
  3436. * Should be run under rtnl lock
  3437. */
  3438. void bnx2x_set_reset_global(struct bnx2x *bp)
  3439. {
  3440. u32 val;
  3441. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3442. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3443. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3444. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3445. }
  3446. /*
  3447. * Clear the GLOBAL_RESET bit.
  3448. *
  3449. * Should be run under rtnl lock
  3450. */
  3451. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3452. {
  3453. u32 val;
  3454. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3455. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3456. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3457. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3458. }
  3459. /*
  3460. * Checks the GLOBAL_RESET bit.
  3461. *
  3462. * should be run under rtnl lock
  3463. */
  3464. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3465. {
  3466. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3467. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3468. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3469. }
  3470. /*
  3471. * Clear RESET_IN_PROGRESS bit for the current engine.
  3472. *
  3473. * Should be run under rtnl lock
  3474. */
  3475. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3476. {
  3477. u32 val;
  3478. u32 bit = BP_PATH(bp) ?
  3479. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3480. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3481. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3482. /* Clear the bit */
  3483. val &= ~bit;
  3484. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3485. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3486. }
  3487. /*
  3488. * Set RESET_IN_PROGRESS for the current engine.
  3489. *
  3490. * should be run under rtnl lock
  3491. */
  3492. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3493. {
  3494. u32 val;
  3495. u32 bit = BP_PATH(bp) ?
  3496. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3497. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3498. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3499. /* Set the bit */
  3500. val |= bit;
  3501. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3502. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3503. }
  3504. /*
  3505. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3506. * should be run under rtnl lock
  3507. */
  3508. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3509. {
  3510. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3511. u32 bit = engine ?
  3512. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3513. /* return false if bit is set */
  3514. return (val & bit) ? false : true;
  3515. }
  3516. /*
  3517. * set pf load for the current pf.
  3518. *
  3519. * should be run under rtnl lock
  3520. */
  3521. void bnx2x_set_pf_load(struct bnx2x *bp)
  3522. {
  3523. u32 val1, val;
  3524. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3525. BNX2X_PATH0_LOAD_CNT_MASK;
  3526. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3527. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3528. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3529. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3530. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3531. /* get the current counter value */
  3532. val1 = (val & mask) >> shift;
  3533. /* set bit of that PF */
  3534. val1 |= (1 << bp->pf_num);
  3535. /* clear the old value */
  3536. val &= ~mask;
  3537. /* set the new one */
  3538. val |= ((val1 << shift) & mask);
  3539. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3540. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3541. }
  3542. /**
  3543. * bnx2x_clear_pf_load - clear pf load mark
  3544. *
  3545. * @bp: driver handle
  3546. *
  3547. * Should be run under rtnl lock.
  3548. * Decrements the load counter for the current engine. Returns
  3549. * whether other functions are still loaded
  3550. */
  3551. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3552. {
  3553. u32 val1, val;
  3554. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3555. BNX2X_PATH0_LOAD_CNT_MASK;
  3556. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3557. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3558. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3559. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3560. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3561. /* get the current counter value */
  3562. val1 = (val & mask) >> shift;
  3563. /* clear bit of that PF */
  3564. val1 &= ~(1 << bp->pf_num);
  3565. /* clear the old value */
  3566. val &= ~mask;
  3567. /* set the new one */
  3568. val |= ((val1 << shift) & mask);
  3569. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3570. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3571. return val1 != 0;
  3572. }
  3573. /*
  3574. * Read the load status for the current engine.
  3575. *
  3576. * should be run under rtnl lock
  3577. */
  3578. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3579. {
  3580. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3581. BNX2X_PATH0_LOAD_CNT_MASK);
  3582. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3583. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3584. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3585. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3586. val = (val & mask) >> shift;
  3587. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3588. engine, val);
  3589. return val != 0;
  3590. }
  3591. static void _print_parity(struct bnx2x *bp, u32 reg)
  3592. {
  3593. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3594. }
  3595. static void _print_next_block(int idx, const char *blk)
  3596. {
  3597. pr_cont("%s%s", idx ? ", " : "", blk);
  3598. }
  3599. static bool bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3600. int *par_num, bool print)
  3601. {
  3602. u32 cur_bit;
  3603. bool res;
  3604. int i;
  3605. res = false;
  3606. for (i = 0; sig; i++) {
  3607. cur_bit = (0x1UL << i);
  3608. if (sig & cur_bit) {
  3609. res |= true; /* Each bit is real error! */
  3610. if (print) {
  3611. switch (cur_bit) {
  3612. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3613. _print_next_block((*par_num)++, "BRB");
  3614. _print_parity(bp,
  3615. BRB1_REG_BRB1_PRTY_STS);
  3616. break;
  3617. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3618. _print_next_block((*par_num)++,
  3619. "PARSER");
  3620. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3621. break;
  3622. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3623. _print_next_block((*par_num)++, "TSDM");
  3624. _print_parity(bp,
  3625. TSDM_REG_TSDM_PRTY_STS);
  3626. break;
  3627. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3628. _print_next_block((*par_num)++,
  3629. "SEARCHER");
  3630. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3631. break;
  3632. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3633. _print_next_block((*par_num)++, "TCM");
  3634. _print_parity(bp, TCM_REG_TCM_PRTY_STS);
  3635. break;
  3636. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3637. _print_next_block((*par_num)++,
  3638. "TSEMI");
  3639. _print_parity(bp,
  3640. TSEM_REG_TSEM_PRTY_STS_0);
  3641. _print_parity(bp,
  3642. TSEM_REG_TSEM_PRTY_STS_1);
  3643. break;
  3644. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3645. _print_next_block((*par_num)++, "XPB");
  3646. _print_parity(bp, GRCBASE_XPB +
  3647. PB_REG_PB_PRTY_STS);
  3648. break;
  3649. }
  3650. }
  3651. /* Clear the bit */
  3652. sig &= ~cur_bit;
  3653. }
  3654. }
  3655. return res;
  3656. }
  3657. static bool bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3658. int *par_num, bool *global,
  3659. bool print)
  3660. {
  3661. u32 cur_bit;
  3662. bool res;
  3663. int i;
  3664. res = false;
  3665. for (i = 0; sig; i++) {
  3666. cur_bit = (0x1UL << i);
  3667. if (sig & cur_bit) {
  3668. res |= true; /* Each bit is real error! */
  3669. switch (cur_bit) {
  3670. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3671. if (print) {
  3672. _print_next_block((*par_num)++, "PBF");
  3673. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3674. }
  3675. break;
  3676. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3677. if (print) {
  3678. _print_next_block((*par_num)++, "QM");
  3679. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3680. }
  3681. break;
  3682. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3683. if (print) {
  3684. _print_next_block((*par_num)++, "TM");
  3685. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3686. }
  3687. break;
  3688. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3689. if (print) {
  3690. _print_next_block((*par_num)++, "XSDM");
  3691. _print_parity(bp,
  3692. XSDM_REG_XSDM_PRTY_STS);
  3693. }
  3694. break;
  3695. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3696. if (print) {
  3697. _print_next_block((*par_num)++, "XCM");
  3698. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3699. }
  3700. break;
  3701. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3702. if (print) {
  3703. _print_next_block((*par_num)++,
  3704. "XSEMI");
  3705. _print_parity(bp,
  3706. XSEM_REG_XSEM_PRTY_STS_0);
  3707. _print_parity(bp,
  3708. XSEM_REG_XSEM_PRTY_STS_1);
  3709. }
  3710. break;
  3711. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3712. if (print) {
  3713. _print_next_block((*par_num)++,
  3714. "DOORBELLQ");
  3715. _print_parity(bp,
  3716. DORQ_REG_DORQ_PRTY_STS);
  3717. }
  3718. break;
  3719. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3720. if (print) {
  3721. _print_next_block((*par_num)++, "NIG");
  3722. if (CHIP_IS_E1x(bp)) {
  3723. _print_parity(bp,
  3724. NIG_REG_NIG_PRTY_STS);
  3725. } else {
  3726. _print_parity(bp,
  3727. NIG_REG_NIG_PRTY_STS_0);
  3728. _print_parity(bp,
  3729. NIG_REG_NIG_PRTY_STS_1);
  3730. }
  3731. }
  3732. break;
  3733. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3734. if (print)
  3735. _print_next_block((*par_num)++,
  3736. "VAUX PCI CORE");
  3737. *global = true;
  3738. break;
  3739. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3740. if (print) {
  3741. _print_next_block((*par_num)++,
  3742. "DEBUG");
  3743. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3744. }
  3745. break;
  3746. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3747. if (print) {
  3748. _print_next_block((*par_num)++, "USDM");
  3749. _print_parity(bp,
  3750. USDM_REG_USDM_PRTY_STS);
  3751. }
  3752. break;
  3753. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3754. if (print) {
  3755. _print_next_block((*par_num)++, "UCM");
  3756. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3757. }
  3758. break;
  3759. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3760. if (print) {
  3761. _print_next_block((*par_num)++,
  3762. "USEMI");
  3763. _print_parity(bp,
  3764. USEM_REG_USEM_PRTY_STS_0);
  3765. _print_parity(bp,
  3766. USEM_REG_USEM_PRTY_STS_1);
  3767. }
  3768. break;
  3769. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3770. if (print) {
  3771. _print_next_block((*par_num)++, "UPB");
  3772. _print_parity(bp, GRCBASE_UPB +
  3773. PB_REG_PB_PRTY_STS);
  3774. }
  3775. break;
  3776. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3777. if (print) {
  3778. _print_next_block((*par_num)++, "CSDM");
  3779. _print_parity(bp,
  3780. CSDM_REG_CSDM_PRTY_STS);
  3781. }
  3782. break;
  3783. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3784. if (print) {
  3785. _print_next_block((*par_num)++, "CCM");
  3786. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3787. }
  3788. break;
  3789. }
  3790. /* Clear the bit */
  3791. sig &= ~cur_bit;
  3792. }
  3793. }
  3794. return res;
  3795. }
  3796. static bool bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3797. int *par_num, bool print)
  3798. {
  3799. u32 cur_bit;
  3800. bool res;
  3801. int i;
  3802. res = false;
  3803. for (i = 0; sig; i++) {
  3804. cur_bit = (0x1UL << i);
  3805. if (sig & cur_bit) {
  3806. res |= true; /* Each bit is real error! */
  3807. if (print) {
  3808. switch (cur_bit) {
  3809. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3810. _print_next_block((*par_num)++,
  3811. "CSEMI");
  3812. _print_parity(bp,
  3813. CSEM_REG_CSEM_PRTY_STS_0);
  3814. _print_parity(bp,
  3815. CSEM_REG_CSEM_PRTY_STS_1);
  3816. break;
  3817. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3818. _print_next_block((*par_num)++, "PXP");
  3819. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  3820. _print_parity(bp,
  3821. PXP2_REG_PXP2_PRTY_STS_0);
  3822. _print_parity(bp,
  3823. PXP2_REG_PXP2_PRTY_STS_1);
  3824. break;
  3825. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3826. _print_next_block((*par_num)++,
  3827. "PXPPCICLOCKCLIENT");
  3828. break;
  3829. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3830. _print_next_block((*par_num)++, "CFC");
  3831. _print_parity(bp,
  3832. CFC_REG_CFC_PRTY_STS);
  3833. break;
  3834. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3835. _print_next_block((*par_num)++, "CDU");
  3836. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  3837. break;
  3838. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3839. _print_next_block((*par_num)++, "DMAE");
  3840. _print_parity(bp,
  3841. DMAE_REG_DMAE_PRTY_STS);
  3842. break;
  3843. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3844. _print_next_block((*par_num)++, "IGU");
  3845. if (CHIP_IS_E1x(bp))
  3846. _print_parity(bp,
  3847. HC_REG_HC_PRTY_STS);
  3848. else
  3849. _print_parity(bp,
  3850. IGU_REG_IGU_PRTY_STS);
  3851. break;
  3852. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3853. _print_next_block((*par_num)++, "MISC");
  3854. _print_parity(bp,
  3855. MISC_REG_MISC_PRTY_STS);
  3856. break;
  3857. }
  3858. }
  3859. /* Clear the bit */
  3860. sig &= ~cur_bit;
  3861. }
  3862. }
  3863. return res;
  3864. }
  3865. static bool bnx2x_check_blocks_with_parity3(struct bnx2x *bp, u32 sig,
  3866. int *par_num, bool *global,
  3867. bool print)
  3868. {
  3869. bool res = false;
  3870. u32 cur_bit;
  3871. int i;
  3872. for (i = 0; sig; i++) {
  3873. cur_bit = (0x1UL << i);
  3874. if (sig & cur_bit) {
  3875. switch (cur_bit) {
  3876. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3877. if (print)
  3878. _print_next_block((*par_num)++,
  3879. "MCP ROM");
  3880. *global = true;
  3881. res |= true;
  3882. break;
  3883. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3884. if (print)
  3885. _print_next_block((*par_num)++,
  3886. "MCP UMP RX");
  3887. *global = true;
  3888. res |= true;
  3889. break;
  3890. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3891. if (print)
  3892. _print_next_block((*par_num)++,
  3893. "MCP UMP TX");
  3894. *global = true;
  3895. res |= true;
  3896. break;
  3897. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3898. if (print)
  3899. _print_next_block((*par_num)++,
  3900. "MCP SCPAD");
  3901. /* clear latched SCPAD PATIRY from MCP */
  3902. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL,
  3903. 1UL << 10);
  3904. break;
  3905. }
  3906. /* Clear the bit */
  3907. sig &= ~cur_bit;
  3908. }
  3909. }
  3910. return res;
  3911. }
  3912. static bool bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  3913. int *par_num, bool print)
  3914. {
  3915. u32 cur_bit;
  3916. bool res;
  3917. int i;
  3918. res = false;
  3919. for (i = 0; sig; i++) {
  3920. cur_bit = (0x1UL << i);
  3921. if (sig & cur_bit) {
  3922. res |= true; /* Each bit is real error! */
  3923. if (print) {
  3924. switch (cur_bit) {
  3925. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3926. _print_next_block((*par_num)++,
  3927. "PGLUE_B");
  3928. _print_parity(bp,
  3929. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  3930. break;
  3931. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3932. _print_next_block((*par_num)++, "ATC");
  3933. _print_parity(bp,
  3934. ATC_REG_ATC_PRTY_STS);
  3935. break;
  3936. }
  3937. }
  3938. /* Clear the bit */
  3939. sig &= ~cur_bit;
  3940. }
  3941. }
  3942. return res;
  3943. }
  3944. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3945. u32 *sig)
  3946. {
  3947. bool res = false;
  3948. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3949. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3950. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3951. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3952. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3953. int par_num = 0;
  3954. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3955. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3956. sig[0] & HW_PRTY_ASSERT_SET_0,
  3957. sig[1] & HW_PRTY_ASSERT_SET_1,
  3958. sig[2] & HW_PRTY_ASSERT_SET_2,
  3959. sig[3] & HW_PRTY_ASSERT_SET_3,
  3960. sig[4] & HW_PRTY_ASSERT_SET_4);
  3961. if (print)
  3962. netdev_err(bp->dev,
  3963. "Parity errors detected in blocks: ");
  3964. res |= bnx2x_check_blocks_with_parity0(bp,
  3965. sig[0] & HW_PRTY_ASSERT_SET_0, &par_num, print);
  3966. res |= bnx2x_check_blocks_with_parity1(bp,
  3967. sig[1] & HW_PRTY_ASSERT_SET_1, &par_num, global, print);
  3968. res |= bnx2x_check_blocks_with_parity2(bp,
  3969. sig[2] & HW_PRTY_ASSERT_SET_2, &par_num, print);
  3970. res |= bnx2x_check_blocks_with_parity3(bp,
  3971. sig[3] & HW_PRTY_ASSERT_SET_3, &par_num, global, print);
  3972. res |= bnx2x_check_blocks_with_parity4(bp,
  3973. sig[4] & HW_PRTY_ASSERT_SET_4, &par_num, print);
  3974. if (print)
  3975. pr_cont("\n");
  3976. }
  3977. return res;
  3978. }
  3979. /**
  3980. * bnx2x_chk_parity_attn - checks for parity attentions.
  3981. *
  3982. * @bp: driver handle
  3983. * @global: true if there was a global attention
  3984. * @print: show parity attention in syslog
  3985. */
  3986. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3987. {
  3988. struct attn_route attn = { {0} };
  3989. int port = BP_PORT(bp);
  3990. attn.sig[0] = REG_RD(bp,
  3991. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3992. port*4);
  3993. attn.sig[1] = REG_RD(bp,
  3994. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3995. port*4);
  3996. attn.sig[2] = REG_RD(bp,
  3997. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3998. port*4);
  3999. attn.sig[3] = REG_RD(bp,
  4000. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  4001. port*4);
  4002. /* Since MCP attentions can't be disabled inside the block, we need to
  4003. * read AEU registers to see whether they're currently disabled
  4004. */
  4005. attn.sig[3] &= ((REG_RD(bp,
  4006. !port ? MISC_REG_AEU_ENABLE4_FUNC_0_OUT_0
  4007. : MISC_REG_AEU_ENABLE4_FUNC_1_OUT_0) &
  4008. MISC_AEU_ENABLE_MCP_PRTY_BITS) |
  4009. ~MISC_AEU_ENABLE_MCP_PRTY_BITS);
  4010. if (!CHIP_IS_E1x(bp))
  4011. attn.sig[4] = REG_RD(bp,
  4012. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  4013. port*4);
  4014. return bnx2x_parity_attn(bp, global, print, attn.sig);
  4015. }
  4016. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  4017. {
  4018. u32 val;
  4019. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  4020. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  4021. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  4022. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  4023. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  4024. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  4025. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  4026. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  4027. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  4028. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  4029. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  4030. if (val &
  4031. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4032. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4033. if (val &
  4034. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4035. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4036. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4037. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4038. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4039. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4040. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4041. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4042. }
  4043. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4044. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4045. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4046. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4047. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4048. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4049. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4050. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4051. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4052. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4053. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4054. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4055. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4056. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4057. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4058. }
  4059. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4060. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4061. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4062. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4063. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4064. }
  4065. }
  4066. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4067. {
  4068. struct attn_route attn, *group_mask;
  4069. int port = BP_PORT(bp);
  4070. int index;
  4071. u32 reg_addr;
  4072. u32 val;
  4073. u32 aeu_mask;
  4074. bool global = false;
  4075. /* need to take HW lock because MCP or other port might also
  4076. try to handle this event */
  4077. bnx2x_acquire_alr(bp);
  4078. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4079. #ifndef BNX2X_STOP_ON_ERROR
  4080. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4081. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4082. /* Disable HW interrupts */
  4083. bnx2x_int_disable(bp);
  4084. /* In case of parity errors don't handle attentions so that
  4085. * other function would "see" parity errors.
  4086. */
  4087. #else
  4088. bnx2x_panic();
  4089. #endif
  4090. bnx2x_release_alr(bp);
  4091. return;
  4092. }
  4093. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4094. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4095. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4096. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4097. if (!CHIP_IS_E1x(bp))
  4098. attn.sig[4] =
  4099. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4100. else
  4101. attn.sig[4] = 0;
  4102. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4103. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4104. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4105. if (deasserted & (1 << index)) {
  4106. group_mask = &bp->attn_group[index];
  4107. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4108. index,
  4109. group_mask->sig[0], group_mask->sig[1],
  4110. group_mask->sig[2], group_mask->sig[3],
  4111. group_mask->sig[4]);
  4112. bnx2x_attn_int_deasserted4(bp,
  4113. attn.sig[4] & group_mask->sig[4]);
  4114. bnx2x_attn_int_deasserted3(bp,
  4115. attn.sig[3] & group_mask->sig[3]);
  4116. bnx2x_attn_int_deasserted1(bp,
  4117. attn.sig[1] & group_mask->sig[1]);
  4118. bnx2x_attn_int_deasserted2(bp,
  4119. attn.sig[2] & group_mask->sig[2]);
  4120. bnx2x_attn_int_deasserted0(bp,
  4121. attn.sig[0] & group_mask->sig[0]);
  4122. }
  4123. }
  4124. bnx2x_release_alr(bp);
  4125. if (bp->common.int_block == INT_BLOCK_HC)
  4126. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4127. COMMAND_REG_ATTN_BITS_CLR);
  4128. else
  4129. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4130. val = ~deasserted;
  4131. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4132. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4133. REG_WR(bp, reg_addr, val);
  4134. if (~bp->attn_state & deasserted)
  4135. BNX2X_ERR("IGU ERROR\n");
  4136. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4137. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4138. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4139. aeu_mask = REG_RD(bp, reg_addr);
  4140. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4141. aeu_mask, deasserted);
  4142. aeu_mask |= (deasserted & 0x3ff);
  4143. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4144. REG_WR(bp, reg_addr, aeu_mask);
  4145. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4146. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4147. bp->attn_state &= ~deasserted;
  4148. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4149. }
  4150. static void bnx2x_attn_int(struct bnx2x *bp)
  4151. {
  4152. /* read local copy of bits */
  4153. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4154. attn_bits);
  4155. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4156. attn_bits_ack);
  4157. u32 attn_state = bp->attn_state;
  4158. /* look for changed bits */
  4159. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4160. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4161. DP(NETIF_MSG_HW,
  4162. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4163. attn_bits, attn_ack, asserted, deasserted);
  4164. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4165. BNX2X_ERR("BAD attention state\n");
  4166. /* handle bits that were raised */
  4167. if (asserted)
  4168. bnx2x_attn_int_asserted(bp, asserted);
  4169. if (deasserted)
  4170. bnx2x_attn_int_deasserted(bp, deasserted);
  4171. }
  4172. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4173. u16 index, u8 op, u8 update)
  4174. {
  4175. u32 igu_addr = bp->igu_base_addr;
  4176. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4177. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4178. igu_addr);
  4179. }
  4180. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4181. {
  4182. /* No memory barriers */
  4183. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4184. mmiowb(); /* keep prod updates ordered */
  4185. }
  4186. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4187. union event_ring_elem *elem)
  4188. {
  4189. u8 err = elem->message.error;
  4190. if (!bp->cnic_eth_dev.starting_cid ||
  4191. (cid < bp->cnic_eth_dev.starting_cid &&
  4192. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4193. return 1;
  4194. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4195. if (unlikely(err)) {
  4196. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4197. cid);
  4198. bnx2x_panic_dump(bp, false);
  4199. }
  4200. bnx2x_cnic_cfc_comp(bp, cid, err);
  4201. return 0;
  4202. }
  4203. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4204. {
  4205. struct bnx2x_mcast_ramrod_params rparam;
  4206. int rc;
  4207. memset(&rparam, 0, sizeof(rparam));
  4208. rparam.mcast_obj = &bp->mcast_obj;
  4209. netif_addr_lock_bh(bp->dev);
  4210. /* Clear pending state for the last command */
  4211. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4212. /* If there are pending mcast commands - send them */
  4213. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4214. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4215. if (rc < 0)
  4216. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4217. rc);
  4218. }
  4219. netif_addr_unlock_bh(bp->dev);
  4220. }
  4221. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4222. union event_ring_elem *elem)
  4223. {
  4224. unsigned long ramrod_flags = 0;
  4225. int rc = 0;
  4226. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4227. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4228. /* Always push next commands out, don't wait here */
  4229. __set_bit(RAMROD_CONT, &ramrod_flags);
  4230. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4231. >> BNX2X_SWCID_SHIFT) {
  4232. case BNX2X_FILTER_MAC_PENDING:
  4233. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4234. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4235. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4236. else
  4237. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4238. break;
  4239. case BNX2X_FILTER_MCAST_PENDING:
  4240. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4241. /* This is only relevant for 57710 where multicast MACs are
  4242. * configured as unicast MACs using the same ramrod.
  4243. */
  4244. bnx2x_handle_mcast_eqe(bp);
  4245. return;
  4246. default:
  4247. BNX2X_ERR("Unsupported classification command: %d\n",
  4248. elem->message.data.eth_event.echo);
  4249. return;
  4250. }
  4251. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4252. if (rc < 0)
  4253. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4254. else if (rc > 0)
  4255. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4256. }
  4257. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4258. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4259. {
  4260. netif_addr_lock_bh(bp->dev);
  4261. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4262. /* Send rx_mode command again if was requested */
  4263. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4264. bnx2x_set_storm_rx_mode(bp);
  4265. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4266. &bp->sp_state))
  4267. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4268. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4269. &bp->sp_state))
  4270. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4271. netif_addr_unlock_bh(bp->dev);
  4272. }
  4273. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4274. union event_ring_elem *elem)
  4275. {
  4276. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4277. DP(BNX2X_MSG_SP,
  4278. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4279. elem->message.data.vif_list_event.func_bit_map);
  4280. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4281. elem->message.data.vif_list_event.func_bit_map);
  4282. } else if (elem->message.data.vif_list_event.echo ==
  4283. VIF_LIST_RULE_SET) {
  4284. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4285. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4286. }
  4287. }
  4288. /* called with rtnl_lock */
  4289. static void bnx2x_after_function_update(struct bnx2x *bp)
  4290. {
  4291. int q, rc;
  4292. struct bnx2x_fastpath *fp;
  4293. struct bnx2x_queue_state_params queue_params = {NULL};
  4294. struct bnx2x_queue_update_params *q_update_params =
  4295. &queue_params.params.update;
  4296. /* Send Q update command with afex vlan removal values for all Qs */
  4297. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4298. /* set silent vlan removal values according to vlan mode */
  4299. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4300. &q_update_params->update_flags);
  4301. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4302. &q_update_params->update_flags);
  4303. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4304. /* in access mode mark mask and value are 0 to strip all vlans */
  4305. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4306. q_update_params->silent_removal_value = 0;
  4307. q_update_params->silent_removal_mask = 0;
  4308. } else {
  4309. q_update_params->silent_removal_value =
  4310. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4311. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4312. }
  4313. for_each_eth_queue(bp, q) {
  4314. /* Set the appropriate Queue object */
  4315. fp = &bp->fp[q];
  4316. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4317. /* send the ramrod */
  4318. rc = bnx2x_queue_state_change(bp, &queue_params);
  4319. if (rc < 0)
  4320. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4321. q);
  4322. }
  4323. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4324. fp = &bp->fp[FCOE_IDX(bp)];
  4325. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4326. /* clear pending completion bit */
  4327. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4328. /* mark latest Q bit */
  4329. smp_mb__before_clear_bit();
  4330. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4331. smp_mb__after_clear_bit();
  4332. /* send Q update ramrod for FCoE Q */
  4333. rc = bnx2x_queue_state_change(bp, &queue_params);
  4334. if (rc < 0)
  4335. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4336. q);
  4337. } else {
  4338. /* If no FCoE ring - ACK MCP now */
  4339. bnx2x_link_report(bp);
  4340. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4341. }
  4342. }
  4343. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4344. struct bnx2x *bp, u32 cid)
  4345. {
  4346. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4347. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4348. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4349. else
  4350. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4351. }
  4352. static void bnx2x_eq_int(struct bnx2x *bp)
  4353. {
  4354. u16 hw_cons, sw_cons, sw_prod;
  4355. union event_ring_elem *elem;
  4356. u8 echo;
  4357. u32 cid;
  4358. u8 opcode;
  4359. int rc, spqe_cnt = 0;
  4360. struct bnx2x_queue_sp_obj *q_obj;
  4361. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4362. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4363. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4364. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4365. * when we get the next-page we need to adjust so the loop
  4366. * condition below will be met. The next element is the size of a
  4367. * regular element and hence incrementing by 1
  4368. */
  4369. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4370. hw_cons++;
  4371. /* This function may never run in parallel with itself for a
  4372. * specific bp, thus there is no need in "paired" read memory
  4373. * barrier here.
  4374. */
  4375. sw_cons = bp->eq_cons;
  4376. sw_prod = bp->eq_prod;
  4377. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4378. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4379. for (; sw_cons != hw_cons;
  4380. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4381. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4382. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4383. if (!rc) {
  4384. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4385. rc);
  4386. goto next_spqe;
  4387. }
  4388. /* elem CID originates from FW; actually LE */
  4389. cid = SW_CID((__force __le32)
  4390. elem->message.data.cfc_del_event.cid);
  4391. opcode = elem->message.opcode;
  4392. /* handle eq element */
  4393. switch (opcode) {
  4394. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4395. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4396. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4397. continue;
  4398. case EVENT_RING_OPCODE_STAT_QUERY:
  4399. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4400. "got statistics comp event %d\n",
  4401. bp->stats_comp++);
  4402. /* nothing to do with stats comp */
  4403. goto next_spqe;
  4404. case EVENT_RING_OPCODE_CFC_DEL:
  4405. /* handle according to cid range */
  4406. /*
  4407. * we may want to verify here that the bp state is
  4408. * HALTING
  4409. */
  4410. DP(BNX2X_MSG_SP,
  4411. "got delete ramrod for MULTI[%d]\n", cid);
  4412. if (CNIC_LOADED(bp) &&
  4413. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4414. goto next_spqe;
  4415. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4416. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4417. break;
  4418. goto next_spqe;
  4419. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4420. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4421. if (f_obj->complete_cmd(bp, f_obj,
  4422. BNX2X_F_CMD_TX_STOP))
  4423. break;
  4424. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4425. goto next_spqe;
  4426. case EVENT_RING_OPCODE_START_TRAFFIC:
  4427. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4428. if (f_obj->complete_cmd(bp, f_obj,
  4429. BNX2X_F_CMD_TX_START))
  4430. break;
  4431. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4432. goto next_spqe;
  4433. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4434. echo = elem->message.data.function_update_event.echo;
  4435. if (echo == SWITCH_UPDATE) {
  4436. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4437. "got FUNC_SWITCH_UPDATE ramrod\n");
  4438. if (f_obj->complete_cmd(
  4439. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4440. break;
  4441. } else {
  4442. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4443. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4444. f_obj->complete_cmd(bp, f_obj,
  4445. BNX2X_F_CMD_AFEX_UPDATE);
  4446. /* We will perform the Queues update from
  4447. * sp_rtnl task as all Queue SP operations
  4448. * should run under rtnl_lock.
  4449. */
  4450. smp_mb__before_clear_bit();
  4451. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4452. &bp->sp_rtnl_state);
  4453. smp_mb__after_clear_bit();
  4454. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4455. }
  4456. goto next_spqe;
  4457. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4458. f_obj->complete_cmd(bp, f_obj,
  4459. BNX2X_F_CMD_AFEX_VIFLISTS);
  4460. bnx2x_after_afex_vif_lists(bp, elem);
  4461. goto next_spqe;
  4462. case EVENT_RING_OPCODE_FUNCTION_START:
  4463. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4464. "got FUNC_START ramrod\n");
  4465. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4466. break;
  4467. goto next_spqe;
  4468. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4469. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4470. "got FUNC_STOP ramrod\n");
  4471. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4472. break;
  4473. goto next_spqe;
  4474. }
  4475. switch (opcode | bp->state) {
  4476. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4477. BNX2X_STATE_OPEN):
  4478. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4479. BNX2X_STATE_OPENING_WAIT4_PORT):
  4480. cid = elem->message.data.eth_event.echo &
  4481. BNX2X_SWCID_MASK;
  4482. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4483. cid);
  4484. rss_raw->clear_pending(rss_raw);
  4485. break;
  4486. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4487. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4488. case (EVENT_RING_OPCODE_SET_MAC |
  4489. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4490. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4491. BNX2X_STATE_OPEN):
  4492. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4493. BNX2X_STATE_DIAG):
  4494. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4495. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4496. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4497. bnx2x_handle_classification_eqe(bp, elem);
  4498. break;
  4499. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4500. BNX2X_STATE_OPEN):
  4501. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4502. BNX2X_STATE_DIAG):
  4503. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4504. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4505. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4506. bnx2x_handle_mcast_eqe(bp);
  4507. break;
  4508. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4509. BNX2X_STATE_OPEN):
  4510. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4511. BNX2X_STATE_DIAG):
  4512. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4513. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4514. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4515. bnx2x_handle_rx_mode_eqe(bp);
  4516. break;
  4517. default:
  4518. /* unknown event log error and continue */
  4519. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4520. elem->message.opcode, bp->state);
  4521. }
  4522. next_spqe:
  4523. spqe_cnt++;
  4524. } /* for */
  4525. smp_mb__before_atomic_inc();
  4526. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4527. bp->eq_cons = sw_cons;
  4528. bp->eq_prod = sw_prod;
  4529. /* Make sure that above mem writes were issued towards the memory */
  4530. smp_wmb();
  4531. /* update producer */
  4532. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4533. }
  4534. static void bnx2x_sp_task(struct work_struct *work)
  4535. {
  4536. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4537. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4538. /* make sure the atomic interrupt_occurred has been written */
  4539. smp_rmb();
  4540. if (atomic_read(&bp->interrupt_occurred)) {
  4541. /* what work needs to be performed? */
  4542. u16 status = bnx2x_update_dsb_idx(bp);
  4543. DP(BNX2X_MSG_SP, "status %x\n", status);
  4544. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4545. atomic_set(&bp->interrupt_occurred, 0);
  4546. /* HW attentions */
  4547. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4548. bnx2x_attn_int(bp);
  4549. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4550. }
  4551. /* SP events: STAT_QUERY and others */
  4552. if (status & BNX2X_DEF_SB_IDX) {
  4553. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4554. if (FCOE_INIT(bp) &&
  4555. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4556. /* Prevent local bottom-halves from running as
  4557. * we are going to change the local NAPI list.
  4558. */
  4559. local_bh_disable();
  4560. napi_schedule(&bnx2x_fcoe(bp, napi));
  4561. local_bh_enable();
  4562. }
  4563. /* Handle EQ completions */
  4564. bnx2x_eq_int(bp);
  4565. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4566. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4567. status &= ~BNX2X_DEF_SB_IDX;
  4568. }
  4569. /* if status is non zero then perhaps something went wrong */
  4570. if (unlikely(status))
  4571. DP(BNX2X_MSG_SP,
  4572. "got an unknown interrupt! (status 0x%x)\n", status);
  4573. /* ack status block only if something was actually handled */
  4574. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4575. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4576. }
  4577. /* must be called after the EQ processing (since eq leads to sriov
  4578. * ramrod completion flows).
  4579. * This flow may have been scheduled by the arrival of a ramrod
  4580. * completion, or by the sriov code rescheduling itself.
  4581. */
  4582. bnx2x_iov_sp_task(bp);
  4583. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4584. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4585. &bp->sp_state)) {
  4586. bnx2x_link_report(bp);
  4587. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4588. }
  4589. }
  4590. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4591. {
  4592. struct net_device *dev = dev_instance;
  4593. struct bnx2x *bp = netdev_priv(dev);
  4594. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4595. IGU_INT_DISABLE, 0);
  4596. #ifdef BNX2X_STOP_ON_ERROR
  4597. if (unlikely(bp->panic))
  4598. return IRQ_HANDLED;
  4599. #endif
  4600. if (CNIC_LOADED(bp)) {
  4601. struct cnic_ops *c_ops;
  4602. rcu_read_lock();
  4603. c_ops = rcu_dereference(bp->cnic_ops);
  4604. if (c_ops)
  4605. c_ops->cnic_handler(bp->cnic_data, NULL);
  4606. rcu_read_unlock();
  4607. }
  4608. /* schedule sp task to perform default status block work, ack
  4609. * attentions and enable interrupts.
  4610. */
  4611. bnx2x_schedule_sp_task(bp);
  4612. return IRQ_HANDLED;
  4613. }
  4614. /* end of slow path */
  4615. void bnx2x_drv_pulse(struct bnx2x *bp)
  4616. {
  4617. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4618. bp->fw_drv_pulse_wr_seq);
  4619. }
  4620. static void bnx2x_timer(unsigned long data)
  4621. {
  4622. struct bnx2x *bp = (struct bnx2x *) data;
  4623. if (!netif_running(bp->dev))
  4624. return;
  4625. if (IS_PF(bp) &&
  4626. !BP_NOMCP(bp)) {
  4627. int mb_idx = BP_FW_MB_IDX(bp);
  4628. u16 drv_pulse;
  4629. u16 mcp_pulse;
  4630. ++bp->fw_drv_pulse_wr_seq;
  4631. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4632. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4633. bnx2x_drv_pulse(bp);
  4634. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4635. MCP_PULSE_SEQ_MASK);
  4636. /* The delta between driver pulse and mcp response
  4637. * should not get too big. If the MFW is more than 5 pulses
  4638. * behind, we should worry about it enough to generate an error
  4639. * log.
  4640. */
  4641. if (((drv_pulse - mcp_pulse) & MCP_PULSE_SEQ_MASK) > 5)
  4642. BNX2X_ERR("MFW seems hanged: drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4643. drv_pulse, mcp_pulse);
  4644. }
  4645. if (bp->state == BNX2X_STATE_OPEN)
  4646. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4647. /* sample pf vf bulletin board for new posts from pf */
  4648. if (IS_VF(bp))
  4649. bnx2x_timer_sriov(bp);
  4650. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4651. }
  4652. /* end of Statistics */
  4653. /* nic init */
  4654. /*
  4655. * nic init service functions
  4656. */
  4657. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4658. {
  4659. u32 i;
  4660. if (!(len%4) && !(addr%4))
  4661. for (i = 0; i < len; i += 4)
  4662. REG_WR(bp, addr + i, fill);
  4663. else
  4664. for (i = 0; i < len; i++)
  4665. REG_WR8(bp, addr + i, fill);
  4666. }
  4667. /* helper: writes FP SP data to FW - data_size in dwords */
  4668. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4669. int fw_sb_id,
  4670. u32 *sb_data_p,
  4671. u32 data_size)
  4672. {
  4673. int index;
  4674. for (index = 0; index < data_size; index++)
  4675. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4676. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4677. sizeof(u32)*index,
  4678. *(sb_data_p + index));
  4679. }
  4680. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4681. {
  4682. u32 *sb_data_p;
  4683. u32 data_size = 0;
  4684. struct hc_status_block_data_e2 sb_data_e2;
  4685. struct hc_status_block_data_e1x sb_data_e1x;
  4686. /* disable the function first */
  4687. if (!CHIP_IS_E1x(bp)) {
  4688. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4689. sb_data_e2.common.state = SB_DISABLED;
  4690. sb_data_e2.common.p_func.vf_valid = false;
  4691. sb_data_p = (u32 *)&sb_data_e2;
  4692. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4693. } else {
  4694. memset(&sb_data_e1x, 0,
  4695. sizeof(struct hc_status_block_data_e1x));
  4696. sb_data_e1x.common.state = SB_DISABLED;
  4697. sb_data_e1x.common.p_func.vf_valid = false;
  4698. sb_data_p = (u32 *)&sb_data_e1x;
  4699. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4700. }
  4701. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4702. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4703. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4704. CSTORM_STATUS_BLOCK_SIZE);
  4705. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4706. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4707. CSTORM_SYNC_BLOCK_SIZE);
  4708. }
  4709. /* helper: writes SP SB data to FW */
  4710. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4711. struct hc_sp_status_block_data *sp_sb_data)
  4712. {
  4713. int func = BP_FUNC(bp);
  4714. int i;
  4715. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4716. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4717. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4718. i*sizeof(u32),
  4719. *((u32 *)sp_sb_data + i));
  4720. }
  4721. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4722. {
  4723. int func = BP_FUNC(bp);
  4724. struct hc_sp_status_block_data sp_sb_data;
  4725. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4726. sp_sb_data.state = SB_DISABLED;
  4727. sp_sb_data.p_func.vf_valid = false;
  4728. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4729. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4730. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4731. CSTORM_SP_STATUS_BLOCK_SIZE);
  4732. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4733. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4734. CSTORM_SP_SYNC_BLOCK_SIZE);
  4735. }
  4736. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4737. int igu_sb_id, int igu_seg_id)
  4738. {
  4739. hc_sm->igu_sb_id = igu_sb_id;
  4740. hc_sm->igu_seg_id = igu_seg_id;
  4741. hc_sm->timer_value = 0xFF;
  4742. hc_sm->time_to_expire = 0xFFFFFFFF;
  4743. }
  4744. /* allocates state machine ids. */
  4745. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4746. {
  4747. /* zero out state machine indices */
  4748. /* rx indices */
  4749. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4750. /* tx indices */
  4751. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4752. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4753. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4754. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4755. /* map indices */
  4756. /* rx indices */
  4757. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4758. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4759. /* tx indices */
  4760. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4761. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4762. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4763. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4764. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4765. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4766. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4767. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4768. }
  4769. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4770. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4771. {
  4772. int igu_seg_id;
  4773. struct hc_status_block_data_e2 sb_data_e2;
  4774. struct hc_status_block_data_e1x sb_data_e1x;
  4775. struct hc_status_block_sm *hc_sm_p;
  4776. int data_size;
  4777. u32 *sb_data_p;
  4778. if (CHIP_INT_MODE_IS_BC(bp))
  4779. igu_seg_id = HC_SEG_ACCESS_NORM;
  4780. else
  4781. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4782. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4783. if (!CHIP_IS_E1x(bp)) {
  4784. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4785. sb_data_e2.common.state = SB_ENABLED;
  4786. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4787. sb_data_e2.common.p_func.vf_id = vfid;
  4788. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4789. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4790. sb_data_e2.common.same_igu_sb_1b = true;
  4791. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4792. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4793. hc_sm_p = sb_data_e2.common.state_machine;
  4794. sb_data_p = (u32 *)&sb_data_e2;
  4795. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4796. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4797. } else {
  4798. memset(&sb_data_e1x, 0,
  4799. sizeof(struct hc_status_block_data_e1x));
  4800. sb_data_e1x.common.state = SB_ENABLED;
  4801. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4802. sb_data_e1x.common.p_func.vf_id = 0xff;
  4803. sb_data_e1x.common.p_func.vf_valid = false;
  4804. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4805. sb_data_e1x.common.same_igu_sb_1b = true;
  4806. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4807. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4808. hc_sm_p = sb_data_e1x.common.state_machine;
  4809. sb_data_p = (u32 *)&sb_data_e1x;
  4810. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4811. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4812. }
  4813. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4814. igu_sb_id, igu_seg_id);
  4815. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4816. igu_sb_id, igu_seg_id);
  4817. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4818. /* write indices to HW - PCI guarantees endianity of regpairs */
  4819. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4820. }
  4821. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4822. u16 tx_usec, u16 rx_usec)
  4823. {
  4824. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4825. false, rx_usec);
  4826. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4827. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4828. tx_usec);
  4829. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4830. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4831. tx_usec);
  4832. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4833. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4834. tx_usec);
  4835. }
  4836. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4837. {
  4838. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4839. dma_addr_t mapping = bp->def_status_blk_mapping;
  4840. int igu_sp_sb_index;
  4841. int igu_seg_id;
  4842. int port = BP_PORT(bp);
  4843. int func = BP_FUNC(bp);
  4844. int reg_offset, reg_offset_en5;
  4845. u64 section;
  4846. int index;
  4847. struct hc_sp_status_block_data sp_sb_data;
  4848. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4849. if (CHIP_INT_MODE_IS_BC(bp)) {
  4850. igu_sp_sb_index = DEF_SB_IGU_ID;
  4851. igu_seg_id = HC_SEG_ACCESS_DEF;
  4852. } else {
  4853. igu_sp_sb_index = bp->igu_dsb_id;
  4854. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4855. }
  4856. /* ATTN */
  4857. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4858. atten_status_block);
  4859. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4860. bp->attn_state = 0;
  4861. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4862. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4863. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4864. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4865. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4866. int sindex;
  4867. /* take care of sig[0]..sig[4] */
  4868. for (sindex = 0; sindex < 4; sindex++)
  4869. bp->attn_group[index].sig[sindex] =
  4870. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4871. if (!CHIP_IS_E1x(bp))
  4872. /*
  4873. * enable5 is separate from the rest of the registers,
  4874. * and therefore the address skip is 4
  4875. * and not 16 between the different groups
  4876. */
  4877. bp->attn_group[index].sig[4] = REG_RD(bp,
  4878. reg_offset_en5 + 0x4*index);
  4879. else
  4880. bp->attn_group[index].sig[4] = 0;
  4881. }
  4882. if (bp->common.int_block == INT_BLOCK_HC) {
  4883. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4884. HC_REG_ATTN_MSG0_ADDR_L);
  4885. REG_WR(bp, reg_offset, U64_LO(section));
  4886. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4887. } else if (!CHIP_IS_E1x(bp)) {
  4888. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4889. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4890. }
  4891. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4892. sp_sb);
  4893. bnx2x_zero_sp_sb(bp);
  4894. /* PCI guarantees endianity of regpairs */
  4895. sp_sb_data.state = SB_ENABLED;
  4896. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4897. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4898. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4899. sp_sb_data.igu_seg_id = igu_seg_id;
  4900. sp_sb_data.p_func.pf_id = func;
  4901. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4902. sp_sb_data.p_func.vf_id = 0xff;
  4903. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4904. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4905. }
  4906. void bnx2x_update_coalesce(struct bnx2x *bp)
  4907. {
  4908. int i;
  4909. for_each_eth_queue(bp, i)
  4910. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4911. bp->tx_ticks, bp->rx_ticks);
  4912. }
  4913. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4914. {
  4915. spin_lock_init(&bp->spq_lock);
  4916. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4917. bp->spq_prod_idx = 0;
  4918. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4919. bp->spq_prod_bd = bp->spq;
  4920. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4921. }
  4922. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4923. {
  4924. int i;
  4925. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4926. union event_ring_elem *elem =
  4927. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4928. elem->next_page.addr.hi =
  4929. cpu_to_le32(U64_HI(bp->eq_mapping +
  4930. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4931. elem->next_page.addr.lo =
  4932. cpu_to_le32(U64_LO(bp->eq_mapping +
  4933. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4934. }
  4935. bp->eq_cons = 0;
  4936. bp->eq_prod = NUM_EQ_DESC;
  4937. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4938. /* we want a warning message before it gets wrought... */
  4939. atomic_set(&bp->eq_spq_left,
  4940. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4941. }
  4942. /* called with netif_addr_lock_bh() */
  4943. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4944. unsigned long rx_mode_flags,
  4945. unsigned long rx_accept_flags,
  4946. unsigned long tx_accept_flags,
  4947. unsigned long ramrod_flags)
  4948. {
  4949. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4950. int rc;
  4951. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4952. /* Prepare ramrod parameters */
  4953. ramrod_param.cid = 0;
  4954. ramrod_param.cl_id = cl_id;
  4955. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4956. ramrod_param.func_id = BP_FUNC(bp);
  4957. ramrod_param.pstate = &bp->sp_state;
  4958. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4959. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4960. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4961. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4962. ramrod_param.ramrod_flags = ramrod_flags;
  4963. ramrod_param.rx_mode_flags = rx_mode_flags;
  4964. ramrod_param.rx_accept_flags = rx_accept_flags;
  4965. ramrod_param.tx_accept_flags = tx_accept_flags;
  4966. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4967. if (rc < 0) {
  4968. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4969. return rc;
  4970. }
  4971. return 0;
  4972. }
  4973. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4974. unsigned long *rx_accept_flags,
  4975. unsigned long *tx_accept_flags)
  4976. {
  4977. /* Clear the flags first */
  4978. *rx_accept_flags = 0;
  4979. *tx_accept_flags = 0;
  4980. switch (rx_mode) {
  4981. case BNX2X_RX_MODE_NONE:
  4982. /*
  4983. * 'drop all' supersedes any accept flags that may have been
  4984. * passed to the function.
  4985. */
  4986. break;
  4987. case BNX2X_RX_MODE_NORMAL:
  4988. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4989. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4990. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4991. /* internal switching mode */
  4992. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4993. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4994. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4995. break;
  4996. case BNX2X_RX_MODE_ALLMULTI:
  4997. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4998. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4999. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5000. /* internal switching mode */
  5001. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5002. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5003. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5004. break;
  5005. case BNX2X_RX_MODE_PROMISC:
  5006. /* According to definition of SI mode, iface in promisc mode
  5007. * should receive matched and unmatched (in resolution of port)
  5008. * unicast packets.
  5009. */
  5010. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  5011. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  5012. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  5013. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  5014. /* internal switching mode */
  5015. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  5016. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  5017. if (IS_MF_SI(bp))
  5018. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  5019. else
  5020. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5021. break;
  5022. default:
  5023. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5024. return -EINVAL;
  5025. }
  5026. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5027. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  5028. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5029. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5030. }
  5031. return 0;
  5032. }
  5033. /* called with netif_addr_lock_bh() */
  5034. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5035. {
  5036. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5037. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5038. int rc;
  5039. if (!NO_FCOE(bp))
  5040. /* Configure rx_mode of FCoE Queue */
  5041. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5042. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5043. &tx_accept_flags);
  5044. if (rc)
  5045. return rc;
  5046. __set_bit(RAMROD_RX, &ramrod_flags);
  5047. __set_bit(RAMROD_TX, &ramrod_flags);
  5048. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5049. rx_accept_flags, tx_accept_flags,
  5050. ramrod_flags);
  5051. }
  5052. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5053. {
  5054. int i;
  5055. if (IS_MF_SI(bp))
  5056. /*
  5057. * In switch independent mode, the TSTORM needs to accept
  5058. * packets that failed classification, since approximate match
  5059. * mac addresses aren't written to NIG LLH
  5060. */
  5061. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5062. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  5063. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  5064. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5065. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  5066. /* Zero this manually as its initialization is
  5067. currently missing in the initTool */
  5068. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5069. REG_WR(bp, BAR_USTRORM_INTMEM +
  5070. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5071. if (!CHIP_IS_E1x(bp)) {
  5072. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5073. CHIP_INT_MODE_IS_BC(bp) ?
  5074. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5075. }
  5076. }
  5077. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5078. {
  5079. switch (load_code) {
  5080. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5081. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5082. bnx2x_init_internal_common(bp);
  5083. /* no break */
  5084. case FW_MSG_CODE_DRV_LOAD_PORT:
  5085. /* nothing to do */
  5086. /* no break */
  5087. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5088. /* internal memory per function is
  5089. initialized inside bnx2x_pf_init */
  5090. break;
  5091. default:
  5092. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5093. break;
  5094. }
  5095. }
  5096. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5097. {
  5098. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5099. }
  5100. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5101. {
  5102. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5103. }
  5104. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5105. {
  5106. if (CHIP_IS_E1x(fp->bp))
  5107. return BP_L_ID(fp->bp) + fp->index;
  5108. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5109. return bnx2x_fp_igu_sb_id(fp);
  5110. }
  5111. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5112. {
  5113. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5114. u8 cos;
  5115. unsigned long q_type = 0;
  5116. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5117. fp->rx_queue = fp_idx;
  5118. fp->cid = fp_idx;
  5119. fp->cl_id = bnx2x_fp_cl_id(fp);
  5120. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5121. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5122. /* qZone id equals to FW (per path) client id */
  5123. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5124. /* init shortcut */
  5125. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5126. /* Setup SB indices */
  5127. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5128. /* Configure Queue State object */
  5129. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5130. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5131. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5132. /* init tx data */
  5133. for_each_cos_in_tx_queue(fp, cos) {
  5134. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5135. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5136. FP_COS_TO_TXQ(fp, cos, bp),
  5137. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5138. cids[cos] = fp->txdata_ptr[cos]->cid;
  5139. }
  5140. /* nothing more for vf to do here */
  5141. if (IS_VF(bp))
  5142. return;
  5143. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5144. fp->fw_sb_id, fp->igu_sb_id);
  5145. bnx2x_update_fpsb_idx(fp);
  5146. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5147. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5148. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5149. /**
  5150. * Configure classification DBs: Always enable Tx switching
  5151. */
  5152. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5153. DP(NETIF_MSG_IFUP,
  5154. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5155. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5156. fp->igu_sb_id);
  5157. }
  5158. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5159. {
  5160. int i;
  5161. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5162. struct eth_tx_next_bd *tx_next_bd =
  5163. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5164. tx_next_bd->addr_hi =
  5165. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5166. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5167. tx_next_bd->addr_lo =
  5168. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5169. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5170. }
  5171. *txdata->tx_cons_sb = cpu_to_le16(0);
  5172. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5173. txdata->tx_db.data.zero_fill1 = 0;
  5174. txdata->tx_db.data.prod = 0;
  5175. txdata->tx_pkt_prod = 0;
  5176. txdata->tx_pkt_cons = 0;
  5177. txdata->tx_bd_prod = 0;
  5178. txdata->tx_bd_cons = 0;
  5179. txdata->tx_pkt = 0;
  5180. }
  5181. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5182. {
  5183. int i;
  5184. for_each_tx_queue_cnic(bp, i)
  5185. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5186. }
  5187. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5188. {
  5189. int i;
  5190. u8 cos;
  5191. for_each_eth_queue(bp, i)
  5192. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5193. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5194. }
  5195. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5196. {
  5197. if (!NO_FCOE(bp))
  5198. bnx2x_init_fcoe_fp(bp);
  5199. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5200. BNX2X_VF_ID_INVALID, false,
  5201. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5202. /* ensure status block indices were read */
  5203. rmb();
  5204. bnx2x_init_rx_rings_cnic(bp);
  5205. bnx2x_init_tx_rings_cnic(bp);
  5206. /* flush all */
  5207. mb();
  5208. mmiowb();
  5209. }
  5210. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5211. {
  5212. int i;
  5213. /* Setup NIC internals and enable interrupts */
  5214. for_each_eth_queue(bp, i)
  5215. bnx2x_init_eth_fp(bp, i);
  5216. /* ensure status block indices were read */
  5217. rmb();
  5218. bnx2x_init_rx_rings(bp);
  5219. bnx2x_init_tx_rings(bp);
  5220. if (IS_PF(bp)) {
  5221. /* Initialize MOD_ABS interrupts */
  5222. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5223. bp->common.shmem_base,
  5224. bp->common.shmem2_base, BP_PORT(bp));
  5225. /* initialize the default status block and sp ring */
  5226. bnx2x_init_def_sb(bp);
  5227. bnx2x_update_dsb_idx(bp);
  5228. bnx2x_init_sp_ring(bp);
  5229. } else {
  5230. bnx2x_memset_stats(bp);
  5231. }
  5232. }
  5233. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5234. {
  5235. bnx2x_init_eq_ring(bp);
  5236. bnx2x_init_internal(bp, load_code);
  5237. bnx2x_pf_init(bp);
  5238. bnx2x_stats_init(bp);
  5239. /* flush all before enabling interrupts */
  5240. mb();
  5241. mmiowb();
  5242. bnx2x_int_enable(bp);
  5243. /* Check for SPIO5 */
  5244. bnx2x_attn_int_deasserted0(bp,
  5245. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5246. AEU_INPUTS_ATTN_BITS_SPIO5);
  5247. }
  5248. /* gzip service functions */
  5249. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5250. {
  5251. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5252. &bp->gunzip_mapping, GFP_KERNEL);
  5253. if (bp->gunzip_buf == NULL)
  5254. goto gunzip_nomem1;
  5255. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5256. if (bp->strm == NULL)
  5257. goto gunzip_nomem2;
  5258. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5259. if (bp->strm->workspace == NULL)
  5260. goto gunzip_nomem3;
  5261. return 0;
  5262. gunzip_nomem3:
  5263. kfree(bp->strm);
  5264. bp->strm = NULL;
  5265. gunzip_nomem2:
  5266. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5267. bp->gunzip_mapping);
  5268. bp->gunzip_buf = NULL;
  5269. gunzip_nomem1:
  5270. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5271. return -ENOMEM;
  5272. }
  5273. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5274. {
  5275. if (bp->strm) {
  5276. vfree(bp->strm->workspace);
  5277. kfree(bp->strm);
  5278. bp->strm = NULL;
  5279. }
  5280. if (bp->gunzip_buf) {
  5281. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5282. bp->gunzip_mapping);
  5283. bp->gunzip_buf = NULL;
  5284. }
  5285. }
  5286. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5287. {
  5288. int n, rc;
  5289. /* check gzip header */
  5290. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5291. BNX2X_ERR("Bad gzip header\n");
  5292. return -EINVAL;
  5293. }
  5294. n = 10;
  5295. #define FNAME 0x8
  5296. if (zbuf[3] & FNAME)
  5297. while ((zbuf[n++] != 0) && (n < len));
  5298. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5299. bp->strm->avail_in = len - n;
  5300. bp->strm->next_out = bp->gunzip_buf;
  5301. bp->strm->avail_out = FW_BUF_SIZE;
  5302. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5303. if (rc != Z_OK)
  5304. return rc;
  5305. rc = zlib_inflate(bp->strm, Z_FINISH);
  5306. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5307. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5308. bp->strm->msg);
  5309. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5310. if (bp->gunzip_outlen & 0x3)
  5311. netdev_err(bp->dev,
  5312. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5313. bp->gunzip_outlen);
  5314. bp->gunzip_outlen >>= 2;
  5315. zlib_inflateEnd(bp->strm);
  5316. if (rc == Z_STREAM_END)
  5317. return 0;
  5318. return rc;
  5319. }
  5320. /* nic load/unload */
  5321. /*
  5322. * General service functions
  5323. */
  5324. /* send a NIG loopback debug packet */
  5325. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5326. {
  5327. u32 wb_write[3];
  5328. /* Ethernet source and destination addresses */
  5329. wb_write[0] = 0x55555555;
  5330. wb_write[1] = 0x55555555;
  5331. wb_write[2] = 0x20; /* SOP */
  5332. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5333. /* NON-IP protocol */
  5334. wb_write[0] = 0x09000000;
  5335. wb_write[1] = 0x55555555;
  5336. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5337. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5338. }
  5339. /* some of the internal memories
  5340. * are not directly readable from the driver
  5341. * to test them we send debug packets
  5342. */
  5343. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5344. {
  5345. int factor;
  5346. int count, i;
  5347. u32 val = 0;
  5348. if (CHIP_REV_IS_FPGA(bp))
  5349. factor = 120;
  5350. else if (CHIP_REV_IS_EMUL(bp))
  5351. factor = 200;
  5352. else
  5353. factor = 1;
  5354. /* Disable inputs of parser neighbor blocks */
  5355. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5356. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5357. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5358. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5359. /* Write 0 to parser credits for CFC search request */
  5360. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5361. /* send Ethernet packet */
  5362. bnx2x_lb_pckt(bp);
  5363. /* TODO do i reset NIG statistic? */
  5364. /* Wait until NIG register shows 1 packet of size 0x10 */
  5365. count = 1000 * factor;
  5366. while (count) {
  5367. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5368. val = *bnx2x_sp(bp, wb_data[0]);
  5369. if (val == 0x10)
  5370. break;
  5371. usleep_range(10000, 20000);
  5372. count--;
  5373. }
  5374. if (val != 0x10) {
  5375. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5376. return -1;
  5377. }
  5378. /* Wait until PRS register shows 1 packet */
  5379. count = 1000 * factor;
  5380. while (count) {
  5381. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5382. if (val == 1)
  5383. break;
  5384. usleep_range(10000, 20000);
  5385. count--;
  5386. }
  5387. if (val != 0x1) {
  5388. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5389. return -2;
  5390. }
  5391. /* Reset and init BRB, PRS */
  5392. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5393. msleep(50);
  5394. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5395. msleep(50);
  5396. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5397. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5398. DP(NETIF_MSG_HW, "part2\n");
  5399. /* Disable inputs of parser neighbor blocks */
  5400. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5401. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5402. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5403. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5404. /* Write 0 to parser credits for CFC search request */
  5405. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5406. /* send 10 Ethernet packets */
  5407. for (i = 0; i < 10; i++)
  5408. bnx2x_lb_pckt(bp);
  5409. /* Wait until NIG register shows 10 + 1
  5410. packets of size 11*0x10 = 0xb0 */
  5411. count = 1000 * factor;
  5412. while (count) {
  5413. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5414. val = *bnx2x_sp(bp, wb_data[0]);
  5415. if (val == 0xb0)
  5416. break;
  5417. usleep_range(10000, 20000);
  5418. count--;
  5419. }
  5420. if (val != 0xb0) {
  5421. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5422. return -3;
  5423. }
  5424. /* Wait until PRS register shows 2 packets */
  5425. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5426. if (val != 2)
  5427. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5428. /* Write 1 to parser credits for CFC search request */
  5429. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5430. /* Wait until PRS register shows 3 packets */
  5431. msleep(10 * factor);
  5432. /* Wait until NIG register shows 1 packet of size 0x10 */
  5433. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5434. if (val != 3)
  5435. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5436. /* clear NIG EOP FIFO */
  5437. for (i = 0; i < 11; i++)
  5438. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5439. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5440. if (val != 1) {
  5441. BNX2X_ERR("clear of NIG failed\n");
  5442. return -4;
  5443. }
  5444. /* Reset and init BRB, PRS, NIG */
  5445. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5446. msleep(50);
  5447. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5448. msleep(50);
  5449. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5450. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5451. if (!CNIC_SUPPORT(bp))
  5452. /* set NIC mode */
  5453. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5454. /* Enable inputs of parser neighbor blocks */
  5455. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5456. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5457. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5458. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5459. DP(NETIF_MSG_HW, "done\n");
  5460. return 0; /* OK */
  5461. }
  5462. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5463. {
  5464. u32 val;
  5465. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5466. if (!CHIP_IS_E1x(bp))
  5467. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5468. else
  5469. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5470. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5471. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5472. /*
  5473. * mask read length error interrupts in brb for parser
  5474. * (parsing unit and 'checksum and crc' unit)
  5475. * these errors are legal (PU reads fixed length and CAC can cause
  5476. * read length error on truncated packets)
  5477. */
  5478. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5479. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5480. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5481. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5482. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5483. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5484. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5485. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5486. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5487. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5488. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5489. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5490. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5491. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5492. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5493. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5494. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5495. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5496. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5497. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5498. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5499. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5500. if (!CHIP_IS_E1x(bp))
  5501. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5502. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5503. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5504. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5505. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5506. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5507. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5508. if (!CHIP_IS_E1x(bp))
  5509. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5510. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5511. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5512. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5513. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5514. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5515. }
  5516. static void bnx2x_reset_common(struct bnx2x *bp)
  5517. {
  5518. u32 val = 0x1400;
  5519. /* reset_common */
  5520. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5521. 0xd3ffff7f);
  5522. if (CHIP_IS_E3(bp)) {
  5523. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5524. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5525. }
  5526. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5527. }
  5528. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5529. {
  5530. bp->dmae_ready = 0;
  5531. spin_lock_init(&bp->dmae_lock);
  5532. }
  5533. static void bnx2x_init_pxp(struct bnx2x *bp)
  5534. {
  5535. u16 devctl;
  5536. int r_order, w_order;
  5537. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5538. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5539. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5540. if (bp->mrrs == -1)
  5541. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5542. else {
  5543. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5544. r_order = bp->mrrs;
  5545. }
  5546. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5547. }
  5548. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5549. {
  5550. int is_required;
  5551. u32 val;
  5552. int port;
  5553. if (BP_NOMCP(bp))
  5554. return;
  5555. is_required = 0;
  5556. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5557. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5558. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5559. is_required = 1;
  5560. /*
  5561. * The fan failure mechanism is usually related to the PHY type since
  5562. * the power consumption of the board is affected by the PHY. Currently,
  5563. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5564. */
  5565. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5566. for (port = PORT_0; port < PORT_MAX; port++) {
  5567. is_required |=
  5568. bnx2x_fan_failure_det_req(
  5569. bp,
  5570. bp->common.shmem_base,
  5571. bp->common.shmem2_base,
  5572. port);
  5573. }
  5574. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5575. if (is_required == 0)
  5576. return;
  5577. /* Fan failure is indicated by SPIO 5 */
  5578. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5579. /* set to active low mode */
  5580. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5581. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5582. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5583. /* enable interrupt to signal the IGU */
  5584. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5585. val |= MISC_SPIO_SPIO5;
  5586. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5587. }
  5588. void bnx2x_pf_disable(struct bnx2x *bp)
  5589. {
  5590. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5591. val &= ~IGU_PF_CONF_FUNC_EN;
  5592. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5593. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5594. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5595. }
  5596. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5597. {
  5598. u32 shmem_base[2], shmem2_base[2];
  5599. /* Avoid common init in case MFW supports LFA */
  5600. if (SHMEM2_RD(bp, size) >
  5601. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5602. return;
  5603. shmem_base[0] = bp->common.shmem_base;
  5604. shmem2_base[0] = bp->common.shmem2_base;
  5605. if (!CHIP_IS_E1x(bp)) {
  5606. shmem_base[1] =
  5607. SHMEM2_RD(bp, other_shmem_base_addr);
  5608. shmem2_base[1] =
  5609. SHMEM2_RD(bp, other_shmem2_base_addr);
  5610. }
  5611. bnx2x_acquire_phy_lock(bp);
  5612. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5613. bp->common.chip_id);
  5614. bnx2x_release_phy_lock(bp);
  5615. }
  5616. /**
  5617. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5618. *
  5619. * @bp: driver handle
  5620. */
  5621. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5622. {
  5623. u32 val;
  5624. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5625. /*
  5626. * take the RESET lock to protect undi_unload flow from accessing
  5627. * registers while we're resetting the chip
  5628. */
  5629. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5630. bnx2x_reset_common(bp);
  5631. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5632. val = 0xfffc;
  5633. if (CHIP_IS_E3(bp)) {
  5634. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5635. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5636. }
  5637. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5638. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5639. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5640. if (!CHIP_IS_E1x(bp)) {
  5641. u8 abs_func_id;
  5642. /**
  5643. * 4-port mode or 2-port mode we need to turn of master-enable
  5644. * for everyone, after that, turn it back on for self.
  5645. * so, we disregard multi-function or not, and always disable
  5646. * for all functions on the given path, this means 0,2,4,6 for
  5647. * path 0 and 1,3,5,7 for path 1
  5648. */
  5649. for (abs_func_id = BP_PATH(bp);
  5650. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5651. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5652. REG_WR(bp,
  5653. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5654. 1);
  5655. continue;
  5656. }
  5657. bnx2x_pretend_func(bp, abs_func_id);
  5658. /* clear pf enable */
  5659. bnx2x_pf_disable(bp);
  5660. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5661. }
  5662. }
  5663. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5664. if (CHIP_IS_E1(bp)) {
  5665. /* enable HW interrupt from PXP on USDM overflow
  5666. bit 16 on INT_MASK_0 */
  5667. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5668. }
  5669. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5670. bnx2x_init_pxp(bp);
  5671. #ifdef __BIG_ENDIAN
  5672. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5673. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5674. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5675. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5676. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5677. /* make sure this value is 0 */
  5678. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5679. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5680. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5681. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5682. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5683. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5684. #endif
  5685. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5686. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5687. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5688. /* let the HW do it's magic ... */
  5689. msleep(100);
  5690. /* finish PXP init */
  5691. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5692. if (val != 1) {
  5693. BNX2X_ERR("PXP2 CFG failed\n");
  5694. return -EBUSY;
  5695. }
  5696. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5697. if (val != 1) {
  5698. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5699. return -EBUSY;
  5700. }
  5701. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5702. * have entries with value "0" and valid bit on.
  5703. * This needs to be done by the first PF that is loaded in a path
  5704. * (i.e. common phase)
  5705. */
  5706. if (!CHIP_IS_E1x(bp)) {
  5707. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5708. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5709. * This occurs when a different function (func2,3) is being marked
  5710. * as "scan-off". Real-life scenario for example: if a driver is being
  5711. * load-unloaded while func6,7 are down. This will cause the timer to access
  5712. * the ilt, translate to a logical address and send a request to read/write.
  5713. * Since the ilt for the function that is down is not valid, this will cause
  5714. * a translation error which is unrecoverable.
  5715. * The Workaround is intended to make sure that when this happens nothing fatal
  5716. * will occur. The workaround:
  5717. * 1. First PF driver which loads on a path will:
  5718. * a. After taking the chip out of reset, by using pretend,
  5719. * it will write "0" to the following registers of
  5720. * the other vnics.
  5721. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5722. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5723. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5724. * And for itself it will write '1' to
  5725. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5726. * dmae-operations (writing to pram for example.)
  5727. * note: can be done for only function 6,7 but cleaner this
  5728. * way.
  5729. * b. Write zero+valid to the entire ILT.
  5730. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5731. * VNIC3 (of that port). The range allocated will be the
  5732. * entire ILT. This is needed to prevent ILT range error.
  5733. * 2. Any PF driver load flow:
  5734. * a. ILT update with the physical addresses of the allocated
  5735. * logical pages.
  5736. * b. Wait 20msec. - note that this timeout is needed to make
  5737. * sure there are no requests in one of the PXP internal
  5738. * queues with "old" ILT addresses.
  5739. * c. PF enable in the PGLC.
  5740. * d. Clear the was_error of the PF in the PGLC. (could have
  5741. * occurred while driver was down)
  5742. * e. PF enable in the CFC (WEAK + STRONG)
  5743. * f. Timers scan enable
  5744. * 3. PF driver unload flow:
  5745. * a. Clear the Timers scan_en.
  5746. * b. Polling for scan_on=0 for that PF.
  5747. * c. Clear the PF enable bit in the PXP.
  5748. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5749. * e. Write zero+valid to all ILT entries (The valid bit must
  5750. * stay set)
  5751. * f. If this is VNIC 3 of a port then also init
  5752. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5753. * to the last entry in the ILT.
  5754. *
  5755. * Notes:
  5756. * Currently the PF error in the PGLC is non recoverable.
  5757. * In the future the there will be a recovery routine for this error.
  5758. * Currently attention is masked.
  5759. * Having an MCP lock on the load/unload process does not guarantee that
  5760. * there is no Timer disable during Func6/7 enable. This is because the
  5761. * Timers scan is currently being cleared by the MCP on FLR.
  5762. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5763. * there is error before clearing it. But the flow above is simpler and
  5764. * more general.
  5765. * All ILT entries are written by zero+valid and not just PF6/7
  5766. * ILT entries since in the future the ILT entries allocation for
  5767. * PF-s might be dynamic.
  5768. */
  5769. struct ilt_client_info ilt_cli;
  5770. struct bnx2x_ilt ilt;
  5771. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5772. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5773. /* initialize dummy TM client */
  5774. ilt_cli.start = 0;
  5775. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5776. ilt_cli.client_num = ILT_CLIENT_TM;
  5777. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5778. * Step 2: set the timers first/last ilt entry to point
  5779. * to the entire range to prevent ILT range error for 3rd/4th
  5780. * vnic (this code assumes existence of the vnic)
  5781. *
  5782. * both steps performed by call to bnx2x_ilt_client_init_op()
  5783. * with dummy TM client
  5784. *
  5785. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5786. * and his brother are split registers
  5787. */
  5788. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5789. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5790. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5791. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5792. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5793. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5794. }
  5795. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5796. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5797. if (!CHIP_IS_E1x(bp)) {
  5798. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5799. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5800. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5801. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5802. /* let the HW do it's magic ... */
  5803. do {
  5804. msleep(200);
  5805. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5806. } while (factor-- && (val != 1));
  5807. if (val != 1) {
  5808. BNX2X_ERR("ATC_INIT failed\n");
  5809. return -EBUSY;
  5810. }
  5811. }
  5812. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5813. bnx2x_iov_init_dmae(bp);
  5814. /* clean the DMAE memory */
  5815. bp->dmae_ready = 1;
  5816. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5817. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5818. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5819. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5820. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5821. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5822. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5823. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5824. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5825. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5826. /* QM queues pointers table */
  5827. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5828. /* soft reset pulse */
  5829. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5830. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5831. if (CNIC_SUPPORT(bp))
  5832. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5833. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5834. if (!CHIP_REV_IS_SLOW(bp))
  5835. /* enable hw interrupt from doorbell Q */
  5836. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5837. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5838. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5839. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5840. if (!CHIP_IS_E1(bp))
  5841. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5842. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5843. if (IS_MF_AFEX(bp)) {
  5844. /* configure that VNTag and VLAN headers must be
  5845. * received in afex mode
  5846. */
  5847. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5848. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5849. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5850. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5851. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5852. } else {
  5853. /* Bit-map indicating which L2 hdrs may appear
  5854. * after the basic Ethernet header
  5855. */
  5856. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5857. bp->path_has_ovlan ? 7 : 6);
  5858. }
  5859. }
  5860. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5861. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5862. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5863. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5864. if (!CHIP_IS_E1x(bp)) {
  5865. /* reset VFC memories */
  5866. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5867. VFC_MEMORIES_RST_REG_CAM_RST |
  5868. VFC_MEMORIES_RST_REG_RAM_RST);
  5869. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5870. VFC_MEMORIES_RST_REG_CAM_RST |
  5871. VFC_MEMORIES_RST_REG_RAM_RST);
  5872. msleep(20);
  5873. }
  5874. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5875. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5876. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5877. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5878. /* sync semi rtc */
  5879. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5880. 0x80000000);
  5881. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5882. 0x80000000);
  5883. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5884. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5885. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5886. if (!CHIP_IS_E1x(bp)) {
  5887. if (IS_MF_AFEX(bp)) {
  5888. /* configure that VNTag and VLAN headers must be
  5889. * sent in afex mode
  5890. */
  5891. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5892. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5893. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5894. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5895. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5896. } else {
  5897. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5898. bp->path_has_ovlan ? 7 : 6);
  5899. }
  5900. }
  5901. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5902. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5903. if (CNIC_SUPPORT(bp)) {
  5904. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5905. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5906. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5907. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5908. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5909. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5910. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5911. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5912. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5913. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5914. }
  5915. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5916. if (sizeof(union cdu_context) != 1024)
  5917. /* we currently assume that a context is 1024 bytes */
  5918. dev_alert(&bp->pdev->dev,
  5919. "please adjust the size of cdu_context(%ld)\n",
  5920. (long)sizeof(union cdu_context));
  5921. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5922. val = (4 << 24) + (0 << 12) + 1024;
  5923. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5924. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5925. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5926. /* enable context validation interrupt from CFC */
  5927. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5928. /* set the thresholds to prevent CFC/CDU race */
  5929. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5930. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5931. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5932. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5933. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5934. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5935. /* Reset PCIE errors for debug */
  5936. REG_WR(bp, 0x2814, 0xffffffff);
  5937. REG_WR(bp, 0x3820, 0xffffffff);
  5938. if (!CHIP_IS_E1x(bp)) {
  5939. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5940. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5941. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5942. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5943. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5944. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5945. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5946. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5947. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5948. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5949. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5950. }
  5951. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5952. if (!CHIP_IS_E1(bp)) {
  5953. /* in E3 this done in per-port section */
  5954. if (!CHIP_IS_E3(bp))
  5955. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5956. }
  5957. if (CHIP_IS_E1H(bp))
  5958. /* not applicable for E2 (and above ...) */
  5959. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5960. if (CHIP_REV_IS_SLOW(bp))
  5961. msleep(200);
  5962. /* finish CFC init */
  5963. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5964. if (val != 1) {
  5965. BNX2X_ERR("CFC LL_INIT failed\n");
  5966. return -EBUSY;
  5967. }
  5968. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5969. if (val != 1) {
  5970. BNX2X_ERR("CFC AC_INIT failed\n");
  5971. return -EBUSY;
  5972. }
  5973. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5974. if (val != 1) {
  5975. BNX2X_ERR("CFC CAM_INIT failed\n");
  5976. return -EBUSY;
  5977. }
  5978. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5979. if (CHIP_IS_E1(bp)) {
  5980. /* read NIG statistic
  5981. to see if this is our first up since powerup */
  5982. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5983. val = *bnx2x_sp(bp, wb_data[0]);
  5984. /* do internal memory self test */
  5985. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5986. BNX2X_ERR("internal mem self test failed\n");
  5987. return -EBUSY;
  5988. }
  5989. }
  5990. bnx2x_setup_fan_failure_detection(bp);
  5991. /* clear PXP2 attentions */
  5992. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5993. bnx2x_enable_blocks_attention(bp);
  5994. bnx2x_enable_blocks_parity(bp);
  5995. if (!BP_NOMCP(bp)) {
  5996. if (CHIP_IS_E1x(bp))
  5997. bnx2x__common_init_phy(bp);
  5998. } else
  5999. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  6000. return 0;
  6001. }
  6002. /**
  6003. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  6004. *
  6005. * @bp: driver handle
  6006. */
  6007. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  6008. {
  6009. int rc = bnx2x_init_hw_common(bp);
  6010. if (rc)
  6011. return rc;
  6012. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  6013. if (!BP_NOMCP(bp))
  6014. bnx2x__common_init_phy(bp);
  6015. return 0;
  6016. }
  6017. static int bnx2x_init_hw_port(struct bnx2x *bp)
  6018. {
  6019. int port = BP_PORT(bp);
  6020. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6021. u32 low, high;
  6022. u32 val, reg;
  6023. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6024. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6025. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6026. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6027. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6028. /* Timers bug workaround: disables the pf_master bit in pglue at
  6029. * common phase, we need to enable it here before any dmae access are
  6030. * attempted. Therefore we manually added the enable-master to the
  6031. * port phase (it also happens in the function phase)
  6032. */
  6033. if (!CHIP_IS_E1x(bp))
  6034. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6035. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6036. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6037. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6038. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6039. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6040. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6041. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6042. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6043. /* QM cid (connection) count */
  6044. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6045. if (CNIC_SUPPORT(bp)) {
  6046. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6047. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6048. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6049. }
  6050. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6051. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6052. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6053. if (IS_MF(bp))
  6054. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6055. else if (bp->dev->mtu > 4096) {
  6056. if (bp->flags & ONE_PORT_FLAG)
  6057. low = 160;
  6058. else {
  6059. val = bp->dev->mtu;
  6060. /* (24*1024 + val*4)/256 */
  6061. low = 96 + (val/64) +
  6062. ((val % 64) ? 1 : 0);
  6063. }
  6064. } else
  6065. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6066. high = low + 56; /* 14*1024/256 */
  6067. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6068. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6069. }
  6070. if (CHIP_MODE_IS_4_PORT(bp))
  6071. REG_WR(bp, (BP_PORT(bp) ?
  6072. BRB1_REG_MAC_GUARANTIED_1 :
  6073. BRB1_REG_MAC_GUARANTIED_0), 40);
  6074. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6075. if (CHIP_IS_E3B0(bp)) {
  6076. if (IS_MF_AFEX(bp)) {
  6077. /* configure headers for AFEX mode */
  6078. REG_WR(bp, BP_PORT(bp) ?
  6079. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6080. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6081. REG_WR(bp, BP_PORT(bp) ?
  6082. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6083. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6084. REG_WR(bp, BP_PORT(bp) ?
  6085. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6086. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6087. } else {
  6088. /* Ovlan exists only if we are in multi-function +
  6089. * switch-dependent mode, in switch-independent there
  6090. * is no ovlan headers
  6091. */
  6092. REG_WR(bp, BP_PORT(bp) ?
  6093. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6094. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6095. (bp->path_has_ovlan ? 7 : 6));
  6096. }
  6097. }
  6098. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6099. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6100. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6101. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6102. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6103. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6104. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6105. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6106. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6107. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6108. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6109. if (CHIP_IS_E1x(bp)) {
  6110. /* configure PBF to work without PAUSE mtu 9000 */
  6111. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6112. /* update threshold */
  6113. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6114. /* update init credit */
  6115. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6116. /* probe changes */
  6117. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6118. udelay(50);
  6119. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6120. }
  6121. if (CNIC_SUPPORT(bp))
  6122. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6123. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6124. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6125. if (CHIP_IS_E1(bp)) {
  6126. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6127. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6128. }
  6129. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6130. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6131. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6132. /* init aeu_mask_attn_func_0/1:
  6133. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6134. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6135. * bits 4-7 are used for "per vn group attention" */
  6136. val = IS_MF(bp) ? 0xF7 : 0x7;
  6137. /* Enable DCBX attention for all but E1 */
  6138. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6139. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6140. /* SCPAD_PARITY should NOT trigger close the gates */
  6141. reg = port ? MISC_REG_AEU_ENABLE4_NIG_1 : MISC_REG_AEU_ENABLE4_NIG_0;
  6142. REG_WR(bp, reg,
  6143. REG_RD(bp, reg) &
  6144. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6145. reg = port ? MISC_REG_AEU_ENABLE4_PXP_1 : MISC_REG_AEU_ENABLE4_PXP_0;
  6146. REG_WR(bp, reg,
  6147. REG_RD(bp, reg) &
  6148. ~AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY);
  6149. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6150. if (!CHIP_IS_E1x(bp)) {
  6151. /* Bit-map indicating which L2 hdrs may appear after the
  6152. * basic Ethernet header
  6153. */
  6154. if (IS_MF_AFEX(bp))
  6155. REG_WR(bp, BP_PORT(bp) ?
  6156. NIG_REG_P1_HDRS_AFTER_BASIC :
  6157. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6158. else
  6159. REG_WR(bp, BP_PORT(bp) ?
  6160. NIG_REG_P1_HDRS_AFTER_BASIC :
  6161. NIG_REG_P0_HDRS_AFTER_BASIC,
  6162. IS_MF_SD(bp) ? 7 : 6);
  6163. if (CHIP_IS_E3(bp))
  6164. REG_WR(bp, BP_PORT(bp) ?
  6165. NIG_REG_LLH1_MF_MODE :
  6166. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6167. }
  6168. if (!CHIP_IS_E3(bp))
  6169. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6170. if (!CHIP_IS_E1(bp)) {
  6171. /* 0x2 disable mf_ov, 0x1 enable */
  6172. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6173. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6174. if (!CHIP_IS_E1x(bp)) {
  6175. val = 0;
  6176. switch (bp->mf_mode) {
  6177. case MULTI_FUNCTION_SD:
  6178. val = 1;
  6179. break;
  6180. case MULTI_FUNCTION_SI:
  6181. case MULTI_FUNCTION_AFEX:
  6182. val = 2;
  6183. break;
  6184. }
  6185. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6186. NIG_REG_LLH0_CLS_TYPE), val);
  6187. }
  6188. {
  6189. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6190. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6191. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6192. }
  6193. }
  6194. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6195. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6196. if (val & MISC_SPIO_SPIO5) {
  6197. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6198. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6199. val = REG_RD(bp, reg_addr);
  6200. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6201. REG_WR(bp, reg_addr, val);
  6202. }
  6203. return 0;
  6204. }
  6205. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6206. {
  6207. int reg;
  6208. u32 wb_write[2];
  6209. if (CHIP_IS_E1(bp))
  6210. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6211. else
  6212. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6213. wb_write[0] = ONCHIP_ADDR1(addr);
  6214. wb_write[1] = ONCHIP_ADDR2(addr);
  6215. REG_WR_DMAE(bp, reg, wb_write, 2);
  6216. }
  6217. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6218. {
  6219. u32 data, ctl, cnt = 100;
  6220. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6221. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6222. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6223. u32 sb_bit = 1 << (idu_sb_id%32);
  6224. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6225. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6226. /* Not supported in BC mode */
  6227. if (CHIP_INT_MODE_IS_BC(bp))
  6228. return;
  6229. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6230. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6231. IGU_REGULAR_CLEANUP_SET |
  6232. IGU_REGULAR_BCLEANUP;
  6233. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6234. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6235. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6236. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6237. data, igu_addr_data);
  6238. REG_WR(bp, igu_addr_data, data);
  6239. mmiowb();
  6240. barrier();
  6241. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6242. ctl, igu_addr_ctl);
  6243. REG_WR(bp, igu_addr_ctl, ctl);
  6244. mmiowb();
  6245. barrier();
  6246. /* wait for clean up to finish */
  6247. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6248. msleep(20);
  6249. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6250. DP(NETIF_MSG_HW,
  6251. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6252. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6253. }
  6254. }
  6255. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6256. {
  6257. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6258. }
  6259. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6260. {
  6261. u32 i, base = FUNC_ILT_BASE(func);
  6262. for (i = base; i < base + ILT_PER_FUNC; i++)
  6263. bnx2x_ilt_wr(bp, i, 0);
  6264. }
  6265. static void bnx2x_init_searcher(struct bnx2x *bp)
  6266. {
  6267. int port = BP_PORT(bp);
  6268. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6269. /* T1 hash bits value determines the T1 number of entries */
  6270. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6271. }
  6272. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6273. {
  6274. int rc;
  6275. struct bnx2x_func_state_params func_params = {NULL};
  6276. struct bnx2x_func_switch_update_params *switch_update_params =
  6277. &func_params.params.switch_update;
  6278. /* Prepare parameters for function state transitions */
  6279. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6280. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6281. func_params.f_obj = &bp->func_obj;
  6282. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6283. /* Function parameters */
  6284. switch_update_params->suspend = suspend;
  6285. rc = bnx2x_func_state_change(bp, &func_params);
  6286. return rc;
  6287. }
  6288. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6289. {
  6290. int rc, i, port = BP_PORT(bp);
  6291. int vlan_en = 0, mac_en[NUM_MACS];
  6292. /* Close input from network */
  6293. if (bp->mf_mode == SINGLE_FUNCTION) {
  6294. bnx2x_set_rx_filter(&bp->link_params, 0);
  6295. } else {
  6296. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6297. NIG_REG_LLH0_FUNC_EN);
  6298. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6299. NIG_REG_LLH0_FUNC_EN, 0);
  6300. for (i = 0; i < NUM_MACS; i++) {
  6301. mac_en[i] = REG_RD(bp, port ?
  6302. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6303. 4 * i) :
  6304. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6305. 4 * i));
  6306. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6307. 4 * i) :
  6308. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6309. }
  6310. }
  6311. /* Close BMC to host */
  6312. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6313. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6314. /* Suspend Tx switching to the PF. Completion of this ramrod
  6315. * further guarantees that all the packets of that PF / child
  6316. * VFs in BRB were processed by the Parser, so it is safe to
  6317. * change the NIC_MODE register.
  6318. */
  6319. rc = bnx2x_func_switch_update(bp, 1);
  6320. if (rc) {
  6321. BNX2X_ERR("Can't suspend tx-switching!\n");
  6322. return rc;
  6323. }
  6324. /* Change NIC_MODE register */
  6325. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6326. /* Open input from network */
  6327. if (bp->mf_mode == SINGLE_FUNCTION) {
  6328. bnx2x_set_rx_filter(&bp->link_params, 1);
  6329. } else {
  6330. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6331. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6332. for (i = 0; i < NUM_MACS; i++) {
  6333. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6334. 4 * i) :
  6335. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6336. mac_en[i]);
  6337. }
  6338. }
  6339. /* Enable BMC to host */
  6340. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6341. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6342. /* Resume Tx switching to the PF */
  6343. rc = bnx2x_func_switch_update(bp, 0);
  6344. if (rc) {
  6345. BNX2X_ERR("Can't resume tx-switching!\n");
  6346. return rc;
  6347. }
  6348. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6349. return 0;
  6350. }
  6351. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6352. {
  6353. int rc;
  6354. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6355. if (CONFIGURE_NIC_MODE(bp)) {
  6356. /* Configure searcher as part of function hw init */
  6357. bnx2x_init_searcher(bp);
  6358. /* Reset NIC mode */
  6359. rc = bnx2x_reset_nic_mode(bp);
  6360. if (rc)
  6361. BNX2X_ERR("Can't change NIC mode!\n");
  6362. return rc;
  6363. }
  6364. return 0;
  6365. }
  6366. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6367. {
  6368. int port = BP_PORT(bp);
  6369. int func = BP_FUNC(bp);
  6370. int init_phase = PHASE_PF0 + func;
  6371. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6372. u16 cdu_ilt_start;
  6373. u32 addr, val;
  6374. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6375. int i, main_mem_width, rc;
  6376. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6377. /* FLR cleanup - hmmm */
  6378. if (!CHIP_IS_E1x(bp)) {
  6379. rc = bnx2x_pf_flr_clnup(bp);
  6380. if (rc) {
  6381. bnx2x_fw_dump(bp);
  6382. return rc;
  6383. }
  6384. }
  6385. /* set MSI reconfigure capability */
  6386. if (bp->common.int_block == INT_BLOCK_HC) {
  6387. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6388. val = REG_RD(bp, addr);
  6389. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6390. REG_WR(bp, addr, val);
  6391. }
  6392. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6393. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6394. ilt = BP_ILT(bp);
  6395. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6396. if (IS_SRIOV(bp))
  6397. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6398. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6399. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6400. * those of the VFs, so start line should be reset
  6401. */
  6402. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6403. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6404. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6405. ilt->lines[cdu_ilt_start + i].page_mapping =
  6406. bp->context[i].cxt_mapping;
  6407. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6408. }
  6409. bnx2x_ilt_init_op(bp, INITOP_SET);
  6410. if (!CONFIGURE_NIC_MODE(bp)) {
  6411. bnx2x_init_searcher(bp);
  6412. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6413. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6414. } else {
  6415. /* Set NIC mode */
  6416. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6417. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6418. }
  6419. if (!CHIP_IS_E1x(bp)) {
  6420. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6421. /* Turn on a single ISR mode in IGU if driver is going to use
  6422. * INT#x or MSI
  6423. */
  6424. if (!(bp->flags & USING_MSIX_FLAG))
  6425. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6426. /*
  6427. * Timers workaround bug: function init part.
  6428. * Need to wait 20msec after initializing ILT,
  6429. * needed to make sure there are no requests in
  6430. * one of the PXP internal queues with "old" ILT addresses
  6431. */
  6432. msleep(20);
  6433. /*
  6434. * Master enable - Due to WB DMAE writes performed before this
  6435. * register is re-initialized as part of the regular function
  6436. * init
  6437. */
  6438. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6439. /* Enable the function in IGU */
  6440. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6441. }
  6442. bp->dmae_ready = 1;
  6443. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6444. if (!CHIP_IS_E1x(bp))
  6445. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6446. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6447. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6448. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6449. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6450. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6451. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6452. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6453. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6454. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6455. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6456. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6457. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6458. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6459. if (!CHIP_IS_E1x(bp))
  6460. REG_WR(bp, QM_REG_PF_EN, 1);
  6461. if (!CHIP_IS_E1x(bp)) {
  6462. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6463. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6464. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6465. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6466. }
  6467. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6468. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6469. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6470. REG_WR(bp, DORQ_REG_MODE_ACT, 1); /* no dpm */
  6471. bnx2x_iov_init_dq(bp);
  6472. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6473. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6474. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6475. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6476. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6477. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6478. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6479. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6480. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6481. if (!CHIP_IS_E1x(bp))
  6482. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6483. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6484. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6485. if (!CHIP_IS_E1x(bp))
  6486. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6487. if (IS_MF(bp)) {
  6488. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6489. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6490. }
  6491. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6492. /* HC init per function */
  6493. if (bp->common.int_block == INT_BLOCK_HC) {
  6494. if (CHIP_IS_E1H(bp)) {
  6495. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6496. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6497. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6498. }
  6499. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6500. } else {
  6501. int num_segs, sb_idx, prod_offset;
  6502. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6503. if (!CHIP_IS_E1x(bp)) {
  6504. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6505. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6506. }
  6507. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6508. if (!CHIP_IS_E1x(bp)) {
  6509. int dsb_idx = 0;
  6510. /**
  6511. * Producer memory:
  6512. * E2 mode: address 0-135 match to the mapping memory;
  6513. * 136 - PF0 default prod; 137 - PF1 default prod;
  6514. * 138 - PF2 default prod; 139 - PF3 default prod;
  6515. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6516. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6517. * 144-147 reserved.
  6518. *
  6519. * E1.5 mode - In backward compatible mode;
  6520. * for non default SB; each even line in the memory
  6521. * holds the U producer and each odd line hold
  6522. * the C producer. The first 128 producers are for
  6523. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6524. * producers are for the DSB for each PF.
  6525. * Each PF has five segments: (the order inside each
  6526. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6527. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6528. * 144-147 attn prods;
  6529. */
  6530. /* non-default-status-blocks */
  6531. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6532. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6533. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6534. prod_offset = (bp->igu_base_sb + sb_idx) *
  6535. num_segs;
  6536. for (i = 0; i < num_segs; i++) {
  6537. addr = IGU_REG_PROD_CONS_MEMORY +
  6538. (prod_offset + i) * 4;
  6539. REG_WR(bp, addr, 0);
  6540. }
  6541. /* send consumer update with value 0 */
  6542. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6543. USTORM_ID, 0, IGU_INT_NOP, 1);
  6544. bnx2x_igu_clear_sb(bp,
  6545. bp->igu_base_sb + sb_idx);
  6546. }
  6547. /* default-status-blocks */
  6548. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6549. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6550. if (CHIP_MODE_IS_4_PORT(bp))
  6551. dsb_idx = BP_FUNC(bp);
  6552. else
  6553. dsb_idx = BP_VN(bp);
  6554. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6555. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6556. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6557. /*
  6558. * igu prods come in chunks of E1HVN_MAX (4) -
  6559. * does not matters what is the current chip mode
  6560. */
  6561. for (i = 0; i < (num_segs * E1HVN_MAX);
  6562. i += E1HVN_MAX) {
  6563. addr = IGU_REG_PROD_CONS_MEMORY +
  6564. (prod_offset + i)*4;
  6565. REG_WR(bp, addr, 0);
  6566. }
  6567. /* send consumer update with 0 */
  6568. if (CHIP_INT_MODE_IS_BC(bp)) {
  6569. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6570. USTORM_ID, 0, IGU_INT_NOP, 1);
  6571. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6572. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6573. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6574. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6575. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6576. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6577. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6578. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6579. } else {
  6580. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6581. USTORM_ID, 0, IGU_INT_NOP, 1);
  6582. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6583. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6584. }
  6585. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6586. /* !!! These should become driver const once
  6587. rf-tool supports split-68 const */
  6588. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6589. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6590. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6591. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6592. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6593. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6594. }
  6595. }
  6596. /* Reset PCIE errors for debug */
  6597. REG_WR(bp, 0x2114, 0xffffffff);
  6598. REG_WR(bp, 0x2120, 0xffffffff);
  6599. if (CHIP_IS_E1x(bp)) {
  6600. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6601. main_mem_base = HC_REG_MAIN_MEMORY +
  6602. BP_PORT(bp) * (main_mem_size * 4);
  6603. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6604. main_mem_width = 8;
  6605. val = REG_RD(bp, main_mem_prty_clr);
  6606. if (val)
  6607. DP(NETIF_MSG_HW,
  6608. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6609. val);
  6610. /* Clear "false" parity errors in MSI-X table */
  6611. for (i = main_mem_base;
  6612. i < main_mem_base + main_mem_size * 4;
  6613. i += main_mem_width) {
  6614. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6615. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6616. i, main_mem_width / 4);
  6617. }
  6618. /* Clear HC parity attention */
  6619. REG_RD(bp, main_mem_prty_clr);
  6620. }
  6621. #ifdef BNX2X_STOP_ON_ERROR
  6622. /* Enable STORMs SP logging */
  6623. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6624. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6625. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6626. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6627. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6628. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6629. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6630. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6631. #endif
  6632. bnx2x_phy_probe(&bp->link_params);
  6633. return 0;
  6634. }
  6635. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6636. {
  6637. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6638. if (!CHIP_IS_E1x(bp))
  6639. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6640. sizeof(struct host_hc_status_block_e2));
  6641. else
  6642. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6643. sizeof(struct host_hc_status_block_e1x));
  6644. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6645. }
  6646. void bnx2x_free_mem(struct bnx2x *bp)
  6647. {
  6648. int i;
  6649. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6650. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6651. if (IS_VF(bp))
  6652. return;
  6653. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6654. sizeof(struct host_sp_status_block));
  6655. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6656. sizeof(struct bnx2x_slowpath));
  6657. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6658. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6659. bp->context[i].size);
  6660. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6661. BNX2X_FREE(bp->ilt->lines);
  6662. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6663. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6664. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6665. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6666. bnx2x_iov_free_mem(bp);
  6667. }
  6668. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6669. {
  6670. if (!CHIP_IS_E1x(bp))
  6671. /* size = the status block + ramrod buffers */
  6672. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6673. sizeof(struct host_hc_status_block_e2));
  6674. else
  6675. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6676. &bp->cnic_sb_mapping,
  6677. sizeof(struct
  6678. host_hc_status_block_e1x));
  6679. if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6680. /* allocate searcher T2 table, as it wasn't allocated before */
  6681. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6682. /* write address to which L5 should insert its values */
  6683. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6684. &bp->slowpath->drv_info_to_mcp;
  6685. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6686. goto alloc_mem_err;
  6687. return 0;
  6688. alloc_mem_err:
  6689. bnx2x_free_mem_cnic(bp);
  6690. BNX2X_ERR("Can't allocate memory\n");
  6691. return -ENOMEM;
  6692. }
  6693. int bnx2x_alloc_mem(struct bnx2x *bp)
  6694. {
  6695. int i, allocated, context_size;
  6696. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6697. /* allocate searcher T2 table */
  6698. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6699. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6700. sizeof(struct host_sp_status_block));
  6701. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6702. sizeof(struct bnx2x_slowpath));
  6703. /* Allocate memory for CDU context:
  6704. * This memory is allocated separately and not in the generic ILT
  6705. * functions because CDU differs in few aspects:
  6706. * 1. There are multiple entities allocating memory for context -
  6707. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6708. * its own ILT lines.
  6709. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6710. * for the other ILT clients), to be efficient we want to support
  6711. * allocation of sub-page-size in the last entry.
  6712. * 3. Context pointers are used by the driver to pass to FW / update
  6713. * the context (for the other ILT clients the pointers are used just to
  6714. * free the memory during unload).
  6715. */
  6716. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6717. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6718. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6719. (context_size - allocated));
  6720. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6721. &bp->context[i].cxt_mapping,
  6722. bp->context[i].size);
  6723. allocated += bp->context[i].size;
  6724. }
  6725. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6726. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6727. goto alloc_mem_err;
  6728. if (bnx2x_iov_alloc_mem(bp))
  6729. goto alloc_mem_err;
  6730. /* Slow path ring */
  6731. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6732. /* EQ */
  6733. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6734. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6735. return 0;
  6736. alloc_mem_err:
  6737. bnx2x_free_mem(bp);
  6738. BNX2X_ERR("Can't allocate memory\n");
  6739. return -ENOMEM;
  6740. }
  6741. /*
  6742. * Init service functions
  6743. */
  6744. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6745. struct bnx2x_vlan_mac_obj *obj, bool set,
  6746. int mac_type, unsigned long *ramrod_flags)
  6747. {
  6748. int rc;
  6749. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6750. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6751. /* Fill general parameters */
  6752. ramrod_param.vlan_mac_obj = obj;
  6753. ramrod_param.ramrod_flags = *ramrod_flags;
  6754. /* Fill a user request section if needed */
  6755. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6756. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6757. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6758. /* Set the command: ADD or DEL */
  6759. if (set)
  6760. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6761. else
  6762. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6763. }
  6764. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6765. if (rc == -EEXIST) {
  6766. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6767. /* do not treat adding same MAC as error */
  6768. rc = 0;
  6769. } else if (rc < 0)
  6770. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6771. return rc;
  6772. }
  6773. int bnx2x_del_all_macs(struct bnx2x *bp,
  6774. struct bnx2x_vlan_mac_obj *mac_obj,
  6775. int mac_type, bool wait_for_comp)
  6776. {
  6777. int rc;
  6778. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6779. /* Wait for completion of requested */
  6780. if (wait_for_comp)
  6781. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6782. /* Set the mac type of addresses we want to clear */
  6783. __set_bit(mac_type, &vlan_mac_flags);
  6784. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6785. if (rc < 0)
  6786. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6787. return rc;
  6788. }
  6789. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6790. {
  6791. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6792. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6793. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6794. "Ignoring Zero MAC for STORAGE SD mode\n");
  6795. return 0;
  6796. }
  6797. if (IS_PF(bp)) {
  6798. unsigned long ramrod_flags = 0;
  6799. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6800. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6801. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6802. &bp->sp_objs->mac_obj, set,
  6803. BNX2X_ETH_MAC, &ramrod_flags);
  6804. } else { /* vf */
  6805. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6806. bp->fp->index, true);
  6807. }
  6808. }
  6809. int bnx2x_setup_leading(struct bnx2x *bp)
  6810. {
  6811. if (IS_PF(bp))
  6812. return bnx2x_setup_queue(bp, &bp->fp[0], true);
  6813. else /* VF */
  6814. return bnx2x_vfpf_setup_q(bp, &bp->fp[0], true);
  6815. }
  6816. /**
  6817. * bnx2x_set_int_mode - configure interrupt mode
  6818. *
  6819. * @bp: driver handle
  6820. *
  6821. * In case of MSI-X it will also try to enable MSI-X.
  6822. */
  6823. int bnx2x_set_int_mode(struct bnx2x *bp)
  6824. {
  6825. int rc = 0;
  6826. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX) {
  6827. BNX2X_ERR("VF not loaded since interrupt mode not msix\n");
  6828. return -EINVAL;
  6829. }
  6830. switch (int_mode) {
  6831. case BNX2X_INT_MODE_MSIX:
  6832. /* attempt to enable msix */
  6833. rc = bnx2x_enable_msix(bp);
  6834. /* msix attained */
  6835. if (!rc)
  6836. return 0;
  6837. /* vfs use only msix */
  6838. if (rc && IS_VF(bp))
  6839. return rc;
  6840. /* failed to enable multiple MSI-X */
  6841. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6842. bp->num_queues,
  6843. 1 + bp->num_cnic_queues);
  6844. /* falling through... */
  6845. case BNX2X_INT_MODE_MSI:
  6846. bnx2x_enable_msi(bp);
  6847. /* falling through... */
  6848. case BNX2X_INT_MODE_INTX:
  6849. bp->num_ethernet_queues = 1;
  6850. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6851. BNX2X_DEV_INFO("set number of queues to 1\n");
  6852. break;
  6853. default:
  6854. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6855. return -EINVAL;
  6856. }
  6857. return 0;
  6858. }
  6859. /* must be called prior to any HW initializations */
  6860. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6861. {
  6862. if (IS_SRIOV(bp))
  6863. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6864. return L2_ILT_LINES(bp);
  6865. }
  6866. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6867. {
  6868. struct ilt_client_info *ilt_client;
  6869. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6870. u16 line = 0;
  6871. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6872. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6873. /* CDU */
  6874. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6875. ilt_client->client_num = ILT_CLIENT_CDU;
  6876. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6877. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6878. ilt_client->start = line;
  6879. line += bnx2x_cid_ilt_lines(bp);
  6880. if (CNIC_SUPPORT(bp))
  6881. line += CNIC_ILT_LINES;
  6882. ilt_client->end = line - 1;
  6883. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6884. ilt_client->start,
  6885. ilt_client->end,
  6886. ilt_client->page_size,
  6887. ilt_client->flags,
  6888. ilog2(ilt_client->page_size >> 12));
  6889. /* QM */
  6890. if (QM_INIT(bp->qm_cid_count)) {
  6891. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6892. ilt_client->client_num = ILT_CLIENT_QM;
  6893. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6894. ilt_client->flags = 0;
  6895. ilt_client->start = line;
  6896. /* 4 bytes for each cid */
  6897. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6898. QM_ILT_PAGE_SZ);
  6899. ilt_client->end = line - 1;
  6900. DP(NETIF_MSG_IFUP,
  6901. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6902. ilt_client->start,
  6903. ilt_client->end,
  6904. ilt_client->page_size,
  6905. ilt_client->flags,
  6906. ilog2(ilt_client->page_size >> 12));
  6907. }
  6908. if (CNIC_SUPPORT(bp)) {
  6909. /* SRC */
  6910. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6911. ilt_client->client_num = ILT_CLIENT_SRC;
  6912. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6913. ilt_client->flags = 0;
  6914. ilt_client->start = line;
  6915. line += SRC_ILT_LINES;
  6916. ilt_client->end = line - 1;
  6917. DP(NETIF_MSG_IFUP,
  6918. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6919. ilt_client->start,
  6920. ilt_client->end,
  6921. ilt_client->page_size,
  6922. ilt_client->flags,
  6923. ilog2(ilt_client->page_size >> 12));
  6924. /* TM */
  6925. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6926. ilt_client->client_num = ILT_CLIENT_TM;
  6927. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6928. ilt_client->flags = 0;
  6929. ilt_client->start = line;
  6930. line += TM_ILT_LINES;
  6931. ilt_client->end = line - 1;
  6932. DP(NETIF_MSG_IFUP,
  6933. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6934. ilt_client->start,
  6935. ilt_client->end,
  6936. ilt_client->page_size,
  6937. ilt_client->flags,
  6938. ilog2(ilt_client->page_size >> 12));
  6939. }
  6940. BUG_ON(line > ILT_MAX_LINES);
  6941. }
  6942. /**
  6943. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6944. *
  6945. * @bp: driver handle
  6946. * @fp: pointer to fastpath
  6947. * @init_params: pointer to parameters structure
  6948. *
  6949. * parameters configured:
  6950. * - HC configuration
  6951. * - Queue's CDU context
  6952. */
  6953. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6954. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6955. {
  6956. u8 cos;
  6957. int cxt_index, cxt_offset;
  6958. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6959. if (!IS_FCOE_FP(fp)) {
  6960. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6961. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6962. /* If HC is supported, enable host coalescing in the transition
  6963. * to INIT state.
  6964. */
  6965. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6966. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6967. /* HC rate */
  6968. init_params->rx.hc_rate = bp->rx_ticks ?
  6969. (1000000 / bp->rx_ticks) : 0;
  6970. init_params->tx.hc_rate = bp->tx_ticks ?
  6971. (1000000 / bp->tx_ticks) : 0;
  6972. /* FW SB ID */
  6973. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6974. fp->fw_sb_id;
  6975. /*
  6976. * CQ index among the SB indices: FCoE clients uses the default
  6977. * SB, therefore it's different.
  6978. */
  6979. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6980. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6981. }
  6982. /* set maximum number of COSs supported by this queue */
  6983. init_params->max_cos = fp->max_cos;
  6984. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6985. fp->index, init_params->max_cos);
  6986. /* set the context pointers queue object */
  6987. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6988. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6989. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6990. ILT_PAGE_CIDS);
  6991. init_params->cxts[cos] =
  6992. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6993. }
  6994. }
  6995. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6996. struct bnx2x_queue_state_params *q_params,
  6997. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6998. int tx_index, bool leading)
  6999. {
  7000. memset(tx_only_params, 0, sizeof(*tx_only_params));
  7001. /* Set the command */
  7002. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  7003. /* Set tx-only QUEUE flags: don't zero statistics */
  7004. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  7005. /* choose the index of the cid to send the slow path on */
  7006. tx_only_params->cid_index = tx_index;
  7007. /* Set general TX_ONLY_SETUP parameters */
  7008. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  7009. /* Set Tx TX_ONLY_SETUP parameters */
  7010. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  7011. DP(NETIF_MSG_IFUP,
  7012. "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",
  7013. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  7014. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  7015. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  7016. /* send the ramrod */
  7017. return bnx2x_queue_state_change(bp, q_params);
  7018. }
  7019. /**
  7020. * bnx2x_setup_queue - setup queue
  7021. *
  7022. * @bp: driver handle
  7023. * @fp: pointer to fastpath
  7024. * @leading: is leading
  7025. *
  7026. * This function performs 2 steps in a Queue state machine
  7027. * actually: 1) RESET->INIT 2) INIT->SETUP
  7028. */
  7029. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  7030. bool leading)
  7031. {
  7032. struct bnx2x_queue_state_params q_params = {NULL};
  7033. struct bnx2x_queue_setup_params *setup_params =
  7034. &q_params.params.setup;
  7035. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  7036. &q_params.params.tx_only;
  7037. int rc;
  7038. u8 tx_index;
  7039. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7040. /* reset IGU state skip FCoE L2 queue */
  7041. if (!IS_FCOE_FP(fp))
  7042. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7043. IGU_INT_ENABLE, 0);
  7044. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7045. /* We want to wait for completion in this context */
  7046. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7047. /* Prepare the INIT parameters */
  7048. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7049. /* Set the command */
  7050. q_params.cmd = BNX2X_Q_CMD_INIT;
  7051. /* Change the state to INIT */
  7052. rc = bnx2x_queue_state_change(bp, &q_params);
  7053. if (rc) {
  7054. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7055. return rc;
  7056. }
  7057. DP(NETIF_MSG_IFUP, "init complete\n");
  7058. /* Now move the Queue to the SETUP state... */
  7059. memset(setup_params, 0, sizeof(*setup_params));
  7060. /* Set QUEUE flags */
  7061. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7062. /* Set general SETUP parameters */
  7063. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7064. FIRST_TX_COS_INDEX);
  7065. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7066. &setup_params->rxq_params);
  7067. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7068. FIRST_TX_COS_INDEX);
  7069. /* Set the command */
  7070. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7071. if (IS_FCOE_FP(fp))
  7072. bp->fcoe_init = true;
  7073. /* Change the state to SETUP */
  7074. rc = bnx2x_queue_state_change(bp, &q_params);
  7075. if (rc) {
  7076. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7077. return rc;
  7078. }
  7079. /* loop through the relevant tx-only indices */
  7080. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7081. tx_index < fp->max_cos;
  7082. tx_index++) {
  7083. /* prepare and send tx-only ramrod*/
  7084. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7085. tx_only_params, tx_index, leading);
  7086. if (rc) {
  7087. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7088. fp->index, tx_index);
  7089. return rc;
  7090. }
  7091. }
  7092. return rc;
  7093. }
  7094. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7095. {
  7096. struct bnx2x_fastpath *fp = &bp->fp[index];
  7097. struct bnx2x_fp_txdata *txdata;
  7098. struct bnx2x_queue_state_params q_params = {NULL};
  7099. int rc, tx_index;
  7100. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7101. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7102. /* We want to wait for completion in this context */
  7103. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7104. /* close tx-only connections */
  7105. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7106. tx_index < fp->max_cos;
  7107. tx_index++){
  7108. /* ascertain this is a normal queue*/
  7109. txdata = fp->txdata_ptr[tx_index];
  7110. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7111. txdata->txq_index);
  7112. /* send halt terminate on tx-only connection */
  7113. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7114. memset(&q_params.params.terminate, 0,
  7115. sizeof(q_params.params.terminate));
  7116. q_params.params.terminate.cid_index = tx_index;
  7117. rc = bnx2x_queue_state_change(bp, &q_params);
  7118. if (rc)
  7119. return rc;
  7120. /* send halt terminate on tx-only connection */
  7121. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7122. memset(&q_params.params.cfc_del, 0,
  7123. sizeof(q_params.params.cfc_del));
  7124. q_params.params.cfc_del.cid_index = tx_index;
  7125. rc = bnx2x_queue_state_change(bp, &q_params);
  7126. if (rc)
  7127. return rc;
  7128. }
  7129. /* Stop the primary connection: */
  7130. /* ...halt the connection */
  7131. q_params.cmd = BNX2X_Q_CMD_HALT;
  7132. rc = bnx2x_queue_state_change(bp, &q_params);
  7133. if (rc)
  7134. return rc;
  7135. /* ...terminate the connection */
  7136. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7137. memset(&q_params.params.terminate, 0,
  7138. sizeof(q_params.params.terminate));
  7139. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7140. rc = bnx2x_queue_state_change(bp, &q_params);
  7141. if (rc)
  7142. return rc;
  7143. /* ...delete cfc entry */
  7144. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7145. memset(&q_params.params.cfc_del, 0,
  7146. sizeof(q_params.params.cfc_del));
  7147. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7148. return bnx2x_queue_state_change(bp, &q_params);
  7149. }
  7150. static void bnx2x_reset_func(struct bnx2x *bp)
  7151. {
  7152. int port = BP_PORT(bp);
  7153. int func = BP_FUNC(bp);
  7154. int i;
  7155. /* Disable the function in the FW */
  7156. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7157. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7158. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7159. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7160. /* FP SBs */
  7161. for_each_eth_queue(bp, i) {
  7162. struct bnx2x_fastpath *fp = &bp->fp[i];
  7163. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7164. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7165. SB_DISABLED);
  7166. }
  7167. if (CNIC_LOADED(bp))
  7168. /* CNIC SB */
  7169. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7170. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7171. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7172. /* SP SB */
  7173. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7174. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7175. SB_DISABLED);
  7176. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7177. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7178. 0);
  7179. /* Configure IGU */
  7180. if (bp->common.int_block == INT_BLOCK_HC) {
  7181. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7182. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7183. } else {
  7184. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7185. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7186. }
  7187. if (CNIC_LOADED(bp)) {
  7188. /* Disable Timer scan */
  7189. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7190. /*
  7191. * Wait for at least 10ms and up to 2 second for the timers
  7192. * scan to complete
  7193. */
  7194. for (i = 0; i < 200; i++) {
  7195. usleep_range(10000, 20000);
  7196. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7197. break;
  7198. }
  7199. }
  7200. /* Clear ILT */
  7201. bnx2x_clear_func_ilt(bp, func);
  7202. /* Timers workaround bug for E2: if this is vnic-3,
  7203. * we need to set the entire ilt range for this timers.
  7204. */
  7205. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7206. struct ilt_client_info ilt_cli;
  7207. /* use dummy TM client */
  7208. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7209. ilt_cli.start = 0;
  7210. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7211. ilt_cli.client_num = ILT_CLIENT_TM;
  7212. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7213. }
  7214. /* this assumes that reset_port() called before reset_func()*/
  7215. if (!CHIP_IS_E1x(bp))
  7216. bnx2x_pf_disable(bp);
  7217. bp->dmae_ready = 0;
  7218. }
  7219. static void bnx2x_reset_port(struct bnx2x *bp)
  7220. {
  7221. int port = BP_PORT(bp);
  7222. u32 val;
  7223. /* Reset physical Link */
  7224. bnx2x__link_reset(bp);
  7225. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7226. /* Do not rcv packets to BRB */
  7227. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7228. /* Do not direct rcv packets that are not for MCP to the BRB */
  7229. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7230. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7231. /* Configure AEU */
  7232. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7233. msleep(100);
  7234. /* Check for BRB port occupancy */
  7235. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7236. if (val)
  7237. DP(NETIF_MSG_IFDOWN,
  7238. "BRB1 is not empty %d blocks are occupied\n", val);
  7239. /* TODO: Close Doorbell port? */
  7240. }
  7241. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7242. {
  7243. struct bnx2x_func_state_params func_params = {NULL};
  7244. /* Prepare parameters for function state transitions */
  7245. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7246. func_params.f_obj = &bp->func_obj;
  7247. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7248. func_params.params.hw_init.load_phase = load_code;
  7249. return bnx2x_func_state_change(bp, &func_params);
  7250. }
  7251. static int bnx2x_func_stop(struct bnx2x *bp)
  7252. {
  7253. struct bnx2x_func_state_params func_params = {NULL};
  7254. int rc;
  7255. /* Prepare parameters for function state transitions */
  7256. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7257. func_params.f_obj = &bp->func_obj;
  7258. func_params.cmd = BNX2X_F_CMD_STOP;
  7259. /*
  7260. * Try to stop the function the 'good way'. If fails (in case
  7261. * of a parity error during bnx2x_chip_cleanup()) and we are
  7262. * not in a debug mode, perform a state transaction in order to
  7263. * enable further HW_RESET transaction.
  7264. */
  7265. rc = bnx2x_func_state_change(bp, &func_params);
  7266. if (rc) {
  7267. #ifdef BNX2X_STOP_ON_ERROR
  7268. return rc;
  7269. #else
  7270. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7271. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7272. return bnx2x_func_state_change(bp, &func_params);
  7273. #endif
  7274. }
  7275. return 0;
  7276. }
  7277. /**
  7278. * bnx2x_send_unload_req - request unload mode from the MCP.
  7279. *
  7280. * @bp: driver handle
  7281. * @unload_mode: requested function's unload mode
  7282. *
  7283. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7284. */
  7285. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7286. {
  7287. u32 reset_code = 0;
  7288. int port = BP_PORT(bp);
  7289. /* Select the UNLOAD request mode */
  7290. if (unload_mode == UNLOAD_NORMAL)
  7291. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7292. else if (bp->flags & NO_WOL_FLAG)
  7293. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7294. else if (bp->wol) {
  7295. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7296. u8 *mac_addr = bp->dev->dev_addr;
  7297. struct pci_dev *pdev = bp->pdev;
  7298. u32 val;
  7299. u16 pmc;
  7300. /* The mac address is written to entries 1-4 to
  7301. * preserve entry 0 which is used by the PMF
  7302. */
  7303. u8 entry = (BP_VN(bp) + 1)*8;
  7304. val = (mac_addr[0] << 8) | mac_addr[1];
  7305. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7306. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7307. (mac_addr[4] << 8) | mac_addr[5];
  7308. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7309. /* Enable the PME and clear the status */
  7310. pci_read_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, &pmc);
  7311. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7312. pci_write_config_word(pdev, pdev->pm_cap + PCI_PM_CTRL, pmc);
  7313. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7314. } else
  7315. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7316. /* Send the request to the MCP */
  7317. if (!BP_NOMCP(bp))
  7318. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7319. else {
  7320. int path = BP_PATH(bp);
  7321. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7322. path, load_count[path][0], load_count[path][1],
  7323. load_count[path][2]);
  7324. load_count[path][0]--;
  7325. load_count[path][1 + port]--;
  7326. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7327. path, load_count[path][0], load_count[path][1],
  7328. load_count[path][2]);
  7329. if (load_count[path][0] == 0)
  7330. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7331. else if (load_count[path][1 + port] == 0)
  7332. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7333. else
  7334. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7335. }
  7336. return reset_code;
  7337. }
  7338. /**
  7339. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7340. *
  7341. * @bp: driver handle
  7342. * @keep_link: true iff link should be kept up
  7343. */
  7344. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7345. {
  7346. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7347. /* Report UNLOAD_DONE to MCP */
  7348. if (!BP_NOMCP(bp))
  7349. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7350. }
  7351. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7352. {
  7353. int tout = 50;
  7354. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7355. if (!bp->port.pmf)
  7356. return 0;
  7357. /*
  7358. * (assumption: No Attention from MCP at this stage)
  7359. * PMF probably in the middle of TX disable/enable transaction
  7360. * 1. Sync IRS for default SB
  7361. * 2. Sync SP queue - this guarantees us that attention handling started
  7362. * 3. Wait, that TX disable/enable transaction completes
  7363. *
  7364. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7365. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7366. * received completion for the transaction the state is TX_STOPPED.
  7367. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7368. * transaction.
  7369. */
  7370. /* make sure default SB ISR is done */
  7371. if (msix)
  7372. synchronize_irq(bp->msix_table[0].vector);
  7373. else
  7374. synchronize_irq(bp->pdev->irq);
  7375. flush_workqueue(bnx2x_wq);
  7376. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7377. BNX2X_F_STATE_STARTED && tout--)
  7378. msleep(20);
  7379. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7380. BNX2X_F_STATE_STARTED) {
  7381. #ifdef BNX2X_STOP_ON_ERROR
  7382. BNX2X_ERR("Wrong function state\n");
  7383. return -EBUSY;
  7384. #else
  7385. /*
  7386. * Failed to complete the transaction in a "good way"
  7387. * Force both transactions with CLR bit
  7388. */
  7389. struct bnx2x_func_state_params func_params = {NULL};
  7390. DP(NETIF_MSG_IFDOWN,
  7391. "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7392. func_params.f_obj = &bp->func_obj;
  7393. __set_bit(RAMROD_DRV_CLR_ONLY,
  7394. &func_params.ramrod_flags);
  7395. /* STARTED-->TX_ST0PPED */
  7396. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7397. bnx2x_func_state_change(bp, &func_params);
  7398. /* TX_ST0PPED-->STARTED */
  7399. func_params.cmd = BNX2X_F_CMD_TX_START;
  7400. return bnx2x_func_state_change(bp, &func_params);
  7401. #endif
  7402. }
  7403. return 0;
  7404. }
  7405. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7406. {
  7407. int port = BP_PORT(bp);
  7408. int i, rc = 0;
  7409. u8 cos;
  7410. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7411. u32 reset_code;
  7412. /* Wait until tx fastpath tasks complete */
  7413. for_each_tx_queue(bp, i) {
  7414. struct bnx2x_fastpath *fp = &bp->fp[i];
  7415. for_each_cos_in_tx_queue(fp, cos)
  7416. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7417. #ifdef BNX2X_STOP_ON_ERROR
  7418. if (rc)
  7419. return;
  7420. #endif
  7421. }
  7422. /* Give HW time to discard old tx messages */
  7423. usleep_range(1000, 2000);
  7424. /* Clean all ETH MACs */
  7425. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7426. false);
  7427. if (rc < 0)
  7428. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7429. /* Clean up UC list */
  7430. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7431. true);
  7432. if (rc < 0)
  7433. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7434. rc);
  7435. /* Disable LLH */
  7436. if (!CHIP_IS_E1(bp))
  7437. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7438. /* Set "drop all" (stop Rx).
  7439. * We need to take a netif_addr_lock() here in order to prevent
  7440. * a race between the completion code and this code.
  7441. */
  7442. netif_addr_lock_bh(bp->dev);
  7443. /* Schedule the rx_mode command */
  7444. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7445. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7446. else
  7447. bnx2x_set_storm_rx_mode(bp);
  7448. /* Cleanup multicast configuration */
  7449. rparam.mcast_obj = &bp->mcast_obj;
  7450. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7451. if (rc < 0)
  7452. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7453. netif_addr_unlock_bh(bp->dev);
  7454. bnx2x_iov_chip_cleanup(bp);
  7455. /*
  7456. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7457. * this function should perform FUNC, PORT or COMMON HW
  7458. * reset.
  7459. */
  7460. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7461. /*
  7462. * (assumption: No Attention from MCP at this stage)
  7463. * PMF probably in the middle of TX disable/enable transaction
  7464. */
  7465. rc = bnx2x_func_wait_started(bp);
  7466. if (rc) {
  7467. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7468. #ifdef BNX2X_STOP_ON_ERROR
  7469. return;
  7470. #endif
  7471. }
  7472. /* Close multi and leading connections
  7473. * Completions for ramrods are collected in a synchronous way
  7474. */
  7475. for_each_eth_queue(bp, i)
  7476. if (bnx2x_stop_queue(bp, i))
  7477. #ifdef BNX2X_STOP_ON_ERROR
  7478. return;
  7479. #else
  7480. goto unload_error;
  7481. #endif
  7482. if (CNIC_LOADED(bp)) {
  7483. for_each_cnic_queue(bp, i)
  7484. if (bnx2x_stop_queue(bp, i))
  7485. #ifdef BNX2X_STOP_ON_ERROR
  7486. return;
  7487. #else
  7488. goto unload_error;
  7489. #endif
  7490. }
  7491. /* If SP settings didn't get completed so far - something
  7492. * very wrong has happen.
  7493. */
  7494. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7495. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7496. #ifndef BNX2X_STOP_ON_ERROR
  7497. unload_error:
  7498. #endif
  7499. rc = bnx2x_func_stop(bp);
  7500. if (rc) {
  7501. BNX2X_ERR("Function stop failed!\n");
  7502. #ifdef BNX2X_STOP_ON_ERROR
  7503. return;
  7504. #endif
  7505. }
  7506. /* Disable HW interrupts, NAPI */
  7507. bnx2x_netif_stop(bp, 1);
  7508. /* Delete all NAPI objects */
  7509. bnx2x_del_all_napi(bp);
  7510. if (CNIC_LOADED(bp))
  7511. bnx2x_del_all_napi_cnic(bp);
  7512. /* Release IRQs */
  7513. bnx2x_free_irq(bp);
  7514. /* Reset the chip */
  7515. rc = bnx2x_reset_hw(bp, reset_code);
  7516. if (rc)
  7517. BNX2X_ERR("HW_RESET failed\n");
  7518. /* Report UNLOAD_DONE to MCP */
  7519. bnx2x_send_unload_done(bp, keep_link);
  7520. }
  7521. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7522. {
  7523. u32 val;
  7524. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7525. if (CHIP_IS_E1(bp)) {
  7526. int port = BP_PORT(bp);
  7527. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7528. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7529. val = REG_RD(bp, addr);
  7530. val &= ~(0x300);
  7531. REG_WR(bp, addr, val);
  7532. } else {
  7533. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7534. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7535. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7536. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7537. }
  7538. }
  7539. /* Close gates #2, #3 and #4: */
  7540. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7541. {
  7542. u32 val;
  7543. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7544. if (!CHIP_IS_E1(bp)) {
  7545. /* #4 */
  7546. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7547. /* #2 */
  7548. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7549. }
  7550. /* #3 */
  7551. if (CHIP_IS_E1x(bp)) {
  7552. /* Prevent interrupts from HC on both ports */
  7553. val = REG_RD(bp, HC_REG_CONFIG_1);
  7554. REG_WR(bp, HC_REG_CONFIG_1,
  7555. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7556. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7557. val = REG_RD(bp, HC_REG_CONFIG_0);
  7558. REG_WR(bp, HC_REG_CONFIG_0,
  7559. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7560. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7561. } else {
  7562. /* Prevent incoming interrupts in IGU */
  7563. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7564. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7565. (!close) ?
  7566. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7567. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7568. }
  7569. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7570. close ? "closing" : "opening");
  7571. mmiowb();
  7572. }
  7573. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7574. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7575. {
  7576. /* Do some magic... */
  7577. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7578. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7579. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7580. }
  7581. /**
  7582. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7583. *
  7584. * @bp: driver handle
  7585. * @magic_val: old value of the `magic' bit.
  7586. */
  7587. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7588. {
  7589. /* Restore the `magic' bit value... */
  7590. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7591. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7592. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7593. }
  7594. /**
  7595. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7596. *
  7597. * @bp: driver handle
  7598. * @magic_val: old value of 'magic' bit.
  7599. *
  7600. * Takes care of CLP configurations.
  7601. */
  7602. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7603. {
  7604. u32 shmem;
  7605. u32 validity_offset;
  7606. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7607. /* Set `magic' bit in order to save MF config */
  7608. if (!CHIP_IS_E1(bp))
  7609. bnx2x_clp_reset_prep(bp, magic_val);
  7610. /* Get shmem offset */
  7611. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7612. validity_offset =
  7613. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7614. /* Clear validity map flags */
  7615. if (shmem > 0)
  7616. REG_WR(bp, shmem + validity_offset, 0);
  7617. }
  7618. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7619. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7620. /**
  7621. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7622. *
  7623. * @bp: driver handle
  7624. */
  7625. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7626. {
  7627. /* special handling for emulation and FPGA,
  7628. wait 10 times longer */
  7629. if (CHIP_REV_IS_SLOW(bp))
  7630. msleep(MCP_ONE_TIMEOUT*10);
  7631. else
  7632. msleep(MCP_ONE_TIMEOUT);
  7633. }
  7634. /*
  7635. * initializes bp->common.shmem_base and waits for validity signature to appear
  7636. */
  7637. static int bnx2x_init_shmem(struct bnx2x *bp)
  7638. {
  7639. int cnt = 0;
  7640. u32 val = 0;
  7641. do {
  7642. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7643. if (bp->common.shmem_base) {
  7644. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7645. if (val & SHR_MEM_VALIDITY_MB)
  7646. return 0;
  7647. }
  7648. bnx2x_mcp_wait_one(bp);
  7649. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7650. BNX2X_ERR("BAD MCP validity signature\n");
  7651. return -ENODEV;
  7652. }
  7653. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7654. {
  7655. int rc = bnx2x_init_shmem(bp);
  7656. /* Restore the `magic' bit value */
  7657. if (!CHIP_IS_E1(bp))
  7658. bnx2x_clp_reset_done(bp, magic_val);
  7659. return rc;
  7660. }
  7661. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7662. {
  7663. if (!CHIP_IS_E1(bp)) {
  7664. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7665. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7666. mmiowb();
  7667. }
  7668. }
  7669. /*
  7670. * Reset the whole chip except for:
  7671. * - PCIE core
  7672. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7673. * one reset bit)
  7674. * - IGU
  7675. * - MISC (including AEU)
  7676. * - GRC
  7677. * - RBCN, RBCP
  7678. */
  7679. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7680. {
  7681. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7682. u32 global_bits2, stay_reset2;
  7683. /*
  7684. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7685. * (per chip) blocks.
  7686. */
  7687. global_bits2 =
  7688. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7689. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7690. /* Don't reset the following blocks.
  7691. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7692. * reset, as in 4 port device they might still be owned
  7693. * by the MCP (there is only one leader per path).
  7694. */
  7695. not_reset_mask1 =
  7696. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7697. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7698. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7699. not_reset_mask2 =
  7700. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7701. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7702. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7703. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7704. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7705. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7706. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7707. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7708. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7709. MISC_REGISTERS_RESET_REG_2_PGLC |
  7710. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7711. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7712. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7713. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7714. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7715. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7716. /*
  7717. * Keep the following blocks in reset:
  7718. * - all xxMACs are handled by the bnx2x_link code.
  7719. */
  7720. stay_reset2 =
  7721. MISC_REGISTERS_RESET_REG_2_XMAC |
  7722. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7723. /* Full reset masks according to the chip */
  7724. reset_mask1 = 0xffffffff;
  7725. if (CHIP_IS_E1(bp))
  7726. reset_mask2 = 0xffff;
  7727. else if (CHIP_IS_E1H(bp))
  7728. reset_mask2 = 0x1ffff;
  7729. else if (CHIP_IS_E2(bp))
  7730. reset_mask2 = 0xfffff;
  7731. else /* CHIP_IS_E3 */
  7732. reset_mask2 = 0x3ffffff;
  7733. /* Don't reset global blocks unless we need to */
  7734. if (!global)
  7735. reset_mask2 &= ~global_bits2;
  7736. /*
  7737. * In case of attention in the QM, we need to reset PXP
  7738. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7739. * because otherwise QM reset would release 'close the gates' shortly
  7740. * before resetting the PXP, then the PSWRQ would send a write
  7741. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7742. * read the payload data from PSWWR, but PSWWR would not
  7743. * respond. The write queue in PGLUE would stuck, dmae commands
  7744. * would not return. Therefore it's important to reset the second
  7745. * reset register (containing the
  7746. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7747. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7748. * bit).
  7749. */
  7750. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7751. reset_mask2 & (~not_reset_mask2));
  7752. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7753. reset_mask1 & (~not_reset_mask1));
  7754. barrier();
  7755. mmiowb();
  7756. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7757. reset_mask2 & (~stay_reset2));
  7758. barrier();
  7759. mmiowb();
  7760. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7761. mmiowb();
  7762. }
  7763. /**
  7764. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7765. * It should get cleared in no more than 1s.
  7766. *
  7767. * @bp: driver handle
  7768. *
  7769. * It should get cleared in no more than 1s. Returns 0 if
  7770. * pending writes bit gets cleared.
  7771. */
  7772. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7773. {
  7774. u32 cnt = 1000;
  7775. u32 pend_bits = 0;
  7776. do {
  7777. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7778. if (pend_bits == 0)
  7779. break;
  7780. usleep_range(1000, 2000);
  7781. } while (cnt-- > 0);
  7782. if (cnt <= 0) {
  7783. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7784. pend_bits);
  7785. return -EBUSY;
  7786. }
  7787. return 0;
  7788. }
  7789. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7790. {
  7791. int cnt = 1000;
  7792. u32 val = 0;
  7793. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7794. u32 tags_63_32 = 0;
  7795. /* Empty the Tetris buffer, wait for 1s */
  7796. do {
  7797. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7798. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7799. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7800. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7801. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7802. if (CHIP_IS_E3(bp))
  7803. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7804. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7805. ((port_is_idle_0 & 0x1) == 0x1) &&
  7806. ((port_is_idle_1 & 0x1) == 0x1) &&
  7807. (pgl_exp_rom2 == 0xffffffff) &&
  7808. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7809. break;
  7810. usleep_range(1000, 2000);
  7811. } while (cnt-- > 0);
  7812. if (cnt <= 0) {
  7813. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7814. 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",
  7815. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7816. pgl_exp_rom2);
  7817. return -EAGAIN;
  7818. }
  7819. barrier();
  7820. /* Close gates #2, #3 and #4 */
  7821. bnx2x_set_234_gates(bp, true);
  7822. /* Poll for IGU VQs for 57712 and newer chips */
  7823. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7824. return -EAGAIN;
  7825. /* TBD: Indicate that "process kill" is in progress to MCP */
  7826. /* Clear "unprepared" bit */
  7827. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7828. barrier();
  7829. /* Make sure all is written to the chip before the reset */
  7830. mmiowb();
  7831. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7832. * PSWHST, GRC and PSWRD Tetris buffer.
  7833. */
  7834. usleep_range(1000, 2000);
  7835. /* Prepare to chip reset: */
  7836. /* MCP */
  7837. if (global)
  7838. bnx2x_reset_mcp_prep(bp, &val);
  7839. /* PXP */
  7840. bnx2x_pxp_prep(bp);
  7841. barrier();
  7842. /* reset the chip */
  7843. bnx2x_process_kill_chip_reset(bp, global);
  7844. barrier();
  7845. /* Recover after reset: */
  7846. /* MCP */
  7847. if (global && bnx2x_reset_mcp_comp(bp, val))
  7848. return -EAGAIN;
  7849. /* TBD: Add resetting the NO_MCP mode DB here */
  7850. /* Open the gates #2, #3 and #4 */
  7851. bnx2x_set_234_gates(bp, false);
  7852. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7853. * reset state, re-enable attentions. */
  7854. return 0;
  7855. }
  7856. static int bnx2x_leader_reset(struct bnx2x *bp)
  7857. {
  7858. int rc = 0;
  7859. bool global = bnx2x_reset_is_global(bp);
  7860. u32 load_code;
  7861. /* if not going to reset MCP - load "fake" driver to reset HW while
  7862. * driver is owner of the HW
  7863. */
  7864. if (!global && !BP_NOMCP(bp)) {
  7865. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7866. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7867. if (!load_code) {
  7868. BNX2X_ERR("MCP response failure, aborting\n");
  7869. rc = -EAGAIN;
  7870. goto exit_leader_reset;
  7871. }
  7872. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7873. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7874. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7875. rc = -EAGAIN;
  7876. goto exit_leader_reset2;
  7877. }
  7878. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7879. if (!load_code) {
  7880. BNX2X_ERR("MCP response failure, aborting\n");
  7881. rc = -EAGAIN;
  7882. goto exit_leader_reset2;
  7883. }
  7884. }
  7885. /* Try to recover after the failure */
  7886. if (bnx2x_process_kill(bp, global)) {
  7887. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7888. BP_PATH(bp));
  7889. rc = -EAGAIN;
  7890. goto exit_leader_reset2;
  7891. }
  7892. /*
  7893. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7894. * state.
  7895. */
  7896. bnx2x_set_reset_done(bp);
  7897. if (global)
  7898. bnx2x_clear_reset_global(bp);
  7899. exit_leader_reset2:
  7900. /* unload "fake driver" if it was loaded */
  7901. if (!global && !BP_NOMCP(bp)) {
  7902. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7903. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7904. }
  7905. exit_leader_reset:
  7906. bp->is_leader = 0;
  7907. bnx2x_release_leader_lock(bp);
  7908. smp_mb();
  7909. return rc;
  7910. }
  7911. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7912. {
  7913. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7914. /* Disconnect this device */
  7915. netif_device_detach(bp->dev);
  7916. /*
  7917. * Block ifup for all function on this engine until "process kill"
  7918. * or power cycle.
  7919. */
  7920. bnx2x_set_reset_in_progress(bp);
  7921. /* Shut down the power */
  7922. bnx2x_set_power_state(bp, PCI_D3hot);
  7923. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7924. smp_mb();
  7925. }
  7926. /*
  7927. * Assumption: runs under rtnl lock. This together with the fact
  7928. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7929. * will never be called when netif_running(bp->dev) is false.
  7930. */
  7931. static void bnx2x_parity_recover(struct bnx2x *bp)
  7932. {
  7933. bool global = false;
  7934. u32 error_recovered, error_unrecovered;
  7935. bool is_parity;
  7936. DP(NETIF_MSG_HW, "Handling parity\n");
  7937. while (1) {
  7938. switch (bp->recovery_state) {
  7939. case BNX2X_RECOVERY_INIT:
  7940. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7941. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7942. WARN_ON(!is_parity);
  7943. /* Try to get a LEADER_LOCK HW lock */
  7944. if (bnx2x_trylock_leader_lock(bp)) {
  7945. bnx2x_set_reset_in_progress(bp);
  7946. /*
  7947. * Check if there is a global attention and if
  7948. * there was a global attention, set the global
  7949. * reset bit.
  7950. */
  7951. if (global)
  7952. bnx2x_set_reset_global(bp);
  7953. bp->is_leader = 1;
  7954. }
  7955. /* Stop the driver */
  7956. /* If interface has been removed - break */
  7957. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7958. return;
  7959. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7960. /* Ensure "is_leader", MCP command sequence and
  7961. * "recovery_state" update values are seen on other
  7962. * CPUs.
  7963. */
  7964. smp_mb();
  7965. break;
  7966. case BNX2X_RECOVERY_WAIT:
  7967. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7968. if (bp->is_leader) {
  7969. int other_engine = BP_PATH(bp) ? 0 : 1;
  7970. bool other_load_status =
  7971. bnx2x_get_load_status(bp, other_engine);
  7972. bool load_status =
  7973. bnx2x_get_load_status(bp, BP_PATH(bp));
  7974. global = bnx2x_reset_is_global(bp);
  7975. /*
  7976. * In case of a parity in a global block, let
  7977. * the first leader that performs a
  7978. * leader_reset() reset the global blocks in
  7979. * order to clear global attentions. Otherwise
  7980. * the gates will remain closed for that
  7981. * engine.
  7982. */
  7983. if (load_status ||
  7984. (global && other_load_status)) {
  7985. /* Wait until all other functions get
  7986. * down.
  7987. */
  7988. schedule_delayed_work(&bp->sp_rtnl_task,
  7989. HZ/10);
  7990. return;
  7991. } else {
  7992. /* If all other functions got down -
  7993. * try to bring the chip back to
  7994. * normal. In any case it's an exit
  7995. * point for a leader.
  7996. */
  7997. if (bnx2x_leader_reset(bp)) {
  7998. bnx2x_recovery_failed(bp);
  7999. return;
  8000. }
  8001. /* If we are here, means that the
  8002. * leader has succeeded and doesn't
  8003. * want to be a leader any more. Try
  8004. * to continue as a none-leader.
  8005. */
  8006. break;
  8007. }
  8008. } else { /* non-leader */
  8009. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  8010. /* Try to get a LEADER_LOCK HW lock as
  8011. * long as a former leader may have
  8012. * been unloaded by the user or
  8013. * released a leadership by another
  8014. * reason.
  8015. */
  8016. if (bnx2x_trylock_leader_lock(bp)) {
  8017. /* I'm a leader now! Restart a
  8018. * switch case.
  8019. */
  8020. bp->is_leader = 1;
  8021. break;
  8022. }
  8023. schedule_delayed_work(&bp->sp_rtnl_task,
  8024. HZ/10);
  8025. return;
  8026. } else {
  8027. /*
  8028. * If there was a global attention, wait
  8029. * for it to be cleared.
  8030. */
  8031. if (bnx2x_reset_is_global(bp)) {
  8032. schedule_delayed_work(
  8033. &bp->sp_rtnl_task,
  8034. HZ/10);
  8035. return;
  8036. }
  8037. error_recovered =
  8038. bp->eth_stats.recoverable_error;
  8039. error_unrecovered =
  8040. bp->eth_stats.unrecoverable_error;
  8041. bp->recovery_state =
  8042. BNX2X_RECOVERY_NIC_LOADING;
  8043. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8044. error_unrecovered++;
  8045. netdev_err(bp->dev,
  8046. "Recovery failed. Power cycle needed\n");
  8047. /* Disconnect this device */
  8048. netif_device_detach(bp->dev);
  8049. /* Shut down the power */
  8050. bnx2x_set_power_state(
  8051. bp, PCI_D3hot);
  8052. smp_mb();
  8053. } else {
  8054. bp->recovery_state =
  8055. BNX2X_RECOVERY_DONE;
  8056. error_recovered++;
  8057. smp_mb();
  8058. }
  8059. bp->eth_stats.recoverable_error =
  8060. error_recovered;
  8061. bp->eth_stats.unrecoverable_error =
  8062. error_unrecovered;
  8063. return;
  8064. }
  8065. }
  8066. default:
  8067. return;
  8068. }
  8069. }
  8070. }
  8071. static int bnx2x_close(struct net_device *dev);
  8072. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8073. * scheduled on a general queue in order to prevent a dead lock.
  8074. */
  8075. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8076. {
  8077. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8078. rtnl_lock();
  8079. if (!netif_running(bp->dev)) {
  8080. rtnl_unlock();
  8081. return;
  8082. }
  8083. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8084. #ifdef BNX2X_STOP_ON_ERROR
  8085. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8086. "you will need to reboot when done\n");
  8087. goto sp_rtnl_not_reset;
  8088. #endif
  8089. /*
  8090. * Clear all pending SP commands as we are going to reset the
  8091. * function anyway.
  8092. */
  8093. bp->sp_rtnl_state = 0;
  8094. smp_mb();
  8095. bnx2x_parity_recover(bp);
  8096. rtnl_unlock();
  8097. return;
  8098. }
  8099. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8100. #ifdef BNX2X_STOP_ON_ERROR
  8101. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8102. "you will need to reboot when done\n");
  8103. goto sp_rtnl_not_reset;
  8104. #endif
  8105. /*
  8106. * Clear all pending SP commands as we are going to reset the
  8107. * function anyway.
  8108. */
  8109. bp->sp_rtnl_state = 0;
  8110. smp_mb();
  8111. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8112. bnx2x_nic_load(bp, LOAD_NORMAL);
  8113. rtnl_unlock();
  8114. return;
  8115. }
  8116. #ifdef BNX2X_STOP_ON_ERROR
  8117. sp_rtnl_not_reset:
  8118. #endif
  8119. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8120. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8121. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8122. bnx2x_after_function_update(bp);
  8123. /*
  8124. * in case of fan failure we need to reset id if the "stop on error"
  8125. * debug flag is set, since we trying to prevent permanent overheating
  8126. * damage
  8127. */
  8128. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8129. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8130. netif_device_detach(bp->dev);
  8131. bnx2x_close(bp->dev);
  8132. rtnl_unlock();
  8133. return;
  8134. }
  8135. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8136. DP(BNX2X_MSG_SP,
  8137. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8138. bnx2x_vfpf_set_mcast(bp->dev);
  8139. }
  8140. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8141. &bp->sp_rtnl_state)){
  8142. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8143. bnx2x_tx_disable(bp);
  8144. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8145. }
  8146. }
  8147. if (test_and_clear_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state)) {
  8148. DP(BNX2X_MSG_SP, "Handling Rx Mode setting\n");
  8149. bnx2x_set_rx_mode_inner(bp);
  8150. }
  8151. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8152. &bp->sp_rtnl_state))
  8153. bnx2x_pf_set_vfs_vlan(bp);
  8154. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_STOP, &bp->sp_rtnl_state))
  8155. bnx2x_dcbx_stop_hw_tx(bp);
  8156. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_RESUME, &bp->sp_rtnl_state))
  8157. bnx2x_dcbx_resume_hw_tx(bp);
  8158. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8159. * can be called from other contexts as well)
  8160. */
  8161. rtnl_unlock();
  8162. /* enable SR-IOV if applicable */
  8163. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8164. &bp->sp_rtnl_state)) {
  8165. bnx2x_disable_sriov(bp);
  8166. bnx2x_enable_sriov(bp);
  8167. }
  8168. }
  8169. static void bnx2x_period_task(struct work_struct *work)
  8170. {
  8171. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8172. if (!netif_running(bp->dev))
  8173. goto period_task_exit;
  8174. if (CHIP_REV_IS_SLOW(bp)) {
  8175. BNX2X_ERR("period task called on emulation, ignoring\n");
  8176. goto period_task_exit;
  8177. }
  8178. bnx2x_acquire_phy_lock(bp);
  8179. /*
  8180. * The barrier is needed to ensure the ordering between the writing to
  8181. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8182. * the reading here.
  8183. */
  8184. smp_mb();
  8185. if (bp->port.pmf) {
  8186. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8187. /* Re-queue task in 1 sec */
  8188. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8189. }
  8190. bnx2x_release_phy_lock(bp);
  8191. period_task_exit:
  8192. return;
  8193. }
  8194. /*
  8195. * Init service functions
  8196. */
  8197. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8198. {
  8199. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8200. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8201. return base + (BP_ABS_FUNC(bp)) * stride;
  8202. }
  8203. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8204. struct bnx2x_mac_vals *vals)
  8205. {
  8206. u32 val, base_addr, offset, mask, reset_reg;
  8207. bool mac_stopped = false;
  8208. u8 port = BP_PORT(bp);
  8209. /* reset addresses as they also mark which values were changed */
  8210. vals->bmac_addr = 0;
  8211. vals->umac_addr = 0;
  8212. vals->xmac_addr = 0;
  8213. vals->emac_addr = 0;
  8214. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8215. if (!CHIP_IS_E3(bp)) {
  8216. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8217. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8218. if ((mask & reset_reg) && val) {
  8219. u32 wb_data[2];
  8220. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8221. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8222. : NIG_REG_INGRESS_BMAC0_MEM;
  8223. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8224. : BIGMAC_REGISTER_BMAC_CONTROL;
  8225. /*
  8226. * use rd/wr since we cannot use dmae. This is safe
  8227. * since MCP won't access the bus due to the request
  8228. * to unload, and no function on the path can be
  8229. * loaded at this time.
  8230. */
  8231. wb_data[0] = REG_RD(bp, base_addr + offset);
  8232. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8233. vals->bmac_addr = base_addr + offset;
  8234. vals->bmac_val[0] = wb_data[0];
  8235. vals->bmac_val[1] = wb_data[1];
  8236. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8237. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8238. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8239. }
  8240. BNX2X_DEV_INFO("Disable emac Rx\n");
  8241. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8242. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8243. REG_WR(bp, vals->emac_addr, 0);
  8244. mac_stopped = true;
  8245. } else {
  8246. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8247. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8248. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8249. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8250. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8251. val & ~(1 << 1));
  8252. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8253. val | (1 << 1));
  8254. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8255. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8256. REG_WR(bp, vals->xmac_addr, 0);
  8257. mac_stopped = true;
  8258. }
  8259. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8260. if (mask & reset_reg) {
  8261. BNX2X_DEV_INFO("Disable umac Rx\n");
  8262. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8263. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8264. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8265. REG_WR(bp, vals->umac_addr, 0);
  8266. mac_stopped = true;
  8267. }
  8268. }
  8269. if (mac_stopped)
  8270. msleep(20);
  8271. }
  8272. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8273. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8274. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8275. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8276. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8277. {
  8278. u16 rcq, bd;
  8279. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8280. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8281. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8282. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8283. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8284. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8285. port, bd, rcq);
  8286. }
  8287. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8288. {
  8289. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8290. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8291. if (!rc) {
  8292. BNX2X_ERR("MCP response failure, aborting\n");
  8293. return -EBUSY;
  8294. }
  8295. return 0;
  8296. }
  8297. static struct bnx2x_prev_path_list *
  8298. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8299. {
  8300. struct bnx2x_prev_path_list *tmp_list;
  8301. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8302. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8303. bp->pdev->bus->number == tmp_list->bus &&
  8304. BP_PATH(bp) == tmp_list->path)
  8305. return tmp_list;
  8306. return NULL;
  8307. }
  8308. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8309. {
  8310. struct bnx2x_prev_path_list *tmp_list;
  8311. int rc;
  8312. rc = down_interruptible(&bnx2x_prev_sem);
  8313. if (rc) {
  8314. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8315. return rc;
  8316. }
  8317. tmp_list = bnx2x_prev_path_get_entry(bp);
  8318. if (tmp_list) {
  8319. tmp_list->aer = 1;
  8320. rc = 0;
  8321. } else {
  8322. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8323. BP_PATH(bp));
  8324. }
  8325. up(&bnx2x_prev_sem);
  8326. return rc;
  8327. }
  8328. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8329. {
  8330. struct bnx2x_prev_path_list *tmp_list;
  8331. bool rc = false;
  8332. if (down_trylock(&bnx2x_prev_sem))
  8333. return false;
  8334. tmp_list = bnx2x_prev_path_get_entry(bp);
  8335. if (tmp_list) {
  8336. if (tmp_list->aer) {
  8337. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8338. BP_PATH(bp));
  8339. } else {
  8340. rc = true;
  8341. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8342. BP_PATH(bp));
  8343. }
  8344. }
  8345. up(&bnx2x_prev_sem);
  8346. return rc;
  8347. }
  8348. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8349. {
  8350. struct bnx2x_prev_path_list *entry;
  8351. bool val;
  8352. down(&bnx2x_prev_sem);
  8353. entry = bnx2x_prev_path_get_entry(bp);
  8354. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8355. up(&bnx2x_prev_sem);
  8356. return val;
  8357. }
  8358. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8359. {
  8360. struct bnx2x_prev_path_list *tmp_list;
  8361. int rc;
  8362. rc = down_interruptible(&bnx2x_prev_sem);
  8363. if (rc) {
  8364. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8365. return rc;
  8366. }
  8367. /* Check whether the entry for this path already exists */
  8368. tmp_list = bnx2x_prev_path_get_entry(bp);
  8369. if (tmp_list) {
  8370. if (!tmp_list->aer) {
  8371. BNX2X_ERR("Re-Marking the path.\n");
  8372. } else {
  8373. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8374. BP_PATH(bp));
  8375. tmp_list->aer = 0;
  8376. }
  8377. up(&bnx2x_prev_sem);
  8378. return 0;
  8379. }
  8380. up(&bnx2x_prev_sem);
  8381. /* Create an entry for this path and add it */
  8382. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8383. if (!tmp_list) {
  8384. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8385. return -ENOMEM;
  8386. }
  8387. tmp_list->bus = bp->pdev->bus->number;
  8388. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8389. tmp_list->path = BP_PATH(bp);
  8390. tmp_list->aer = 0;
  8391. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8392. rc = down_interruptible(&bnx2x_prev_sem);
  8393. if (rc) {
  8394. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8395. kfree(tmp_list);
  8396. } else {
  8397. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8398. BP_PATH(bp));
  8399. list_add(&tmp_list->list, &bnx2x_prev_list);
  8400. up(&bnx2x_prev_sem);
  8401. }
  8402. return rc;
  8403. }
  8404. static int bnx2x_do_flr(struct bnx2x *bp)
  8405. {
  8406. struct pci_dev *dev = bp->pdev;
  8407. if (CHIP_IS_E1x(bp)) {
  8408. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8409. return -EINVAL;
  8410. }
  8411. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8412. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8413. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8414. bp->common.bc_ver);
  8415. return -EINVAL;
  8416. }
  8417. if (!pci_wait_for_pending_transaction(dev))
  8418. dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
  8419. BNX2X_DEV_INFO("Initiating FLR\n");
  8420. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8421. return 0;
  8422. }
  8423. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8424. {
  8425. int rc;
  8426. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8427. /* Test if previous unload process was already finished for this path */
  8428. if (bnx2x_prev_is_path_marked(bp))
  8429. return bnx2x_prev_mcp_done(bp);
  8430. BNX2X_DEV_INFO("Path is unmarked\n");
  8431. /* If function has FLR capabilities, and existing FW version matches
  8432. * the one required, then FLR will be sufficient to clean any residue
  8433. * left by previous driver
  8434. */
  8435. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8436. if (!rc) {
  8437. /* fw version is good */
  8438. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8439. rc = bnx2x_do_flr(bp);
  8440. }
  8441. if (!rc) {
  8442. /* FLR was performed */
  8443. BNX2X_DEV_INFO("FLR successful\n");
  8444. return 0;
  8445. }
  8446. BNX2X_DEV_INFO("Could not FLR\n");
  8447. /* Close the MCP request, return failure*/
  8448. rc = bnx2x_prev_mcp_done(bp);
  8449. if (!rc)
  8450. rc = BNX2X_PREV_WAIT_NEEDED;
  8451. return rc;
  8452. }
  8453. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8454. {
  8455. u32 reset_reg, tmp_reg = 0, rc;
  8456. bool prev_undi = false;
  8457. struct bnx2x_mac_vals mac_vals;
  8458. /* It is possible a previous function received 'common' answer,
  8459. * but hasn't loaded yet, therefore creating a scenario of
  8460. * multiple functions receiving 'common' on the same path.
  8461. */
  8462. BNX2X_DEV_INFO("Common unload Flow\n");
  8463. memset(&mac_vals, 0, sizeof(mac_vals));
  8464. if (bnx2x_prev_is_path_marked(bp))
  8465. return bnx2x_prev_mcp_done(bp);
  8466. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8467. /* Reset should be performed after BRB is emptied */
  8468. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8469. u32 timer_count = 1000;
  8470. /* Close the MAC Rx to prevent BRB from filling up */
  8471. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8472. /* close LLH filters towards the BRB */
  8473. bnx2x_set_rx_filter(&bp->link_params, 0);
  8474. /* Check if the UNDI driver was previously loaded
  8475. * UNDI driver initializes CID offset for normal bell to 0x7
  8476. */
  8477. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8478. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8479. if (tmp_reg == 0x7) {
  8480. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8481. prev_undi = true;
  8482. /* clear the UNDI indication */
  8483. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8484. /* clear possible idle check errors */
  8485. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8486. }
  8487. }
  8488. if (!CHIP_IS_E1x(bp))
  8489. /* block FW from writing to host */
  8490. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8491. /* wait until BRB is empty */
  8492. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8493. while (timer_count) {
  8494. u32 prev_brb = tmp_reg;
  8495. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8496. if (!tmp_reg)
  8497. break;
  8498. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8499. /* reset timer as long as BRB actually gets emptied */
  8500. if (prev_brb > tmp_reg)
  8501. timer_count = 1000;
  8502. else
  8503. timer_count--;
  8504. /* If UNDI resides in memory, manually increment it */
  8505. if (prev_undi)
  8506. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8507. udelay(10);
  8508. }
  8509. if (!timer_count)
  8510. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8511. }
  8512. /* No packets are in the pipeline, path is ready for reset */
  8513. bnx2x_reset_common(bp);
  8514. if (mac_vals.xmac_addr)
  8515. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8516. if (mac_vals.umac_addr)
  8517. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8518. if (mac_vals.emac_addr)
  8519. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8520. if (mac_vals.bmac_addr) {
  8521. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8522. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8523. }
  8524. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8525. if (rc) {
  8526. bnx2x_prev_mcp_done(bp);
  8527. return rc;
  8528. }
  8529. return bnx2x_prev_mcp_done(bp);
  8530. }
  8531. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8532. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8533. * the addresses of the transaction, resulting in was-error bit set in the pci
  8534. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8535. * to clear the interrupt which detected this from the pglueb and the was done
  8536. * bit
  8537. */
  8538. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8539. {
  8540. if (!CHIP_IS_E1x(bp)) {
  8541. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8542. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8543. DP(BNX2X_MSG_SP,
  8544. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8545. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8546. 1 << BP_FUNC(bp));
  8547. }
  8548. }
  8549. }
  8550. static int bnx2x_prev_unload(struct bnx2x *bp)
  8551. {
  8552. int time_counter = 10;
  8553. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8554. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8555. /* clear hw from errors which may have resulted from an interrupted
  8556. * dmae transaction.
  8557. */
  8558. bnx2x_prev_interrupted_dmae(bp);
  8559. /* Release previously held locks */
  8560. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8561. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8562. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8563. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8564. if (hw_lock_val) {
  8565. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8566. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8567. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8568. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8569. }
  8570. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8571. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8572. } else
  8573. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8574. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8575. BNX2X_DEV_INFO("Release previously held alr\n");
  8576. bnx2x_release_alr(bp);
  8577. }
  8578. do {
  8579. int aer = 0;
  8580. /* Lock MCP using an unload request */
  8581. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8582. if (!fw) {
  8583. BNX2X_ERR("MCP response failure, aborting\n");
  8584. rc = -EBUSY;
  8585. break;
  8586. }
  8587. rc = down_interruptible(&bnx2x_prev_sem);
  8588. if (rc) {
  8589. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8590. rc);
  8591. } else {
  8592. /* If Path is marked by EEH, ignore unload status */
  8593. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8594. bnx2x_prev_path_get_entry(bp)->aer);
  8595. up(&bnx2x_prev_sem);
  8596. }
  8597. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8598. rc = bnx2x_prev_unload_common(bp);
  8599. break;
  8600. }
  8601. /* non-common reply from MCP might require looping */
  8602. rc = bnx2x_prev_unload_uncommon(bp);
  8603. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8604. break;
  8605. msleep(20);
  8606. } while (--time_counter);
  8607. if (!time_counter || rc) {
  8608. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8609. rc = -EBUSY;
  8610. }
  8611. /* Mark function if its port was used to boot from SAN */
  8612. if (bnx2x_port_after_undi(bp))
  8613. bp->link_params.feature_config_flags |=
  8614. FEATURE_CONFIG_BOOT_FROM_SAN;
  8615. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8616. return rc;
  8617. }
  8618. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8619. {
  8620. u32 val, val2, val3, val4, id, boot_mode;
  8621. u16 pmc;
  8622. /* Get the chip revision id and number. */
  8623. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8624. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8625. id = ((val & 0xffff) << 16);
  8626. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8627. id |= ((val & 0xf) << 12);
  8628. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8629. * the configuration space (so we need to reg_rd)
  8630. */
  8631. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8632. id |= (((val >> 24) & 0xf) << 4);
  8633. val = REG_RD(bp, MISC_REG_BOND_ID);
  8634. id |= (val & 0xf);
  8635. bp->common.chip_id = id;
  8636. /* force 57811 according to MISC register */
  8637. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8638. if (CHIP_IS_57810(bp))
  8639. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8640. (bp->common.chip_id & 0x0000FFFF);
  8641. else if (CHIP_IS_57810_MF(bp))
  8642. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8643. (bp->common.chip_id & 0x0000FFFF);
  8644. bp->common.chip_id |= 0x1;
  8645. }
  8646. /* Set doorbell size */
  8647. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8648. if (!CHIP_IS_E1x(bp)) {
  8649. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8650. if ((val & 1) == 0)
  8651. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8652. else
  8653. val = (val >> 1) & 1;
  8654. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8655. "2_PORT_MODE");
  8656. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8657. CHIP_2_PORT_MODE;
  8658. if (CHIP_MODE_IS_4_PORT(bp))
  8659. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8660. else
  8661. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8662. } else {
  8663. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8664. bp->pfid = bp->pf_num; /* 0..7 */
  8665. }
  8666. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8667. bp->link_params.chip_id = bp->common.chip_id;
  8668. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8669. val = (REG_RD(bp, 0x2874) & 0x55);
  8670. if ((bp->common.chip_id & 0x1) ||
  8671. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8672. bp->flags |= ONE_PORT_FLAG;
  8673. BNX2X_DEV_INFO("single port device\n");
  8674. }
  8675. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8676. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8677. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8678. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8679. bp->common.flash_size, bp->common.flash_size);
  8680. bnx2x_init_shmem(bp);
  8681. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8682. MISC_REG_GENERIC_CR_1 :
  8683. MISC_REG_GENERIC_CR_0));
  8684. bp->link_params.shmem_base = bp->common.shmem_base;
  8685. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8686. if (SHMEM2_RD(bp, size) >
  8687. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8688. bp->link_params.lfa_base =
  8689. REG_RD(bp, bp->common.shmem2_base +
  8690. (u32)offsetof(struct shmem2_region,
  8691. lfa_host_addr[BP_PORT(bp)]));
  8692. else
  8693. bp->link_params.lfa_base = 0;
  8694. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8695. bp->common.shmem_base, bp->common.shmem2_base);
  8696. if (!bp->common.shmem_base) {
  8697. BNX2X_DEV_INFO("MCP not active\n");
  8698. bp->flags |= NO_MCP_FLAG;
  8699. return;
  8700. }
  8701. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8702. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8703. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8704. SHARED_HW_CFG_LED_MODE_MASK) >>
  8705. SHARED_HW_CFG_LED_MODE_SHIFT);
  8706. bp->link_params.feature_config_flags = 0;
  8707. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8708. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8709. bp->link_params.feature_config_flags |=
  8710. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8711. else
  8712. bp->link_params.feature_config_flags &=
  8713. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8714. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8715. bp->common.bc_ver = val;
  8716. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8717. if (val < BNX2X_BC_VER) {
  8718. /* for now only warn
  8719. * later we might need to enforce this */
  8720. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8721. BNX2X_BC_VER, val);
  8722. }
  8723. bp->link_params.feature_config_flags |=
  8724. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8725. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8726. bp->link_params.feature_config_flags |=
  8727. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8728. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8729. bp->link_params.feature_config_flags |=
  8730. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8731. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8732. bp->link_params.feature_config_flags |=
  8733. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8734. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8735. bp->link_params.feature_config_flags |=
  8736. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8737. FEATURE_CONFIG_MT_SUPPORT : 0;
  8738. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8739. BC_SUPPORTS_PFC_STATS : 0;
  8740. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8741. BC_SUPPORTS_FCOE_FEATURES : 0;
  8742. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8743. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8744. bp->flags |= (val >= REQ_BC_VER_4_RMMOD_CMD) ?
  8745. BC_SUPPORTS_RMMOD_CMD : 0;
  8746. boot_mode = SHMEM_RD(bp,
  8747. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8748. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8749. switch (boot_mode) {
  8750. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8751. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8752. break;
  8753. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8754. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8755. break;
  8756. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8757. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8758. break;
  8759. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8760. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8761. break;
  8762. }
  8763. pci_read_config_word(bp->pdev, bp->pdev->pm_cap + PCI_PM_PMC, &pmc);
  8764. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8765. BNX2X_DEV_INFO("%sWoL capable\n",
  8766. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8767. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8768. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8769. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8770. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8771. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8772. val, val2, val3, val4);
  8773. }
  8774. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8775. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8776. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8777. {
  8778. int pfid = BP_FUNC(bp);
  8779. int igu_sb_id;
  8780. u32 val;
  8781. u8 fid, igu_sb_cnt = 0;
  8782. bp->igu_base_sb = 0xff;
  8783. if (CHIP_INT_MODE_IS_BC(bp)) {
  8784. int vn = BP_VN(bp);
  8785. igu_sb_cnt = bp->igu_sb_cnt;
  8786. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8787. FP_SB_MAX_E1x;
  8788. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8789. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8790. return 0;
  8791. }
  8792. /* IGU in normal mode - read CAM */
  8793. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8794. igu_sb_id++) {
  8795. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8796. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8797. continue;
  8798. fid = IGU_FID(val);
  8799. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8800. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8801. continue;
  8802. if (IGU_VEC(val) == 0)
  8803. /* default status block */
  8804. bp->igu_dsb_id = igu_sb_id;
  8805. else {
  8806. if (bp->igu_base_sb == 0xff)
  8807. bp->igu_base_sb = igu_sb_id;
  8808. igu_sb_cnt++;
  8809. }
  8810. }
  8811. }
  8812. #ifdef CONFIG_PCI_MSI
  8813. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8814. * optional that number of CAM entries will not be equal to the value
  8815. * advertised in PCI.
  8816. * Driver should use the minimal value of both as the actual status
  8817. * block count
  8818. */
  8819. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8820. #endif
  8821. if (igu_sb_cnt == 0) {
  8822. BNX2X_ERR("CAM configuration error\n");
  8823. return -EINVAL;
  8824. }
  8825. return 0;
  8826. }
  8827. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8828. {
  8829. int cfg_size = 0, idx, port = BP_PORT(bp);
  8830. /* Aggregation of supported attributes of all external phys */
  8831. bp->port.supported[0] = 0;
  8832. bp->port.supported[1] = 0;
  8833. switch (bp->link_params.num_phys) {
  8834. case 1:
  8835. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8836. cfg_size = 1;
  8837. break;
  8838. case 2:
  8839. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8840. cfg_size = 1;
  8841. break;
  8842. case 3:
  8843. if (bp->link_params.multi_phy_config &
  8844. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8845. bp->port.supported[1] =
  8846. bp->link_params.phy[EXT_PHY1].supported;
  8847. bp->port.supported[0] =
  8848. bp->link_params.phy[EXT_PHY2].supported;
  8849. } else {
  8850. bp->port.supported[0] =
  8851. bp->link_params.phy[EXT_PHY1].supported;
  8852. bp->port.supported[1] =
  8853. bp->link_params.phy[EXT_PHY2].supported;
  8854. }
  8855. cfg_size = 2;
  8856. break;
  8857. }
  8858. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8859. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8860. SHMEM_RD(bp,
  8861. dev_info.port_hw_config[port].external_phy_config),
  8862. SHMEM_RD(bp,
  8863. dev_info.port_hw_config[port].external_phy_config2));
  8864. return;
  8865. }
  8866. if (CHIP_IS_E3(bp))
  8867. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8868. else {
  8869. switch (switch_cfg) {
  8870. case SWITCH_CFG_1G:
  8871. bp->port.phy_addr = REG_RD(
  8872. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8873. break;
  8874. case SWITCH_CFG_10G:
  8875. bp->port.phy_addr = REG_RD(
  8876. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8877. break;
  8878. default:
  8879. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8880. bp->port.link_config[0]);
  8881. return;
  8882. }
  8883. }
  8884. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8885. /* mask what we support according to speed_cap_mask per configuration */
  8886. for (idx = 0; idx < cfg_size; idx++) {
  8887. if (!(bp->link_params.speed_cap_mask[idx] &
  8888. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8889. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8890. if (!(bp->link_params.speed_cap_mask[idx] &
  8891. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8892. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8893. if (!(bp->link_params.speed_cap_mask[idx] &
  8894. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8895. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8896. if (!(bp->link_params.speed_cap_mask[idx] &
  8897. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8898. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8899. if (!(bp->link_params.speed_cap_mask[idx] &
  8900. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8901. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8902. SUPPORTED_1000baseT_Full);
  8903. if (!(bp->link_params.speed_cap_mask[idx] &
  8904. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8905. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8906. if (!(bp->link_params.speed_cap_mask[idx] &
  8907. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8908. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8909. if (!(bp->link_params.speed_cap_mask[idx] &
  8910. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  8911. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  8912. }
  8913. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8914. bp->port.supported[1]);
  8915. }
  8916. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8917. {
  8918. u32 link_config, idx, cfg_size = 0;
  8919. bp->port.advertising[0] = 0;
  8920. bp->port.advertising[1] = 0;
  8921. switch (bp->link_params.num_phys) {
  8922. case 1:
  8923. case 2:
  8924. cfg_size = 1;
  8925. break;
  8926. case 3:
  8927. cfg_size = 2;
  8928. break;
  8929. }
  8930. for (idx = 0; idx < cfg_size; idx++) {
  8931. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8932. link_config = bp->port.link_config[idx];
  8933. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8934. case PORT_FEATURE_LINK_SPEED_AUTO:
  8935. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8936. bp->link_params.req_line_speed[idx] =
  8937. SPEED_AUTO_NEG;
  8938. bp->port.advertising[idx] |=
  8939. bp->port.supported[idx];
  8940. if (bp->link_params.phy[EXT_PHY1].type ==
  8941. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8942. bp->port.advertising[idx] |=
  8943. (SUPPORTED_100baseT_Half |
  8944. SUPPORTED_100baseT_Full);
  8945. } else {
  8946. /* force 10G, no AN */
  8947. bp->link_params.req_line_speed[idx] =
  8948. SPEED_10000;
  8949. bp->port.advertising[idx] |=
  8950. (ADVERTISED_10000baseT_Full |
  8951. ADVERTISED_FIBRE);
  8952. continue;
  8953. }
  8954. break;
  8955. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8956. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8957. bp->link_params.req_line_speed[idx] =
  8958. SPEED_10;
  8959. bp->port.advertising[idx] |=
  8960. (ADVERTISED_10baseT_Full |
  8961. ADVERTISED_TP);
  8962. } else {
  8963. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8964. link_config,
  8965. bp->link_params.speed_cap_mask[idx]);
  8966. return;
  8967. }
  8968. break;
  8969. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8970. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8971. bp->link_params.req_line_speed[idx] =
  8972. SPEED_10;
  8973. bp->link_params.req_duplex[idx] =
  8974. DUPLEX_HALF;
  8975. bp->port.advertising[idx] |=
  8976. (ADVERTISED_10baseT_Half |
  8977. ADVERTISED_TP);
  8978. } else {
  8979. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8980. link_config,
  8981. bp->link_params.speed_cap_mask[idx]);
  8982. return;
  8983. }
  8984. break;
  8985. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8986. if (bp->port.supported[idx] &
  8987. SUPPORTED_100baseT_Full) {
  8988. bp->link_params.req_line_speed[idx] =
  8989. SPEED_100;
  8990. bp->port.advertising[idx] |=
  8991. (ADVERTISED_100baseT_Full |
  8992. ADVERTISED_TP);
  8993. } else {
  8994. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8995. link_config,
  8996. bp->link_params.speed_cap_mask[idx]);
  8997. return;
  8998. }
  8999. break;
  9000. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  9001. if (bp->port.supported[idx] &
  9002. SUPPORTED_100baseT_Half) {
  9003. bp->link_params.req_line_speed[idx] =
  9004. SPEED_100;
  9005. bp->link_params.req_duplex[idx] =
  9006. DUPLEX_HALF;
  9007. bp->port.advertising[idx] |=
  9008. (ADVERTISED_100baseT_Half |
  9009. ADVERTISED_TP);
  9010. } else {
  9011. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9012. link_config,
  9013. bp->link_params.speed_cap_mask[idx]);
  9014. return;
  9015. }
  9016. break;
  9017. case PORT_FEATURE_LINK_SPEED_1G:
  9018. if (bp->port.supported[idx] &
  9019. SUPPORTED_1000baseT_Full) {
  9020. bp->link_params.req_line_speed[idx] =
  9021. SPEED_1000;
  9022. bp->port.advertising[idx] |=
  9023. (ADVERTISED_1000baseT_Full |
  9024. ADVERTISED_TP);
  9025. } else {
  9026. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9027. link_config,
  9028. bp->link_params.speed_cap_mask[idx]);
  9029. return;
  9030. }
  9031. break;
  9032. case PORT_FEATURE_LINK_SPEED_2_5G:
  9033. if (bp->port.supported[idx] &
  9034. SUPPORTED_2500baseX_Full) {
  9035. bp->link_params.req_line_speed[idx] =
  9036. SPEED_2500;
  9037. bp->port.advertising[idx] |=
  9038. (ADVERTISED_2500baseX_Full |
  9039. ADVERTISED_TP);
  9040. } else {
  9041. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9042. link_config,
  9043. bp->link_params.speed_cap_mask[idx]);
  9044. return;
  9045. }
  9046. break;
  9047. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9048. if (bp->port.supported[idx] &
  9049. SUPPORTED_10000baseT_Full) {
  9050. bp->link_params.req_line_speed[idx] =
  9051. SPEED_10000;
  9052. bp->port.advertising[idx] |=
  9053. (ADVERTISED_10000baseT_Full |
  9054. ADVERTISED_FIBRE);
  9055. } else {
  9056. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9057. link_config,
  9058. bp->link_params.speed_cap_mask[idx]);
  9059. return;
  9060. }
  9061. break;
  9062. case PORT_FEATURE_LINK_SPEED_20G:
  9063. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9064. break;
  9065. default:
  9066. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9067. link_config);
  9068. bp->link_params.req_line_speed[idx] =
  9069. SPEED_AUTO_NEG;
  9070. bp->port.advertising[idx] =
  9071. bp->port.supported[idx];
  9072. break;
  9073. }
  9074. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9075. PORT_FEATURE_FLOW_CONTROL_MASK);
  9076. if (bp->link_params.req_flow_ctrl[idx] ==
  9077. BNX2X_FLOW_CTRL_AUTO) {
  9078. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9079. bp->link_params.req_flow_ctrl[idx] =
  9080. BNX2X_FLOW_CTRL_NONE;
  9081. else
  9082. bnx2x_set_requested_fc(bp);
  9083. }
  9084. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9085. bp->link_params.req_line_speed[idx],
  9086. bp->link_params.req_duplex[idx],
  9087. bp->link_params.req_flow_ctrl[idx],
  9088. bp->port.advertising[idx]);
  9089. }
  9090. }
  9091. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9092. {
  9093. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9094. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9095. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9096. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9097. }
  9098. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9099. {
  9100. int port = BP_PORT(bp);
  9101. u32 config;
  9102. u32 ext_phy_type, ext_phy_config, eee_mode;
  9103. bp->link_params.bp = bp;
  9104. bp->link_params.port = port;
  9105. bp->link_params.lane_config =
  9106. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9107. bp->link_params.speed_cap_mask[0] =
  9108. SHMEM_RD(bp,
  9109. dev_info.port_hw_config[port].speed_capability_mask) &
  9110. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9111. bp->link_params.speed_cap_mask[1] =
  9112. SHMEM_RD(bp,
  9113. dev_info.port_hw_config[port].speed_capability_mask2) &
  9114. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9115. bp->port.link_config[0] =
  9116. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9117. bp->port.link_config[1] =
  9118. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9119. bp->link_params.multi_phy_config =
  9120. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9121. /* If the device is capable of WoL, set the default state according
  9122. * to the HW
  9123. */
  9124. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9125. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9126. (config & PORT_FEATURE_WOL_ENABLED));
  9127. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9128. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9129. bp->flags |= NO_ISCSI_FLAG;
  9130. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9131. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9132. bp->flags |= NO_FCOE_FLAG;
  9133. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9134. bp->link_params.lane_config,
  9135. bp->link_params.speed_cap_mask[0],
  9136. bp->port.link_config[0]);
  9137. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9138. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9139. bnx2x_phy_probe(&bp->link_params);
  9140. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9141. bnx2x_link_settings_requested(bp);
  9142. /*
  9143. * If connected directly, work with the internal PHY, otherwise, work
  9144. * with the external PHY
  9145. */
  9146. ext_phy_config =
  9147. SHMEM_RD(bp,
  9148. dev_info.port_hw_config[port].external_phy_config);
  9149. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9150. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9151. bp->mdio.prtad = bp->port.phy_addr;
  9152. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9153. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9154. bp->mdio.prtad =
  9155. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9156. /* Configure link feature according to nvram value */
  9157. eee_mode = (((SHMEM_RD(bp, dev_info.
  9158. port_feature_config[port].eee_power_mode)) &
  9159. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9160. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9161. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9162. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9163. EEE_MODE_ENABLE_LPI |
  9164. EEE_MODE_OUTPUT_TIME;
  9165. } else {
  9166. bp->link_params.eee_mode = 0;
  9167. }
  9168. }
  9169. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9170. {
  9171. u32 no_flags = NO_ISCSI_FLAG;
  9172. int port = BP_PORT(bp);
  9173. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9174. drv_lic_key[port].max_iscsi_conn);
  9175. if (!CNIC_SUPPORT(bp)) {
  9176. bp->flags |= no_flags;
  9177. return;
  9178. }
  9179. /* Get the number of maximum allowed iSCSI connections */
  9180. bp->cnic_eth_dev.max_iscsi_conn =
  9181. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9182. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9183. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9184. bp->cnic_eth_dev.max_iscsi_conn);
  9185. /*
  9186. * If maximum allowed number of connections is zero -
  9187. * disable the feature.
  9188. */
  9189. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9190. bp->flags |= no_flags;
  9191. }
  9192. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9193. {
  9194. /* Port info */
  9195. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9196. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9197. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9198. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9199. /* Node info */
  9200. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9201. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9202. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9203. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9204. }
  9205. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9206. {
  9207. u8 count = 0;
  9208. if (IS_MF(bp)) {
  9209. u8 fid;
  9210. /* iterate over absolute function ids for this path: */
  9211. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9212. if (IS_MF_SD(bp)) {
  9213. u32 cfg = MF_CFG_RD(bp,
  9214. func_mf_config[fid].config);
  9215. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9216. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9217. FUNC_MF_CFG_PROTOCOL_FCOE))
  9218. count++;
  9219. } else {
  9220. u32 cfg = MF_CFG_RD(bp,
  9221. func_ext_config[fid].
  9222. func_cfg);
  9223. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9224. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9225. count++;
  9226. }
  9227. }
  9228. } else { /* SF */
  9229. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9230. for (port = 0; port < port_cnt; port++) {
  9231. u32 lic = SHMEM_RD(bp,
  9232. drv_lic_key[port].max_fcoe_conn) ^
  9233. FW_ENCODE_32BIT_PATTERN;
  9234. if (lic)
  9235. count++;
  9236. }
  9237. }
  9238. return count;
  9239. }
  9240. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9241. {
  9242. int port = BP_PORT(bp);
  9243. int func = BP_ABS_FUNC(bp);
  9244. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9245. drv_lic_key[port].max_fcoe_conn);
  9246. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9247. if (!CNIC_SUPPORT(bp)) {
  9248. bp->flags |= NO_FCOE_FLAG;
  9249. return;
  9250. }
  9251. /* Get the number of maximum allowed FCoE connections */
  9252. bp->cnic_eth_dev.max_fcoe_conn =
  9253. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9254. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9255. /* Calculate the number of maximum allowed FCoE tasks */
  9256. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9257. /* check if FCoE resources must be shared between different functions */
  9258. if (num_fcoe_func)
  9259. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9260. /* Read the WWN: */
  9261. if (!IS_MF(bp)) {
  9262. /* Port info */
  9263. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9264. SHMEM_RD(bp,
  9265. dev_info.port_hw_config[port].
  9266. fcoe_wwn_port_name_upper);
  9267. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9268. SHMEM_RD(bp,
  9269. dev_info.port_hw_config[port].
  9270. fcoe_wwn_port_name_lower);
  9271. /* Node info */
  9272. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9273. SHMEM_RD(bp,
  9274. dev_info.port_hw_config[port].
  9275. fcoe_wwn_node_name_upper);
  9276. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9277. SHMEM_RD(bp,
  9278. dev_info.port_hw_config[port].
  9279. fcoe_wwn_node_name_lower);
  9280. } else if (!IS_MF_SD(bp)) {
  9281. /*
  9282. * Read the WWN info only if the FCoE feature is enabled for
  9283. * this function.
  9284. */
  9285. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9286. bnx2x_get_ext_wwn_info(bp, func);
  9287. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9288. bnx2x_get_ext_wwn_info(bp, func);
  9289. }
  9290. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9291. /*
  9292. * If maximum allowed number of connections is zero -
  9293. * disable the feature.
  9294. */
  9295. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9296. bp->flags |= NO_FCOE_FLAG;
  9297. }
  9298. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9299. {
  9300. /*
  9301. * iSCSI may be dynamically disabled but reading
  9302. * info here we will decrease memory usage by driver
  9303. * if the feature is disabled for good
  9304. */
  9305. bnx2x_get_iscsi_info(bp);
  9306. bnx2x_get_fcoe_info(bp);
  9307. }
  9308. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9309. {
  9310. u32 val, val2;
  9311. int func = BP_ABS_FUNC(bp);
  9312. int port = BP_PORT(bp);
  9313. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9314. u8 *fip_mac = bp->fip_mac;
  9315. if (IS_MF(bp)) {
  9316. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9317. * FCoE MAC then the appropriate feature should be disabled.
  9318. * In non SD mode features configuration comes from struct
  9319. * func_ext_config.
  9320. */
  9321. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9322. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9323. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9324. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9325. iscsi_mac_addr_upper);
  9326. val = MF_CFG_RD(bp, func_ext_config[func].
  9327. iscsi_mac_addr_lower);
  9328. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9329. BNX2X_DEV_INFO
  9330. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9331. } else {
  9332. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9333. }
  9334. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9335. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9336. fcoe_mac_addr_upper);
  9337. val = MF_CFG_RD(bp, func_ext_config[func].
  9338. fcoe_mac_addr_lower);
  9339. bnx2x_set_mac_buf(fip_mac, val, val2);
  9340. BNX2X_DEV_INFO
  9341. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9342. } else {
  9343. bp->flags |= NO_FCOE_FLAG;
  9344. }
  9345. bp->mf_ext_config = cfg;
  9346. } else { /* SD MODE */
  9347. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9348. /* use primary mac as iscsi mac */
  9349. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9350. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9351. BNX2X_DEV_INFO
  9352. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9353. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9354. /* use primary mac as fip mac */
  9355. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9356. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9357. BNX2X_DEV_INFO
  9358. ("Read FIP MAC: %pM\n", fip_mac);
  9359. }
  9360. }
  9361. /* If this is a storage-only interface, use SAN mac as
  9362. * primary MAC. Notice that for SD this is already the case,
  9363. * as the SAN mac was copied from the primary MAC.
  9364. */
  9365. if (IS_MF_FCOE_AFEX(bp))
  9366. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9367. } else {
  9368. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9369. iscsi_mac_upper);
  9370. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9371. iscsi_mac_lower);
  9372. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9373. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9374. fcoe_fip_mac_upper);
  9375. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9376. fcoe_fip_mac_lower);
  9377. bnx2x_set_mac_buf(fip_mac, val, val2);
  9378. }
  9379. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9380. if (!is_valid_ether_addr(iscsi_mac)) {
  9381. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9382. memset(iscsi_mac, 0, ETH_ALEN);
  9383. }
  9384. /* Disable FCoE if MAC configuration is invalid. */
  9385. if (!is_valid_ether_addr(fip_mac)) {
  9386. bp->flags |= NO_FCOE_FLAG;
  9387. memset(bp->fip_mac, 0, ETH_ALEN);
  9388. }
  9389. }
  9390. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9391. {
  9392. u32 val, val2;
  9393. int func = BP_ABS_FUNC(bp);
  9394. int port = BP_PORT(bp);
  9395. /* Zero primary MAC configuration */
  9396. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9397. if (BP_NOMCP(bp)) {
  9398. BNX2X_ERROR("warning: random MAC workaround active\n");
  9399. eth_hw_addr_random(bp->dev);
  9400. } else if (IS_MF(bp)) {
  9401. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9402. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9403. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9404. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9405. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9406. if (CNIC_SUPPORT(bp))
  9407. bnx2x_get_cnic_mac_hwinfo(bp);
  9408. } else {
  9409. /* in SF read MACs from port configuration */
  9410. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9411. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9412. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9413. if (CNIC_SUPPORT(bp))
  9414. bnx2x_get_cnic_mac_hwinfo(bp);
  9415. }
  9416. if (!BP_NOMCP(bp)) {
  9417. /* Read physical port identifier from shmem */
  9418. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9419. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9420. bnx2x_set_mac_buf(bp->phys_port_id, val, val2);
  9421. bp->flags |= HAS_PHYS_PORT_ID;
  9422. }
  9423. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9424. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9425. dev_err(&bp->pdev->dev,
  9426. "bad Ethernet MAC address configuration: %pM\n"
  9427. "change it manually before bringing up the appropriate network interface\n",
  9428. bp->dev->dev_addr);
  9429. }
  9430. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9431. {
  9432. int tmp;
  9433. u32 cfg;
  9434. if (IS_VF(bp))
  9435. return 0;
  9436. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9437. /* Take function: tmp = func */
  9438. tmp = BP_ABS_FUNC(bp);
  9439. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9440. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9441. } else {
  9442. /* Take port: tmp = port */
  9443. tmp = BP_PORT(bp);
  9444. cfg = SHMEM_RD(bp,
  9445. dev_info.port_hw_config[tmp].generic_features);
  9446. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9447. }
  9448. return cfg;
  9449. }
  9450. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9451. {
  9452. int /*abs*/func = BP_ABS_FUNC(bp);
  9453. int vn;
  9454. u32 val = 0;
  9455. int rc = 0;
  9456. bnx2x_get_common_hwinfo(bp);
  9457. /*
  9458. * initialize IGU parameters
  9459. */
  9460. if (CHIP_IS_E1x(bp)) {
  9461. bp->common.int_block = INT_BLOCK_HC;
  9462. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9463. bp->igu_base_sb = 0;
  9464. } else {
  9465. bp->common.int_block = INT_BLOCK_IGU;
  9466. /* do not allow device reset during IGU info processing */
  9467. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9468. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9469. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9470. int tout = 5000;
  9471. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9472. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9473. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9474. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9475. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9476. tout--;
  9477. usleep_range(1000, 2000);
  9478. }
  9479. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9480. dev_err(&bp->pdev->dev,
  9481. "FORCING Normal Mode failed!!!\n");
  9482. bnx2x_release_hw_lock(bp,
  9483. HW_LOCK_RESOURCE_RESET);
  9484. return -EPERM;
  9485. }
  9486. }
  9487. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9488. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9489. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9490. } else
  9491. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9492. rc = bnx2x_get_igu_cam_info(bp);
  9493. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9494. if (rc)
  9495. return rc;
  9496. }
  9497. /*
  9498. * set base FW non-default (fast path) status block id, this value is
  9499. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9500. * determine the id used by the FW.
  9501. */
  9502. if (CHIP_IS_E1x(bp))
  9503. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9504. else /*
  9505. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9506. * the same queue are indicated on the same IGU SB). So we prefer
  9507. * FW and IGU SBs to be the same value.
  9508. */
  9509. bp->base_fw_ndsb = bp->igu_base_sb;
  9510. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9511. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9512. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9513. /*
  9514. * Initialize MF configuration
  9515. */
  9516. bp->mf_ov = 0;
  9517. bp->mf_mode = 0;
  9518. vn = BP_VN(bp);
  9519. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9520. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9521. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9522. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9523. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9524. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9525. else
  9526. bp->common.mf_cfg_base = bp->common.shmem_base +
  9527. offsetof(struct shmem_region, func_mb) +
  9528. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9529. /*
  9530. * get mf configuration:
  9531. * 1. Existence of MF configuration
  9532. * 2. MAC address must be legal (check only upper bytes)
  9533. * for Switch-Independent mode;
  9534. * OVLAN must be legal for Switch-Dependent mode
  9535. * 3. SF_MODE configures specific MF mode
  9536. */
  9537. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9538. /* get mf configuration */
  9539. val = SHMEM_RD(bp,
  9540. dev_info.shared_feature_config.config);
  9541. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9542. switch (val) {
  9543. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9544. val = MF_CFG_RD(bp, func_mf_config[func].
  9545. mac_upper);
  9546. /* check for legal mac (upper bytes)*/
  9547. if (val != 0xffff) {
  9548. bp->mf_mode = MULTI_FUNCTION_SI;
  9549. bp->mf_config[vn] = MF_CFG_RD(bp,
  9550. func_mf_config[func].config);
  9551. } else
  9552. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9553. break;
  9554. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9555. if ((!CHIP_IS_E1x(bp)) &&
  9556. (MF_CFG_RD(bp, func_mf_config[func].
  9557. mac_upper) != 0xffff) &&
  9558. (SHMEM2_HAS(bp,
  9559. afex_driver_support))) {
  9560. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9561. bp->mf_config[vn] = MF_CFG_RD(bp,
  9562. func_mf_config[func].config);
  9563. } else {
  9564. BNX2X_DEV_INFO("can not configure afex mode\n");
  9565. }
  9566. break;
  9567. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9568. /* get OV configuration */
  9569. val = MF_CFG_RD(bp,
  9570. func_mf_config[FUNC_0].e1hov_tag);
  9571. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9572. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9573. bp->mf_mode = MULTI_FUNCTION_SD;
  9574. bp->mf_config[vn] = MF_CFG_RD(bp,
  9575. func_mf_config[func].config);
  9576. } else
  9577. BNX2X_DEV_INFO("illegal OV for SD\n");
  9578. break;
  9579. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9580. bp->mf_config[vn] = 0;
  9581. break;
  9582. default:
  9583. /* Unknown configuration: reset mf_config */
  9584. bp->mf_config[vn] = 0;
  9585. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9586. }
  9587. }
  9588. BNX2X_DEV_INFO("%s function mode\n",
  9589. IS_MF(bp) ? "multi" : "single");
  9590. switch (bp->mf_mode) {
  9591. case MULTI_FUNCTION_SD:
  9592. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9593. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9594. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9595. bp->mf_ov = val;
  9596. bp->path_has_ovlan = true;
  9597. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9598. func, bp->mf_ov, bp->mf_ov);
  9599. } else {
  9600. dev_err(&bp->pdev->dev,
  9601. "No valid MF OV for func %d, aborting\n",
  9602. func);
  9603. return -EPERM;
  9604. }
  9605. break;
  9606. case MULTI_FUNCTION_AFEX:
  9607. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9608. break;
  9609. case MULTI_FUNCTION_SI:
  9610. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9611. func);
  9612. break;
  9613. default:
  9614. if (vn) {
  9615. dev_err(&bp->pdev->dev,
  9616. "VN %d is in a single function mode, aborting\n",
  9617. vn);
  9618. return -EPERM;
  9619. }
  9620. break;
  9621. }
  9622. /* check if other port on the path needs ovlan:
  9623. * Since MF configuration is shared between ports
  9624. * Possible mixed modes are only
  9625. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9626. */
  9627. if (CHIP_MODE_IS_4_PORT(bp) &&
  9628. !bp->path_has_ovlan &&
  9629. !IS_MF(bp) &&
  9630. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9631. u8 other_port = !BP_PORT(bp);
  9632. u8 other_func = BP_PATH(bp) + 2*other_port;
  9633. val = MF_CFG_RD(bp,
  9634. func_mf_config[other_func].e1hov_tag);
  9635. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9636. bp->path_has_ovlan = true;
  9637. }
  9638. }
  9639. /* adjust igu_sb_cnt to MF for E1x */
  9640. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9641. bp->igu_sb_cnt /= E1HVN_MAX;
  9642. /* port info */
  9643. bnx2x_get_port_hwinfo(bp);
  9644. /* Get MAC addresses */
  9645. bnx2x_get_mac_hwinfo(bp);
  9646. bnx2x_get_cnic_info(bp);
  9647. return rc;
  9648. }
  9649. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9650. {
  9651. int cnt, i, block_end, rodi;
  9652. char vpd_start[BNX2X_VPD_LEN+1];
  9653. char str_id_reg[VENDOR_ID_LEN+1];
  9654. char str_id_cap[VENDOR_ID_LEN+1];
  9655. char *vpd_data;
  9656. char *vpd_extended_data = NULL;
  9657. u8 len;
  9658. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9659. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9660. if (cnt < BNX2X_VPD_LEN)
  9661. goto out_not_found;
  9662. /* VPD RO tag should be first tag after identifier string, hence
  9663. * we should be able to find it in first BNX2X_VPD_LEN chars
  9664. */
  9665. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9666. PCI_VPD_LRDT_RO_DATA);
  9667. if (i < 0)
  9668. goto out_not_found;
  9669. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9670. pci_vpd_lrdt_size(&vpd_start[i]);
  9671. i += PCI_VPD_LRDT_TAG_SIZE;
  9672. if (block_end > BNX2X_VPD_LEN) {
  9673. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9674. if (vpd_extended_data == NULL)
  9675. goto out_not_found;
  9676. /* read rest of vpd image into vpd_extended_data */
  9677. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9678. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9679. block_end - BNX2X_VPD_LEN,
  9680. vpd_extended_data + BNX2X_VPD_LEN);
  9681. if (cnt < (block_end - BNX2X_VPD_LEN))
  9682. goto out_not_found;
  9683. vpd_data = vpd_extended_data;
  9684. } else
  9685. vpd_data = vpd_start;
  9686. /* now vpd_data holds full vpd content in both cases */
  9687. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9688. PCI_VPD_RO_KEYWORD_MFR_ID);
  9689. if (rodi < 0)
  9690. goto out_not_found;
  9691. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9692. if (len != VENDOR_ID_LEN)
  9693. goto out_not_found;
  9694. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9695. /* vendor specific info */
  9696. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9697. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9698. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9699. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9700. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9701. PCI_VPD_RO_KEYWORD_VENDOR0);
  9702. if (rodi >= 0) {
  9703. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9704. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9705. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9706. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9707. bp->fw_ver[len] = ' ';
  9708. }
  9709. }
  9710. kfree(vpd_extended_data);
  9711. return;
  9712. }
  9713. out_not_found:
  9714. kfree(vpd_extended_data);
  9715. return;
  9716. }
  9717. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9718. {
  9719. u32 flags = 0;
  9720. if (CHIP_REV_IS_FPGA(bp))
  9721. SET_FLAGS(flags, MODE_FPGA);
  9722. else if (CHIP_REV_IS_EMUL(bp))
  9723. SET_FLAGS(flags, MODE_EMUL);
  9724. else
  9725. SET_FLAGS(flags, MODE_ASIC);
  9726. if (CHIP_MODE_IS_4_PORT(bp))
  9727. SET_FLAGS(flags, MODE_PORT4);
  9728. else
  9729. SET_FLAGS(flags, MODE_PORT2);
  9730. if (CHIP_IS_E2(bp))
  9731. SET_FLAGS(flags, MODE_E2);
  9732. else if (CHIP_IS_E3(bp)) {
  9733. SET_FLAGS(flags, MODE_E3);
  9734. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9735. SET_FLAGS(flags, MODE_E3_A0);
  9736. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9737. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9738. }
  9739. if (IS_MF(bp)) {
  9740. SET_FLAGS(flags, MODE_MF);
  9741. switch (bp->mf_mode) {
  9742. case MULTI_FUNCTION_SD:
  9743. SET_FLAGS(flags, MODE_MF_SD);
  9744. break;
  9745. case MULTI_FUNCTION_SI:
  9746. SET_FLAGS(flags, MODE_MF_SI);
  9747. break;
  9748. case MULTI_FUNCTION_AFEX:
  9749. SET_FLAGS(flags, MODE_MF_AFEX);
  9750. break;
  9751. }
  9752. } else
  9753. SET_FLAGS(flags, MODE_SF);
  9754. #if defined(__LITTLE_ENDIAN)
  9755. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9756. #else /*(__BIG_ENDIAN)*/
  9757. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9758. #endif
  9759. INIT_MODE_FLAGS(bp) = flags;
  9760. }
  9761. static int bnx2x_init_bp(struct bnx2x *bp)
  9762. {
  9763. int func;
  9764. int rc;
  9765. mutex_init(&bp->port.phy_mutex);
  9766. mutex_init(&bp->fw_mb_mutex);
  9767. spin_lock_init(&bp->stats_lock);
  9768. sema_init(&bp->stats_sema, 1);
  9769. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9770. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9771. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9772. if (IS_PF(bp)) {
  9773. rc = bnx2x_get_hwinfo(bp);
  9774. if (rc)
  9775. return rc;
  9776. } else {
  9777. eth_zero_addr(bp->dev->dev_addr);
  9778. }
  9779. bnx2x_set_modes_bitmap(bp);
  9780. rc = bnx2x_alloc_mem_bp(bp);
  9781. if (rc)
  9782. return rc;
  9783. bnx2x_read_fwinfo(bp);
  9784. func = BP_FUNC(bp);
  9785. /* need to reset chip if undi was active */
  9786. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9787. /* init fw_seq */
  9788. bp->fw_seq =
  9789. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9790. DRV_MSG_SEQ_NUMBER_MASK;
  9791. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9792. bnx2x_prev_unload(bp);
  9793. }
  9794. if (CHIP_REV_IS_FPGA(bp))
  9795. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9796. if (BP_NOMCP(bp) && (func == 0))
  9797. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9798. bp->disable_tpa = disable_tpa;
  9799. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9800. /* Set TPA flags */
  9801. if (bp->disable_tpa) {
  9802. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9803. bp->dev->features &= ~NETIF_F_LRO;
  9804. } else {
  9805. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9806. bp->dev->features |= NETIF_F_LRO;
  9807. }
  9808. if (CHIP_IS_E1(bp))
  9809. bp->dropless_fc = 0;
  9810. else
  9811. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9812. bp->mrrs = mrrs;
  9813. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9814. if (IS_VF(bp))
  9815. bp->rx_ring_size = MAX_RX_AVAIL;
  9816. /* make sure that the numbers are in the right granularity */
  9817. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9818. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9819. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9820. init_timer(&bp->timer);
  9821. bp->timer.expires = jiffies + bp->current_interval;
  9822. bp->timer.data = (unsigned long) bp;
  9823. bp->timer.function = bnx2x_timer;
  9824. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9825. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9826. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9827. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9828. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9829. bnx2x_dcbx_init_params(bp);
  9830. } else {
  9831. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9832. }
  9833. if (CHIP_IS_E1x(bp))
  9834. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9835. else
  9836. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9837. /* multiple tx priority */
  9838. if (IS_VF(bp))
  9839. bp->max_cos = 1;
  9840. else if (CHIP_IS_E1x(bp))
  9841. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9842. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9843. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9844. else if (CHIP_IS_E3B0(bp))
  9845. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9846. else
  9847. BNX2X_ERR("unknown chip %x revision %x\n",
  9848. CHIP_NUM(bp), CHIP_REV(bp));
  9849. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9850. /* We need at least one default status block for slow-path events,
  9851. * second status block for the L2 queue, and a third status block for
  9852. * CNIC if supported.
  9853. */
  9854. if (IS_VF(bp))
  9855. bp->min_msix_vec_cnt = 1;
  9856. else if (CNIC_SUPPORT(bp))
  9857. bp->min_msix_vec_cnt = 3;
  9858. else /* PF w/o cnic */
  9859. bp->min_msix_vec_cnt = 2;
  9860. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9861. bp->dump_preset_idx = 1;
  9862. return rc;
  9863. }
  9864. /****************************************************************************
  9865. * General service functions
  9866. ****************************************************************************/
  9867. /*
  9868. * net_device service functions
  9869. */
  9870. /* called with rtnl_lock */
  9871. static int bnx2x_open(struct net_device *dev)
  9872. {
  9873. struct bnx2x *bp = netdev_priv(dev);
  9874. int rc;
  9875. bp->stats_init = true;
  9876. netif_carrier_off(dev);
  9877. bnx2x_set_power_state(bp, PCI_D0);
  9878. /* If parity had happen during the unload, then attentions
  9879. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9880. * want the first function loaded on the current engine to
  9881. * complete the recovery.
  9882. * Parity recovery is only relevant for PF driver.
  9883. */
  9884. if (IS_PF(bp)) {
  9885. int other_engine = BP_PATH(bp) ? 0 : 1;
  9886. bool other_load_status, load_status;
  9887. bool global = false;
  9888. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9889. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9890. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9891. bnx2x_chk_parity_attn(bp, &global, true)) {
  9892. do {
  9893. /* If there are attentions and they are in a
  9894. * global blocks, set the GLOBAL_RESET bit
  9895. * regardless whether it will be this function
  9896. * that will complete the recovery or not.
  9897. */
  9898. if (global)
  9899. bnx2x_set_reset_global(bp);
  9900. /* Only the first function on the current
  9901. * engine should try to recover in open. In case
  9902. * of attentions in global blocks only the first
  9903. * in the chip should try to recover.
  9904. */
  9905. if ((!load_status &&
  9906. (!global || !other_load_status)) &&
  9907. bnx2x_trylock_leader_lock(bp) &&
  9908. !bnx2x_leader_reset(bp)) {
  9909. netdev_info(bp->dev,
  9910. "Recovered in open\n");
  9911. break;
  9912. }
  9913. /* recovery has failed... */
  9914. bnx2x_set_power_state(bp, PCI_D3hot);
  9915. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9916. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9917. "If you still see this message after a few retries then power cycle is required.\n");
  9918. return -EAGAIN;
  9919. } while (0);
  9920. }
  9921. }
  9922. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9923. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9924. if (rc)
  9925. return rc;
  9926. return 0;
  9927. }
  9928. /* called with rtnl_lock */
  9929. static int bnx2x_close(struct net_device *dev)
  9930. {
  9931. struct bnx2x *bp = netdev_priv(dev);
  9932. /* Unload the driver, release IRQs */
  9933. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9934. return 0;
  9935. }
  9936. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9937. struct bnx2x_mcast_ramrod_params *p)
  9938. {
  9939. int mc_count = netdev_mc_count(bp->dev);
  9940. struct bnx2x_mcast_list_elem *mc_mac =
  9941. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9942. struct netdev_hw_addr *ha;
  9943. if (!mc_mac)
  9944. return -ENOMEM;
  9945. INIT_LIST_HEAD(&p->mcast_list);
  9946. netdev_for_each_mc_addr(ha, bp->dev) {
  9947. mc_mac->mac = bnx2x_mc_addr(ha);
  9948. list_add_tail(&mc_mac->link, &p->mcast_list);
  9949. mc_mac++;
  9950. }
  9951. p->mcast_list_len = mc_count;
  9952. return 0;
  9953. }
  9954. static void bnx2x_free_mcast_macs_list(
  9955. struct bnx2x_mcast_ramrod_params *p)
  9956. {
  9957. struct bnx2x_mcast_list_elem *mc_mac =
  9958. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9959. link);
  9960. WARN_ON(!mc_mac);
  9961. kfree(mc_mac);
  9962. }
  9963. /**
  9964. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9965. *
  9966. * @bp: driver handle
  9967. *
  9968. * We will use zero (0) as a MAC type for these MACs.
  9969. */
  9970. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9971. {
  9972. int rc;
  9973. struct net_device *dev = bp->dev;
  9974. struct netdev_hw_addr *ha;
  9975. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9976. unsigned long ramrod_flags = 0;
  9977. /* First schedule a cleanup up of old configuration */
  9978. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9979. if (rc < 0) {
  9980. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9981. return rc;
  9982. }
  9983. netdev_for_each_uc_addr(ha, dev) {
  9984. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9985. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9986. if (rc == -EEXIST) {
  9987. DP(BNX2X_MSG_SP,
  9988. "Failed to schedule ADD operations: %d\n", rc);
  9989. /* do not treat adding same MAC as error */
  9990. rc = 0;
  9991. } else if (rc < 0) {
  9992. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9993. rc);
  9994. return rc;
  9995. }
  9996. }
  9997. /* Execute the pending commands */
  9998. __set_bit(RAMROD_CONT, &ramrod_flags);
  9999. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  10000. BNX2X_UC_LIST_MAC, &ramrod_flags);
  10001. }
  10002. static int bnx2x_set_mc_list(struct bnx2x *bp)
  10003. {
  10004. struct net_device *dev = bp->dev;
  10005. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  10006. int rc = 0;
  10007. rparam.mcast_obj = &bp->mcast_obj;
  10008. /* first, clear all configured multicast MACs */
  10009. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  10010. if (rc < 0) {
  10011. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  10012. return rc;
  10013. }
  10014. /* then, configure a new MACs list */
  10015. if (netdev_mc_count(dev)) {
  10016. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  10017. if (rc) {
  10018. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  10019. rc);
  10020. return rc;
  10021. }
  10022. /* Now add the new MACs */
  10023. rc = bnx2x_config_mcast(bp, &rparam,
  10024. BNX2X_MCAST_CMD_ADD);
  10025. if (rc < 0)
  10026. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  10027. rc);
  10028. bnx2x_free_mcast_macs_list(&rparam);
  10029. }
  10030. return rc;
  10031. }
  10032. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  10033. void bnx2x_set_rx_mode(struct net_device *dev)
  10034. {
  10035. struct bnx2x *bp = netdev_priv(dev);
  10036. if (bp->state != BNX2X_STATE_OPEN) {
  10037. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  10038. return;
  10039. } else {
  10040. /* Schedule an SP task to handle rest of change */
  10041. DP(NETIF_MSG_IFUP, "Scheduling an Rx mode change\n");
  10042. smp_mb__before_clear_bit();
  10043. set_bit(BNX2X_SP_RTNL_RX_MODE, &bp->sp_rtnl_state);
  10044. smp_mb__after_clear_bit();
  10045. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10046. }
  10047. }
  10048. void bnx2x_set_rx_mode_inner(struct bnx2x *bp)
  10049. {
  10050. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  10051. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  10052. netif_addr_lock_bh(bp->dev);
  10053. if (bp->dev->flags & IFF_PROMISC) {
  10054. rx_mode = BNX2X_RX_MODE_PROMISC;
  10055. } else if ((bp->dev->flags & IFF_ALLMULTI) ||
  10056. ((netdev_mc_count(bp->dev) > BNX2X_MAX_MULTICAST) &&
  10057. CHIP_IS_E1(bp))) {
  10058. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10059. } else {
  10060. if (IS_PF(bp)) {
  10061. /* some multicasts */
  10062. if (bnx2x_set_mc_list(bp) < 0)
  10063. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10064. /* release bh lock, as bnx2x_set_uc_list might sleep */
  10065. netif_addr_unlock_bh(bp->dev);
  10066. if (bnx2x_set_uc_list(bp) < 0)
  10067. rx_mode = BNX2X_RX_MODE_PROMISC;
  10068. netif_addr_lock_bh(bp->dev);
  10069. } else {
  10070. /* configuring mcast to a vf involves sleeping (when we
  10071. * wait for the pf's response).
  10072. */
  10073. smp_mb__before_clear_bit();
  10074. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  10075. &bp->sp_rtnl_state);
  10076. smp_mb__after_clear_bit();
  10077. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10078. }
  10079. }
  10080. bp->rx_mode = rx_mode;
  10081. /* handle ISCSI SD mode */
  10082. if (IS_MF_ISCSI_SD(bp))
  10083. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10084. /* Schedule the rx_mode command */
  10085. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10086. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10087. netif_addr_unlock_bh(bp->dev);
  10088. return;
  10089. }
  10090. if (IS_PF(bp)) {
  10091. bnx2x_set_storm_rx_mode(bp);
  10092. netif_addr_unlock_bh(bp->dev);
  10093. } else {
  10094. /* VF will need to request the PF to make this change, and so
  10095. * the VF needs to release the bottom-half lock prior to the
  10096. * request (as it will likely require sleep on the VF side)
  10097. */
  10098. netif_addr_unlock_bh(bp->dev);
  10099. bnx2x_vfpf_storm_rx_mode(bp);
  10100. }
  10101. }
  10102. /* called with rtnl_lock */
  10103. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10104. int devad, u16 addr)
  10105. {
  10106. struct bnx2x *bp = netdev_priv(netdev);
  10107. u16 value;
  10108. int rc;
  10109. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10110. prtad, devad, addr);
  10111. /* The HW expects different devad if CL22 is used */
  10112. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10113. bnx2x_acquire_phy_lock(bp);
  10114. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10115. bnx2x_release_phy_lock(bp);
  10116. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10117. if (!rc)
  10118. rc = value;
  10119. return rc;
  10120. }
  10121. /* called with rtnl_lock */
  10122. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10123. u16 addr, u16 value)
  10124. {
  10125. struct bnx2x *bp = netdev_priv(netdev);
  10126. int rc;
  10127. DP(NETIF_MSG_LINK,
  10128. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10129. prtad, devad, addr, value);
  10130. /* The HW expects different devad if CL22 is used */
  10131. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10132. bnx2x_acquire_phy_lock(bp);
  10133. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10134. bnx2x_release_phy_lock(bp);
  10135. return rc;
  10136. }
  10137. /* called with rtnl_lock */
  10138. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10139. {
  10140. struct bnx2x *bp = netdev_priv(dev);
  10141. struct mii_ioctl_data *mdio = if_mii(ifr);
  10142. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10143. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10144. if (!netif_running(dev))
  10145. return -EAGAIN;
  10146. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10147. }
  10148. #ifdef CONFIG_NET_POLL_CONTROLLER
  10149. static void poll_bnx2x(struct net_device *dev)
  10150. {
  10151. struct bnx2x *bp = netdev_priv(dev);
  10152. int i;
  10153. for_each_eth_queue(bp, i) {
  10154. struct bnx2x_fastpath *fp = &bp->fp[i];
  10155. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10156. }
  10157. }
  10158. #endif
  10159. static int bnx2x_validate_addr(struct net_device *dev)
  10160. {
  10161. struct bnx2x *bp = netdev_priv(dev);
  10162. /* query the bulletin board for mac address configured by the PF */
  10163. if (IS_VF(bp))
  10164. bnx2x_sample_bulletin(bp);
  10165. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  10166. BNX2X_ERR("Non-valid Ethernet address\n");
  10167. return -EADDRNOTAVAIL;
  10168. }
  10169. return 0;
  10170. }
  10171. static int bnx2x_get_phys_port_id(struct net_device *netdev,
  10172. struct netdev_phys_port_id *ppid)
  10173. {
  10174. struct bnx2x *bp = netdev_priv(netdev);
  10175. if (!(bp->flags & HAS_PHYS_PORT_ID))
  10176. return -EOPNOTSUPP;
  10177. ppid->id_len = sizeof(bp->phys_port_id);
  10178. memcpy(ppid->id, bp->phys_port_id, ppid->id_len);
  10179. return 0;
  10180. }
  10181. static const struct net_device_ops bnx2x_netdev_ops = {
  10182. .ndo_open = bnx2x_open,
  10183. .ndo_stop = bnx2x_close,
  10184. .ndo_start_xmit = bnx2x_start_xmit,
  10185. .ndo_select_queue = bnx2x_select_queue,
  10186. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10187. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10188. .ndo_validate_addr = bnx2x_validate_addr,
  10189. .ndo_do_ioctl = bnx2x_ioctl,
  10190. .ndo_change_mtu = bnx2x_change_mtu,
  10191. .ndo_fix_features = bnx2x_fix_features,
  10192. .ndo_set_features = bnx2x_set_features,
  10193. .ndo_tx_timeout = bnx2x_tx_timeout,
  10194. #ifdef CONFIG_NET_POLL_CONTROLLER
  10195. .ndo_poll_controller = poll_bnx2x,
  10196. #endif
  10197. .ndo_setup_tc = bnx2x_setup_tc,
  10198. #ifdef CONFIG_BNX2X_SRIOV
  10199. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10200. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10201. .ndo_get_vf_config = bnx2x_get_vf_config,
  10202. #endif
  10203. #ifdef NETDEV_FCOE_WWNN
  10204. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10205. #endif
  10206. #ifdef CONFIG_NET_RX_BUSY_POLL
  10207. .ndo_busy_poll = bnx2x_low_latency_recv,
  10208. #endif
  10209. .ndo_get_phys_port_id = bnx2x_get_phys_port_id,
  10210. };
  10211. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10212. {
  10213. struct device *dev = &bp->pdev->dev;
  10214. if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)) != 0 &&
  10215. dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) != 0) {
  10216. dev_err(dev, "System does not support DMA, aborting\n");
  10217. return -EIO;
  10218. }
  10219. return 0;
  10220. }
  10221. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10222. struct net_device *dev, unsigned long board_type)
  10223. {
  10224. int rc;
  10225. u32 pci_cfg_dword;
  10226. bool chip_is_e1x = (board_type == BCM57710 ||
  10227. board_type == BCM57711 ||
  10228. board_type == BCM57711E);
  10229. SET_NETDEV_DEV(dev, &pdev->dev);
  10230. bp->dev = dev;
  10231. bp->pdev = pdev;
  10232. rc = pci_enable_device(pdev);
  10233. if (rc) {
  10234. dev_err(&bp->pdev->dev,
  10235. "Cannot enable PCI device, aborting\n");
  10236. goto err_out;
  10237. }
  10238. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10239. dev_err(&bp->pdev->dev,
  10240. "Cannot find PCI device base address, aborting\n");
  10241. rc = -ENODEV;
  10242. goto err_out_disable;
  10243. }
  10244. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10245. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10246. rc = -ENODEV;
  10247. goto err_out_disable;
  10248. }
  10249. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10250. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10251. PCICFG_REVESION_ID_ERROR_VAL) {
  10252. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10253. rc = -ENODEV;
  10254. goto err_out_disable;
  10255. }
  10256. if (atomic_read(&pdev->enable_cnt) == 1) {
  10257. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10258. if (rc) {
  10259. dev_err(&bp->pdev->dev,
  10260. "Cannot obtain PCI resources, aborting\n");
  10261. goto err_out_disable;
  10262. }
  10263. pci_set_master(pdev);
  10264. pci_save_state(pdev);
  10265. }
  10266. if (IS_PF(bp)) {
  10267. if (!pdev->pm_cap) {
  10268. dev_err(&bp->pdev->dev,
  10269. "Cannot find power management capability, aborting\n");
  10270. rc = -EIO;
  10271. goto err_out_release;
  10272. }
  10273. }
  10274. if (!pci_is_pcie(pdev)) {
  10275. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10276. rc = -EIO;
  10277. goto err_out_release;
  10278. }
  10279. rc = bnx2x_set_coherency_mask(bp);
  10280. if (rc)
  10281. goto err_out_release;
  10282. dev->mem_start = pci_resource_start(pdev, 0);
  10283. dev->base_addr = dev->mem_start;
  10284. dev->mem_end = pci_resource_end(pdev, 0);
  10285. dev->irq = pdev->irq;
  10286. bp->regview = pci_ioremap_bar(pdev, 0);
  10287. if (!bp->regview) {
  10288. dev_err(&bp->pdev->dev,
  10289. "Cannot map register space, aborting\n");
  10290. rc = -ENOMEM;
  10291. goto err_out_release;
  10292. }
  10293. /* In E1/E1H use pci device function given by kernel.
  10294. * In E2/E3 read physical function from ME register since these chips
  10295. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10296. * (depending on hypervisor).
  10297. */
  10298. if (chip_is_e1x) {
  10299. bp->pf_num = PCI_FUNC(pdev->devfn);
  10300. } else {
  10301. /* chip is E2/3*/
  10302. pci_read_config_dword(bp->pdev,
  10303. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10304. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10305. ME_REG_ABS_PF_NUM_SHIFT);
  10306. }
  10307. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10308. /* clean indirect addresses */
  10309. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10310. PCICFG_VENDOR_ID_OFFSET);
  10311. /*
  10312. * Clean the following indirect addresses for all functions since it
  10313. * is not used by the driver.
  10314. */
  10315. if (IS_PF(bp)) {
  10316. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10317. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10318. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10319. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10320. if (chip_is_e1x) {
  10321. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10322. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10323. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10324. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10325. }
  10326. /* Enable internal target-read (in case we are probed after PF
  10327. * FLR). Must be done prior to any BAR read access. Only for
  10328. * 57712 and up
  10329. */
  10330. if (!chip_is_e1x)
  10331. REG_WR(bp,
  10332. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10333. }
  10334. dev->watchdog_timeo = TX_TIMEOUT;
  10335. dev->netdev_ops = &bnx2x_netdev_ops;
  10336. bnx2x_set_ethtool_ops(bp, dev);
  10337. dev->priv_flags |= IFF_UNICAST_FLT;
  10338. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10339. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10340. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10341. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10342. if (!CHIP_IS_E1x(bp)) {
  10343. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL |
  10344. NETIF_F_GSO_IPIP | NETIF_F_GSO_SIT;
  10345. dev->hw_enc_features =
  10346. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10347. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10348. NETIF_F_GSO_IPIP |
  10349. NETIF_F_GSO_SIT |
  10350. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10351. }
  10352. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10353. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10354. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10355. dev->features |= NETIF_F_HIGHDMA;
  10356. /* Add Loopback capability to the device */
  10357. dev->hw_features |= NETIF_F_LOOPBACK;
  10358. #ifdef BCM_DCBNL
  10359. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10360. #endif
  10361. /* get_port_hwinfo() will set prtad and mmds properly */
  10362. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10363. bp->mdio.mmds = 0;
  10364. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10365. bp->mdio.dev = dev;
  10366. bp->mdio.mdio_read = bnx2x_mdio_read;
  10367. bp->mdio.mdio_write = bnx2x_mdio_write;
  10368. return 0;
  10369. err_out_release:
  10370. if (atomic_read(&pdev->enable_cnt) == 1)
  10371. pci_release_regions(pdev);
  10372. err_out_disable:
  10373. pci_disable_device(pdev);
  10374. err_out:
  10375. return rc;
  10376. }
  10377. static int bnx2x_check_firmware(struct bnx2x *bp)
  10378. {
  10379. const struct firmware *firmware = bp->firmware;
  10380. struct bnx2x_fw_file_hdr *fw_hdr;
  10381. struct bnx2x_fw_file_section *sections;
  10382. u32 offset, len, num_ops;
  10383. __be16 *ops_offsets;
  10384. int i;
  10385. const u8 *fw_ver;
  10386. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10387. BNX2X_ERR("Wrong FW size\n");
  10388. return -EINVAL;
  10389. }
  10390. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10391. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10392. /* Make sure none of the offsets and sizes make us read beyond
  10393. * the end of the firmware data */
  10394. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10395. offset = be32_to_cpu(sections[i].offset);
  10396. len = be32_to_cpu(sections[i].len);
  10397. if (offset + len > firmware->size) {
  10398. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10399. return -EINVAL;
  10400. }
  10401. }
  10402. /* Likewise for the init_ops offsets */
  10403. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10404. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10405. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10406. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10407. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10408. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10409. return -EINVAL;
  10410. }
  10411. }
  10412. /* Check FW version */
  10413. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10414. fw_ver = firmware->data + offset;
  10415. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10416. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10417. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10418. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10419. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10420. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10421. BCM_5710_FW_MAJOR_VERSION,
  10422. BCM_5710_FW_MINOR_VERSION,
  10423. BCM_5710_FW_REVISION_VERSION,
  10424. BCM_5710_FW_ENGINEERING_VERSION);
  10425. return -EINVAL;
  10426. }
  10427. return 0;
  10428. }
  10429. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10430. {
  10431. const __be32 *source = (const __be32 *)_source;
  10432. u32 *target = (u32 *)_target;
  10433. u32 i;
  10434. for (i = 0; i < n/4; i++)
  10435. target[i] = be32_to_cpu(source[i]);
  10436. }
  10437. /*
  10438. Ops array is stored in the following format:
  10439. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10440. */
  10441. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10442. {
  10443. const __be32 *source = (const __be32 *)_source;
  10444. struct raw_op *target = (struct raw_op *)_target;
  10445. u32 i, j, tmp;
  10446. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10447. tmp = be32_to_cpu(source[j]);
  10448. target[i].op = (tmp >> 24) & 0xff;
  10449. target[i].offset = tmp & 0xffffff;
  10450. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10451. }
  10452. }
  10453. /* IRO array is stored in the following format:
  10454. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10455. */
  10456. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10457. {
  10458. const __be32 *source = (const __be32 *)_source;
  10459. struct iro *target = (struct iro *)_target;
  10460. u32 i, j, tmp;
  10461. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10462. target[i].base = be32_to_cpu(source[j]);
  10463. j++;
  10464. tmp = be32_to_cpu(source[j]);
  10465. target[i].m1 = (tmp >> 16) & 0xffff;
  10466. target[i].m2 = tmp & 0xffff;
  10467. j++;
  10468. tmp = be32_to_cpu(source[j]);
  10469. target[i].m3 = (tmp >> 16) & 0xffff;
  10470. target[i].size = tmp & 0xffff;
  10471. j++;
  10472. }
  10473. }
  10474. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10475. {
  10476. const __be16 *source = (const __be16 *)_source;
  10477. u16 *target = (u16 *)_target;
  10478. u32 i;
  10479. for (i = 0; i < n/2; i++)
  10480. target[i] = be16_to_cpu(source[i]);
  10481. }
  10482. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10483. do { \
  10484. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10485. bp->arr = kmalloc(len, GFP_KERNEL); \
  10486. if (!bp->arr) \
  10487. goto lbl; \
  10488. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10489. (u8 *)bp->arr, len); \
  10490. } while (0)
  10491. static int bnx2x_init_firmware(struct bnx2x *bp)
  10492. {
  10493. const char *fw_file_name;
  10494. struct bnx2x_fw_file_hdr *fw_hdr;
  10495. int rc;
  10496. if (bp->firmware)
  10497. return 0;
  10498. if (CHIP_IS_E1(bp))
  10499. fw_file_name = FW_FILE_NAME_E1;
  10500. else if (CHIP_IS_E1H(bp))
  10501. fw_file_name = FW_FILE_NAME_E1H;
  10502. else if (!CHIP_IS_E1x(bp))
  10503. fw_file_name = FW_FILE_NAME_E2;
  10504. else {
  10505. BNX2X_ERR("Unsupported chip revision\n");
  10506. return -EINVAL;
  10507. }
  10508. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10509. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10510. if (rc) {
  10511. BNX2X_ERR("Can't load firmware file %s\n",
  10512. fw_file_name);
  10513. goto request_firmware_exit;
  10514. }
  10515. rc = bnx2x_check_firmware(bp);
  10516. if (rc) {
  10517. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10518. goto request_firmware_exit;
  10519. }
  10520. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10521. /* Initialize the pointers to the init arrays */
  10522. /* Blob */
  10523. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10524. /* Opcodes */
  10525. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10526. /* Offsets */
  10527. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10528. be16_to_cpu_n);
  10529. /* STORMs firmware */
  10530. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10531. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10532. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10533. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10534. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10535. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10536. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10537. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10538. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10539. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10540. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10541. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10542. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10543. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10544. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10545. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10546. /* IRO */
  10547. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10548. return 0;
  10549. iro_alloc_err:
  10550. kfree(bp->init_ops_offsets);
  10551. init_offsets_alloc_err:
  10552. kfree(bp->init_ops);
  10553. init_ops_alloc_err:
  10554. kfree(bp->init_data);
  10555. request_firmware_exit:
  10556. release_firmware(bp->firmware);
  10557. bp->firmware = NULL;
  10558. return rc;
  10559. }
  10560. static void bnx2x_release_firmware(struct bnx2x *bp)
  10561. {
  10562. kfree(bp->init_ops_offsets);
  10563. kfree(bp->init_ops);
  10564. kfree(bp->init_data);
  10565. release_firmware(bp->firmware);
  10566. bp->firmware = NULL;
  10567. }
  10568. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10569. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10570. .init_hw_cmn = bnx2x_init_hw_common,
  10571. .init_hw_port = bnx2x_init_hw_port,
  10572. .init_hw_func = bnx2x_init_hw_func,
  10573. .reset_hw_cmn = bnx2x_reset_common,
  10574. .reset_hw_port = bnx2x_reset_port,
  10575. .reset_hw_func = bnx2x_reset_func,
  10576. .gunzip_init = bnx2x_gunzip_init,
  10577. .gunzip_end = bnx2x_gunzip_end,
  10578. .init_fw = bnx2x_init_firmware,
  10579. .release_fw = bnx2x_release_firmware,
  10580. };
  10581. void bnx2x__init_func_obj(struct bnx2x *bp)
  10582. {
  10583. /* Prepare DMAE related driver resources */
  10584. bnx2x_setup_dmae(bp);
  10585. bnx2x_init_func_obj(bp, &bp->func_obj,
  10586. bnx2x_sp(bp, func_rdata),
  10587. bnx2x_sp_mapping(bp, func_rdata),
  10588. bnx2x_sp(bp, func_afex_rdata),
  10589. bnx2x_sp_mapping(bp, func_afex_rdata),
  10590. &bnx2x_func_sp_drv);
  10591. }
  10592. /* must be called after sriov-enable */
  10593. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10594. {
  10595. int cid_count = BNX2X_L2_MAX_CID(bp);
  10596. if (IS_SRIOV(bp))
  10597. cid_count += BNX2X_VF_CIDS;
  10598. if (CNIC_SUPPORT(bp))
  10599. cid_count += CNIC_CID_MAX;
  10600. return roundup(cid_count, QM_CID_ROUND);
  10601. }
  10602. /**
  10603. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10604. *
  10605. * @dev: pci device
  10606. *
  10607. */
  10608. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev, int cnic_cnt)
  10609. {
  10610. int index;
  10611. u16 control = 0;
  10612. /*
  10613. * If MSI-X is not supported - return number of SBs needed to support
  10614. * one fast path queue: one FP queue + SB for CNIC
  10615. */
  10616. if (!pdev->msix_cap) {
  10617. dev_info(&pdev->dev, "no msix capability found\n");
  10618. return 1 + cnic_cnt;
  10619. }
  10620. dev_info(&pdev->dev, "msix capability found\n");
  10621. /*
  10622. * The value in the PCI configuration space is the index of the last
  10623. * entry, namely one less than the actual size of the table, which is
  10624. * exactly what we want to return from this function: number of all SBs
  10625. * without the default SB.
  10626. * For VFs there is no default SB, then we return (index+1).
  10627. */
  10628. pci_read_config_word(pdev, pdev->msix_cap + PCI_MSI_FLAGS, &control);
  10629. index = control & PCI_MSIX_FLAGS_QSIZE;
  10630. return index;
  10631. }
  10632. static int set_max_cos_est(int chip_id)
  10633. {
  10634. switch (chip_id) {
  10635. case BCM57710:
  10636. case BCM57711:
  10637. case BCM57711E:
  10638. return BNX2X_MULTI_TX_COS_E1X;
  10639. case BCM57712:
  10640. case BCM57712_MF:
  10641. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10642. case BCM57800:
  10643. case BCM57800_MF:
  10644. case BCM57810:
  10645. case BCM57810_MF:
  10646. case BCM57840_4_10:
  10647. case BCM57840_2_20:
  10648. case BCM57840_O:
  10649. case BCM57840_MFO:
  10650. case BCM57840_MF:
  10651. case BCM57811:
  10652. case BCM57811_MF:
  10653. return BNX2X_MULTI_TX_COS_E3B0;
  10654. case BCM57712_VF:
  10655. case BCM57800_VF:
  10656. case BCM57810_VF:
  10657. case BCM57840_VF:
  10658. case BCM57811_VF:
  10659. return 1;
  10660. default:
  10661. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10662. return -ENODEV;
  10663. }
  10664. }
  10665. static int set_is_vf(int chip_id)
  10666. {
  10667. switch (chip_id) {
  10668. case BCM57712_VF:
  10669. case BCM57800_VF:
  10670. case BCM57810_VF:
  10671. case BCM57840_VF:
  10672. case BCM57811_VF:
  10673. return true;
  10674. default:
  10675. return false;
  10676. }
  10677. }
  10678. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10679. static int bnx2x_init_one(struct pci_dev *pdev,
  10680. const struct pci_device_id *ent)
  10681. {
  10682. struct net_device *dev = NULL;
  10683. struct bnx2x *bp;
  10684. enum pcie_link_width pcie_width;
  10685. enum pci_bus_speed pcie_speed;
  10686. int rc, max_non_def_sbs;
  10687. int rx_count, tx_count, rss_count, doorbell_size;
  10688. int max_cos_est;
  10689. bool is_vf;
  10690. int cnic_cnt;
  10691. /* An estimated maximum supported CoS number according to the chip
  10692. * version.
  10693. * We will try to roughly estimate the maximum number of CoSes this chip
  10694. * may support in order to minimize the memory allocated for Tx
  10695. * netdev_queue's. This number will be accurately calculated during the
  10696. * initialization of bp->max_cos based on the chip versions AND chip
  10697. * revision in the bnx2x_init_bp().
  10698. */
  10699. max_cos_est = set_max_cos_est(ent->driver_data);
  10700. if (max_cos_est < 0)
  10701. return max_cos_est;
  10702. is_vf = set_is_vf(ent->driver_data);
  10703. cnic_cnt = is_vf ? 0 : 1;
  10704. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt);
  10705. /* add another SB for VF as it has no default SB */
  10706. max_non_def_sbs += is_vf ? 1 : 0;
  10707. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10708. rss_count = max_non_def_sbs - cnic_cnt;
  10709. if (rss_count < 1)
  10710. return -EINVAL;
  10711. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10712. rx_count = rss_count + cnic_cnt;
  10713. /* Maximum number of netdev Tx queues:
  10714. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10715. */
  10716. tx_count = rss_count * max_cos_est + cnic_cnt;
  10717. /* dev zeroed in init_etherdev */
  10718. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10719. if (!dev)
  10720. return -ENOMEM;
  10721. bp = netdev_priv(dev);
  10722. bp->flags = 0;
  10723. if (is_vf)
  10724. bp->flags |= IS_VF_FLAG;
  10725. bp->igu_sb_cnt = max_non_def_sbs;
  10726. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10727. bp->msg_enable = debug;
  10728. bp->cnic_support = cnic_cnt;
  10729. bp->cnic_probe = bnx2x_cnic_probe;
  10730. pci_set_drvdata(pdev, dev);
  10731. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10732. if (rc < 0) {
  10733. free_netdev(dev);
  10734. return rc;
  10735. }
  10736. BNX2X_DEV_INFO("This is a %s function\n",
  10737. IS_PF(bp) ? "physical" : "virtual");
  10738. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10739. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10740. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10741. tx_count, rx_count);
  10742. rc = bnx2x_init_bp(bp);
  10743. if (rc)
  10744. goto init_one_exit;
  10745. /* Map doorbells here as we need the real value of bp->max_cos which
  10746. * is initialized in bnx2x_init_bp() to determine the number of
  10747. * l2 connections.
  10748. */
  10749. if (IS_VF(bp)) {
  10750. bp->doorbells = bnx2x_vf_doorbells(bp);
  10751. rc = bnx2x_vf_pci_alloc(bp);
  10752. if (rc)
  10753. goto init_one_exit;
  10754. } else {
  10755. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10756. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10757. dev_err(&bp->pdev->dev,
  10758. "Cannot map doorbells, bar size too small, aborting\n");
  10759. rc = -ENOMEM;
  10760. goto init_one_exit;
  10761. }
  10762. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10763. doorbell_size);
  10764. }
  10765. if (!bp->doorbells) {
  10766. dev_err(&bp->pdev->dev,
  10767. "Cannot map doorbell space, aborting\n");
  10768. rc = -ENOMEM;
  10769. goto init_one_exit;
  10770. }
  10771. if (IS_VF(bp)) {
  10772. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10773. if (rc)
  10774. goto init_one_exit;
  10775. }
  10776. /* Enable SRIOV if capability found in configuration space */
  10777. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10778. if (rc)
  10779. goto init_one_exit;
  10780. /* calc qm_cid_count */
  10781. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10782. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10783. /* disable FCOE L2 queue for E1x*/
  10784. if (CHIP_IS_E1x(bp))
  10785. bp->flags |= NO_FCOE_FLAG;
  10786. /* Set bp->num_queues for MSI-X mode*/
  10787. bnx2x_set_num_queues(bp);
  10788. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10789. * needed.
  10790. */
  10791. rc = bnx2x_set_int_mode(bp);
  10792. if (rc) {
  10793. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10794. goto init_one_exit;
  10795. }
  10796. BNX2X_DEV_INFO("set interrupts successfully\n");
  10797. /* register the net device */
  10798. rc = register_netdev(dev);
  10799. if (rc) {
  10800. dev_err(&pdev->dev, "Cannot register net device\n");
  10801. goto init_one_exit;
  10802. }
  10803. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10804. if (!NO_FCOE(bp)) {
  10805. /* Add storage MAC address */
  10806. rtnl_lock();
  10807. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10808. rtnl_unlock();
  10809. }
  10810. if (pcie_get_minimum_link(bp->pdev, &pcie_speed, &pcie_width) ||
  10811. pcie_speed == PCI_SPEED_UNKNOWN ||
  10812. pcie_width == PCIE_LNK_WIDTH_UNKNOWN)
  10813. BNX2X_DEV_INFO("Failed to determine PCI Express Bandwidth\n");
  10814. else
  10815. BNX2X_DEV_INFO(
  10816. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10817. board_info[ent->driver_data].name,
  10818. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10819. pcie_width,
  10820. pcie_speed == PCIE_SPEED_2_5GT ? "2.5GHz" :
  10821. pcie_speed == PCIE_SPEED_5_0GT ? "5.0GHz" :
  10822. pcie_speed == PCIE_SPEED_8_0GT ? "8.0GHz" :
  10823. "Unknown",
  10824. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10825. return 0;
  10826. init_one_exit:
  10827. if (bp->regview)
  10828. iounmap(bp->regview);
  10829. if (IS_PF(bp) && bp->doorbells)
  10830. iounmap(bp->doorbells);
  10831. free_netdev(dev);
  10832. if (atomic_read(&pdev->enable_cnt) == 1)
  10833. pci_release_regions(pdev);
  10834. pci_disable_device(pdev);
  10835. return rc;
  10836. }
  10837. static void __bnx2x_remove(struct pci_dev *pdev,
  10838. struct net_device *dev,
  10839. struct bnx2x *bp,
  10840. bool remove_netdev)
  10841. {
  10842. /* Delete storage MAC address */
  10843. if (!NO_FCOE(bp)) {
  10844. rtnl_lock();
  10845. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10846. rtnl_unlock();
  10847. }
  10848. #ifdef BCM_DCBNL
  10849. /* Delete app tlvs from dcbnl */
  10850. bnx2x_dcbnl_update_applist(bp, true);
  10851. #endif
  10852. if (IS_PF(bp) &&
  10853. !BP_NOMCP(bp) &&
  10854. (bp->flags & BC_SUPPORTS_RMMOD_CMD))
  10855. bnx2x_fw_command(bp, DRV_MSG_CODE_RMMOD, 0);
  10856. /* Close the interface - either directly or implicitly */
  10857. if (remove_netdev) {
  10858. unregister_netdev(dev);
  10859. } else {
  10860. rtnl_lock();
  10861. dev_close(dev);
  10862. rtnl_unlock();
  10863. }
  10864. bnx2x_iov_remove_one(bp);
  10865. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10866. if (IS_PF(bp))
  10867. bnx2x_set_power_state(bp, PCI_D0);
  10868. /* Disable MSI/MSI-X */
  10869. bnx2x_disable_msi(bp);
  10870. /* Power off */
  10871. if (IS_PF(bp))
  10872. bnx2x_set_power_state(bp, PCI_D3hot);
  10873. /* Make sure RESET task is not scheduled before continuing */
  10874. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10875. /* send message via vfpf channel to release the resources of this vf */
  10876. if (IS_VF(bp))
  10877. bnx2x_vfpf_release(bp);
  10878. /* Assumes no further PCIe PM changes will occur */
  10879. if (system_state == SYSTEM_POWER_OFF) {
  10880. pci_wake_from_d3(pdev, bp->wol);
  10881. pci_set_power_state(pdev, PCI_D3hot);
  10882. }
  10883. if (bp->regview)
  10884. iounmap(bp->regview);
  10885. /* for vf doorbells are part of the regview and were unmapped along with
  10886. * it. FW is only loaded by PF.
  10887. */
  10888. if (IS_PF(bp)) {
  10889. if (bp->doorbells)
  10890. iounmap(bp->doorbells);
  10891. bnx2x_release_firmware(bp);
  10892. }
  10893. bnx2x_free_mem_bp(bp);
  10894. if (remove_netdev)
  10895. free_netdev(dev);
  10896. if (atomic_read(&pdev->enable_cnt) == 1)
  10897. pci_release_regions(pdev);
  10898. pci_disable_device(pdev);
  10899. }
  10900. static void bnx2x_remove_one(struct pci_dev *pdev)
  10901. {
  10902. struct net_device *dev = pci_get_drvdata(pdev);
  10903. struct bnx2x *bp;
  10904. if (!dev) {
  10905. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10906. return;
  10907. }
  10908. bp = netdev_priv(dev);
  10909. __bnx2x_remove(pdev, dev, bp, true);
  10910. }
  10911. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10912. {
  10913. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  10914. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10915. if (CNIC_LOADED(bp))
  10916. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10917. /* Stop Tx */
  10918. bnx2x_tx_disable(bp);
  10919. /* Delete all NAPI objects */
  10920. bnx2x_del_all_napi(bp);
  10921. if (CNIC_LOADED(bp))
  10922. bnx2x_del_all_napi_cnic(bp);
  10923. netdev_reset_tc(bp->dev);
  10924. del_timer_sync(&bp->timer);
  10925. cancel_delayed_work(&bp->sp_task);
  10926. cancel_delayed_work(&bp->period_task);
  10927. spin_lock_bh(&bp->stats_lock);
  10928. bp->stats_state = STATS_STATE_DISABLED;
  10929. spin_unlock_bh(&bp->stats_lock);
  10930. bnx2x_save_statistics(bp);
  10931. netif_carrier_off(bp->dev);
  10932. return 0;
  10933. }
  10934. /**
  10935. * bnx2x_io_error_detected - called when PCI error is detected
  10936. * @pdev: Pointer to PCI device
  10937. * @state: The current pci connection state
  10938. *
  10939. * This function is called after a PCI bus error affecting
  10940. * this device has been detected.
  10941. */
  10942. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10943. pci_channel_state_t state)
  10944. {
  10945. struct net_device *dev = pci_get_drvdata(pdev);
  10946. struct bnx2x *bp = netdev_priv(dev);
  10947. rtnl_lock();
  10948. BNX2X_ERR("IO error detected\n");
  10949. netif_device_detach(dev);
  10950. if (state == pci_channel_io_perm_failure) {
  10951. rtnl_unlock();
  10952. return PCI_ERS_RESULT_DISCONNECT;
  10953. }
  10954. if (netif_running(dev))
  10955. bnx2x_eeh_nic_unload(bp);
  10956. bnx2x_prev_path_mark_eeh(bp);
  10957. pci_disable_device(pdev);
  10958. rtnl_unlock();
  10959. /* Request a slot reset */
  10960. return PCI_ERS_RESULT_NEED_RESET;
  10961. }
  10962. /**
  10963. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10964. * @pdev: Pointer to PCI device
  10965. *
  10966. * Restart the card from scratch, as if from a cold-boot.
  10967. */
  10968. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10969. {
  10970. struct net_device *dev = pci_get_drvdata(pdev);
  10971. struct bnx2x *bp = netdev_priv(dev);
  10972. int i;
  10973. rtnl_lock();
  10974. BNX2X_ERR("IO slot reset initializing...\n");
  10975. if (pci_enable_device(pdev)) {
  10976. dev_err(&pdev->dev,
  10977. "Cannot re-enable PCI device after reset\n");
  10978. rtnl_unlock();
  10979. return PCI_ERS_RESULT_DISCONNECT;
  10980. }
  10981. pci_set_master(pdev);
  10982. pci_restore_state(pdev);
  10983. pci_save_state(pdev);
  10984. if (netif_running(dev))
  10985. bnx2x_set_power_state(bp, PCI_D0);
  10986. if (netif_running(dev)) {
  10987. BNX2X_ERR("IO slot reset --> driver unload\n");
  10988. /* MCP should have been reset; Need to wait for validity */
  10989. bnx2x_init_shmem(bp);
  10990. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  10991. u32 v;
  10992. v = SHMEM2_RD(bp,
  10993. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  10994. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  10995. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  10996. }
  10997. bnx2x_drain_tx_queues(bp);
  10998. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  10999. bnx2x_netif_stop(bp, 1);
  11000. bnx2x_free_irq(bp);
  11001. /* Report UNLOAD_DONE to MCP */
  11002. bnx2x_send_unload_done(bp, true);
  11003. bp->sp_state = 0;
  11004. bp->port.pmf = 0;
  11005. bnx2x_prev_unload(bp);
  11006. /* We should have reseted the engine, so It's fair to
  11007. * assume the FW will no longer write to the bnx2x driver.
  11008. */
  11009. bnx2x_squeeze_objects(bp);
  11010. bnx2x_free_skbs(bp);
  11011. for_each_rx_queue(bp, i)
  11012. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  11013. bnx2x_free_fp_mem(bp);
  11014. bnx2x_free_mem(bp);
  11015. bp->state = BNX2X_STATE_CLOSED;
  11016. }
  11017. rtnl_unlock();
  11018. return PCI_ERS_RESULT_RECOVERED;
  11019. }
  11020. /**
  11021. * bnx2x_io_resume - called when traffic can start flowing again
  11022. * @pdev: Pointer to PCI device
  11023. *
  11024. * This callback is called when the error recovery driver tells us that
  11025. * its OK to resume normal operation.
  11026. */
  11027. static void bnx2x_io_resume(struct pci_dev *pdev)
  11028. {
  11029. struct net_device *dev = pci_get_drvdata(pdev);
  11030. struct bnx2x *bp = netdev_priv(dev);
  11031. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  11032. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  11033. return;
  11034. }
  11035. rtnl_lock();
  11036. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  11037. DRV_MSG_SEQ_NUMBER_MASK;
  11038. if (netif_running(dev))
  11039. bnx2x_nic_load(bp, LOAD_NORMAL);
  11040. netif_device_attach(dev);
  11041. rtnl_unlock();
  11042. }
  11043. static const struct pci_error_handlers bnx2x_err_handler = {
  11044. .error_detected = bnx2x_io_error_detected,
  11045. .slot_reset = bnx2x_io_slot_reset,
  11046. .resume = bnx2x_io_resume,
  11047. };
  11048. static void bnx2x_shutdown(struct pci_dev *pdev)
  11049. {
  11050. struct net_device *dev = pci_get_drvdata(pdev);
  11051. struct bnx2x *bp;
  11052. if (!dev)
  11053. return;
  11054. bp = netdev_priv(dev);
  11055. if (!bp)
  11056. return;
  11057. rtnl_lock();
  11058. netif_device_detach(dev);
  11059. rtnl_unlock();
  11060. /* Don't remove the netdevice, as there are scenarios which will cause
  11061. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11062. * rootfs is mounted from SAN.
  11063. */
  11064. __bnx2x_remove(pdev, dev, bp, false);
  11065. }
  11066. static struct pci_driver bnx2x_pci_driver = {
  11067. .name = DRV_MODULE_NAME,
  11068. .id_table = bnx2x_pci_tbl,
  11069. .probe = bnx2x_init_one,
  11070. .remove = bnx2x_remove_one,
  11071. .suspend = bnx2x_suspend,
  11072. .resume = bnx2x_resume,
  11073. .err_handler = &bnx2x_err_handler,
  11074. #ifdef CONFIG_BNX2X_SRIOV
  11075. .sriov_configure = bnx2x_sriov_configure,
  11076. #endif
  11077. .shutdown = bnx2x_shutdown,
  11078. };
  11079. static int __init bnx2x_init(void)
  11080. {
  11081. int ret;
  11082. pr_info("%s", version);
  11083. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11084. if (bnx2x_wq == NULL) {
  11085. pr_err("Cannot create workqueue\n");
  11086. return -ENOMEM;
  11087. }
  11088. ret = pci_register_driver(&bnx2x_pci_driver);
  11089. if (ret) {
  11090. pr_err("Cannot register driver\n");
  11091. destroy_workqueue(bnx2x_wq);
  11092. }
  11093. return ret;
  11094. }
  11095. static void __exit bnx2x_cleanup(void)
  11096. {
  11097. struct list_head *pos, *q;
  11098. pci_unregister_driver(&bnx2x_pci_driver);
  11099. destroy_workqueue(bnx2x_wq);
  11100. /* Free globally allocated resources */
  11101. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11102. struct bnx2x_prev_path_list *tmp =
  11103. list_entry(pos, struct bnx2x_prev_path_list, list);
  11104. list_del(pos);
  11105. kfree(tmp);
  11106. }
  11107. }
  11108. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11109. {
  11110. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11111. }
  11112. module_init(bnx2x_init);
  11113. module_exit(bnx2x_cleanup);
  11114. /**
  11115. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11116. *
  11117. * @bp: driver handle
  11118. * @set: set or clear the CAM entry
  11119. *
  11120. * This function will wait until the ramrod completion returns.
  11121. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11122. */
  11123. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11124. {
  11125. unsigned long ramrod_flags = 0;
  11126. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11127. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11128. &bp->iscsi_l2_mac_obj, true,
  11129. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11130. }
  11131. /* count denotes the number of new completions we have seen */
  11132. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11133. {
  11134. struct eth_spe *spe;
  11135. int cxt_index, cxt_offset;
  11136. #ifdef BNX2X_STOP_ON_ERROR
  11137. if (unlikely(bp->panic))
  11138. return;
  11139. #endif
  11140. spin_lock_bh(&bp->spq_lock);
  11141. BUG_ON(bp->cnic_spq_pending < count);
  11142. bp->cnic_spq_pending -= count;
  11143. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11144. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11145. & SPE_HDR_CONN_TYPE) >>
  11146. SPE_HDR_CONN_TYPE_SHIFT;
  11147. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11148. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11149. /* Set validation for iSCSI L2 client before sending SETUP
  11150. * ramrod
  11151. */
  11152. if (type == ETH_CONNECTION_TYPE) {
  11153. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11154. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11155. ILT_PAGE_CIDS;
  11156. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11157. (cxt_index * ILT_PAGE_CIDS);
  11158. bnx2x_set_ctx_validation(bp,
  11159. &bp->context[cxt_index].
  11160. vcxt[cxt_offset].eth,
  11161. BNX2X_ISCSI_ETH_CID(bp));
  11162. }
  11163. }
  11164. /*
  11165. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11166. * and in the air. We also check that number of outstanding
  11167. * COMMON ramrods is not more than the EQ and SPQ can
  11168. * accommodate.
  11169. */
  11170. if (type == ETH_CONNECTION_TYPE) {
  11171. if (!atomic_read(&bp->cq_spq_left))
  11172. break;
  11173. else
  11174. atomic_dec(&bp->cq_spq_left);
  11175. } else if (type == NONE_CONNECTION_TYPE) {
  11176. if (!atomic_read(&bp->eq_spq_left))
  11177. break;
  11178. else
  11179. atomic_dec(&bp->eq_spq_left);
  11180. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11181. (type == FCOE_CONNECTION_TYPE)) {
  11182. if (bp->cnic_spq_pending >=
  11183. bp->cnic_eth_dev.max_kwqe_pending)
  11184. break;
  11185. else
  11186. bp->cnic_spq_pending++;
  11187. } else {
  11188. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11189. bnx2x_panic();
  11190. break;
  11191. }
  11192. spe = bnx2x_sp_get_next(bp);
  11193. *spe = *bp->cnic_kwq_cons;
  11194. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11195. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11196. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11197. bp->cnic_kwq_cons = bp->cnic_kwq;
  11198. else
  11199. bp->cnic_kwq_cons++;
  11200. }
  11201. bnx2x_sp_prod_update(bp);
  11202. spin_unlock_bh(&bp->spq_lock);
  11203. }
  11204. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11205. struct kwqe_16 *kwqes[], u32 count)
  11206. {
  11207. struct bnx2x *bp = netdev_priv(dev);
  11208. int i;
  11209. #ifdef BNX2X_STOP_ON_ERROR
  11210. if (unlikely(bp->panic)) {
  11211. BNX2X_ERR("Can't post to SP queue while panic\n");
  11212. return -EIO;
  11213. }
  11214. #endif
  11215. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11216. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11217. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11218. return -EAGAIN;
  11219. }
  11220. spin_lock_bh(&bp->spq_lock);
  11221. for (i = 0; i < count; i++) {
  11222. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11223. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11224. break;
  11225. *bp->cnic_kwq_prod = *spe;
  11226. bp->cnic_kwq_pending++;
  11227. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11228. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11229. spe->data.update_data_addr.hi,
  11230. spe->data.update_data_addr.lo,
  11231. bp->cnic_kwq_pending);
  11232. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11233. bp->cnic_kwq_prod = bp->cnic_kwq;
  11234. else
  11235. bp->cnic_kwq_prod++;
  11236. }
  11237. spin_unlock_bh(&bp->spq_lock);
  11238. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11239. bnx2x_cnic_sp_post(bp, 0);
  11240. return i;
  11241. }
  11242. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11243. {
  11244. struct cnic_ops *c_ops;
  11245. int rc = 0;
  11246. mutex_lock(&bp->cnic_mutex);
  11247. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11248. lockdep_is_held(&bp->cnic_mutex));
  11249. if (c_ops)
  11250. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11251. mutex_unlock(&bp->cnic_mutex);
  11252. return rc;
  11253. }
  11254. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11255. {
  11256. struct cnic_ops *c_ops;
  11257. int rc = 0;
  11258. rcu_read_lock();
  11259. c_ops = rcu_dereference(bp->cnic_ops);
  11260. if (c_ops)
  11261. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11262. rcu_read_unlock();
  11263. return rc;
  11264. }
  11265. /*
  11266. * for commands that have no data
  11267. */
  11268. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11269. {
  11270. struct cnic_ctl_info ctl = {0};
  11271. ctl.cmd = cmd;
  11272. return bnx2x_cnic_ctl_send(bp, &ctl);
  11273. }
  11274. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11275. {
  11276. struct cnic_ctl_info ctl = {0};
  11277. /* first we tell CNIC and only then we count this as a completion */
  11278. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11279. ctl.data.comp.cid = cid;
  11280. ctl.data.comp.error = err;
  11281. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11282. bnx2x_cnic_sp_post(bp, 0);
  11283. }
  11284. /* Called with netif_addr_lock_bh() taken.
  11285. * Sets an rx_mode config for an iSCSI ETH client.
  11286. * Doesn't block.
  11287. * Completion should be checked outside.
  11288. */
  11289. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11290. {
  11291. unsigned long accept_flags = 0, ramrod_flags = 0;
  11292. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11293. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11294. if (start) {
  11295. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11296. * because it's the only way for UIO Queue to accept
  11297. * multicasts (in non-promiscuous mode only one Queue per
  11298. * function will receive multicast packets (leading in our
  11299. * case).
  11300. */
  11301. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11302. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11303. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11304. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11305. /* Clear STOP_PENDING bit if START is requested */
  11306. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11307. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11308. } else
  11309. /* Clear START_PENDING bit if STOP is requested */
  11310. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11311. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11312. set_bit(sched_state, &bp->sp_state);
  11313. else {
  11314. __set_bit(RAMROD_RX, &ramrod_flags);
  11315. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11316. ramrod_flags);
  11317. }
  11318. }
  11319. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11320. {
  11321. struct bnx2x *bp = netdev_priv(dev);
  11322. int rc = 0;
  11323. switch (ctl->cmd) {
  11324. case DRV_CTL_CTXTBL_WR_CMD: {
  11325. u32 index = ctl->data.io.offset;
  11326. dma_addr_t addr = ctl->data.io.dma_addr;
  11327. bnx2x_ilt_wr(bp, index, addr);
  11328. break;
  11329. }
  11330. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11331. int count = ctl->data.credit.credit_count;
  11332. bnx2x_cnic_sp_post(bp, count);
  11333. break;
  11334. }
  11335. /* rtnl_lock is held. */
  11336. case DRV_CTL_START_L2_CMD: {
  11337. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11338. unsigned long sp_bits = 0;
  11339. /* Configure the iSCSI classification object */
  11340. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11341. cp->iscsi_l2_client_id,
  11342. cp->iscsi_l2_cid, BP_FUNC(bp),
  11343. bnx2x_sp(bp, mac_rdata),
  11344. bnx2x_sp_mapping(bp, mac_rdata),
  11345. BNX2X_FILTER_MAC_PENDING,
  11346. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11347. &bp->macs_pool);
  11348. /* Set iSCSI MAC address */
  11349. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11350. if (rc)
  11351. break;
  11352. mmiowb();
  11353. barrier();
  11354. /* Start accepting on iSCSI L2 ring */
  11355. netif_addr_lock_bh(dev);
  11356. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11357. netif_addr_unlock_bh(dev);
  11358. /* bits to wait on */
  11359. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11360. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11361. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11362. BNX2X_ERR("rx_mode completion timed out!\n");
  11363. break;
  11364. }
  11365. /* rtnl_lock is held. */
  11366. case DRV_CTL_STOP_L2_CMD: {
  11367. unsigned long sp_bits = 0;
  11368. /* Stop accepting on iSCSI L2 ring */
  11369. netif_addr_lock_bh(dev);
  11370. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11371. netif_addr_unlock_bh(dev);
  11372. /* bits to wait on */
  11373. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11374. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11375. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11376. BNX2X_ERR("rx_mode completion timed out!\n");
  11377. mmiowb();
  11378. barrier();
  11379. /* Unset iSCSI L2 MAC */
  11380. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11381. BNX2X_ISCSI_ETH_MAC, true);
  11382. break;
  11383. }
  11384. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11385. int count = ctl->data.credit.credit_count;
  11386. smp_mb__before_atomic_inc();
  11387. atomic_add(count, &bp->cq_spq_left);
  11388. smp_mb__after_atomic_inc();
  11389. break;
  11390. }
  11391. case DRV_CTL_ULP_REGISTER_CMD: {
  11392. int ulp_type = ctl->data.register_data.ulp_type;
  11393. if (CHIP_IS_E3(bp)) {
  11394. int idx = BP_FW_MB_IDX(bp);
  11395. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11396. int path = BP_PATH(bp);
  11397. int port = BP_PORT(bp);
  11398. int i;
  11399. u32 scratch_offset;
  11400. u32 *host_addr;
  11401. /* first write capability to shmem2 */
  11402. if (ulp_type == CNIC_ULP_ISCSI)
  11403. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11404. else if (ulp_type == CNIC_ULP_FCOE)
  11405. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11406. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11407. if ((ulp_type != CNIC_ULP_FCOE) ||
  11408. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11409. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11410. break;
  11411. /* if reached here - should write fcoe capabilities */
  11412. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11413. if (!scratch_offset)
  11414. break;
  11415. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11416. fcoe_features[path][port]);
  11417. host_addr = (u32 *) &(ctl->data.register_data.
  11418. fcoe_features);
  11419. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11420. i += 4)
  11421. REG_WR(bp, scratch_offset + i,
  11422. *(host_addr + i/4));
  11423. }
  11424. break;
  11425. }
  11426. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11427. int ulp_type = ctl->data.ulp_type;
  11428. if (CHIP_IS_E3(bp)) {
  11429. int idx = BP_FW_MB_IDX(bp);
  11430. u32 cap;
  11431. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11432. if (ulp_type == CNIC_ULP_ISCSI)
  11433. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11434. else if (ulp_type == CNIC_ULP_FCOE)
  11435. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11436. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11437. }
  11438. break;
  11439. }
  11440. default:
  11441. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11442. rc = -EINVAL;
  11443. }
  11444. return rc;
  11445. }
  11446. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11447. {
  11448. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11449. if (bp->flags & USING_MSIX_FLAG) {
  11450. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11451. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11452. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11453. } else {
  11454. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11455. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11456. }
  11457. if (!CHIP_IS_E1x(bp))
  11458. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11459. else
  11460. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11461. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11462. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11463. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11464. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11465. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11466. cp->num_irq = 2;
  11467. }
  11468. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11469. {
  11470. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11471. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11472. bnx2x_cid_ilt_lines(bp);
  11473. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11474. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11475. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11476. DP(NETIF_MSG_IFUP, "BNX2X_1st_NON_L2_ETH_CID(bp) %x, cp->starting_cid %x, cp->fcoe_init_cid %x, cp->iscsi_l2_cid %x\n",
  11477. BNX2X_1st_NON_L2_ETH_CID(bp), cp->starting_cid, cp->fcoe_init_cid,
  11478. cp->iscsi_l2_cid);
  11479. if (NO_ISCSI_OOO(bp))
  11480. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11481. }
  11482. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11483. void *data)
  11484. {
  11485. struct bnx2x *bp = netdev_priv(dev);
  11486. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11487. int rc;
  11488. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11489. if (ops == NULL) {
  11490. BNX2X_ERR("NULL ops received\n");
  11491. return -EINVAL;
  11492. }
  11493. if (!CNIC_SUPPORT(bp)) {
  11494. BNX2X_ERR("Can't register CNIC when not supported\n");
  11495. return -EOPNOTSUPP;
  11496. }
  11497. if (!CNIC_LOADED(bp)) {
  11498. rc = bnx2x_load_cnic(bp);
  11499. if (rc) {
  11500. BNX2X_ERR("CNIC-related load failed\n");
  11501. return rc;
  11502. }
  11503. }
  11504. bp->cnic_enabled = true;
  11505. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11506. if (!bp->cnic_kwq)
  11507. return -ENOMEM;
  11508. bp->cnic_kwq_cons = bp->cnic_kwq;
  11509. bp->cnic_kwq_prod = bp->cnic_kwq;
  11510. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11511. bp->cnic_spq_pending = 0;
  11512. bp->cnic_kwq_pending = 0;
  11513. bp->cnic_data = data;
  11514. cp->num_irq = 0;
  11515. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11516. cp->iro_arr = bp->iro_arr;
  11517. bnx2x_setup_cnic_irq_info(bp);
  11518. rcu_assign_pointer(bp->cnic_ops, ops);
  11519. return 0;
  11520. }
  11521. static int bnx2x_unregister_cnic(struct net_device *dev)
  11522. {
  11523. struct bnx2x *bp = netdev_priv(dev);
  11524. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11525. mutex_lock(&bp->cnic_mutex);
  11526. cp->drv_state = 0;
  11527. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11528. mutex_unlock(&bp->cnic_mutex);
  11529. synchronize_rcu();
  11530. bp->cnic_enabled = false;
  11531. kfree(bp->cnic_kwq);
  11532. bp->cnic_kwq = NULL;
  11533. return 0;
  11534. }
  11535. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11536. {
  11537. struct bnx2x *bp = netdev_priv(dev);
  11538. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11539. /* If both iSCSI and FCoE are disabled - return NULL in
  11540. * order to indicate CNIC that it should not try to work
  11541. * with this device.
  11542. */
  11543. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11544. return NULL;
  11545. cp->drv_owner = THIS_MODULE;
  11546. cp->chip_id = CHIP_ID(bp);
  11547. cp->pdev = bp->pdev;
  11548. cp->io_base = bp->regview;
  11549. cp->io_base2 = bp->doorbells;
  11550. cp->max_kwqe_pending = 8;
  11551. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11552. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11553. bnx2x_cid_ilt_lines(bp);
  11554. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11555. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11556. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11557. cp->drv_ctl = bnx2x_drv_ctl;
  11558. cp->drv_register_cnic = bnx2x_register_cnic;
  11559. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11560. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11561. cp->iscsi_l2_client_id =
  11562. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11563. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11564. if (NO_ISCSI_OOO(bp))
  11565. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11566. if (NO_ISCSI(bp))
  11567. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11568. if (NO_FCOE(bp))
  11569. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11570. BNX2X_DEV_INFO(
  11571. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11572. cp->ctx_blk_size,
  11573. cp->ctx_tbl_offset,
  11574. cp->ctx_tbl_len,
  11575. cp->starting_cid);
  11576. return cp;
  11577. }
  11578. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11579. {
  11580. struct bnx2x *bp = fp->bp;
  11581. u32 offset = BAR_USTRORM_INTMEM;
  11582. if (IS_VF(bp))
  11583. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11584. else if (!CHIP_IS_E1x(bp))
  11585. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11586. else
  11587. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11588. return offset;
  11589. }
  11590. /* called only on E1H or E2.
  11591. * When pretending to be PF, the pretend value is the function number 0...7
  11592. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11593. * combination
  11594. */
  11595. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11596. {
  11597. u32 pretend_reg;
  11598. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11599. return -1;
  11600. /* get my own pretend register */
  11601. pretend_reg = bnx2x_get_pretend_reg(bp);
  11602. REG_WR(bp, pretend_reg, pretend_func_val);
  11603. REG_RD(bp, pretend_reg);
  11604. return 0;
  11605. }