bnx2x_main.c 362 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433
  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. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  74. /* Time in jiffies before concluding the transmitter is hung */
  75. #define TX_TIMEOUT (5*HZ)
  76. static char version[] =
  77. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  78. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  79. MODULE_AUTHOR("Eliezer Tamir");
  80. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  81. "BCM57710/57711/57711E/"
  82. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  83. "57840/57840_MF Driver");
  84. MODULE_LICENSE("GPL");
  85. MODULE_VERSION(DRV_MODULE_VERSION);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  89. int num_queues;
  90. module_param(num_queues, int, 0);
  91. MODULE_PARM_DESC(num_queues,
  92. " Set number of queues (default is as a number of CPUs)");
  93. static int disable_tpa;
  94. module_param(disable_tpa, int, 0);
  95. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  96. #define INT_MODE_INTx 1
  97. #define INT_MODE_MSI 2
  98. int int_mode;
  99. module_param(int_mode, int, 0);
  100. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  101. "(1 INT#x; 2 MSI)");
  102. static int dropless_fc;
  103. module_param(dropless_fc, int, 0);
  104. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  105. static int mrrs = -1;
  106. module_param(mrrs, int, 0);
  107. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  108. static int debug;
  109. module_param(debug, int, 0);
  110. MODULE_PARM_DESC(debug, " Default debug msglevel");
  111. struct workqueue_struct *bnx2x_wq;
  112. struct bnx2x_mac_vals {
  113. u32 xmac_addr;
  114. u32 xmac_val;
  115. u32 emac_addr;
  116. u32 emac_val;
  117. u32 umac_addr;
  118. u32 umac_val;
  119. u32 bmac_addr;
  120. u32 bmac_val[2];
  121. };
  122. enum bnx2x_board_type {
  123. BCM57710 = 0,
  124. BCM57711,
  125. BCM57711E,
  126. BCM57712,
  127. BCM57712_MF,
  128. BCM57712_VF,
  129. BCM57800,
  130. BCM57800_MF,
  131. BCM57800_VF,
  132. BCM57810,
  133. BCM57810_MF,
  134. BCM57810_VF,
  135. BCM57840_4_10,
  136. BCM57840_2_20,
  137. BCM57840_MF,
  138. BCM57840_VF,
  139. BCM57811,
  140. BCM57811_MF,
  141. BCM57840_O,
  142. BCM57840_MFO,
  143. BCM57811_VF
  144. };
  145. /* indexed by board_type, above */
  146. static struct {
  147. char *name;
  148. } board_info[] = {
  149. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  150. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  151. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  152. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  153. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  154. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  156. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  157. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  159. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  160. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  162. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  163. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  164. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  165. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  166. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  167. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  168. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  169. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  170. };
  171. #ifndef PCI_DEVICE_ID_NX2_57710
  172. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711
  175. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711E
  178. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712
  181. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  184. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  187. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800
  190. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  193. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  196. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810
  199. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  202. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57840_O
  205. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  208. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  211. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  214. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  217. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  220. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  223. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811
  226. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  229. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  232. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  233. #endif
  234. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  256. { 0 }
  257. };
  258. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  259. /* Global resources for unloading a previously loaded device */
  260. #define BNX2X_PREV_WAIT_NEEDED 1
  261. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  262. static LIST_HEAD(bnx2x_prev_list);
  263. /****************************************************************************
  264. * General service functions
  265. ****************************************************************************/
  266. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  267. u32 addr, dma_addr_t mapping)
  268. {
  269. REG_WR(bp, addr, U64_LO(mapping));
  270. REG_WR(bp, addr + 4, U64_HI(mapping));
  271. }
  272. static void storm_memset_spq_addr(struct bnx2x *bp,
  273. dma_addr_t mapping, u16 abs_fid)
  274. {
  275. u32 addr = XSEM_REG_FAST_MEMORY +
  276. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  277. __storm_memset_dma_mapping(bp, addr, mapping);
  278. }
  279. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  280. u16 pf_id)
  281. {
  282. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  283. pf_id);
  284. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  285. pf_id);
  286. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  287. pf_id);
  288. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  289. pf_id);
  290. }
  291. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  292. u8 enable)
  293. {
  294. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  295. enable);
  296. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  297. enable);
  298. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  299. enable);
  300. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  301. enable);
  302. }
  303. static void storm_memset_eq_data(struct bnx2x *bp,
  304. struct event_ring_data *eq_data,
  305. u16 pfid)
  306. {
  307. size_t size = sizeof(struct event_ring_data);
  308. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  309. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  310. }
  311. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  312. u16 pfid)
  313. {
  314. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  315. REG_WR16(bp, addr, eq_prod);
  316. }
  317. /* used only at init
  318. * locking is done by mcp
  319. */
  320. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  321. {
  322. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  323. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  324. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  325. PCICFG_VENDOR_ID_OFFSET);
  326. }
  327. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  328. {
  329. u32 val;
  330. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  331. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  332. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  333. PCICFG_VENDOR_ID_OFFSET);
  334. return val;
  335. }
  336. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  337. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  338. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  339. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  340. #define DMAE_DP_DST_NONE "dst_addr [none]"
  341. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  342. {
  343. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  344. switch (dmae->opcode & DMAE_COMMAND_DST) {
  345. case DMAE_CMD_DST_PCI:
  346. if (src_type == DMAE_CMD_SRC_PCI)
  347. DP(msglvl, "DMAE: opcode 0x%08x\n"
  348. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  349. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  350. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  351. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  352. dmae->comp_addr_hi, dmae->comp_addr_lo,
  353. dmae->comp_val);
  354. else
  355. DP(msglvl, "DMAE: opcode 0x%08x\n"
  356. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  357. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  358. dmae->opcode, dmae->src_addr_lo >> 2,
  359. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  360. dmae->comp_addr_hi, dmae->comp_addr_lo,
  361. dmae->comp_val);
  362. break;
  363. case DMAE_CMD_DST_GRC:
  364. if (src_type == DMAE_CMD_SRC_PCI)
  365. DP(msglvl, "DMAE: opcode 0x%08x\n"
  366. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  367. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  368. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  369. dmae->len, dmae->dst_addr_lo >> 2,
  370. dmae->comp_addr_hi, dmae->comp_addr_lo,
  371. dmae->comp_val);
  372. else
  373. DP(msglvl, "DMAE: opcode 0x%08x\n"
  374. "src [%08x], len [%d*4], dst [%08x]\n"
  375. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  376. dmae->opcode, dmae->src_addr_lo >> 2,
  377. dmae->len, dmae->dst_addr_lo >> 2,
  378. dmae->comp_addr_hi, dmae->comp_addr_lo,
  379. dmae->comp_val);
  380. break;
  381. default:
  382. if (src_type == DMAE_CMD_SRC_PCI)
  383. DP(msglvl, "DMAE: opcode 0x%08x\n"
  384. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  385. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  386. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  387. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  388. dmae->comp_val);
  389. else
  390. DP(msglvl, "DMAE: opcode 0x%08x\n"
  391. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  392. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  393. dmae->opcode, dmae->src_addr_lo >> 2,
  394. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  395. dmae->comp_val);
  396. break;
  397. }
  398. }
  399. /* copy command into DMAE command memory and set DMAE command go */
  400. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  401. {
  402. u32 cmd_offset;
  403. int i;
  404. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  405. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  406. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  407. }
  408. REG_WR(bp, dmae_reg_go_c[idx], 1);
  409. }
  410. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  411. {
  412. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  413. DMAE_CMD_C_ENABLE);
  414. }
  415. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  416. {
  417. return opcode & ~DMAE_CMD_SRC_RESET;
  418. }
  419. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  420. bool with_comp, u8 comp_type)
  421. {
  422. u32 opcode = 0;
  423. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  424. (dst_type << DMAE_COMMAND_DST_SHIFT));
  425. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  426. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  427. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  428. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  429. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  430. #ifdef __BIG_ENDIAN
  431. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  432. #else
  433. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  434. #endif
  435. if (with_comp)
  436. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  437. return opcode;
  438. }
  439. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  440. struct dmae_command *dmae,
  441. u8 src_type, u8 dst_type)
  442. {
  443. memset(dmae, 0, sizeof(struct dmae_command));
  444. /* set the opcode */
  445. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  446. true, DMAE_COMP_PCI);
  447. /* fill in the completion parameters */
  448. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  449. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  450. dmae->comp_val = DMAE_COMP_VAL;
  451. }
  452. /* issue a dmae command over the init-channel and wait for completion */
  453. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  454. {
  455. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  456. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  457. int rc = 0;
  458. /*
  459. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  460. * as long as this code is called both from syscall context and
  461. * from ndo_set_rx_mode() flow that may be called from BH.
  462. */
  463. spin_lock_bh(&bp->dmae_lock);
  464. /* reset completion */
  465. *wb_comp = 0;
  466. /* post the command on the channel used for initializations */
  467. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  468. /* wait for completion */
  469. udelay(5);
  470. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  471. if (!cnt ||
  472. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  473. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  474. BNX2X_ERR("DMAE timeout!\n");
  475. rc = DMAE_TIMEOUT;
  476. goto unlock;
  477. }
  478. cnt--;
  479. udelay(50);
  480. }
  481. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  482. BNX2X_ERR("DMAE PCI error!\n");
  483. rc = DMAE_PCI_ERROR;
  484. }
  485. unlock:
  486. spin_unlock_bh(&bp->dmae_lock);
  487. return rc;
  488. }
  489. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  490. u32 len32)
  491. {
  492. struct dmae_command dmae;
  493. if (!bp->dmae_ready) {
  494. u32 *data = bnx2x_sp(bp, wb_data[0]);
  495. if (CHIP_IS_E1(bp))
  496. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  497. else
  498. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  499. return;
  500. }
  501. /* set opcode and fixed command fields */
  502. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  503. /* fill in addresses and len */
  504. dmae.src_addr_lo = U64_LO(dma_addr);
  505. dmae.src_addr_hi = U64_HI(dma_addr);
  506. dmae.dst_addr_lo = dst_addr >> 2;
  507. dmae.dst_addr_hi = 0;
  508. dmae.len = len32;
  509. /* issue the command and wait for completion */
  510. bnx2x_issue_dmae_with_comp(bp, &dmae);
  511. }
  512. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  513. {
  514. struct dmae_command dmae;
  515. if (!bp->dmae_ready) {
  516. u32 *data = bnx2x_sp(bp, wb_data[0]);
  517. int i;
  518. if (CHIP_IS_E1(bp))
  519. for (i = 0; i < len32; i++)
  520. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  521. else
  522. for (i = 0; i < len32; i++)
  523. data[i] = REG_RD(bp, src_addr + i*4);
  524. return;
  525. }
  526. /* set opcode and fixed command fields */
  527. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  528. /* fill in addresses and len */
  529. dmae.src_addr_lo = src_addr >> 2;
  530. dmae.src_addr_hi = 0;
  531. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  532. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  533. dmae.len = len32;
  534. /* issue the command and wait for completion */
  535. bnx2x_issue_dmae_with_comp(bp, &dmae);
  536. }
  537. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  538. u32 addr, u32 len)
  539. {
  540. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  541. int offset = 0;
  542. while (len > dmae_wr_max) {
  543. bnx2x_write_dmae(bp, phys_addr + offset,
  544. addr + offset, dmae_wr_max);
  545. offset += dmae_wr_max * 4;
  546. len -= dmae_wr_max;
  547. }
  548. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  549. }
  550. static int bnx2x_mc_assert(struct bnx2x *bp)
  551. {
  552. char last_idx;
  553. int i, rc = 0;
  554. u32 row0, row1, row2, row3;
  555. /* XSTORM */
  556. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  557. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  558. if (last_idx)
  559. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  560. /* print the asserts */
  561. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  562. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  563. XSTORM_ASSERT_LIST_OFFSET(i));
  564. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  565. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  566. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  567. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  568. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  569. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  570. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  571. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  572. i, row3, row2, row1, row0);
  573. rc++;
  574. } else {
  575. break;
  576. }
  577. }
  578. /* TSTORM */
  579. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  580. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  581. if (last_idx)
  582. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  583. /* print the asserts */
  584. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  585. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  586. TSTORM_ASSERT_LIST_OFFSET(i));
  587. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  588. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  589. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  590. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  591. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  592. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  593. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  594. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  595. i, row3, row2, row1, row0);
  596. rc++;
  597. } else {
  598. break;
  599. }
  600. }
  601. /* CSTORM */
  602. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  603. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  604. if (last_idx)
  605. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  606. /* print the asserts */
  607. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  608. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  609. CSTORM_ASSERT_LIST_OFFSET(i));
  610. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  611. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  612. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  613. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  614. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  615. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  616. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  617. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  618. i, row3, row2, row1, row0);
  619. rc++;
  620. } else {
  621. break;
  622. }
  623. }
  624. /* USTORM */
  625. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  626. USTORM_ASSERT_LIST_INDEX_OFFSET);
  627. if (last_idx)
  628. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  629. /* print the asserts */
  630. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  631. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  632. USTORM_ASSERT_LIST_OFFSET(i));
  633. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  634. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  635. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  636. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  637. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  638. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  639. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  640. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  641. i, row3, row2, row1, row0);
  642. rc++;
  643. } else {
  644. break;
  645. }
  646. }
  647. return rc;
  648. }
  649. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  650. {
  651. u32 addr, val;
  652. u32 mark, offset;
  653. __be32 data[9];
  654. int word;
  655. u32 trace_shmem_base;
  656. if (BP_NOMCP(bp)) {
  657. BNX2X_ERR("NO MCP - can not dump\n");
  658. return;
  659. }
  660. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  661. (bp->common.bc_ver & 0xff0000) >> 16,
  662. (bp->common.bc_ver & 0xff00) >> 8,
  663. (bp->common.bc_ver & 0xff));
  664. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  665. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  666. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  667. if (BP_PATH(bp) == 0)
  668. trace_shmem_base = bp->common.shmem_base;
  669. else
  670. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  671. addr = trace_shmem_base - 0x800;
  672. /* validate TRCB signature */
  673. mark = REG_RD(bp, addr);
  674. if (mark != MFW_TRACE_SIGNATURE) {
  675. BNX2X_ERR("Trace buffer signature is missing.");
  676. return ;
  677. }
  678. /* read cyclic buffer pointer */
  679. addr += 4;
  680. mark = REG_RD(bp, addr);
  681. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  682. + ((mark + 0x3) & ~0x3) - 0x08000000;
  683. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  684. printk("%s", lvl);
  685. /* dump buffer after the mark */
  686. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  687. for (word = 0; word < 8; word++)
  688. data[word] = htonl(REG_RD(bp, offset + 4*word));
  689. data[8] = 0x0;
  690. pr_cont("%s", (char *)data);
  691. }
  692. /* dump buffer before the mark */
  693. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  694. for (word = 0; word < 8; word++)
  695. data[word] = htonl(REG_RD(bp, offset + 4*word));
  696. data[8] = 0x0;
  697. pr_cont("%s", (char *)data);
  698. }
  699. printk("%s" "end of fw dump\n", lvl);
  700. }
  701. static void bnx2x_fw_dump(struct bnx2x *bp)
  702. {
  703. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  704. }
  705. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  706. {
  707. int port = BP_PORT(bp);
  708. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  709. u32 val = REG_RD(bp, addr);
  710. /* in E1 we must use only PCI configuration space to disable
  711. * MSI/MSIX capablility
  712. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  713. */
  714. if (CHIP_IS_E1(bp)) {
  715. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  716. * Use mask register to prevent from HC sending interrupts
  717. * after we exit the function
  718. */
  719. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  720. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  721. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  722. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  723. } else
  724. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  725. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  726. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  727. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  728. DP(NETIF_MSG_IFDOWN,
  729. "write %x to HC %d (addr 0x%x)\n",
  730. val, port, addr);
  731. /* flush all outstanding writes */
  732. mmiowb();
  733. REG_WR(bp, addr, val);
  734. if (REG_RD(bp, addr) != val)
  735. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  736. }
  737. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  738. {
  739. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  740. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  741. IGU_PF_CONF_INT_LINE_EN |
  742. IGU_PF_CONF_ATTN_BIT_EN);
  743. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  744. /* flush all outstanding writes */
  745. mmiowb();
  746. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  747. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  748. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  749. }
  750. static void bnx2x_int_disable(struct bnx2x *bp)
  751. {
  752. if (bp->common.int_block == INT_BLOCK_HC)
  753. bnx2x_hc_int_disable(bp);
  754. else
  755. bnx2x_igu_int_disable(bp);
  756. }
  757. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  758. {
  759. int i;
  760. u16 j;
  761. struct hc_sp_status_block_data sp_sb_data;
  762. int func = BP_FUNC(bp);
  763. #ifdef BNX2X_STOP_ON_ERROR
  764. u16 start = 0, end = 0;
  765. u8 cos;
  766. #endif
  767. if (disable_int)
  768. bnx2x_int_disable(bp);
  769. bp->stats_state = STATS_STATE_DISABLED;
  770. bp->eth_stats.unrecoverable_error++;
  771. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  772. BNX2X_ERR("begin crash dump -----------------\n");
  773. /* Indices */
  774. /* Common */
  775. 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",
  776. bp->def_idx, bp->def_att_idx, bp->attn_state,
  777. bp->spq_prod_idx, bp->stats_counter);
  778. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  779. bp->def_status_blk->atten_status_block.attn_bits,
  780. bp->def_status_blk->atten_status_block.attn_bits_ack,
  781. bp->def_status_blk->atten_status_block.status_block_id,
  782. bp->def_status_blk->atten_status_block.attn_bits_index);
  783. BNX2X_ERR(" def (");
  784. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  785. pr_cont("0x%x%s",
  786. bp->def_status_blk->sp_sb.index_values[i],
  787. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  788. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  789. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  790. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  791. i*sizeof(u32));
  792. 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",
  793. sp_sb_data.igu_sb_id,
  794. sp_sb_data.igu_seg_id,
  795. sp_sb_data.p_func.pf_id,
  796. sp_sb_data.p_func.vnic_id,
  797. sp_sb_data.p_func.vf_id,
  798. sp_sb_data.p_func.vf_valid,
  799. sp_sb_data.state);
  800. for_each_eth_queue(bp, i) {
  801. struct bnx2x_fastpath *fp = &bp->fp[i];
  802. int loop;
  803. struct hc_status_block_data_e2 sb_data_e2;
  804. struct hc_status_block_data_e1x sb_data_e1x;
  805. struct hc_status_block_sm *hc_sm_p =
  806. CHIP_IS_E1x(bp) ?
  807. sb_data_e1x.common.state_machine :
  808. sb_data_e2.common.state_machine;
  809. struct hc_index_data *hc_index_p =
  810. CHIP_IS_E1x(bp) ?
  811. sb_data_e1x.index_data :
  812. sb_data_e2.index_data;
  813. u8 data_size, cos;
  814. u32 *sb_data_p;
  815. struct bnx2x_fp_txdata txdata;
  816. /* Rx */
  817. 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",
  818. i, fp->rx_bd_prod, fp->rx_bd_cons,
  819. fp->rx_comp_prod,
  820. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  821. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  822. fp->rx_sge_prod, fp->last_max_sge,
  823. le16_to_cpu(fp->fp_hc_idx));
  824. /* Tx */
  825. for_each_cos_in_tx_queue(fp, cos)
  826. {
  827. txdata = *fp->txdata_ptr[cos];
  828. 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",
  829. i, txdata.tx_pkt_prod,
  830. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  831. txdata.tx_bd_cons,
  832. le16_to_cpu(*txdata.tx_cons_sb));
  833. }
  834. loop = CHIP_IS_E1x(bp) ?
  835. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  836. /* host sb data */
  837. if (IS_FCOE_FP(fp))
  838. continue;
  839. BNX2X_ERR(" run indexes (");
  840. for (j = 0; j < HC_SB_MAX_SM; j++)
  841. pr_cont("0x%x%s",
  842. fp->sb_running_index[j],
  843. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  844. BNX2X_ERR(" indexes (");
  845. for (j = 0; j < loop; j++)
  846. pr_cont("0x%x%s",
  847. fp->sb_index_values[j],
  848. (j == loop - 1) ? ")" : " ");
  849. /* fw sb data */
  850. data_size = CHIP_IS_E1x(bp) ?
  851. sizeof(struct hc_status_block_data_e1x) :
  852. sizeof(struct hc_status_block_data_e2);
  853. data_size /= sizeof(u32);
  854. sb_data_p = CHIP_IS_E1x(bp) ?
  855. (u32 *)&sb_data_e1x :
  856. (u32 *)&sb_data_e2;
  857. /* copy sb data in here */
  858. for (j = 0; j < data_size; j++)
  859. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  860. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  861. j * sizeof(u32));
  862. if (!CHIP_IS_E1x(bp)) {
  863. 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",
  864. sb_data_e2.common.p_func.pf_id,
  865. sb_data_e2.common.p_func.vf_id,
  866. sb_data_e2.common.p_func.vf_valid,
  867. sb_data_e2.common.p_func.vnic_id,
  868. sb_data_e2.common.same_igu_sb_1b,
  869. sb_data_e2.common.state);
  870. } else {
  871. 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",
  872. sb_data_e1x.common.p_func.pf_id,
  873. sb_data_e1x.common.p_func.vf_id,
  874. sb_data_e1x.common.p_func.vf_valid,
  875. sb_data_e1x.common.p_func.vnic_id,
  876. sb_data_e1x.common.same_igu_sb_1b,
  877. sb_data_e1x.common.state);
  878. }
  879. /* SB_SMs data */
  880. for (j = 0; j < HC_SB_MAX_SM; j++) {
  881. 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",
  882. j, hc_sm_p[j].__flags,
  883. hc_sm_p[j].igu_sb_id,
  884. hc_sm_p[j].igu_seg_id,
  885. hc_sm_p[j].time_to_expire,
  886. hc_sm_p[j].timer_value);
  887. }
  888. /* Indecies data */
  889. for (j = 0; j < loop; j++) {
  890. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  891. hc_index_p[j].flags,
  892. hc_index_p[j].timeout);
  893. }
  894. }
  895. #ifdef BNX2X_STOP_ON_ERROR
  896. /* Rings */
  897. /* Rx */
  898. for_each_valid_rx_queue(bp, i) {
  899. struct bnx2x_fastpath *fp = &bp->fp[i];
  900. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  901. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  902. for (j = start; j != end; j = RX_BD(j + 1)) {
  903. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  904. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  905. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  906. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  907. }
  908. start = RX_SGE(fp->rx_sge_prod);
  909. end = RX_SGE(fp->last_max_sge);
  910. for (j = start; j != end; j = RX_SGE(j + 1)) {
  911. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  912. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  913. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  914. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  915. }
  916. start = RCQ_BD(fp->rx_comp_cons - 10);
  917. end = RCQ_BD(fp->rx_comp_cons + 503);
  918. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  919. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  920. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  921. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  922. }
  923. }
  924. /* Tx */
  925. for_each_valid_tx_queue(bp, i) {
  926. struct bnx2x_fastpath *fp = &bp->fp[i];
  927. for_each_cos_in_tx_queue(fp, cos) {
  928. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  929. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  930. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  931. for (j = start; j != end; j = TX_BD(j + 1)) {
  932. struct sw_tx_bd *sw_bd =
  933. &txdata->tx_buf_ring[j];
  934. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  935. i, cos, j, sw_bd->skb,
  936. sw_bd->first_bd);
  937. }
  938. start = TX_BD(txdata->tx_bd_cons - 10);
  939. end = TX_BD(txdata->tx_bd_cons + 254);
  940. for (j = start; j != end; j = TX_BD(j + 1)) {
  941. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  942. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  943. i, cos, j, tx_bd[0], tx_bd[1],
  944. tx_bd[2], tx_bd[3]);
  945. }
  946. }
  947. }
  948. #endif
  949. bnx2x_fw_dump(bp);
  950. bnx2x_mc_assert(bp);
  951. BNX2X_ERR("end crash dump -----------------\n");
  952. }
  953. /*
  954. * FLR Support for E2
  955. *
  956. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  957. * initialization.
  958. */
  959. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  960. #define FLR_WAIT_INTERVAL 50 /* usec */
  961. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  962. struct pbf_pN_buf_regs {
  963. int pN;
  964. u32 init_crd;
  965. u32 crd;
  966. u32 crd_freed;
  967. };
  968. struct pbf_pN_cmd_regs {
  969. int pN;
  970. u32 lines_occup;
  971. u32 lines_freed;
  972. };
  973. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  974. struct pbf_pN_buf_regs *regs,
  975. u32 poll_count)
  976. {
  977. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  978. u32 cur_cnt = poll_count;
  979. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  980. crd = crd_start = REG_RD(bp, regs->crd);
  981. init_crd = REG_RD(bp, regs->init_crd);
  982. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  983. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  984. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  985. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  986. (init_crd - crd_start))) {
  987. if (cur_cnt--) {
  988. udelay(FLR_WAIT_INTERVAL);
  989. crd = REG_RD(bp, regs->crd);
  990. crd_freed = REG_RD(bp, regs->crd_freed);
  991. } else {
  992. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  993. regs->pN);
  994. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  995. regs->pN, crd);
  996. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  997. regs->pN, crd_freed);
  998. break;
  999. }
  1000. }
  1001. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1002. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1003. }
  1004. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1005. struct pbf_pN_cmd_regs *regs,
  1006. u32 poll_count)
  1007. {
  1008. u32 occup, to_free, freed, freed_start;
  1009. u32 cur_cnt = poll_count;
  1010. occup = to_free = REG_RD(bp, regs->lines_occup);
  1011. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1012. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1013. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1014. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1015. if (cur_cnt--) {
  1016. udelay(FLR_WAIT_INTERVAL);
  1017. occup = REG_RD(bp, regs->lines_occup);
  1018. freed = REG_RD(bp, regs->lines_freed);
  1019. } else {
  1020. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1021. regs->pN);
  1022. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1023. regs->pN, occup);
  1024. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1025. regs->pN, freed);
  1026. break;
  1027. }
  1028. }
  1029. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1030. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1031. }
  1032. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1033. u32 expected, u32 poll_count)
  1034. {
  1035. u32 cur_cnt = poll_count;
  1036. u32 val;
  1037. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1038. udelay(FLR_WAIT_INTERVAL);
  1039. return val;
  1040. }
  1041. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1042. char *msg, u32 poll_cnt)
  1043. {
  1044. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1045. if (val != 0) {
  1046. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1047. return 1;
  1048. }
  1049. return 0;
  1050. }
  1051. /* Common routines with VF FLR cleanup */
  1052. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1053. {
  1054. /* adjust polling timeout */
  1055. if (CHIP_REV_IS_EMUL(bp))
  1056. return FLR_POLL_CNT * 2000;
  1057. if (CHIP_REV_IS_FPGA(bp))
  1058. return FLR_POLL_CNT * 120;
  1059. return FLR_POLL_CNT;
  1060. }
  1061. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1062. {
  1063. struct pbf_pN_cmd_regs cmd_regs[] = {
  1064. {0, (CHIP_IS_E3B0(bp)) ?
  1065. PBF_REG_TQ_OCCUPANCY_Q0 :
  1066. PBF_REG_P0_TQ_OCCUPANCY,
  1067. (CHIP_IS_E3B0(bp)) ?
  1068. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1069. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1070. {1, (CHIP_IS_E3B0(bp)) ?
  1071. PBF_REG_TQ_OCCUPANCY_Q1 :
  1072. PBF_REG_P1_TQ_OCCUPANCY,
  1073. (CHIP_IS_E3B0(bp)) ?
  1074. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1075. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1076. {4, (CHIP_IS_E3B0(bp)) ?
  1077. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1078. PBF_REG_P4_TQ_OCCUPANCY,
  1079. (CHIP_IS_E3B0(bp)) ?
  1080. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1081. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1082. };
  1083. struct pbf_pN_buf_regs buf_regs[] = {
  1084. {0, (CHIP_IS_E3B0(bp)) ?
  1085. PBF_REG_INIT_CRD_Q0 :
  1086. PBF_REG_P0_INIT_CRD ,
  1087. (CHIP_IS_E3B0(bp)) ?
  1088. PBF_REG_CREDIT_Q0 :
  1089. PBF_REG_P0_CREDIT,
  1090. (CHIP_IS_E3B0(bp)) ?
  1091. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1092. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1093. {1, (CHIP_IS_E3B0(bp)) ?
  1094. PBF_REG_INIT_CRD_Q1 :
  1095. PBF_REG_P1_INIT_CRD,
  1096. (CHIP_IS_E3B0(bp)) ?
  1097. PBF_REG_CREDIT_Q1 :
  1098. PBF_REG_P1_CREDIT,
  1099. (CHIP_IS_E3B0(bp)) ?
  1100. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1101. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1102. {4, (CHIP_IS_E3B0(bp)) ?
  1103. PBF_REG_INIT_CRD_LB_Q :
  1104. PBF_REG_P4_INIT_CRD,
  1105. (CHIP_IS_E3B0(bp)) ?
  1106. PBF_REG_CREDIT_LB_Q :
  1107. PBF_REG_P4_CREDIT,
  1108. (CHIP_IS_E3B0(bp)) ?
  1109. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1110. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1111. };
  1112. int i;
  1113. /* Verify the command queues are flushed P0, P1, P4 */
  1114. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1115. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1116. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1117. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1118. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1119. }
  1120. #define OP_GEN_PARAM(param) \
  1121. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1122. #define OP_GEN_TYPE(type) \
  1123. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1124. #define OP_GEN_AGG_VECT(index) \
  1125. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1126. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1127. {
  1128. struct sdm_op_gen op_gen = {0};
  1129. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1130. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1131. int ret = 0;
  1132. if (REG_RD(bp, comp_addr)) {
  1133. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1134. return 1;
  1135. }
  1136. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1137. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1138. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  1139. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1140. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1141. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1142. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1143. BNX2X_ERR("FW final cleanup did not succeed\n");
  1144. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1145. (REG_RD(bp, comp_addr)));
  1146. bnx2x_panic();
  1147. return 1;
  1148. }
  1149. /* Zero completion for nxt FLR */
  1150. REG_WR(bp, comp_addr, 0);
  1151. return ret;
  1152. }
  1153. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1154. {
  1155. u16 status;
  1156. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1157. return status & PCI_EXP_DEVSTA_TRPND;
  1158. }
  1159. /* PF FLR specific routines
  1160. */
  1161. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1162. {
  1163. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1164. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1165. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1166. "CFC PF usage counter timed out",
  1167. poll_cnt))
  1168. return 1;
  1169. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1170. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1171. DORQ_REG_PF_USAGE_CNT,
  1172. "DQ PF usage counter timed out",
  1173. poll_cnt))
  1174. return 1;
  1175. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1176. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1177. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1178. "QM PF usage counter timed out",
  1179. poll_cnt))
  1180. return 1;
  1181. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1182. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1183. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1184. "Timers VNIC usage counter timed out",
  1185. poll_cnt))
  1186. return 1;
  1187. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1188. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1189. "Timers NUM_SCANS usage counter timed out",
  1190. poll_cnt))
  1191. return 1;
  1192. /* Wait DMAE PF usage counter to zero */
  1193. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1194. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1195. "DMAE dommand register timed out",
  1196. poll_cnt))
  1197. return 1;
  1198. return 0;
  1199. }
  1200. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1201. {
  1202. u32 val;
  1203. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1204. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1205. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1206. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1207. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1208. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1209. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1210. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1211. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1212. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1213. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1214. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1215. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1216. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1217. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1218. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1219. val);
  1220. }
  1221. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1222. {
  1223. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1224. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1225. /* Re-enable PF target read access */
  1226. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1227. /* Poll HW usage counters */
  1228. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1229. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1230. return -EBUSY;
  1231. /* Zero the igu 'trailing edge' and 'leading edge' */
  1232. /* Send the FW cleanup command */
  1233. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1234. return -EBUSY;
  1235. /* ATC cleanup */
  1236. /* Verify TX hw is flushed */
  1237. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1238. /* Wait 100ms (not adjusted according to platform) */
  1239. msleep(100);
  1240. /* Verify no pending pci transactions */
  1241. if (bnx2x_is_pcie_pending(bp->pdev))
  1242. BNX2X_ERR("PCIE Transactions still pending\n");
  1243. /* Debug */
  1244. bnx2x_hw_enable_status(bp);
  1245. /*
  1246. * Master enable - Due to WB DMAE writes performed before this
  1247. * register is re-initialized as part of the regular function init
  1248. */
  1249. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1250. return 0;
  1251. }
  1252. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1253. {
  1254. int port = BP_PORT(bp);
  1255. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1256. u32 val = REG_RD(bp, addr);
  1257. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1258. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1259. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1260. if (msix) {
  1261. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1262. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1263. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1264. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1265. if (single_msix)
  1266. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1267. } else if (msi) {
  1268. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1269. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1270. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1271. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1272. } else {
  1273. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1274. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1275. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1276. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1277. if (!CHIP_IS_E1(bp)) {
  1278. DP(NETIF_MSG_IFUP,
  1279. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1280. REG_WR(bp, addr, val);
  1281. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1282. }
  1283. }
  1284. if (CHIP_IS_E1(bp))
  1285. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1286. DP(NETIF_MSG_IFUP,
  1287. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1288. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1289. REG_WR(bp, addr, val);
  1290. /*
  1291. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1292. */
  1293. mmiowb();
  1294. barrier();
  1295. if (!CHIP_IS_E1(bp)) {
  1296. /* init leading/trailing edge */
  1297. if (IS_MF(bp)) {
  1298. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1299. if (bp->port.pmf)
  1300. /* enable nig and gpio3 attention */
  1301. val |= 0x1100;
  1302. } else
  1303. val = 0xffff;
  1304. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1305. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1306. }
  1307. /* Make sure that interrupts are indeed enabled from here on */
  1308. mmiowb();
  1309. }
  1310. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1311. {
  1312. u32 val;
  1313. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1314. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1315. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1316. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1317. if (msix) {
  1318. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1319. IGU_PF_CONF_SINGLE_ISR_EN);
  1320. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1321. IGU_PF_CONF_ATTN_BIT_EN);
  1322. if (single_msix)
  1323. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1324. } else if (msi) {
  1325. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1326. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1327. IGU_PF_CONF_ATTN_BIT_EN |
  1328. IGU_PF_CONF_SINGLE_ISR_EN);
  1329. } else {
  1330. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1331. val |= (IGU_PF_CONF_INT_LINE_EN |
  1332. IGU_PF_CONF_ATTN_BIT_EN |
  1333. IGU_PF_CONF_SINGLE_ISR_EN);
  1334. }
  1335. /* Clean previous status - need to configure igu prior to ack*/
  1336. if ((!msix) || single_msix) {
  1337. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1338. bnx2x_ack_int(bp);
  1339. }
  1340. val |= IGU_PF_CONF_FUNC_EN;
  1341. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1342. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1343. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1344. if (val & IGU_PF_CONF_INT_LINE_EN)
  1345. pci_intx(bp->pdev, true);
  1346. barrier();
  1347. /* init leading/trailing edge */
  1348. if (IS_MF(bp)) {
  1349. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1350. if (bp->port.pmf)
  1351. /* enable nig and gpio3 attention */
  1352. val |= 0x1100;
  1353. } else
  1354. val = 0xffff;
  1355. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1356. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1357. /* Make sure that interrupts are indeed enabled from here on */
  1358. mmiowb();
  1359. }
  1360. void bnx2x_int_enable(struct bnx2x *bp)
  1361. {
  1362. if (bp->common.int_block == INT_BLOCK_HC)
  1363. bnx2x_hc_int_enable(bp);
  1364. else
  1365. bnx2x_igu_int_enable(bp);
  1366. }
  1367. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1368. {
  1369. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1370. int i, offset;
  1371. if (disable_hw)
  1372. /* prevent the HW from sending interrupts */
  1373. bnx2x_int_disable(bp);
  1374. /* make sure all ISRs are done */
  1375. if (msix) {
  1376. synchronize_irq(bp->msix_table[0].vector);
  1377. offset = 1;
  1378. if (CNIC_SUPPORT(bp))
  1379. offset++;
  1380. for_each_eth_queue(bp, i)
  1381. synchronize_irq(bp->msix_table[offset++].vector);
  1382. } else
  1383. synchronize_irq(bp->pdev->irq);
  1384. /* make sure sp_task is not running */
  1385. cancel_delayed_work(&bp->sp_task);
  1386. cancel_delayed_work(&bp->period_task);
  1387. flush_workqueue(bnx2x_wq);
  1388. }
  1389. /* fast path */
  1390. /*
  1391. * General service functions
  1392. */
  1393. /* Return true if succeeded to acquire the lock */
  1394. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1395. {
  1396. u32 lock_status;
  1397. u32 resource_bit = (1 << resource);
  1398. int func = BP_FUNC(bp);
  1399. u32 hw_lock_control_reg;
  1400. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1401. "Trying to take a lock on resource %d\n", resource);
  1402. /* Validating that the resource is within range */
  1403. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1404. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1405. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1406. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1407. return false;
  1408. }
  1409. if (func <= 5)
  1410. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1411. else
  1412. hw_lock_control_reg =
  1413. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1414. /* Try to acquire the lock */
  1415. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1416. lock_status = REG_RD(bp, hw_lock_control_reg);
  1417. if (lock_status & resource_bit)
  1418. return true;
  1419. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1420. "Failed to get a lock on resource %d\n", resource);
  1421. return false;
  1422. }
  1423. /**
  1424. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1425. *
  1426. * @bp: driver handle
  1427. *
  1428. * Returns the recovery leader resource id according to the engine this function
  1429. * belongs to. Currently only only 2 engines is supported.
  1430. */
  1431. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1432. {
  1433. if (BP_PATH(bp))
  1434. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1435. else
  1436. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1437. }
  1438. /**
  1439. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1440. *
  1441. * @bp: driver handle
  1442. *
  1443. * Tries to acquire a leader lock for current engine.
  1444. */
  1445. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1446. {
  1447. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1448. }
  1449. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1450. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1451. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1452. {
  1453. /* Set the interrupt occurred bit for the sp-task to recognize it
  1454. * must ack the interrupt and transition according to the IGU
  1455. * state machine.
  1456. */
  1457. atomic_set(&bp->interrupt_occurred, 1);
  1458. /* The sp_task must execute only after this bit
  1459. * is set, otherwise we will get out of sync and miss all
  1460. * further interrupts. Hence, the barrier.
  1461. */
  1462. smp_wmb();
  1463. /* schedule sp_task to workqueue */
  1464. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1465. }
  1466. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1467. {
  1468. struct bnx2x *bp = fp->bp;
  1469. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1470. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1471. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1472. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1473. DP(BNX2X_MSG_SP,
  1474. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1475. fp->index, cid, command, bp->state,
  1476. rr_cqe->ramrod_cqe.ramrod_type);
  1477. /* If cid is within VF range, replace the slowpath object with the
  1478. * one corresponding to this VF
  1479. */
  1480. if (cid >= BNX2X_FIRST_VF_CID &&
  1481. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1482. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1483. switch (command) {
  1484. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1485. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1486. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1487. break;
  1488. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1489. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1490. drv_cmd = BNX2X_Q_CMD_SETUP;
  1491. break;
  1492. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1493. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1494. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1495. break;
  1496. case (RAMROD_CMD_ID_ETH_HALT):
  1497. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1498. drv_cmd = BNX2X_Q_CMD_HALT;
  1499. break;
  1500. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1501. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1502. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1503. break;
  1504. case (RAMROD_CMD_ID_ETH_EMPTY):
  1505. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1506. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1507. break;
  1508. default:
  1509. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1510. command, fp->index);
  1511. return;
  1512. }
  1513. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1514. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1515. /* q_obj->complete_cmd() failure means that this was
  1516. * an unexpected completion.
  1517. *
  1518. * In this case we don't want to increase the bp->spq_left
  1519. * because apparently we haven't sent this command the first
  1520. * place.
  1521. */
  1522. #ifdef BNX2X_STOP_ON_ERROR
  1523. bnx2x_panic();
  1524. #else
  1525. return;
  1526. #endif
  1527. /* SRIOV: reschedule any 'in_progress' operations */
  1528. bnx2x_iov_sp_event(bp, cid, true);
  1529. smp_mb__before_atomic_inc();
  1530. atomic_inc(&bp->cq_spq_left);
  1531. /* push the change in bp->spq_left and towards the memory */
  1532. smp_mb__after_atomic_inc();
  1533. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1534. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1535. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1536. /* if Q update ramrod is completed for last Q in AFEX vif set
  1537. * flow, then ACK MCP at the end
  1538. *
  1539. * mark pending ACK to MCP bit.
  1540. * prevent case that both bits are cleared.
  1541. * At the end of load/unload driver checks that
  1542. * sp_state is cleared, and this order prevents
  1543. * races
  1544. */
  1545. smp_mb__before_clear_bit();
  1546. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1547. wmb();
  1548. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1549. smp_mb__after_clear_bit();
  1550. /* schedule the sp task as mcp ack is required */
  1551. bnx2x_schedule_sp_task(bp);
  1552. }
  1553. return;
  1554. }
  1555. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1556. {
  1557. struct bnx2x *bp = netdev_priv(dev_instance);
  1558. u16 status = bnx2x_ack_int(bp);
  1559. u16 mask;
  1560. int i;
  1561. u8 cos;
  1562. /* Return here if interrupt is shared and it's not for us */
  1563. if (unlikely(status == 0)) {
  1564. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1565. return IRQ_NONE;
  1566. }
  1567. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1568. #ifdef BNX2X_STOP_ON_ERROR
  1569. if (unlikely(bp->panic))
  1570. return IRQ_HANDLED;
  1571. #endif
  1572. for_each_eth_queue(bp, i) {
  1573. struct bnx2x_fastpath *fp = &bp->fp[i];
  1574. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1575. if (status & mask) {
  1576. /* Handle Rx or Tx according to SB id */
  1577. prefetch(fp->rx_cons_sb);
  1578. for_each_cos_in_tx_queue(fp, cos)
  1579. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1580. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1581. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1582. status &= ~mask;
  1583. }
  1584. }
  1585. if (CNIC_SUPPORT(bp)) {
  1586. mask = 0x2;
  1587. if (status & (mask | 0x1)) {
  1588. struct cnic_ops *c_ops = NULL;
  1589. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1590. rcu_read_lock();
  1591. c_ops = rcu_dereference(bp->cnic_ops);
  1592. if (c_ops)
  1593. c_ops->cnic_handler(bp->cnic_data,
  1594. NULL);
  1595. rcu_read_unlock();
  1596. }
  1597. status &= ~mask;
  1598. }
  1599. }
  1600. if (unlikely(status & 0x1)) {
  1601. /* schedule sp task to perform default status block work, ack
  1602. * attentions and enable interrupts.
  1603. */
  1604. bnx2x_schedule_sp_task(bp);
  1605. status &= ~0x1;
  1606. if (!status)
  1607. return IRQ_HANDLED;
  1608. }
  1609. if (unlikely(status))
  1610. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1611. status);
  1612. return IRQ_HANDLED;
  1613. }
  1614. /* Link */
  1615. /*
  1616. * General service functions
  1617. */
  1618. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1619. {
  1620. u32 lock_status;
  1621. u32 resource_bit = (1 << resource);
  1622. int func = BP_FUNC(bp);
  1623. u32 hw_lock_control_reg;
  1624. int cnt;
  1625. /* Validating that the resource is within range */
  1626. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1627. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1628. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1629. return -EINVAL;
  1630. }
  1631. if (func <= 5) {
  1632. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1633. } else {
  1634. hw_lock_control_reg =
  1635. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1636. }
  1637. /* Validating that the resource is not already taken */
  1638. lock_status = REG_RD(bp, hw_lock_control_reg);
  1639. if (lock_status & resource_bit) {
  1640. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1641. lock_status, resource_bit);
  1642. return -EEXIST;
  1643. }
  1644. /* Try for 5 second every 5ms */
  1645. for (cnt = 0; cnt < 1000; cnt++) {
  1646. /* Try to acquire the lock */
  1647. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1648. lock_status = REG_RD(bp, hw_lock_control_reg);
  1649. if (lock_status & resource_bit)
  1650. return 0;
  1651. msleep(5);
  1652. }
  1653. BNX2X_ERR("Timeout\n");
  1654. return -EAGAIN;
  1655. }
  1656. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1657. {
  1658. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1659. }
  1660. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1661. {
  1662. u32 lock_status;
  1663. u32 resource_bit = (1 << resource);
  1664. int func = BP_FUNC(bp);
  1665. u32 hw_lock_control_reg;
  1666. /* Validating that the resource is within range */
  1667. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1668. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1669. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1670. return -EINVAL;
  1671. }
  1672. if (func <= 5) {
  1673. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1674. } else {
  1675. hw_lock_control_reg =
  1676. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1677. }
  1678. /* Validating that the resource is currently taken */
  1679. lock_status = REG_RD(bp, hw_lock_control_reg);
  1680. if (!(lock_status & resource_bit)) {
  1681. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1682. lock_status, resource_bit);
  1683. return -EFAULT;
  1684. }
  1685. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1686. return 0;
  1687. }
  1688. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1689. {
  1690. /* The GPIO should be swapped if swap register is set and active */
  1691. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1692. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1693. int gpio_shift = gpio_num +
  1694. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1695. u32 gpio_mask = (1 << gpio_shift);
  1696. u32 gpio_reg;
  1697. int value;
  1698. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1699. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1700. return -EINVAL;
  1701. }
  1702. /* read GPIO value */
  1703. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1704. /* get the requested pin value */
  1705. if ((gpio_reg & gpio_mask) == gpio_mask)
  1706. value = 1;
  1707. else
  1708. value = 0;
  1709. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1710. return value;
  1711. }
  1712. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1713. {
  1714. /* The GPIO should be swapped if swap register is set and active */
  1715. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1716. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1717. int gpio_shift = gpio_num +
  1718. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1719. u32 gpio_mask = (1 << gpio_shift);
  1720. u32 gpio_reg;
  1721. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1722. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1723. return -EINVAL;
  1724. }
  1725. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1726. /* read GPIO and mask except the float bits */
  1727. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1728. switch (mode) {
  1729. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1730. DP(NETIF_MSG_LINK,
  1731. "Set GPIO %d (shift %d) -> output low\n",
  1732. gpio_num, gpio_shift);
  1733. /* clear FLOAT and set CLR */
  1734. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1735. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1736. break;
  1737. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1738. DP(NETIF_MSG_LINK,
  1739. "Set GPIO %d (shift %d) -> output high\n",
  1740. gpio_num, gpio_shift);
  1741. /* clear FLOAT and set SET */
  1742. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1743. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1744. break;
  1745. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1746. DP(NETIF_MSG_LINK,
  1747. "Set GPIO %d (shift %d) -> input\n",
  1748. gpio_num, gpio_shift);
  1749. /* set FLOAT */
  1750. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1751. break;
  1752. default:
  1753. break;
  1754. }
  1755. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1756. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1757. return 0;
  1758. }
  1759. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1760. {
  1761. u32 gpio_reg = 0;
  1762. int rc = 0;
  1763. /* Any port swapping should be handled by caller. */
  1764. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1765. /* read GPIO and mask except the float bits */
  1766. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1767. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1768. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1769. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1770. switch (mode) {
  1771. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1772. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1773. /* set CLR */
  1774. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1775. break;
  1776. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1777. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1778. /* set SET */
  1779. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1780. break;
  1781. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1782. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1783. /* set FLOAT */
  1784. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1785. break;
  1786. default:
  1787. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1788. rc = -EINVAL;
  1789. break;
  1790. }
  1791. if (rc == 0)
  1792. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1793. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1794. return rc;
  1795. }
  1796. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1797. {
  1798. /* The GPIO should be swapped if swap register is set and active */
  1799. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1800. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1801. int gpio_shift = gpio_num +
  1802. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1803. u32 gpio_mask = (1 << gpio_shift);
  1804. u32 gpio_reg;
  1805. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1806. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1807. return -EINVAL;
  1808. }
  1809. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1810. /* read GPIO int */
  1811. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1812. switch (mode) {
  1813. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1814. DP(NETIF_MSG_LINK,
  1815. "Clear GPIO INT %d (shift %d) -> output low\n",
  1816. gpio_num, gpio_shift);
  1817. /* clear SET and set CLR */
  1818. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1819. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1820. break;
  1821. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1822. DP(NETIF_MSG_LINK,
  1823. "Set GPIO INT %d (shift %d) -> output high\n",
  1824. gpio_num, gpio_shift);
  1825. /* clear CLR and set SET */
  1826. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1827. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1828. break;
  1829. default:
  1830. break;
  1831. }
  1832. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1833. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1834. return 0;
  1835. }
  1836. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1837. {
  1838. u32 spio_reg;
  1839. /* Only 2 SPIOs are configurable */
  1840. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1841. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1842. return -EINVAL;
  1843. }
  1844. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1845. /* read SPIO and mask except the float bits */
  1846. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1847. switch (mode) {
  1848. case MISC_SPIO_OUTPUT_LOW:
  1849. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1850. /* clear FLOAT and set CLR */
  1851. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1852. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1853. break;
  1854. case MISC_SPIO_OUTPUT_HIGH:
  1855. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1856. /* clear FLOAT and set SET */
  1857. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1858. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1859. break;
  1860. case MISC_SPIO_INPUT_HI_Z:
  1861. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1862. /* set FLOAT */
  1863. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1864. break;
  1865. default:
  1866. break;
  1867. }
  1868. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1869. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1870. return 0;
  1871. }
  1872. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1873. {
  1874. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1875. switch (bp->link_vars.ieee_fc &
  1876. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1877. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1878. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1879. ADVERTISED_Pause);
  1880. break;
  1881. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1882. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1883. ADVERTISED_Pause);
  1884. break;
  1885. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1886. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1887. break;
  1888. default:
  1889. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1890. ADVERTISED_Pause);
  1891. break;
  1892. }
  1893. }
  1894. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1895. {
  1896. /* Initialize link parameters structure variables
  1897. * It is recommended to turn off RX FC for jumbo frames
  1898. * for better performance
  1899. */
  1900. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1901. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1902. else
  1903. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1904. }
  1905. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1906. {
  1907. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1908. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1909. if (!BP_NOMCP(bp)) {
  1910. bnx2x_set_requested_fc(bp);
  1911. bnx2x_acquire_phy_lock(bp);
  1912. if (load_mode == LOAD_DIAG) {
  1913. struct link_params *lp = &bp->link_params;
  1914. lp->loopback_mode = LOOPBACK_XGXS;
  1915. /* do PHY loopback at 10G speed, if possible */
  1916. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1917. if (lp->speed_cap_mask[cfx_idx] &
  1918. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1919. lp->req_line_speed[cfx_idx] =
  1920. SPEED_10000;
  1921. else
  1922. lp->req_line_speed[cfx_idx] =
  1923. SPEED_1000;
  1924. }
  1925. }
  1926. if (load_mode == LOAD_LOOPBACK_EXT) {
  1927. struct link_params *lp = &bp->link_params;
  1928. lp->loopback_mode = LOOPBACK_EXT;
  1929. }
  1930. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1931. bnx2x_release_phy_lock(bp);
  1932. bnx2x_calc_fc_adv(bp);
  1933. if (bp->link_vars.link_up) {
  1934. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1935. bnx2x_link_report(bp);
  1936. }
  1937. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1938. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1939. return rc;
  1940. }
  1941. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1942. return -EINVAL;
  1943. }
  1944. void bnx2x_link_set(struct bnx2x *bp)
  1945. {
  1946. if (!BP_NOMCP(bp)) {
  1947. bnx2x_acquire_phy_lock(bp);
  1948. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1949. bnx2x_release_phy_lock(bp);
  1950. bnx2x_calc_fc_adv(bp);
  1951. } else
  1952. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1953. }
  1954. static void bnx2x__link_reset(struct bnx2x *bp)
  1955. {
  1956. if (!BP_NOMCP(bp)) {
  1957. bnx2x_acquire_phy_lock(bp);
  1958. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1959. bnx2x_release_phy_lock(bp);
  1960. } else
  1961. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1962. }
  1963. void bnx2x_force_link_reset(struct bnx2x *bp)
  1964. {
  1965. bnx2x_acquire_phy_lock(bp);
  1966. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1967. bnx2x_release_phy_lock(bp);
  1968. }
  1969. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1970. {
  1971. u8 rc = 0;
  1972. if (!BP_NOMCP(bp)) {
  1973. bnx2x_acquire_phy_lock(bp);
  1974. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1975. is_serdes);
  1976. bnx2x_release_phy_lock(bp);
  1977. } else
  1978. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1979. return rc;
  1980. }
  1981. /* Calculates the sum of vn_min_rates.
  1982. It's needed for further normalizing of the min_rates.
  1983. Returns:
  1984. sum of vn_min_rates.
  1985. or
  1986. 0 - if all the min_rates are 0.
  1987. In the later case fainess algorithm should be deactivated.
  1988. If not all min_rates are zero then those that are zeroes will be set to 1.
  1989. */
  1990. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1991. struct cmng_init_input *input)
  1992. {
  1993. int all_zero = 1;
  1994. int vn;
  1995. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1996. u32 vn_cfg = bp->mf_config[vn];
  1997. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1998. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1999. /* Skip hidden vns */
  2000. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2001. vn_min_rate = 0;
  2002. /* If min rate is zero - set it to 1 */
  2003. else if (!vn_min_rate)
  2004. vn_min_rate = DEF_MIN_RATE;
  2005. else
  2006. all_zero = 0;
  2007. input->vnic_min_rate[vn] = vn_min_rate;
  2008. }
  2009. /* if ETS or all min rates are zeros - disable fairness */
  2010. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2011. input->flags.cmng_enables &=
  2012. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2013. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2014. } else if (all_zero) {
  2015. input->flags.cmng_enables &=
  2016. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2017. DP(NETIF_MSG_IFUP,
  2018. "All MIN values are zeroes fairness will be disabled\n");
  2019. } else
  2020. input->flags.cmng_enables |=
  2021. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2022. }
  2023. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2024. struct cmng_init_input *input)
  2025. {
  2026. u16 vn_max_rate;
  2027. u32 vn_cfg = bp->mf_config[vn];
  2028. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2029. vn_max_rate = 0;
  2030. else {
  2031. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2032. if (IS_MF_SI(bp)) {
  2033. /* maxCfg in percents of linkspeed */
  2034. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2035. } else /* SD modes */
  2036. /* maxCfg is absolute in 100Mb units */
  2037. vn_max_rate = maxCfg * 100;
  2038. }
  2039. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2040. input->vnic_max_rate[vn] = vn_max_rate;
  2041. }
  2042. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2043. {
  2044. if (CHIP_REV_IS_SLOW(bp))
  2045. return CMNG_FNS_NONE;
  2046. if (IS_MF(bp))
  2047. return CMNG_FNS_MINMAX;
  2048. return CMNG_FNS_NONE;
  2049. }
  2050. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2051. {
  2052. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2053. if (BP_NOMCP(bp))
  2054. return; /* what should be the default bvalue in this case */
  2055. /* For 2 port configuration the absolute function number formula
  2056. * is:
  2057. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2058. *
  2059. * and there are 4 functions per port
  2060. *
  2061. * For 4 port configuration it is
  2062. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2063. *
  2064. * and there are 2 functions per port
  2065. */
  2066. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2067. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2068. if (func >= E1H_FUNC_MAX)
  2069. break;
  2070. bp->mf_config[vn] =
  2071. MF_CFG_RD(bp, func_mf_config[func].config);
  2072. }
  2073. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2074. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2075. bp->flags |= MF_FUNC_DIS;
  2076. } else {
  2077. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2078. bp->flags &= ~MF_FUNC_DIS;
  2079. }
  2080. }
  2081. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2082. {
  2083. struct cmng_init_input input;
  2084. memset(&input, 0, sizeof(struct cmng_init_input));
  2085. input.port_rate = bp->link_vars.line_speed;
  2086. if (cmng_type == CMNG_FNS_MINMAX) {
  2087. int vn;
  2088. /* read mf conf from shmem */
  2089. if (read_cfg)
  2090. bnx2x_read_mf_cfg(bp);
  2091. /* vn_weight_sum and enable fairness if not 0 */
  2092. bnx2x_calc_vn_min(bp, &input);
  2093. /* calculate and set min-max rate for each vn */
  2094. if (bp->port.pmf)
  2095. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2096. bnx2x_calc_vn_max(bp, vn, &input);
  2097. /* always enable rate shaping and fairness */
  2098. input.flags.cmng_enables |=
  2099. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2100. bnx2x_init_cmng(&input, &bp->cmng);
  2101. return;
  2102. }
  2103. /* rate shaping and fairness are disabled */
  2104. DP(NETIF_MSG_IFUP,
  2105. "rate shaping and fairness are disabled\n");
  2106. }
  2107. static void storm_memset_cmng(struct bnx2x *bp,
  2108. struct cmng_init *cmng,
  2109. u8 port)
  2110. {
  2111. int vn;
  2112. size_t size = sizeof(struct cmng_struct_per_port);
  2113. u32 addr = BAR_XSTRORM_INTMEM +
  2114. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2115. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2116. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2117. int func = func_by_vn(bp, vn);
  2118. addr = BAR_XSTRORM_INTMEM +
  2119. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2120. size = sizeof(struct rate_shaping_vars_per_vn);
  2121. __storm_memset_struct(bp, addr, size,
  2122. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2123. addr = BAR_XSTRORM_INTMEM +
  2124. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2125. size = sizeof(struct fairness_vars_per_vn);
  2126. __storm_memset_struct(bp, addr, size,
  2127. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2128. }
  2129. }
  2130. /* This function is called upon link interrupt */
  2131. static void bnx2x_link_attn(struct bnx2x *bp)
  2132. {
  2133. /* Make sure that we are synced with the current statistics */
  2134. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2135. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2136. if (bp->link_vars.link_up) {
  2137. /* dropless flow control */
  2138. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2139. int port = BP_PORT(bp);
  2140. u32 pause_enabled = 0;
  2141. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2142. pause_enabled = 1;
  2143. REG_WR(bp, BAR_USTRORM_INTMEM +
  2144. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2145. pause_enabled);
  2146. }
  2147. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2148. struct host_port_stats *pstats;
  2149. pstats = bnx2x_sp(bp, port_stats);
  2150. /* reset old mac stats */
  2151. memset(&(pstats->mac_stx[0]), 0,
  2152. sizeof(struct mac_stx));
  2153. }
  2154. if (bp->state == BNX2X_STATE_OPEN)
  2155. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2156. }
  2157. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2158. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2159. if (cmng_fns != CMNG_FNS_NONE) {
  2160. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2161. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2162. } else
  2163. /* rate shaping and fairness are disabled */
  2164. DP(NETIF_MSG_IFUP,
  2165. "single function mode without fairness\n");
  2166. }
  2167. __bnx2x_link_report(bp);
  2168. if (IS_MF(bp))
  2169. bnx2x_link_sync_notify(bp);
  2170. }
  2171. void bnx2x__link_status_update(struct bnx2x *bp)
  2172. {
  2173. if (bp->state != BNX2X_STATE_OPEN)
  2174. return;
  2175. /* read updated dcb configuration */
  2176. if (IS_PF(bp)) {
  2177. bnx2x_dcbx_pmf_update(bp);
  2178. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2179. if (bp->link_vars.link_up)
  2180. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2181. else
  2182. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2183. /* indicate link status */
  2184. bnx2x_link_report(bp);
  2185. } else { /* VF */
  2186. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2187. SUPPORTED_10baseT_Full |
  2188. SUPPORTED_100baseT_Half |
  2189. SUPPORTED_100baseT_Full |
  2190. SUPPORTED_1000baseT_Full |
  2191. SUPPORTED_2500baseX_Full |
  2192. SUPPORTED_10000baseT_Full |
  2193. SUPPORTED_TP |
  2194. SUPPORTED_FIBRE |
  2195. SUPPORTED_Autoneg |
  2196. SUPPORTED_Pause |
  2197. SUPPORTED_Asym_Pause);
  2198. bp->port.advertising[0] = bp->port.supported[0];
  2199. bp->link_params.bp = bp;
  2200. bp->link_params.port = BP_PORT(bp);
  2201. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2202. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2203. bp->link_params.req_line_speed[0] = SPEED_10000;
  2204. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2205. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2206. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2207. bp->link_vars.line_speed = SPEED_10000;
  2208. bp->link_vars.link_status =
  2209. (LINK_STATUS_LINK_UP |
  2210. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2211. bp->link_vars.link_up = 1;
  2212. bp->link_vars.duplex = DUPLEX_FULL;
  2213. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2214. __bnx2x_link_report(bp);
  2215. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2216. }
  2217. }
  2218. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2219. u16 vlan_val, u8 allowed_prio)
  2220. {
  2221. struct bnx2x_func_state_params func_params = {0};
  2222. struct bnx2x_func_afex_update_params *f_update_params =
  2223. &func_params.params.afex_update;
  2224. func_params.f_obj = &bp->func_obj;
  2225. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2226. /* no need to wait for RAMROD completion, so don't
  2227. * set RAMROD_COMP_WAIT flag
  2228. */
  2229. f_update_params->vif_id = vifid;
  2230. f_update_params->afex_default_vlan = vlan_val;
  2231. f_update_params->allowed_priorities = allowed_prio;
  2232. /* if ramrod can not be sent, response to MCP immediately */
  2233. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2234. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2235. return 0;
  2236. }
  2237. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2238. u16 vif_index, u8 func_bit_map)
  2239. {
  2240. struct bnx2x_func_state_params func_params = {0};
  2241. struct bnx2x_func_afex_viflists_params *update_params =
  2242. &func_params.params.afex_viflists;
  2243. int rc;
  2244. u32 drv_msg_code;
  2245. /* validate only LIST_SET and LIST_GET are received from switch */
  2246. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2247. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2248. cmd_type);
  2249. func_params.f_obj = &bp->func_obj;
  2250. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2251. /* set parameters according to cmd_type */
  2252. update_params->afex_vif_list_command = cmd_type;
  2253. update_params->vif_list_index = cpu_to_le16(vif_index);
  2254. update_params->func_bit_map =
  2255. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2256. update_params->func_to_clear = 0;
  2257. drv_msg_code =
  2258. (cmd_type == VIF_LIST_RULE_GET) ?
  2259. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2260. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2261. /* if ramrod can not be sent, respond to MCP immediately for
  2262. * SET and GET requests (other are not triggered from MCP)
  2263. */
  2264. rc = bnx2x_func_state_change(bp, &func_params);
  2265. if (rc < 0)
  2266. bnx2x_fw_command(bp, drv_msg_code, 0);
  2267. return 0;
  2268. }
  2269. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2270. {
  2271. struct afex_stats afex_stats;
  2272. u32 func = BP_ABS_FUNC(bp);
  2273. u32 mf_config;
  2274. u16 vlan_val;
  2275. u32 vlan_prio;
  2276. u16 vif_id;
  2277. u8 allowed_prio;
  2278. u8 vlan_mode;
  2279. u32 addr_to_write, vifid, addrs, stats_type, i;
  2280. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2281. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2282. DP(BNX2X_MSG_MCP,
  2283. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2284. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2285. }
  2286. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2287. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2288. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2289. DP(BNX2X_MSG_MCP,
  2290. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2291. vifid, addrs);
  2292. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2293. addrs);
  2294. }
  2295. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2296. addr_to_write = SHMEM2_RD(bp,
  2297. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2298. stats_type = SHMEM2_RD(bp,
  2299. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2300. DP(BNX2X_MSG_MCP,
  2301. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2302. addr_to_write);
  2303. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2304. /* write response to scratchpad, for MCP */
  2305. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2306. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2307. *(((u32 *)(&afex_stats))+i));
  2308. /* send ack message to MCP */
  2309. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2310. }
  2311. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2312. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2313. bp->mf_config[BP_VN(bp)] = mf_config;
  2314. DP(BNX2X_MSG_MCP,
  2315. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2316. mf_config);
  2317. /* if VIF_SET is "enabled" */
  2318. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2319. /* set rate limit directly to internal RAM */
  2320. struct cmng_init_input cmng_input;
  2321. struct rate_shaping_vars_per_vn m_rs_vn;
  2322. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2323. u32 addr = BAR_XSTRORM_INTMEM +
  2324. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2325. bp->mf_config[BP_VN(bp)] = mf_config;
  2326. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2327. m_rs_vn.vn_counter.rate =
  2328. cmng_input.vnic_max_rate[BP_VN(bp)];
  2329. m_rs_vn.vn_counter.quota =
  2330. (m_rs_vn.vn_counter.rate *
  2331. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2332. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2333. /* read relevant values from mf_cfg struct in shmem */
  2334. vif_id =
  2335. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2336. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2337. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2338. vlan_val =
  2339. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2340. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2341. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2342. vlan_prio = (mf_config &
  2343. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2344. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2345. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2346. vlan_mode =
  2347. (MF_CFG_RD(bp,
  2348. func_mf_config[func].afex_config) &
  2349. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2350. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2351. allowed_prio =
  2352. (MF_CFG_RD(bp,
  2353. func_mf_config[func].afex_config) &
  2354. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2355. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2356. /* send ramrod to FW, return in case of failure */
  2357. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2358. allowed_prio))
  2359. return;
  2360. bp->afex_def_vlan_tag = vlan_val;
  2361. bp->afex_vlan_mode = vlan_mode;
  2362. } else {
  2363. /* notify link down because BP->flags is disabled */
  2364. bnx2x_link_report(bp);
  2365. /* send INVALID VIF ramrod to FW */
  2366. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2367. /* Reset the default afex VLAN */
  2368. bp->afex_def_vlan_tag = -1;
  2369. }
  2370. }
  2371. }
  2372. static void bnx2x_pmf_update(struct bnx2x *bp)
  2373. {
  2374. int port = BP_PORT(bp);
  2375. u32 val;
  2376. bp->port.pmf = 1;
  2377. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2378. /*
  2379. * We need the mb() to ensure the ordering between the writing to
  2380. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2381. */
  2382. smp_mb();
  2383. /* queue a periodic task */
  2384. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2385. bnx2x_dcbx_pmf_update(bp);
  2386. /* enable nig attention */
  2387. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2388. if (bp->common.int_block == INT_BLOCK_HC) {
  2389. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2390. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2391. } else if (!CHIP_IS_E1x(bp)) {
  2392. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2393. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2394. }
  2395. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2396. }
  2397. /* end of Link */
  2398. /* slow path */
  2399. /*
  2400. * General service functions
  2401. */
  2402. /* send the MCP a request, block until there is a reply */
  2403. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2404. {
  2405. int mb_idx = BP_FW_MB_IDX(bp);
  2406. u32 seq;
  2407. u32 rc = 0;
  2408. u32 cnt = 1;
  2409. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2410. mutex_lock(&bp->fw_mb_mutex);
  2411. seq = ++bp->fw_seq;
  2412. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2413. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2414. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2415. (command | seq), param);
  2416. do {
  2417. /* let the FW do it's magic ... */
  2418. msleep(delay);
  2419. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2420. /* Give the FW up to 5 second (500*10ms) */
  2421. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2422. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2423. cnt*delay, rc, seq);
  2424. /* is this a reply to our command? */
  2425. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2426. rc &= FW_MSG_CODE_MASK;
  2427. else {
  2428. /* FW BUG! */
  2429. BNX2X_ERR("FW failed to respond!\n");
  2430. bnx2x_fw_dump(bp);
  2431. rc = 0;
  2432. }
  2433. mutex_unlock(&bp->fw_mb_mutex);
  2434. return rc;
  2435. }
  2436. static void storm_memset_func_cfg(struct bnx2x *bp,
  2437. struct tstorm_eth_function_common_config *tcfg,
  2438. u16 abs_fid)
  2439. {
  2440. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2441. u32 addr = BAR_TSTRORM_INTMEM +
  2442. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2443. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2444. }
  2445. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2446. {
  2447. if (CHIP_IS_E1x(bp)) {
  2448. struct tstorm_eth_function_common_config tcfg = {0};
  2449. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2450. }
  2451. /* Enable the function in the FW */
  2452. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2453. storm_memset_func_en(bp, p->func_id, 1);
  2454. /* spq */
  2455. if (p->func_flgs & FUNC_FLG_SPQ) {
  2456. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2457. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2458. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2459. }
  2460. }
  2461. /**
  2462. * bnx2x_get_tx_only_flags - Return common flags
  2463. *
  2464. * @bp device handle
  2465. * @fp queue handle
  2466. * @zero_stats TRUE if statistics zeroing is needed
  2467. *
  2468. * Return the flags that are common for the Tx-only and not normal connections.
  2469. */
  2470. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2471. struct bnx2x_fastpath *fp,
  2472. bool zero_stats)
  2473. {
  2474. unsigned long flags = 0;
  2475. /* PF driver will always initialize the Queue to an ACTIVE state */
  2476. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2477. /* tx only connections collect statistics (on the same index as the
  2478. * parent connection). The statistics are zeroed when the parent
  2479. * connection is initialized.
  2480. */
  2481. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2482. if (zero_stats)
  2483. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2484. #ifdef BNX2X_STOP_ON_ERROR
  2485. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2486. #endif
  2487. return flags;
  2488. }
  2489. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2490. struct bnx2x_fastpath *fp,
  2491. bool leading)
  2492. {
  2493. unsigned long flags = 0;
  2494. /* calculate other queue flags */
  2495. if (IS_MF_SD(bp))
  2496. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2497. if (IS_FCOE_FP(fp)) {
  2498. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2499. /* For FCoE - force usage of default priority (for afex) */
  2500. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2501. }
  2502. if (!fp->disable_tpa) {
  2503. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2504. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2505. if (fp->mode == TPA_MODE_GRO)
  2506. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2507. }
  2508. if (leading) {
  2509. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2510. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2511. }
  2512. /* Always set HW VLAN stripping */
  2513. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2514. /* configure silent vlan removal */
  2515. if (IS_MF_AFEX(bp))
  2516. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2517. return flags | bnx2x_get_common_flags(bp, fp, true);
  2518. }
  2519. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2520. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2521. u8 cos)
  2522. {
  2523. gen_init->stat_id = bnx2x_stats_id(fp);
  2524. gen_init->spcl_id = fp->cl_id;
  2525. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2526. if (IS_FCOE_FP(fp))
  2527. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2528. else
  2529. gen_init->mtu = bp->dev->mtu;
  2530. gen_init->cos = cos;
  2531. }
  2532. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2533. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2534. struct bnx2x_rxq_setup_params *rxq_init)
  2535. {
  2536. u8 max_sge = 0;
  2537. u16 sge_sz = 0;
  2538. u16 tpa_agg_size = 0;
  2539. if (!fp->disable_tpa) {
  2540. pause->sge_th_lo = SGE_TH_LO(bp);
  2541. pause->sge_th_hi = SGE_TH_HI(bp);
  2542. /* validate SGE ring has enough to cross high threshold */
  2543. WARN_ON(bp->dropless_fc &&
  2544. pause->sge_th_hi + FW_PREFETCH_CNT >
  2545. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2546. tpa_agg_size = min_t(u32,
  2547. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2548. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2549. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2550. SGE_PAGE_SHIFT;
  2551. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2552. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2553. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2554. 0xffff);
  2555. }
  2556. /* pause - not for e1 */
  2557. if (!CHIP_IS_E1(bp)) {
  2558. pause->bd_th_lo = BD_TH_LO(bp);
  2559. pause->bd_th_hi = BD_TH_HI(bp);
  2560. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2561. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2562. /*
  2563. * validate that rings have enough entries to cross
  2564. * high thresholds
  2565. */
  2566. WARN_ON(bp->dropless_fc &&
  2567. pause->bd_th_hi + FW_PREFETCH_CNT >
  2568. bp->rx_ring_size);
  2569. WARN_ON(bp->dropless_fc &&
  2570. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2571. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2572. pause->pri_map = 1;
  2573. }
  2574. /* rxq setup */
  2575. rxq_init->dscr_map = fp->rx_desc_mapping;
  2576. rxq_init->sge_map = fp->rx_sge_mapping;
  2577. rxq_init->rcq_map = fp->rx_comp_mapping;
  2578. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2579. /* This should be a maximum number of data bytes that may be
  2580. * placed on the BD (not including paddings).
  2581. */
  2582. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2583. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2584. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2585. rxq_init->tpa_agg_sz = tpa_agg_size;
  2586. rxq_init->sge_buf_sz = sge_sz;
  2587. rxq_init->max_sges_pkt = max_sge;
  2588. rxq_init->rss_engine_id = BP_FUNC(bp);
  2589. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2590. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2591. *
  2592. * For PF Clients it should be the maximum available number.
  2593. * VF driver(s) may want to define it to a smaller value.
  2594. */
  2595. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2596. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2597. rxq_init->fw_sb_id = fp->fw_sb_id;
  2598. if (IS_FCOE_FP(fp))
  2599. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2600. else
  2601. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2602. /* configure silent vlan removal
  2603. * if multi function mode is afex, then mask default vlan
  2604. */
  2605. if (IS_MF_AFEX(bp)) {
  2606. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2607. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2608. }
  2609. }
  2610. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2611. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2612. u8 cos)
  2613. {
  2614. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2615. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2616. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2617. txq_init->fw_sb_id = fp->fw_sb_id;
  2618. /*
  2619. * set the tss leading client id for TX classfication ==
  2620. * leading RSS client id
  2621. */
  2622. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2623. if (IS_FCOE_FP(fp)) {
  2624. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2625. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2626. }
  2627. }
  2628. static void bnx2x_pf_init(struct bnx2x *bp)
  2629. {
  2630. struct bnx2x_func_init_params func_init = {0};
  2631. struct event_ring_data eq_data = { {0} };
  2632. u16 flags;
  2633. if (!CHIP_IS_E1x(bp)) {
  2634. /* reset IGU PF statistics: MSIX + ATTN */
  2635. /* PF */
  2636. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2637. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2638. (CHIP_MODE_IS_4_PORT(bp) ?
  2639. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2640. /* ATTN */
  2641. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2642. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2643. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2644. (CHIP_MODE_IS_4_PORT(bp) ?
  2645. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2646. }
  2647. /* function setup flags */
  2648. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2649. /* This flag is relevant for E1x only.
  2650. * E2 doesn't have a TPA configuration in a function level.
  2651. */
  2652. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2653. func_init.func_flgs = flags;
  2654. func_init.pf_id = BP_FUNC(bp);
  2655. func_init.func_id = BP_FUNC(bp);
  2656. func_init.spq_map = bp->spq_mapping;
  2657. func_init.spq_prod = bp->spq_prod_idx;
  2658. bnx2x_func_init(bp, &func_init);
  2659. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2660. /*
  2661. * Congestion management values depend on the link rate
  2662. * There is no active link so initial link rate is set to 10 Gbps.
  2663. * When the link comes up The congestion management values are
  2664. * re-calculated according to the actual link rate.
  2665. */
  2666. bp->link_vars.line_speed = SPEED_10000;
  2667. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2668. /* Only the PMF sets the HW */
  2669. if (bp->port.pmf)
  2670. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2671. /* init Event Queue */
  2672. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2673. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2674. eq_data.producer = bp->eq_prod;
  2675. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2676. eq_data.sb_id = DEF_SB_ID;
  2677. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2678. }
  2679. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2680. {
  2681. int port = BP_PORT(bp);
  2682. bnx2x_tx_disable(bp);
  2683. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2684. }
  2685. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2686. {
  2687. int port = BP_PORT(bp);
  2688. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2689. /* Tx queue should be only reenabled */
  2690. netif_tx_wake_all_queues(bp->dev);
  2691. /*
  2692. * Should not call netif_carrier_on since it will be called if the link
  2693. * is up when checking for link state
  2694. */
  2695. }
  2696. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2697. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2698. {
  2699. struct eth_stats_info *ether_stat =
  2700. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2701. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2702. ETH_STAT_INFO_VERSION_LEN);
  2703. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2704. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2705. ether_stat->mac_local);
  2706. ether_stat->mtu_size = bp->dev->mtu;
  2707. if (bp->dev->features & NETIF_F_RXCSUM)
  2708. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2709. if (bp->dev->features & NETIF_F_TSO)
  2710. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2711. ether_stat->feature_flags |= bp->common.boot_mode;
  2712. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2713. ether_stat->txq_size = bp->tx_ring_size;
  2714. ether_stat->rxq_size = bp->rx_ring_size;
  2715. }
  2716. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2717. {
  2718. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2719. struct fcoe_stats_info *fcoe_stat =
  2720. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2721. if (!CNIC_LOADED(bp))
  2722. return;
  2723. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2724. bp->fip_mac, ETH_ALEN);
  2725. fcoe_stat->qos_priority =
  2726. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2727. /* insert FCoE stats from ramrod response */
  2728. if (!NO_FCOE(bp)) {
  2729. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2730. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2731. tstorm_queue_statistics;
  2732. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2733. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2734. xstorm_queue_statistics;
  2735. struct fcoe_statistics_params *fw_fcoe_stat =
  2736. &bp->fw_stats_data->fcoe;
  2737. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2738. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2739. ADD_64(fcoe_stat->rx_bytes_hi,
  2740. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2741. fcoe_stat->rx_bytes_lo,
  2742. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2743. ADD_64(fcoe_stat->rx_bytes_hi,
  2744. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2745. fcoe_stat->rx_bytes_lo,
  2746. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2747. ADD_64(fcoe_stat->rx_bytes_hi,
  2748. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2749. fcoe_stat->rx_bytes_lo,
  2750. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2751. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2752. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2753. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2754. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2755. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2756. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2757. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2758. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2759. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2760. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2761. ADD_64(fcoe_stat->tx_bytes_hi,
  2762. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2763. fcoe_stat->tx_bytes_lo,
  2764. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2765. ADD_64(fcoe_stat->tx_bytes_hi,
  2766. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2767. fcoe_stat->tx_bytes_lo,
  2768. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2769. ADD_64(fcoe_stat->tx_bytes_hi,
  2770. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2771. fcoe_stat->tx_bytes_lo,
  2772. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2773. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2774. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2775. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2776. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2777. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2778. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2779. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2780. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2781. }
  2782. /* ask L5 driver to add data to the struct */
  2783. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2784. }
  2785. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2786. {
  2787. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2788. struct iscsi_stats_info *iscsi_stat =
  2789. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2790. if (!CNIC_LOADED(bp))
  2791. return;
  2792. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2793. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2794. iscsi_stat->qos_priority =
  2795. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2796. /* ask L5 driver to add data to the struct */
  2797. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2798. }
  2799. /* called due to MCP event (on pmf):
  2800. * reread new bandwidth configuration
  2801. * configure FW
  2802. * notify others function about the change
  2803. */
  2804. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2805. {
  2806. if (bp->link_vars.link_up) {
  2807. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2808. bnx2x_link_sync_notify(bp);
  2809. }
  2810. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2811. }
  2812. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2813. {
  2814. bnx2x_config_mf_bw(bp);
  2815. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2816. }
  2817. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2818. {
  2819. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2820. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2821. }
  2822. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2823. {
  2824. enum drv_info_opcode op_code;
  2825. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2826. /* if drv_info version supported by MFW doesn't match - send NACK */
  2827. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2828. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2829. return;
  2830. }
  2831. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2832. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2833. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2834. sizeof(union drv_info_to_mcp));
  2835. switch (op_code) {
  2836. case ETH_STATS_OPCODE:
  2837. bnx2x_drv_info_ether_stat(bp);
  2838. break;
  2839. case FCOE_STATS_OPCODE:
  2840. bnx2x_drv_info_fcoe_stat(bp);
  2841. break;
  2842. case ISCSI_STATS_OPCODE:
  2843. bnx2x_drv_info_iscsi_stat(bp);
  2844. break;
  2845. default:
  2846. /* if op code isn't supported - send NACK */
  2847. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2848. return;
  2849. }
  2850. /* if we got drv_info attn from MFW then these fields are defined in
  2851. * shmem2 for sure
  2852. */
  2853. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2854. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2855. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2856. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2857. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2858. }
  2859. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2860. {
  2861. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2862. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2863. /*
  2864. * This is the only place besides the function initialization
  2865. * where the bp->flags can change so it is done without any
  2866. * locks
  2867. */
  2868. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2869. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2870. bp->flags |= MF_FUNC_DIS;
  2871. bnx2x_e1h_disable(bp);
  2872. } else {
  2873. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2874. bp->flags &= ~MF_FUNC_DIS;
  2875. bnx2x_e1h_enable(bp);
  2876. }
  2877. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2878. }
  2879. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2880. bnx2x_config_mf_bw(bp);
  2881. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2882. }
  2883. /* Report results to MCP */
  2884. if (dcc_event)
  2885. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2886. else
  2887. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2888. }
  2889. /* must be called under the spq lock */
  2890. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2891. {
  2892. struct eth_spe *next_spe = bp->spq_prod_bd;
  2893. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2894. bp->spq_prod_bd = bp->spq;
  2895. bp->spq_prod_idx = 0;
  2896. DP(BNX2X_MSG_SP, "end of spq\n");
  2897. } else {
  2898. bp->spq_prod_bd++;
  2899. bp->spq_prod_idx++;
  2900. }
  2901. return next_spe;
  2902. }
  2903. /* must be called under the spq lock */
  2904. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2905. {
  2906. int func = BP_FUNC(bp);
  2907. /*
  2908. * Make sure that BD data is updated before writing the producer:
  2909. * BD data is written to the memory, the producer is read from the
  2910. * memory, thus we need a full memory barrier to ensure the ordering.
  2911. */
  2912. mb();
  2913. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2914. bp->spq_prod_idx);
  2915. mmiowb();
  2916. }
  2917. /**
  2918. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2919. *
  2920. * @cmd: command to check
  2921. * @cmd_type: command type
  2922. */
  2923. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2924. {
  2925. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2926. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2927. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2928. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2929. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2930. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2931. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2932. return true;
  2933. else
  2934. return false;
  2935. }
  2936. /**
  2937. * bnx2x_sp_post - place a single command on an SP ring
  2938. *
  2939. * @bp: driver handle
  2940. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2941. * @cid: SW CID the command is related to
  2942. * @data_hi: command private data address (high 32 bits)
  2943. * @data_lo: command private data address (low 32 bits)
  2944. * @cmd_type: command type (e.g. NONE, ETH)
  2945. *
  2946. * SP data is handled as if it's always an address pair, thus data fields are
  2947. * not swapped to little endian in upper functions. Instead this function swaps
  2948. * data as if it's two u32 fields.
  2949. */
  2950. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2951. u32 data_hi, u32 data_lo, int cmd_type)
  2952. {
  2953. struct eth_spe *spe;
  2954. u16 type;
  2955. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2956. #ifdef BNX2X_STOP_ON_ERROR
  2957. if (unlikely(bp->panic)) {
  2958. BNX2X_ERR("Can't post SP when there is panic\n");
  2959. return -EIO;
  2960. }
  2961. #endif
  2962. spin_lock_bh(&bp->spq_lock);
  2963. if (common) {
  2964. if (!atomic_read(&bp->eq_spq_left)) {
  2965. BNX2X_ERR("BUG! EQ ring full!\n");
  2966. spin_unlock_bh(&bp->spq_lock);
  2967. bnx2x_panic();
  2968. return -EBUSY;
  2969. }
  2970. } else if (!atomic_read(&bp->cq_spq_left)) {
  2971. BNX2X_ERR("BUG! SPQ ring full!\n");
  2972. spin_unlock_bh(&bp->spq_lock);
  2973. bnx2x_panic();
  2974. return -EBUSY;
  2975. }
  2976. spe = bnx2x_sp_get_next(bp);
  2977. /* CID needs port number to be encoded int it */
  2978. spe->hdr.conn_and_cmd_data =
  2979. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2980. HW_CID(bp, cid));
  2981. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2982. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2983. SPE_HDR_FUNCTION_ID);
  2984. spe->hdr.type = cpu_to_le16(type);
  2985. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2986. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2987. /*
  2988. * It's ok if the actual decrement is issued towards the memory
  2989. * somewhere between the spin_lock and spin_unlock. Thus no
  2990. * more explict memory barrier is needed.
  2991. */
  2992. if (common)
  2993. atomic_dec(&bp->eq_spq_left);
  2994. else
  2995. atomic_dec(&bp->cq_spq_left);
  2996. DP(BNX2X_MSG_SP,
  2997. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2998. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2999. (u32)(U64_LO(bp->spq_mapping) +
  3000. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3001. HW_CID(bp, cid), data_hi, data_lo, type,
  3002. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3003. bnx2x_sp_prod_update(bp);
  3004. spin_unlock_bh(&bp->spq_lock);
  3005. return 0;
  3006. }
  3007. /* acquire split MCP access lock register */
  3008. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3009. {
  3010. u32 j, val;
  3011. int rc = 0;
  3012. might_sleep();
  3013. for (j = 0; j < 1000; j++) {
  3014. val = (1UL << 31);
  3015. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  3016. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  3017. if (val & (1L << 31))
  3018. break;
  3019. msleep(5);
  3020. }
  3021. if (!(val & (1L << 31))) {
  3022. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3023. rc = -EBUSY;
  3024. }
  3025. return rc;
  3026. }
  3027. /* release split MCP access lock register */
  3028. static void bnx2x_release_alr(struct bnx2x *bp)
  3029. {
  3030. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  3031. }
  3032. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3033. #define BNX2X_DEF_SB_IDX 0x0002
  3034. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3035. {
  3036. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3037. u16 rc = 0;
  3038. barrier(); /* status block is written to by the chip */
  3039. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3040. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3041. rc |= BNX2X_DEF_SB_ATT_IDX;
  3042. }
  3043. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3044. bp->def_idx = def_sb->sp_sb.running_index;
  3045. rc |= BNX2X_DEF_SB_IDX;
  3046. }
  3047. /* Do not reorder: indecies reading should complete before handling */
  3048. barrier();
  3049. return rc;
  3050. }
  3051. /*
  3052. * slow path service functions
  3053. */
  3054. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3055. {
  3056. int port = BP_PORT(bp);
  3057. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3058. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3059. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3060. NIG_REG_MASK_INTERRUPT_PORT0;
  3061. u32 aeu_mask;
  3062. u32 nig_mask = 0;
  3063. u32 reg_addr;
  3064. if (bp->attn_state & asserted)
  3065. BNX2X_ERR("IGU ERROR\n");
  3066. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3067. aeu_mask = REG_RD(bp, aeu_addr);
  3068. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3069. aeu_mask, asserted);
  3070. aeu_mask &= ~(asserted & 0x3ff);
  3071. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3072. REG_WR(bp, aeu_addr, aeu_mask);
  3073. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3074. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3075. bp->attn_state |= asserted;
  3076. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3077. if (asserted & ATTN_HARD_WIRED_MASK) {
  3078. if (asserted & ATTN_NIG_FOR_FUNC) {
  3079. bnx2x_acquire_phy_lock(bp);
  3080. /* save nig interrupt mask */
  3081. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3082. /* If nig_mask is not set, no need to call the update
  3083. * function.
  3084. */
  3085. if (nig_mask) {
  3086. REG_WR(bp, nig_int_mask_addr, 0);
  3087. bnx2x_link_attn(bp);
  3088. }
  3089. /* handle unicore attn? */
  3090. }
  3091. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3092. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3093. if (asserted & GPIO_2_FUNC)
  3094. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3095. if (asserted & GPIO_3_FUNC)
  3096. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3097. if (asserted & GPIO_4_FUNC)
  3098. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3099. if (port == 0) {
  3100. if (asserted & ATTN_GENERAL_ATTN_1) {
  3101. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3102. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3103. }
  3104. if (asserted & ATTN_GENERAL_ATTN_2) {
  3105. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3106. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3107. }
  3108. if (asserted & ATTN_GENERAL_ATTN_3) {
  3109. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3110. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3111. }
  3112. } else {
  3113. if (asserted & ATTN_GENERAL_ATTN_4) {
  3114. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3115. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3116. }
  3117. if (asserted & ATTN_GENERAL_ATTN_5) {
  3118. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3119. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3120. }
  3121. if (asserted & ATTN_GENERAL_ATTN_6) {
  3122. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3123. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3124. }
  3125. }
  3126. } /* if hardwired */
  3127. if (bp->common.int_block == INT_BLOCK_HC)
  3128. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3129. COMMAND_REG_ATTN_BITS_SET);
  3130. else
  3131. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3132. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3133. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3134. REG_WR(bp, reg_addr, asserted);
  3135. /* now set back the mask */
  3136. if (asserted & ATTN_NIG_FOR_FUNC) {
  3137. /* Verify that IGU ack through BAR was written before restoring
  3138. * NIG mask. This loop should exit after 2-3 iterations max.
  3139. */
  3140. if (bp->common.int_block != INT_BLOCK_HC) {
  3141. u32 cnt = 0, igu_acked;
  3142. do {
  3143. igu_acked = REG_RD(bp,
  3144. IGU_REG_ATTENTION_ACK_BITS);
  3145. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3146. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3147. if (!igu_acked)
  3148. DP(NETIF_MSG_HW,
  3149. "Failed to verify IGU ack on time\n");
  3150. barrier();
  3151. }
  3152. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3153. bnx2x_release_phy_lock(bp);
  3154. }
  3155. }
  3156. static void bnx2x_fan_failure(struct bnx2x *bp)
  3157. {
  3158. int port = BP_PORT(bp);
  3159. u32 ext_phy_config;
  3160. /* mark the failure */
  3161. ext_phy_config =
  3162. SHMEM_RD(bp,
  3163. dev_info.port_hw_config[port].external_phy_config);
  3164. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3165. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3166. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3167. ext_phy_config);
  3168. /* log the failure */
  3169. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3170. "Please contact OEM Support for assistance\n");
  3171. /*
  3172. * Schedule device reset (unload)
  3173. * This is due to some boards consuming sufficient power when driver is
  3174. * up to overheat if fan fails.
  3175. */
  3176. smp_mb__before_clear_bit();
  3177. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3178. smp_mb__after_clear_bit();
  3179. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3180. }
  3181. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3182. {
  3183. int port = BP_PORT(bp);
  3184. int reg_offset;
  3185. u32 val;
  3186. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3187. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3188. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3189. val = REG_RD(bp, reg_offset);
  3190. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3191. REG_WR(bp, reg_offset, val);
  3192. BNX2X_ERR("SPIO5 hw attention\n");
  3193. /* Fan failure attention */
  3194. bnx2x_hw_reset_phy(&bp->link_params);
  3195. bnx2x_fan_failure(bp);
  3196. }
  3197. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3198. bnx2x_acquire_phy_lock(bp);
  3199. bnx2x_handle_module_detect_int(&bp->link_params);
  3200. bnx2x_release_phy_lock(bp);
  3201. }
  3202. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3203. val = REG_RD(bp, reg_offset);
  3204. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3205. REG_WR(bp, reg_offset, val);
  3206. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3207. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3208. bnx2x_panic();
  3209. }
  3210. }
  3211. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3212. {
  3213. u32 val;
  3214. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3215. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3216. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3217. /* DORQ discard attention */
  3218. if (val & 0x2)
  3219. BNX2X_ERR("FATAL error from DORQ\n");
  3220. }
  3221. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3222. int port = BP_PORT(bp);
  3223. int reg_offset;
  3224. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3225. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3226. val = REG_RD(bp, reg_offset);
  3227. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3228. REG_WR(bp, reg_offset, val);
  3229. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3230. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3231. bnx2x_panic();
  3232. }
  3233. }
  3234. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3235. {
  3236. u32 val;
  3237. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3238. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3239. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3240. /* CFC error attention */
  3241. if (val & 0x2)
  3242. BNX2X_ERR("FATAL error from CFC\n");
  3243. }
  3244. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3245. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3246. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3247. /* RQ_USDMDP_FIFO_OVERFLOW */
  3248. if (val & 0x18000)
  3249. BNX2X_ERR("FATAL error from PXP\n");
  3250. if (!CHIP_IS_E1x(bp)) {
  3251. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3252. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3253. }
  3254. }
  3255. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3256. int port = BP_PORT(bp);
  3257. int reg_offset;
  3258. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3259. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3260. val = REG_RD(bp, reg_offset);
  3261. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3262. REG_WR(bp, reg_offset, val);
  3263. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3264. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3265. bnx2x_panic();
  3266. }
  3267. }
  3268. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3269. {
  3270. u32 val;
  3271. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3272. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3273. int func = BP_FUNC(bp);
  3274. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3275. bnx2x_read_mf_cfg(bp);
  3276. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3277. func_mf_config[BP_ABS_FUNC(bp)].config);
  3278. val = SHMEM_RD(bp,
  3279. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3280. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3281. bnx2x_dcc_event(bp,
  3282. (val & DRV_STATUS_DCC_EVENT_MASK));
  3283. if (val & DRV_STATUS_SET_MF_BW)
  3284. bnx2x_set_mf_bw(bp);
  3285. if (val & DRV_STATUS_DRV_INFO_REQ)
  3286. bnx2x_handle_drv_info_req(bp);
  3287. if (val & DRV_STATUS_VF_DISABLED)
  3288. bnx2x_vf_handle_flr_event(bp);
  3289. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3290. bnx2x_pmf_update(bp);
  3291. if (bp->port.pmf &&
  3292. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3293. bp->dcbx_enabled > 0)
  3294. /* start dcbx state machine */
  3295. bnx2x_dcbx_set_params(bp,
  3296. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3297. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3298. bnx2x_handle_afex_cmd(bp,
  3299. val & DRV_STATUS_AFEX_EVENT_MASK);
  3300. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3301. bnx2x_handle_eee_event(bp);
  3302. if (bp->link_vars.periodic_flags &
  3303. PERIODIC_FLAGS_LINK_EVENT) {
  3304. /* sync with link */
  3305. bnx2x_acquire_phy_lock(bp);
  3306. bp->link_vars.periodic_flags &=
  3307. ~PERIODIC_FLAGS_LINK_EVENT;
  3308. bnx2x_release_phy_lock(bp);
  3309. if (IS_MF(bp))
  3310. bnx2x_link_sync_notify(bp);
  3311. bnx2x_link_report(bp);
  3312. }
  3313. /* Always call it here: bnx2x_link_report() will
  3314. * prevent the link indication duplication.
  3315. */
  3316. bnx2x__link_status_update(bp);
  3317. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3318. BNX2X_ERR("MC assert!\n");
  3319. bnx2x_mc_assert(bp);
  3320. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3321. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3322. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3323. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3324. bnx2x_panic();
  3325. } else if (attn & BNX2X_MCP_ASSERT) {
  3326. BNX2X_ERR("MCP assert!\n");
  3327. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3328. bnx2x_fw_dump(bp);
  3329. } else
  3330. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3331. }
  3332. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3333. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3334. if (attn & BNX2X_GRC_TIMEOUT) {
  3335. val = CHIP_IS_E1(bp) ? 0 :
  3336. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3337. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3338. }
  3339. if (attn & BNX2X_GRC_RSV) {
  3340. val = CHIP_IS_E1(bp) ? 0 :
  3341. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3342. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3343. }
  3344. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3345. }
  3346. }
  3347. /*
  3348. * Bits map:
  3349. * 0-7 - Engine0 load counter.
  3350. * 8-15 - Engine1 load counter.
  3351. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3352. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3353. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3354. * on the engine
  3355. * 19 - Engine1 ONE_IS_LOADED.
  3356. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3357. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3358. * just the one belonging to its engine).
  3359. *
  3360. */
  3361. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3362. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3363. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3364. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3365. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3366. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3367. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3368. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3369. /*
  3370. * Set the GLOBAL_RESET bit.
  3371. *
  3372. * Should be run under rtnl lock
  3373. */
  3374. void bnx2x_set_reset_global(struct bnx2x *bp)
  3375. {
  3376. u32 val;
  3377. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3378. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3379. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3380. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3381. }
  3382. /*
  3383. * Clear the GLOBAL_RESET bit.
  3384. *
  3385. * Should be run under rtnl lock
  3386. */
  3387. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3388. {
  3389. u32 val;
  3390. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3391. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3392. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3393. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3394. }
  3395. /*
  3396. * Checks the GLOBAL_RESET bit.
  3397. *
  3398. * should be run under rtnl lock
  3399. */
  3400. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3401. {
  3402. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3403. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3404. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3405. }
  3406. /*
  3407. * Clear RESET_IN_PROGRESS bit for the current engine.
  3408. *
  3409. * Should be run under rtnl lock
  3410. */
  3411. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3412. {
  3413. u32 val;
  3414. u32 bit = BP_PATH(bp) ?
  3415. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3416. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3417. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3418. /* Clear the bit */
  3419. val &= ~bit;
  3420. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3421. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3422. }
  3423. /*
  3424. * Set RESET_IN_PROGRESS for the current engine.
  3425. *
  3426. * should be run under rtnl lock
  3427. */
  3428. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3429. {
  3430. u32 val;
  3431. u32 bit = BP_PATH(bp) ?
  3432. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3433. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3434. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3435. /* Set the bit */
  3436. val |= bit;
  3437. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3438. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3439. }
  3440. /*
  3441. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3442. * should be run under rtnl lock
  3443. */
  3444. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3445. {
  3446. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3447. u32 bit = engine ?
  3448. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3449. /* return false if bit is set */
  3450. return (val & bit) ? false : true;
  3451. }
  3452. /*
  3453. * set pf load for the current pf.
  3454. *
  3455. * should be run under rtnl lock
  3456. */
  3457. void bnx2x_set_pf_load(struct bnx2x *bp)
  3458. {
  3459. u32 val1, val;
  3460. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3461. BNX2X_PATH0_LOAD_CNT_MASK;
  3462. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3463. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3464. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3465. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3466. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3467. /* get the current counter value */
  3468. val1 = (val & mask) >> shift;
  3469. /* set bit of that PF */
  3470. val1 |= (1 << bp->pf_num);
  3471. /* clear the old value */
  3472. val &= ~mask;
  3473. /* set the new one */
  3474. val |= ((val1 << shift) & mask);
  3475. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3476. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3477. }
  3478. /**
  3479. * bnx2x_clear_pf_load - clear pf load mark
  3480. *
  3481. * @bp: driver handle
  3482. *
  3483. * Should be run under rtnl lock.
  3484. * Decrements the load counter for the current engine. Returns
  3485. * whether other functions are still loaded
  3486. */
  3487. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3488. {
  3489. u32 val1, val;
  3490. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3491. BNX2X_PATH0_LOAD_CNT_MASK;
  3492. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3493. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3494. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3495. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3496. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3497. /* get the current counter value */
  3498. val1 = (val & mask) >> shift;
  3499. /* clear bit of that PF */
  3500. val1 &= ~(1 << bp->pf_num);
  3501. /* clear the old value */
  3502. val &= ~mask;
  3503. /* set the new one */
  3504. val |= ((val1 << shift) & mask);
  3505. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3506. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3507. return val1 != 0;
  3508. }
  3509. /*
  3510. * Read the load status for the current engine.
  3511. *
  3512. * should be run under rtnl lock
  3513. */
  3514. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3515. {
  3516. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3517. BNX2X_PATH0_LOAD_CNT_MASK);
  3518. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3519. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3520. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3521. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3522. val = (val & mask) >> shift;
  3523. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3524. engine, val);
  3525. return val != 0;
  3526. }
  3527. static void _print_next_block(int idx, const char *blk)
  3528. {
  3529. pr_cont("%s%s", idx ? ", " : "", blk);
  3530. }
  3531. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3532. bool print)
  3533. {
  3534. int i = 0;
  3535. u32 cur_bit = 0;
  3536. for (i = 0; sig; i++) {
  3537. cur_bit = ((u32)0x1 << i);
  3538. if (sig & cur_bit) {
  3539. switch (cur_bit) {
  3540. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3541. if (print)
  3542. _print_next_block(par_num++, "BRB");
  3543. break;
  3544. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3545. if (print)
  3546. _print_next_block(par_num++, "PARSER");
  3547. break;
  3548. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3549. if (print)
  3550. _print_next_block(par_num++, "TSDM");
  3551. break;
  3552. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3553. if (print)
  3554. _print_next_block(par_num++,
  3555. "SEARCHER");
  3556. break;
  3557. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3558. if (print)
  3559. _print_next_block(par_num++, "TCM");
  3560. break;
  3561. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3562. if (print)
  3563. _print_next_block(par_num++, "TSEMI");
  3564. break;
  3565. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3566. if (print)
  3567. _print_next_block(par_num++, "XPB");
  3568. break;
  3569. }
  3570. /* Clear the bit */
  3571. sig &= ~cur_bit;
  3572. }
  3573. }
  3574. return par_num;
  3575. }
  3576. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3577. bool *global, bool print)
  3578. {
  3579. int i = 0;
  3580. u32 cur_bit = 0;
  3581. for (i = 0; sig; i++) {
  3582. cur_bit = ((u32)0x1 << i);
  3583. if (sig & cur_bit) {
  3584. switch (cur_bit) {
  3585. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3586. if (print)
  3587. _print_next_block(par_num++, "PBF");
  3588. break;
  3589. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3590. if (print)
  3591. _print_next_block(par_num++, "QM");
  3592. break;
  3593. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3594. if (print)
  3595. _print_next_block(par_num++, "TM");
  3596. break;
  3597. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3598. if (print)
  3599. _print_next_block(par_num++, "XSDM");
  3600. break;
  3601. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3602. if (print)
  3603. _print_next_block(par_num++, "XCM");
  3604. break;
  3605. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3606. if (print)
  3607. _print_next_block(par_num++, "XSEMI");
  3608. break;
  3609. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3610. if (print)
  3611. _print_next_block(par_num++,
  3612. "DOORBELLQ");
  3613. break;
  3614. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3615. if (print)
  3616. _print_next_block(par_num++, "NIG");
  3617. break;
  3618. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3619. if (print)
  3620. _print_next_block(par_num++,
  3621. "VAUX PCI CORE");
  3622. *global = true;
  3623. break;
  3624. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3625. if (print)
  3626. _print_next_block(par_num++, "DEBUG");
  3627. break;
  3628. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3629. if (print)
  3630. _print_next_block(par_num++, "USDM");
  3631. break;
  3632. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3633. if (print)
  3634. _print_next_block(par_num++, "UCM");
  3635. break;
  3636. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3637. if (print)
  3638. _print_next_block(par_num++, "USEMI");
  3639. break;
  3640. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3641. if (print)
  3642. _print_next_block(par_num++, "UPB");
  3643. break;
  3644. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3645. if (print)
  3646. _print_next_block(par_num++, "CSDM");
  3647. break;
  3648. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3649. if (print)
  3650. _print_next_block(par_num++, "CCM");
  3651. break;
  3652. }
  3653. /* Clear the bit */
  3654. sig &= ~cur_bit;
  3655. }
  3656. }
  3657. return par_num;
  3658. }
  3659. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3660. bool print)
  3661. {
  3662. int i = 0;
  3663. u32 cur_bit = 0;
  3664. for (i = 0; sig; i++) {
  3665. cur_bit = ((u32)0x1 << i);
  3666. if (sig & cur_bit) {
  3667. switch (cur_bit) {
  3668. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3669. if (print)
  3670. _print_next_block(par_num++, "CSEMI");
  3671. break;
  3672. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3673. if (print)
  3674. _print_next_block(par_num++, "PXP");
  3675. break;
  3676. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3677. if (print)
  3678. _print_next_block(par_num++,
  3679. "PXPPCICLOCKCLIENT");
  3680. break;
  3681. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3682. if (print)
  3683. _print_next_block(par_num++, "CFC");
  3684. break;
  3685. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3686. if (print)
  3687. _print_next_block(par_num++, "CDU");
  3688. break;
  3689. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3690. if (print)
  3691. _print_next_block(par_num++, "DMAE");
  3692. break;
  3693. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3694. if (print)
  3695. _print_next_block(par_num++, "IGU");
  3696. break;
  3697. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3698. if (print)
  3699. _print_next_block(par_num++, "MISC");
  3700. break;
  3701. }
  3702. /* Clear the bit */
  3703. sig &= ~cur_bit;
  3704. }
  3705. }
  3706. return par_num;
  3707. }
  3708. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3709. bool *global, bool print)
  3710. {
  3711. int i = 0;
  3712. u32 cur_bit = 0;
  3713. for (i = 0; sig; i++) {
  3714. cur_bit = ((u32)0x1 << i);
  3715. if (sig & cur_bit) {
  3716. switch (cur_bit) {
  3717. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3718. if (print)
  3719. _print_next_block(par_num++, "MCP ROM");
  3720. *global = true;
  3721. break;
  3722. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3723. if (print)
  3724. _print_next_block(par_num++,
  3725. "MCP UMP RX");
  3726. *global = true;
  3727. break;
  3728. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3729. if (print)
  3730. _print_next_block(par_num++,
  3731. "MCP UMP TX");
  3732. *global = true;
  3733. break;
  3734. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3735. if (print)
  3736. _print_next_block(par_num++,
  3737. "MCP SCPAD");
  3738. *global = true;
  3739. break;
  3740. }
  3741. /* Clear the bit */
  3742. sig &= ~cur_bit;
  3743. }
  3744. }
  3745. return par_num;
  3746. }
  3747. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3748. bool print)
  3749. {
  3750. int i = 0;
  3751. u32 cur_bit = 0;
  3752. for (i = 0; sig; i++) {
  3753. cur_bit = ((u32)0x1 << i);
  3754. if (sig & cur_bit) {
  3755. switch (cur_bit) {
  3756. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3757. if (print)
  3758. _print_next_block(par_num++, "PGLUE_B");
  3759. break;
  3760. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3761. if (print)
  3762. _print_next_block(par_num++, "ATC");
  3763. break;
  3764. }
  3765. /* Clear the bit */
  3766. sig &= ~cur_bit;
  3767. }
  3768. }
  3769. return par_num;
  3770. }
  3771. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3772. u32 *sig)
  3773. {
  3774. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3775. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3776. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3777. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3778. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3779. int par_num = 0;
  3780. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3781. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3782. sig[0] & HW_PRTY_ASSERT_SET_0,
  3783. sig[1] & HW_PRTY_ASSERT_SET_1,
  3784. sig[2] & HW_PRTY_ASSERT_SET_2,
  3785. sig[3] & HW_PRTY_ASSERT_SET_3,
  3786. sig[4] & HW_PRTY_ASSERT_SET_4);
  3787. if (print)
  3788. netdev_err(bp->dev,
  3789. "Parity errors detected in blocks: ");
  3790. par_num = bnx2x_check_blocks_with_parity0(
  3791. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3792. par_num = bnx2x_check_blocks_with_parity1(
  3793. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3794. par_num = bnx2x_check_blocks_with_parity2(
  3795. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3796. par_num = bnx2x_check_blocks_with_parity3(
  3797. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3798. par_num = bnx2x_check_blocks_with_parity4(
  3799. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3800. if (print)
  3801. pr_cont("\n");
  3802. return true;
  3803. } else
  3804. return false;
  3805. }
  3806. /**
  3807. * bnx2x_chk_parity_attn - checks for parity attentions.
  3808. *
  3809. * @bp: driver handle
  3810. * @global: true if there was a global attention
  3811. * @print: show parity attention in syslog
  3812. */
  3813. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3814. {
  3815. struct attn_route attn = { {0} };
  3816. int port = BP_PORT(bp);
  3817. attn.sig[0] = REG_RD(bp,
  3818. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3819. port*4);
  3820. attn.sig[1] = REG_RD(bp,
  3821. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3822. port*4);
  3823. attn.sig[2] = REG_RD(bp,
  3824. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3825. port*4);
  3826. attn.sig[3] = REG_RD(bp,
  3827. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3828. port*4);
  3829. if (!CHIP_IS_E1x(bp))
  3830. attn.sig[4] = REG_RD(bp,
  3831. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3832. port*4);
  3833. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3834. }
  3835. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3836. {
  3837. u32 val;
  3838. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3839. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3840. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3841. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3842. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3843. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3844. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3845. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3846. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3847. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3848. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3849. if (val &
  3850. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3851. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3852. if (val &
  3853. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3854. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3855. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3856. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3857. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3858. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3859. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3860. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3861. }
  3862. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3863. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3864. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3865. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3866. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3867. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3868. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3869. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3870. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3871. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3872. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3873. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3874. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3875. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3876. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3877. }
  3878. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3879. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3880. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3881. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3882. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3883. }
  3884. }
  3885. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3886. {
  3887. struct attn_route attn, *group_mask;
  3888. int port = BP_PORT(bp);
  3889. int index;
  3890. u32 reg_addr;
  3891. u32 val;
  3892. u32 aeu_mask;
  3893. bool global = false;
  3894. /* need to take HW lock because MCP or other port might also
  3895. try to handle this event */
  3896. bnx2x_acquire_alr(bp);
  3897. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3898. #ifndef BNX2X_STOP_ON_ERROR
  3899. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3900. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3901. /* Disable HW interrupts */
  3902. bnx2x_int_disable(bp);
  3903. /* In case of parity errors don't handle attentions so that
  3904. * other function would "see" parity errors.
  3905. */
  3906. #else
  3907. bnx2x_panic();
  3908. #endif
  3909. bnx2x_release_alr(bp);
  3910. return;
  3911. }
  3912. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3913. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3914. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3915. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3916. if (!CHIP_IS_E1x(bp))
  3917. attn.sig[4] =
  3918. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3919. else
  3920. attn.sig[4] = 0;
  3921. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3922. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3923. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3924. if (deasserted & (1 << index)) {
  3925. group_mask = &bp->attn_group[index];
  3926. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3927. index,
  3928. group_mask->sig[0], group_mask->sig[1],
  3929. group_mask->sig[2], group_mask->sig[3],
  3930. group_mask->sig[4]);
  3931. bnx2x_attn_int_deasserted4(bp,
  3932. attn.sig[4] & group_mask->sig[4]);
  3933. bnx2x_attn_int_deasserted3(bp,
  3934. attn.sig[3] & group_mask->sig[3]);
  3935. bnx2x_attn_int_deasserted1(bp,
  3936. attn.sig[1] & group_mask->sig[1]);
  3937. bnx2x_attn_int_deasserted2(bp,
  3938. attn.sig[2] & group_mask->sig[2]);
  3939. bnx2x_attn_int_deasserted0(bp,
  3940. attn.sig[0] & group_mask->sig[0]);
  3941. }
  3942. }
  3943. bnx2x_release_alr(bp);
  3944. if (bp->common.int_block == INT_BLOCK_HC)
  3945. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3946. COMMAND_REG_ATTN_BITS_CLR);
  3947. else
  3948. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3949. val = ~deasserted;
  3950. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3951. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3952. REG_WR(bp, reg_addr, val);
  3953. if (~bp->attn_state & deasserted)
  3954. BNX2X_ERR("IGU ERROR\n");
  3955. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3956. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3957. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3958. aeu_mask = REG_RD(bp, reg_addr);
  3959. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3960. aeu_mask, deasserted);
  3961. aeu_mask |= (deasserted & 0x3ff);
  3962. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3963. REG_WR(bp, reg_addr, aeu_mask);
  3964. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3965. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3966. bp->attn_state &= ~deasserted;
  3967. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3968. }
  3969. static void bnx2x_attn_int(struct bnx2x *bp)
  3970. {
  3971. /* read local copy of bits */
  3972. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3973. attn_bits);
  3974. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3975. attn_bits_ack);
  3976. u32 attn_state = bp->attn_state;
  3977. /* look for changed bits */
  3978. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3979. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3980. DP(NETIF_MSG_HW,
  3981. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3982. attn_bits, attn_ack, asserted, deasserted);
  3983. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3984. BNX2X_ERR("BAD attention state\n");
  3985. /* handle bits that were raised */
  3986. if (asserted)
  3987. bnx2x_attn_int_asserted(bp, asserted);
  3988. if (deasserted)
  3989. bnx2x_attn_int_deasserted(bp, deasserted);
  3990. }
  3991. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3992. u16 index, u8 op, u8 update)
  3993. {
  3994. u32 igu_addr = bp->igu_base_addr;
  3995. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3996. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3997. igu_addr);
  3998. }
  3999. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4000. {
  4001. /* No memory barriers */
  4002. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4003. mmiowb(); /* keep prod updates ordered */
  4004. }
  4005. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4006. union event_ring_elem *elem)
  4007. {
  4008. u8 err = elem->message.error;
  4009. if (!bp->cnic_eth_dev.starting_cid ||
  4010. (cid < bp->cnic_eth_dev.starting_cid &&
  4011. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4012. return 1;
  4013. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4014. if (unlikely(err)) {
  4015. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4016. cid);
  4017. bnx2x_panic_dump(bp, false);
  4018. }
  4019. bnx2x_cnic_cfc_comp(bp, cid, err);
  4020. return 0;
  4021. }
  4022. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4023. {
  4024. struct bnx2x_mcast_ramrod_params rparam;
  4025. int rc;
  4026. memset(&rparam, 0, sizeof(rparam));
  4027. rparam.mcast_obj = &bp->mcast_obj;
  4028. netif_addr_lock_bh(bp->dev);
  4029. /* Clear pending state for the last command */
  4030. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4031. /* If there are pending mcast commands - send them */
  4032. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4033. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4034. if (rc < 0)
  4035. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4036. rc);
  4037. }
  4038. netif_addr_unlock_bh(bp->dev);
  4039. }
  4040. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4041. union event_ring_elem *elem)
  4042. {
  4043. unsigned long ramrod_flags = 0;
  4044. int rc = 0;
  4045. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4046. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4047. /* Always push next commands out, don't wait here */
  4048. __set_bit(RAMROD_CONT, &ramrod_flags);
  4049. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  4050. case BNX2X_FILTER_MAC_PENDING:
  4051. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4052. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4053. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4054. else
  4055. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4056. break;
  4057. case BNX2X_FILTER_MCAST_PENDING:
  4058. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4059. /* This is only relevant for 57710 where multicast MACs are
  4060. * configured as unicast MACs using the same ramrod.
  4061. */
  4062. bnx2x_handle_mcast_eqe(bp);
  4063. return;
  4064. default:
  4065. BNX2X_ERR("Unsupported classification command: %d\n",
  4066. elem->message.data.eth_event.echo);
  4067. return;
  4068. }
  4069. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4070. if (rc < 0)
  4071. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4072. else if (rc > 0)
  4073. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4074. }
  4075. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4076. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4077. {
  4078. netif_addr_lock_bh(bp->dev);
  4079. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4080. /* Send rx_mode command again if was requested */
  4081. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4082. bnx2x_set_storm_rx_mode(bp);
  4083. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4084. &bp->sp_state))
  4085. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4086. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4087. &bp->sp_state))
  4088. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4089. netif_addr_unlock_bh(bp->dev);
  4090. }
  4091. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4092. union event_ring_elem *elem)
  4093. {
  4094. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4095. DP(BNX2X_MSG_SP,
  4096. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4097. elem->message.data.vif_list_event.func_bit_map);
  4098. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4099. elem->message.data.vif_list_event.func_bit_map);
  4100. } else if (elem->message.data.vif_list_event.echo ==
  4101. VIF_LIST_RULE_SET) {
  4102. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4103. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4104. }
  4105. }
  4106. /* called with rtnl_lock */
  4107. static void bnx2x_after_function_update(struct bnx2x *bp)
  4108. {
  4109. int q, rc;
  4110. struct bnx2x_fastpath *fp;
  4111. struct bnx2x_queue_state_params queue_params = {NULL};
  4112. struct bnx2x_queue_update_params *q_update_params =
  4113. &queue_params.params.update;
  4114. /* Send Q update command with afex vlan removal values for all Qs */
  4115. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4116. /* set silent vlan removal values according to vlan mode */
  4117. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4118. &q_update_params->update_flags);
  4119. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4120. &q_update_params->update_flags);
  4121. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4122. /* in access mode mark mask and value are 0 to strip all vlans */
  4123. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4124. q_update_params->silent_removal_value = 0;
  4125. q_update_params->silent_removal_mask = 0;
  4126. } else {
  4127. q_update_params->silent_removal_value =
  4128. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4129. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4130. }
  4131. for_each_eth_queue(bp, q) {
  4132. /* Set the appropriate Queue object */
  4133. fp = &bp->fp[q];
  4134. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4135. /* send the ramrod */
  4136. rc = bnx2x_queue_state_change(bp, &queue_params);
  4137. if (rc < 0)
  4138. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4139. q);
  4140. }
  4141. if (!NO_FCOE(bp)) {
  4142. fp = &bp->fp[FCOE_IDX(bp)];
  4143. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4144. /* clear pending completion bit */
  4145. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4146. /* mark latest Q bit */
  4147. smp_mb__before_clear_bit();
  4148. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4149. smp_mb__after_clear_bit();
  4150. /* send Q update ramrod for FCoE Q */
  4151. rc = bnx2x_queue_state_change(bp, &queue_params);
  4152. if (rc < 0)
  4153. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4154. q);
  4155. } else {
  4156. /* If no FCoE ring - ACK MCP now */
  4157. bnx2x_link_report(bp);
  4158. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4159. }
  4160. }
  4161. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4162. struct bnx2x *bp, u32 cid)
  4163. {
  4164. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4165. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4166. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4167. else
  4168. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4169. }
  4170. static void bnx2x_eq_int(struct bnx2x *bp)
  4171. {
  4172. u16 hw_cons, sw_cons, sw_prod;
  4173. union event_ring_elem *elem;
  4174. u8 echo;
  4175. u32 cid;
  4176. u8 opcode;
  4177. int rc, spqe_cnt = 0;
  4178. struct bnx2x_queue_sp_obj *q_obj;
  4179. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4180. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4181. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4182. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4183. * when we get the the next-page we nned to adjust so the loop
  4184. * condition below will be met. The next element is the size of a
  4185. * regular element and hence incrementing by 1
  4186. */
  4187. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4188. hw_cons++;
  4189. /* This function may never run in parallel with itself for a
  4190. * specific bp, thus there is no need in "paired" read memory
  4191. * barrier here.
  4192. */
  4193. sw_cons = bp->eq_cons;
  4194. sw_prod = bp->eq_prod;
  4195. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4196. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4197. for (; sw_cons != hw_cons;
  4198. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4199. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4200. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4201. if (!rc) {
  4202. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4203. rc);
  4204. goto next_spqe;
  4205. }
  4206. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4207. opcode = elem->message.opcode;
  4208. /* handle eq element */
  4209. switch (opcode) {
  4210. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4211. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4212. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4213. continue;
  4214. case EVENT_RING_OPCODE_STAT_QUERY:
  4215. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4216. "got statistics comp event %d\n",
  4217. bp->stats_comp++);
  4218. /* nothing to do with stats comp */
  4219. goto next_spqe;
  4220. case EVENT_RING_OPCODE_CFC_DEL:
  4221. /* handle according to cid range */
  4222. /*
  4223. * we may want to verify here that the bp state is
  4224. * HALTING
  4225. */
  4226. DP(BNX2X_MSG_SP,
  4227. "got delete ramrod for MULTI[%d]\n", cid);
  4228. if (CNIC_LOADED(bp) &&
  4229. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4230. goto next_spqe;
  4231. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4232. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4233. break;
  4234. goto next_spqe;
  4235. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4236. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4237. if (f_obj->complete_cmd(bp, f_obj,
  4238. BNX2X_F_CMD_TX_STOP))
  4239. break;
  4240. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4241. goto next_spqe;
  4242. case EVENT_RING_OPCODE_START_TRAFFIC:
  4243. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4244. if (f_obj->complete_cmd(bp, f_obj,
  4245. BNX2X_F_CMD_TX_START))
  4246. break;
  4247. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4248. goto next_spqe;
  4249. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4250. echo = elem->message.data.function_update_event.echo;
  4251. if (echo == SWITCH_UPDATE) {
  4252. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4253. "got FUNC_SWITCH_UPDATE ramrod\n");
  4254. if (f_obj->complete_cmd(
  4255. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4256. break;
  4257. } else {
  4258. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4259. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4260. f_obj->complete_cmd(bp, f_obj,
  4261. BNX2X_F_CMD_AFEX_UPDATE);
  4262. /* We will perform the Queues update from
  4263. * sp_rtnl task as all Queue SP operations
  4264. * should run under rtnl_lock.
  4265. */
  4266. smp_mb__before_clear_bit();
  4267. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4268. &bp->sp_rtnl_state);
  4269. smp_mb__after_clear_bit();
  4270. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4271. }
  4272. goto next_spqe;
  4273. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4274. f_obj->complete_cmd(bp, f_obj,
  4275. BNX2X_F_CMD_AFEX_VIFLISTS);
  4276. bnx2x_after_afex_vif_lists(bp, elem);
  4277. goto next_spqe;
  4278. case EVENT_RING_OPCODE_FUNCTION_START:
  4279. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4280. "got FUNC_START ramrod\n");
  4281. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4282. break;
  4283. goto next_spqe;
  4284. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4285. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4286. "got FUNC_STOP ramrod\n");
  4287. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4288. break;
  4289. goto next_spqe;
  4290. }
  4291. switch (opcode | bp->state) {
  4292. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4293. BNX2X_STATE_OPEN):
  4294. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4295. BNX2X_STATE_OPENING_WAIT4_PORT):
  4296. cid = elem->message.data.eth_event.echo &
  4297. BNX2X_SWCID_MASK;
  4298. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4299. cid);
  4300. rss_raw->clear_pending(rss_raw);
  4301. break;
  4302. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4303. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4304. case (EVENT_RING_OPCODE_SET_MAC |
  4305. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4306. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4307. BNX2X_STATE_OPEN):
  4308. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4309. BNX2X_STATE_DIAG):
  4310. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4311. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4312. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4313. bnx2x_handle_classification_eqe(bp, elem);
  4314. break;
  4315. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4316. BNX2X_STATE_OPEN):
  4317. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4318. BNX2X_STATE_DIAG):
  4319. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4320. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4321. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4322. bnx2x_handle_mcast_eqe(bp);
  4323. break;
  4324. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4325. BNX2X_STATE_OPEN):
  4326. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4327. BNX2X_STATE_DIAG):
  4328. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4329. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4330. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4331. bnx2x_handle_rx_mode_eqe(bp);
  4332. break;
  4333. default:
  4334. /* unknown event log error and continue */
  4335. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4336. elem->message.opcode, bp->state);
  4337. }
  4338. next_spqe:
  4339. spqe_cnt++;
  4340. } /* for */
  4341. smp_mb__before_atomic_inc();
  4342. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4343. bp->eq_cons = sw_cons;
  4344. bp->eq_prod = sw_prod;
  4345. /* Make sure that above mem writes were issued towards the memory */
  4346. smp_wmb();
  4347. /* update producer */
  4348. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4349. }
  4350. static void bnx2x_sp_task(struct work_struct *work)
  4351. {
  4352. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4353. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4354. /* make sure the atomic interupt_occurred has been written */
  4355. smp_rmb();
  4356. if (atomic_read(&bp->interrupt_occurred)) {
  4357. /* what work needs to be performed? */
  4358. u16 status = bnx2x_update_dsb_idx(bp);
  4359. DP(BNX2X_MSG_SP, "status %x\n", status);
  4360. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4361. atomic_set(&bp->interrupt_occurred, 0);
  4362. /* HW attentions */
  4363. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4364. bnx2x_attn_int(bp);
  4365. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4366. }
  4367. /* SP events: STAT_QUERY and others */
  4368. if (status & BNX2X_DEF_SB_IDX) {
  4369. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4370. if (FCOE_INIT(bp) &&
  4371. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4372. /* Prevent local bottom-halves from running as
  4373. * we are going to change the local NAPI list.
  4374. */
  4375. local_bh_disable();
  4376. napi_schedule(&bnx2x_fcoe(bp, napi));
  4377. local_bh_enable();
  4378. }
  4379. /* Handle EQ completions */
  4380. bnx2x_eq_int(bp);
  4381. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4382. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4383. status &= ~BNX2X_DEF_SB_IDX;
  4384. }
  4385. /* if status is non zero then perhaps something went wrong */
  4386. if (unlikely(status))
  4387. DP(BNX2X_MSG_SP,
  4388. "got an unknown interrupt! (status 0x%x)\n", status);
  4389. /* ack status block only if something was actually handled */
  4390. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4391. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4392. }
  4393. /* must be called after the EQ processing (since eq leads to sriov
  4394. * ramrod completion flows).
  4395. * This flow may have been scheduled by the arrival of a ramrod
  4396. * completion, or by the sriov code rescheduling itself.
  4397. */
  4398. bnx2x_iov_sp_task(bp);
  4399. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4400. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4401. &bp->sp_state)) {
  4402. bnx2x_link_report(bp);
  4403. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4404. }
  4405. }
  4406. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4407. {
  4408. struct net_device *dev = dev_instance;
  4409. struct bnx2x *bp = netdev_priv(dev);
  4410. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4411. IGU_INT_DISABLE, 0);
  4412. #ifdef BNX2X_STOP_ON_ERROR
  4413. if (unlikely(bp->panic))
  4414. return IRQ_HANDLED;
  4415. #endif
  4416. if (CNIC_LOADED(bp)) {
  4417. struct cnic_ops *c_ops;
  4418. rcu_read_lock();
  4419. c_ops = rcu_dereference(bp->cnic_ops);
  4420. if (c_ops)
  4421. c_ops->cnic_handler(bp->cnic_data, NULL);
  4422. rcu_read_unlock();
  4423. }
  4424. /* schedule sp task to perform default status block work, ack
  4425. * attentions and enable interrupts.
  4426. */
  4427. bnx2x_schedule_sp_task(bp);
  4428. return IRQ_HANDLED;
  4429. }
  4430. /* end of slow path */
  4431. void bnx2x_drv_pulse(struct bnx2x *bp)
  4432. {
  4433. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4434. bp->fw_drv_pulse_wr_seq);
  4435. }
  4436. static void bnx2x_timer(unsigned long data)
  4437. {
  4438. struct bnx2x *bp = (struct bnx2x *) data;
  4439. if (!netif_running(bp->dev))
  4440. return;
  4441. if (IS_PF(bp) &&
  4442. !BP_NOMCP(bp)) {
  4443. int mb_idx = BP_FW_MB_IDX(bp);
  4444. u32 drv_pulse;
  4445. u32 mcp_pulse;
  4446. ++bp->fw_drv_pulse_wr_seq;
  4447. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4448. /* TBD - add SYSTEM_TIME */
  4449. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4450. bnx2x_drv_pulse(bp);
  4451. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4452. MCP_PULSE_SEQ_MASK);
  4453. /* The delta between driver pulse and mcp response
  4454. * should be 1 (before mcp response) or 0 (after mcp response)
  4455. */
  4456. if ((drv_pulse != mcp_pulse) &&
  4457. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4458. /* someone lost a heartbeat... */
  4459. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4460. drv_pulse, mcp_pulse);
  4461. }
  4462. }
  4463. if (bp->state == BNX2X_STATE_OPEN)
  4464. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4465. /* sample pf vf bulletin board for new posts from pf */
  4466. if (IS_VF(bp))
  4467. bnx2x_sample_bulletin(bp);
  4468. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4469. }
  4470. /* end of Statistics */
  4471. /* nic init */
  4472. /*
  4473. * nic init service functions
  4474. */
  4475. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4476. {
  4477. u32 i;
  4478. if (!(len%4) && !(addr%4))
  4479. for (i = 0; i < len; i += 4)
  4480. REG_WR(bp, addr + i, fill);
  4481. else
  4482. for (i = 0; i < len; i++)
  4483. REG_WR8(bp, addr + i, fill);
  4484. }
  4485. /* helper: writes FP SP data to FW - data_size in dwords */
  4486. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4487. int fw_sb_id,
  4488. u32 *sb_data_p,
  4489. u32 data_size)
  4490. {
  4491. int index;
  4492. for (index = 0; index < data_size; index++)
  4493. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4494. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4495. sizeof(u32)*index,
  4496. *(sb_data_p + index));
  4497. }
  4498. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4499. {
  4500. u32 *sb_data_p;
  4501. u32 data_size = 0;
  4502. struct hc_status_block_data_e2 sb_data_e2;
  4503. struct hc_status_block_data_e1x sb_data_e1x;
  4504. /* disable the function first */
  4505. if (!CHIP_IS_E1x(bp)) {
  4506. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4507. sb_data_e2.common.state = SB_DISABLED;
  4508. sb_data_e2.common.p_func.vf_valid = false;
  4509. sb_data_p = (u32 *)&sb_data_e2;
  4510. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4511. } else {
  4512. memset(&sb_data_e1x, 0,
  4513. sizeof(struct hc_status_block_data_e1x));
  4514. sb_data_e1x.common.state = SB_DISABLED;
  4515. sb_data_e1x.common.p_func.vf_valid = false;
  4516. sb_data_p = (u32 *)&sb_data_e1x;
  4517. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4518. }
  4519. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4520. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4521. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4522. CSTORM_STATUS_BLOCK_SIZE);
  4523. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4524. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4525. CSTORM_SYNC_BLOCK_SIZE);
  4526. }
  4527. /* helper: writes SP SB data to FW */
  4528. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4529. struct hc_sp_status_block_data *sp_sb_data)
  4530. {
  4531. int func = BP_FUNC(bp);
  4532. int i;
  4533. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4534. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4535. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4536. i*sizeof(u32),
  4537. *((u32 *)sp_sb_data + i));
  4538. }
  4539. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4540. {
  4541. int func = BP_FUNC(bp);
  4542. struct hc_sp_status_block_data sp_sb_data;
  4543. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4544. sp_sb_data.state = SB_DISABLED;
  4545. sp_sb_data.p_func.vf_valid = false;
  4546. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4547. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4548. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4549. CSTORM_SP_STATUS_BLOCK_SIZE);
  4550. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4551. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4552. CSTORM_SP_SYNC_BLOCK_SIZE);
  4553. }
  4554. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4555. int igu_sb_id, int igu_seg_id)
  4556. {
  4557. hc_sm->igu_sb_id = igu_sb_id;
  4558. hc_sm->igu_seg_id = igu_seg_id;
  4559. hc_sm->timer_value = 0xFF;
  4560. hc_sm->time_to_expire = 0xFFFFFFFF;
  4561. }
  4562. /* allocates state machine ids. */
  4563. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4564. {
  4565. /* zero out state machine indices */
  4566. /* rx indices */
  4567. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4568. /* tx indices */
  4569. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4570. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4571. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4572. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4573. /* map indices */
  4574. /* rx indices */
  4575. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4576. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4577. /* tx indices */
  4578. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4579. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4580. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4581. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4582. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4583. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4584. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4585. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4586. }
  4587. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4588. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4589. {
  4590. int igu_seg_id;
  4591. struct hc_status_block_data_e2 sb_data_e2;
  4592. struct hc_status_block_data_e1x sb_data_e1x;
  4593. struct hc_status_block_sm *hc_sm_p;
  4594. int data_size;
  4595. u32 *sb_data_p;
  4596. if (CHIP_INT_MODE_IS_BC(bp))
  4597. igu_seg_id = HC_SEG_ACCESS_NORM;
  4598. else
  4599. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4600. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4601. if (!CHIP_IS_E1x(bp)) {
  4602. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4603. sb_data_e2.common.state = SB_ENABLED;
  4604. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4605. sb_data_e2.common.p_func.vf_id = vfid;
  4606. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4607. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4608. sb_data_e2.common.same_igu_sb_1b = true;
  4609. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4610. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4611. hc_sm_p = sb_data_e2.common.state_machine;
  4612. sb_data_p = (u32 *)&sb_data_e2;
  4613. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4614. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4615. } else {
  4616. memset(&sb_data_e1x, 0,
  4617. sizeof(struct hc_status_block_data_e1x));
  4618. sb_data_e1x.common.state = SB_ENABLED;
  4619. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4620. sb_data_e1x.common.p_func.vf_id = 0xff;
  4621. sb_data_e1x.common.p_func.vf_valid = false;
  4622. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4623. sb_data_e1x.common.same_igu_sb_1b = true;
  4624. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4625. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4626. hc_sm_p = sb_data_e1x.common.state_machine;
  4627. sb_data_p = (u32 *)&sb_data_e1x;
  4628. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4629. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4630. }
  4631. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4632. igu_sb_id, igu_seg_id);
  4633. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4634. igu_sb_id, igu_seg_id);
  4635. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4636. /* write indecies to HW */
  4637. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4638. }
  4639. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4640. u16 tx_usec, u16 rx_usec)
  4641. {
  4642. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4643. false, rx_usec);
  4644. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4645. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4646. tx_usec);
  4647. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4648. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4649. tx_usec);
  4650. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4651. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4652. tx_usec);
  4653. }
  4654. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4655. {
  4656. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4657. dma_addr_t mapping = bp->def_status_blk_mapping;
  4658. int igu_sp_sb_index;
  4659. int igu_seg_id;
  4660. int port = BP_PORT(bp);
  4661. int func = BP_FUNC(bp);
  4662. int reg_offset, reg_offset_en5;
  4663. u64 section;
  4664. int index;
  4665. struct hc_sp_status_block_data sp_sb_data;
  4666. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4667. if (CHIP_INT_MODE_IS_BC(bp)) {
  4668. igu_sp_sb_index = DEF_SB_IGU_ID;
  4669. igu_seg_id = HC_SEG_ACCESS_DEF;
  4670. } else {
  4671. igu_sp_sb_index = bp->igu_dsb_id;
  4672. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4673. }
  4674. /* ATTN */
  4675. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4676. atten_status_block);
  4677. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4678. bp->attn_state = 0;
  4679. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4680. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4681. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4682. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4683. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4684. int sindex;
  4685. /* take care of sig[0]..sig[4] */
  4686. for (sindex = 0; sindex < 4; sindex++)
  4687. bp->attn_group[index].sig[sindex] =
  4688. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4689. if (!CHIP_IS_E1x(bp))
  4690. /*
  4691. * enable5 is separate from the rest of the registers,
  4692. * and therefore the address skip is 4
  4693. * and not 16 between the different groups
  4694. */
  4695. bp->attn_group[index].sig[4] = REG_RD(bp,
  4696. reg_offset_en5 + 0x4*index);
  4697. else
  4698. bp->attn_group[index].sig[4] = 0;
  4699. }
  4700. if (bp->common.int_block == INT_BLOCK_HC) {
  4701. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4702. HC_REG_ATTN_MSG0_ADDR_L);
  4703. REG_WR(bp, reg_offset, U64_LO(section));
  4704. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4705. } else if (!CHIP_IS_E1x(bp)) {
  4706. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4707. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4708. }
  4709. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4710. sp_sb);
  4711. bnx2x_zero_sp_sb(bp);
  4712. sp_sb_data.state = SB_ENABLED;
  4713. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4714. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4715. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4716. sp_sb_data.igu_seg_id = igu_seg_id;
  4717. sp_sb_data.p_func.pf_id = func;
  4718. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4719. sp_sb_data.p_func.vf_id = 0xff;
  4720. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4721. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4722. }
  4723. void bnx2x_update_coalesce(struct bnx2x *bp)
  4724. {
  4725. int i;
  4726. for_each_eth_queue(bp, i)
  4727. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4728. bp->tx_ticks, bp->rx_ticks);
  4729. }
  4730. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4731. {
  4732. spin_lock_init(&bp->spq_lock);
  4733. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4734. bp->spq_prod_idx = 0;
  4735. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4736. bp->spq_prod_bd = bp->spq;
  4737. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4738. }
  4739. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4740. {
  4741. int i;
  4742. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4743. union event_ring_elem *elem =
  4744. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4745. elem->next_page.addr.hi =
  4746. cpu_to_le32(U64_HI(bp->eq_mapping +
  4747. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4748. elem->next_page.addr.lo =
  4749. cpu_to_le32(U64_LO(bp->eq_mapping +
  4750. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4751. }
  4752. bp->eq_cons = 0;
  4753. bp->eq_prod = NUM_EQ_DESC;
  4754. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4755. /* we want a warning message before it gets rought... */
  4756. atomic_set(&bp->eq_spq_left,
  4757. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4758. }
  4759. /* called with netif_addr_lock_bh() */
  4760. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4761. unsigned long rx_mode_flags,
  4762. unsigned long rx_accept_flags,
  4763. unsigned long tx_accept_flags,
  4764. unsigned long ramrod_flags)
  4765. {
  4766. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4767. int rc;
  4768. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4769. /* Prepare ramrod parameters */
  4770. ramrod_param.cid = 0;
  4771. ramrod_param.cl_id = cl_id;
  4772. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4773. ramrod_param.func_id = BP_FUNC(bp);
  4774. ramrod_param.pstate = &bp->sp_state;
  4775. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4776. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4777. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4778. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4779. ramrod_param.ramrod_flags = ramrod_flags;
  4780. ramrod_param.rx_mode_flags = rx_mode_flags;
  4781. ramrod_param.rx_accept_flags = rx_accept_flags;
  4782. ramrod_param.tx_accept_flags = tx_accept_flags;
  4783. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4784. if (rc < 0) {
  4785. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4786. return;
  4787. }
  4788. }
  4789. /* called with netif_addr_lock_bh() */
  4790. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4791. {
  4792. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4793. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4794. if (!NO_FCOE(bp))
  4795. /* Configure rx_mode of FCoE Queue */
  4796. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4797. switch (bp->rx_mode) {
  4798. case BNX2X_RX_MODE_NONE:
  4799. /*
  4800. * 'drop all' supersedes any accept flags that may have been
  4801. * passed to the function.
  4802. */
  4803. break;
  4804. case BNX2X_RX_MODE_NORMAL:
  4805. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4806. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4807. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4808. /* internal switching mode */
  4809. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4810. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4811. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4812. break;
  4813. case BNX2X_RX_MODE_ALLMULTI:
  4814. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4815. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4816. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4817. /* internal switching mode */
  4818. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4819. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4820. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4821. break;
  4822. case BNX2X_RX_MODE_PROMISC:
  4823. /* According to deffinition of SI mode, iface in promisc mode
  4824. * should receive matched and unmatched (in resolution of port)
  4825. * unicast packets.
  4826. */
  4827. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4828. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4829. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4830. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4831. /* internal switching mode */
  4832. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4833. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4834. if (IS_MF_SI(bp))
  4835. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4836. else
  4837. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4838. break;
  4839. default:
  4840. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4841. return;
  4842. }
  4843. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4844. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4845. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4846. }
  4847. __set_bit(RAMROD_RX, &ramrod_flags);
  4848. __set_bit(RAMROD_TX, &ramrod_flags);
  4849. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4850. tx_accept_flags, ramrod_flags);
  4851. }
  4852. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4853. {
  4854. int i;
  4855. if (IS_MF_SI(bp))
  4856. /*
  4857. * In switch independent mode, the TSTORM needs to accept
  4858. * packets that failed classification, since approximate match
  4859. * mac addresses aren't written to NIG LLH
  4860. */
  4861. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4862. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4863. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4864. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4865. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4866. /* Zero this manually as its initialization is
  4867. currently missing in the initTool */
  4868. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4869. REG_WR(bp, BAR_USTRORM_INTMEM +
  4870. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4871. if (!CHIP_IS_E1x(bp)) {
  4872. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4873. CHIP_INT_MODE_IS_BC(bp) ?
  4874. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4875. }
  4876. }
  4877. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4878. {
  4879. switch (load_code) {
  4880. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4881. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4882. bnx2x_init_internal_common(bp);
  4883. /* no break */
  4884. case FW_MSG_CODE_DRV_LOAD_PORT:
  4885. /* nothing to do */
  4886. /* no break */
  4887. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4888. /* internal memory per function is
  4889. initialized inside bnx2x_pf_init */
  4890. break;
  4891. default:
  4892. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4893. break;
  4894. }
  4895. }
  4896. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4897. {
  4898. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4899. }
  4900. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4901. {
  4902. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4903. }
  4904. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4905. {
  4906. if (CHIP_IS_E1x(fp->bp))
  4907. return BP_L_ID(fp->bp) + fp->index;
  4908. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4909. return bnx2x_fp_igu_sb_id(fp);
  4910. }
  4911. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4912. {
  4913. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4914. u8 cos;
  4915. unsigned long q_type = 0;
  4916. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4917. fp->rx_queue = fp_idx;
  4918. fp->cid = fp_idx;
  4919. fp->cl_id = bnx2x_fp_cl_id(fp);
  4920. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4921. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4922. /* qZone id equals to FW (per path) client id */
  4923. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4924. /* init shortcut */
  4925. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4926. /* Setup SB indicies */
  4927. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4928. /* Configure Queue State object */
  4929. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4930. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4931. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4932. /* init tx data */
  4933. for_each_cos_in_tx_queue(fp, cos) {
  4934. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4935. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4936. FP_COS_TO_TXQ(fp, cos, bp),
  4937. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4938. cids[cos] = fp->txdata_ptr[cos]->cid;
  4939. }
  4940. /* nothing more for vf to do here */
  4941. if (IS_VF(bp))
  4942. return;
  4943. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4944. fp->fw_sb_id, fp->igu_sb_id);
  4945. bnx2x_update_fpsb_idx(fp);
  4946. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4947. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4948. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4949. /**
  4950. * Configure classification DBs: Always enable Tx switching
  4951. */
  4952. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4953. DP(NETIF_MSG_IFUP,
  4954. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4955. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4956. fp->igu_sb_id);
  4957. }
  4958. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4959. {
  4960. int i;
  4961. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4962. struct eth_tx_next_bd *tx_next_bd =
  4963. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4964. tx_next_bd->addr_hi =
  4965. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4966. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4967. tx_next_bd->addr_lo =
  4968. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4969. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4970. }
  4971. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4972. txdata->tx_db.data.zero_fill1 = 0;
  4973. txdata->tx_db.data.prod = 0;
  4974. txdata->tx_pkt_prod = 0;
  4975. txdata->tx_pkt_cons = 0;
  4976. txdata->tx_bd_prod = 0;
  4977. txdata->tx_bd_cons = 0;
  4978. txdata->tx_pkt = 0;
  4979. }
  4980. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  4981. {
  4982. int i;
  4983. for_each_tx_queue_cnic(bp, i)
  4984. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  4985. }
  4986. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4987. {
  4988. int i;
  4989. u8 cos;
  4990. for_each_eth_queue(bp, i)
  4991. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4992. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4993. }
  4994. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  4995. {
  4996. if (!NO_FCOE(bp))
  4997. bnx2x_init_fcoe_fp(bp);
  4998. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4999. BNX2X_VF_ID_INVALID, false,
  5000. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5001. /* ensure status block indices were read */
  5002. rmb();
  5003. bnx2x_init_rx_rings_cnic(bp);
  5004. bnx2x_init_tx_rings_cnic(bp);
  5005. /* flush all */
  5006. mb();
  5007. mmiowb();
  5008. }
  5009. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  5010. {
  5011. int i;
  5012. for_each_eth_queue(bp, i)
  5013. bnx2x_init_eth_fp(bp, i);
  5014. /* ensure status block indices were read */
  5015. rmb();
  5016. bnx2x_init_rx_rings(bp);
  5017. bnx2x_init_tx_rings(bp);
  5018. if (IS_VF(bp))
  5019. return;
  5020. /* Initialize MOD_ABS interrupts */
  5021. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5022. bp->common.shmem_base, bp->common.shmem2_base,
  5023. BP_PORT(bp));
  5024. bnx2x_init_def_sb(bp);
  5025. bnx2x_update_dsb_idx(bp);
  5026. bnx2x_init_sp_ring(bp);
  5027. bnx2x_init_eq_ring(bp);
  5028. bnx2x_init_internal(bp, load_code);
  5029. bnx2x_pf_init(bp);
  5030. bnx2x_stats_init(bp);
  5031. /* flush all before enabling interrupts */
  5032. mb();
  5033. mmiowb();
  5034. bnx2x_int_enable(bp);
  5035. /* Check for SPIO5 */
  5036. bnx2x_attn_int_deasserted0(bp,
  5037. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5038. AEU_INPUTS_ATTN_BITS_SPIO5);
  5039. }
  5040. /* end of nic init */
  5041. /*
  5042. * gzip service functions
  5043. */
  5044. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5045. {
  5046. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5047. &bp->gunzip_mapping, GFP_KERNEL);
  5048. if (bp->gunzip_buf == NULL)
  5049. goto gunzip_nomem1;
  5050. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5051. if (bp->strm == NULL)
  5052. goto gunzip_nomem2;
  5053. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5054. if (bp->strm->workspace == NULL)
  5055. goto gunzip_nomem3;
  5056. return 0;
  5057. gunzip_nomem3:
  5058. kfree(bp->strm);
  5059. bp->strm = NULL;
  5060. gunzip_nomem2:
  5061. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5062. bp->gunzip_mapping);
  5063. bp->gunzip_buf = NULL;
  5064. gunzip_nomem1:
  5065. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5066. return -ENOMEM;
  5067. }
  5068. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5069. {
  5070. if (bp->strm) {
  5071. vfree(bp->strm->workspace);
  5072. kfree(bp->strm);
  5073. bp->strm = NULL;
  5074. }
  5075. if (bp->gunzip_buf) {
  5076. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5077. bp->gunzip_mapping);
  5078. bp->gunzip_buf = NULL;
  5079. }
  5080. }
  5081. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5082. {
  5083. int n, rc;
  5084. /* check gzip header */
  5085. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5086. BNX2X_ERR("Bad gzip header\n");
  5087. return -EINVAL;
  5088. }
  5089. n = 10;
  5090. #define FNAME 0x8
  5091. if (zbuf[3] & FNAME)
  5092. while ((zbuf[n++] != 0) && (n < len));
  5093. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5094. bp->strm->avail_in = len - n;
  5095. bp->strm->next_out = bp->gunzip_buf;
  5096. bp->strm->avail_out = FW_BUF_SIZE;
  5097. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5098. if (rc != Z_OK)
  5099. return rc;
  5100. rc = zlib_inflate(bp->strm, Z_FINISH);
  5101. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5102. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5103. bp->strm->msg);
  5104. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5105. if (bp->gunzip_outlen & 0x3)
  5106. netdev_err(bp->dev,
  5107. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5108. bp->gunzip_outlen);
  5109. bp->gunzip_outlen >>= 2;
  5110. zlib_inflateEnd(bp->strm);
  5111. if (rc == Z_STREAM_END)
  5112. return 0;
  5113. return rc;
  5114. }
  5115. /* nic load/unload */
  5116. /*
  5117. * General service functions
  5118. */
  5119. /* send a NIG loopback debug packet */
  5120. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5121. {
  5122. u32 wb_write[3];
  5123. /* Ethernet source and destination addresses */
  5124. wb_write[0] = 0x55555555;
  5125. wb_write[1] = 0x55555555;
  5126. wb_write[2] = 0x20; /* SOP */
  5127. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5128. /* NON-IP protocol */
  5129. wb_write[0] = 0x09000000;
  5130. wb_write[1] = 0x55555555;
  5131. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5132. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5133. }
  5134. /* some of the internal memories
  5135. * are not directly readable from the driver
  5136. * to test them we send debug packets
  5137. */
  5138. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5139. {
  5140. int factor;
  5141. int count, i;
  5142. u32 val = 0;
  5143. if (CHIP_REV_IS_FPGA(bp))
  5144. factor = 120;
  5145. else if (CHIP_REV_IS_EMUL(bp))
  5146. factor = 200;
  5147. else
  5148. factor = 1;
  5149. /* Disable inputs of parser neighbor blocks */
  5150. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5151. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5152. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5153. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5154. /* Write 0 to parser credits for CFC search request */
  5155. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5156. /* send Ethernet packet */
  5157. bnx2x_lb_pckt(bp);
  5158. /* TODO do i reset NIG statistic? */
  5159. /* Wait until NIG register shows 1 packet of size 0x10 */
  5160. count = 1000 * factor;
  5161. while (count) {
  5162. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5163. val = *bnx2x_sp(bp, wb_data[0]);
  5164. if (val == 0x10)
  5165. break;
  5166. msleep(10);
  5167. count--;
  5168. }
  5169. if (val != 0x10) {
  5170. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5171. return -1;
  5172. }
  5173. /* Wait until PRS register shows 1 packet */
  5174. count = 1000 * factor;
  5175. while (count) {
  5176. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5177. if (val == 1)
  5178. break;
  5179. msleep(10);
  5180. count--;
  5181. }
  5182. if (val != 0x1) {
  5183. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5184. return -2;
  5185. }
  5186. /* Reset and init BRB, PRS */
  5187. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5188. msleep(50);
  5189. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5190. msleep(50);
  5191. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5192. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5193. DP(NETIF_MSG_HW, "part2\n");
  5194. /* Disable inputs of parser neighbor blocks */
  5195. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5196. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5197. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5198. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5199. /* Write 0 to parser credits for CFC search request */
  5200. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5201. /* send 10 Ethernet packets */
  5202. for (i = 0; i < 10; i++)
  5203. bnx2x_lb_pckt(bp);
  5204. /* Wait until NIG register shows 10 + 1
  5205. packets of size 11*0x10 = 0xb0 */
  5206. count = 1000 * factor;
  5207. while (count) {
  5208. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5209. val = *bnx2x_sp(bp, wb_data[0]);
  5210. if (val == 0xb0)
  5211. break;
  5212. msleep(10);
  5213. count--;
  5214. }
  5215. if (val != 0xb0) {
  5216. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5217. return -3;
  5218. }
  5219. /* Wait until PRS register shows 2 packets */
  5220. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5221. if (val != 2)
  5222. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5223. /* Write 1 to parser credits for CFC search request */
  5224. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5225. /* Wait until PRS register shows 3 packets */
  5226. msleep(10 * factor);
  5227. /* Wait until NIG register shows 1 packet of size 0x10 */
  5228. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5229. if (val != 3)
  5230. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5231. /* clear NIG EOP FIFO */
  5232. for (i = 0; i < 11; i++)
  5233. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5234. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5235. if (val != 1) {
  5236. BNX2X_ERR("clear of NIG failed\n");
  5237. return -4;
  5238. }
  5239. /* Reset and init BRB, PRS, NIG */
  5240. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5241. msleep(50);
  5242. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5243. msleep(50);
  5244. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5245. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5246. if (!CNIC_SUPPORT(bp))
  5247. /* set NIC mode */
  5248. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5249. /* Enable inputs of parser neighbor blocks */
  5250. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5251. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5252. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5253. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5254. DP(NETIF_MSG_HW, "done\n");
  5255. return 0; /* OK */
  5256. }
  5257. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5258. {
  5259. u32 val;
  5260. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5261. if (!CHIP_IS_E1x(bp))
  5262. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5263. else
  5264. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5265. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5266. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5267. /*
  5268. * mask read length error interrupts in brb for parser
  5269. * (parsing unit and 'checksum and crc' unit)
  5270. * these errors are legal (PU reads fixed length and CAC can cause
  5271. * read length error on truncated packets)
  5272. */
  5273. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5274. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5275. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5276. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5277. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5278. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5279. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5280. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5281. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5282. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5283. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5284. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5285. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5286. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5287. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5288. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5289. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5290. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5291. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5292. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5293. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5294. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5295. if (!CHIP_IS_E1x(bp))
  5296. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5297. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5298. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5299. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5300. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5301. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5302. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5303. if (!CHIP_IS_E1x(bp))
  5304. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5305. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5306. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5307. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5308. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5309. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5310. }
  5311. static void bnx2x_reset_common(struct bnx2x *bp)
  5312. {
  5313. u32 val = 0x1400;
  5314. /* reset_common */
  5315. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5316. 0xd3ffff7f);
  5317. if (CHIP_IS_E3(bp)) {
  5318. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5319. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5320. }
  5321. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5322. }
  5323. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5324. {
  5325. bp->dmae_ready = 0;
  5326. spin_lock_init(&bp->dmae_lock);
  5327. }
  5328. static void bnx2x_init_pxp(struct bnx2x *bp)
  5329. {
  5330. u16 devctl;
  5331. int r_order, w_order;
  5332. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5333. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5334. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5335. if (bp->mrrs == -1)
  5336. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5337. else {
  5338. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5339. r_order = bp->mrrs;
  5340. }
  5341. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5342. }
  5343. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5344. {
  5345. int is_required;
  5346. u32 val;
  5347. int port;
  5348. if (BP_NOMCP(bp))
  5349. return;
  5350. is_required = 0;
  5351. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5352. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5353. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5354. is_required = 1;
  5355. /*
  5356. * The fan failure mechanism is usually related to the PHY type since
  5357. * the power consumption of the board is affected by the PHY. Currently,
  5358. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5359. */
  5360. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5361. for (port = PORT_0; port < PORT_MAX; port++) {
  5362. is_required |=
  5363. bnx2x_fan_failure_det_req(
  5364. bp,
  5365. bp->common.shmem_base,
  5366. bp->common.shmem2_base,
  5367. port);
  5368. }
  5369. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5370. if (is_required == 0)
  5371. return;
  5372. /* Fan failure is indicated by SPIO 5 */
  5373. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5374. /* set to active low mode */
  5375. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5376. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5377. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5378. /* enable interrupt to signal the IGU */
  5379. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5380. val |= MISC_SPIO_SPIO5;
  5381. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5382. }
  5383. void bnx2x_pf_disable(struct bnx2x *bp)
  5384. {
  5385. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5386. val &= ~IGU_PF_CONF_FUNC_EN;
  5387. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5388. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5389. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5390. }
  5391. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5392. {
  5393. u32 shmem_base[2], shmem2_base[2];
  5394. /* Avoid common init in case MFW supports LFA */
  5395. if (SHMEM2_RD(bp, size) >
  5396. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5397. return;
  5398. shmem_base[0] = bp->common.shmem_base;
  5399. shmem2_base[0] = bp->common.shmem2_base;
  5400. if (!CHIP_IS_E1x(bp)) {
  5401. shmem_base[1] =
  5402. SHMEM2_RD(bp, other_shmem_base_addr);
  5403. shmem2_base[1] =
  5404. SHMEM2_RD(bp, other_shmem2_base_addr);
  5405. }
  5406. bnx2x_acquire_phy_lock(bp);
  5407. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5408. bp->common.chip_id);
  5409. bnx2x_release_phy_lock(bp);
  5410. }
  5411. /**
  5412. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5413. *
  5414. * @bp: driver handle
  5415. */
  5416. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5417. {
  5418. u32 val;
  5419. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5420. /*
  5421. * take the RESET lock to protect undi_unload flow from accessing
  5422. * registers while we're resetting the chip
  5423. */
  5424. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5425. bnx2x_reset_common(bp);
  5426. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5427. val = 0xfffc;
  5428. if (CHIP_IS_E3(bp)) {
  5429. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5430. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5431. }
  5432. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5433. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5434. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5435. if (!CHIP_IS_E1x(bp)) {
  5436. u8 abs_func_id;
  5437. /**
  5438. * 4-port mode or 2-port mode we need to turn of master-enable
  5439. * for everyone, after that, turn it back on for self.
  5440. * so, we disregard multi-function or not, and always disable
  5441. * for all functions on the given path, this means 0,2,4,6 for
  5442. * path 0 and 1,3,5,7 for path 1
  5443. */
  5444. for (abs_func_id = BP_PATH(bp);
  5445. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5446. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5447. REG_WR(bp,
  5448. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5449. 1);
  5450. continue;
  5451. }
  5452. bnx2x_pretend_func(bp, abs_func_id);
  5453. /* clear pf enable */
  5454. bnx2x_pf_disable(bp);
  5455. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5456. }
  5457. }
  5458. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5459. if (CHIP_IS_E1(bp)) {
  5460. /* enable HW interrupt from PXP on USDM overflow
  5461. bit 16 on INT_MASK_0 */
  5462. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5463. }
  5464. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5465. bnx2x_init_pxp(bp);
  5466. #ifdef __BIG_ENDIAN
  5467. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5468. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5469. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5470. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5471. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5472. /* make sure this value is 0 */
  5473. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5474. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5475. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5476. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5477. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5478. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5479. #endif
  5480. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5481. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5482. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5483. /* let the HW do it's magic ... */
  5484. msleep(100);
  5485. /* finish PXP init */
  5486. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5487. if (val != 1) {
  5488. BNX2X_ERR("PXP2 CFG failed\n");
  5489. return -EBUSY;
  5490. }
  5491. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5492. if (val != 1) {
  5493. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5494. return -EBUSY;
  5495. }
  5496. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5497. * have entries with value "0" and valid bit on.
  5498. * This needs to be done by the first PF that is loaded in a path
  5499. * (i.e. common phase)
  5500. */
  5501. if (!CHIP_IS_E1x(bp)) {
  5502. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5503. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5504. * This occurs when a different function (func2,3) is being marked
  5505. * as "scan-off". Real-life scenario for example: if a driver is being
  5506. * load-unloaded while func6,7 are down. This will cause the timer to access
  5507. * the ilt, translate to a logical address and send a request to read/write.
  5508. * Since the ilt for the function that is down is not valid, this will cause
  5509. * a translation error which is unrecoverable.
  5510. * The Workaround is intended to make sure that when this happens nothing fatal
  5511. * will occur. The workaround:
  5512. * 1. First PF driver which loads on a path will:
  5513. * a. After taking the chip out of reset, by using pretend,
  5514. * it will write "0" to the following registers of
  5515. * the other vnics.
  5516. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5517. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5518. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5519. * And for itself it will write '1' to
  5520. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5521. * dmae-operations (writing to pram for example.)
  5522. * note: can be done for only function 6,7 but cleaner this
  5523. * way.
  5524. * b. Write zero+valid to the entire ILT.
  5525. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5526. * VNIC3 (of that port). The range allocated will be the
  5527. * entire ILT. This is needed to prevent ILT range error.
  5528. * 2. Any PF driver load flow:
  5529. * a. ILT update with the physical addresses of the allocated
  5530. * logical pages.
  5531. * b. Wait 20msec. - note that this timeout is needed to make
  5532. * sure there are no requests in one of the PXP internal
  5533. * queues with "old" ILT addresses.
  5534. * c. PF enable in the PGLC.
  5535. * d. Clear the was_error of the PF in the PGLC. (could have
  5536. * occurred while driver was down)
  5537. * e. PF enable in the CFC (WEAK + STRONG)
  5538. * f. Timers scan enable
  5539. * 3. PF driver unload flow:
  5540. * a. Clear the Timers scan_en.
  5541. * b. Polling for scan_on=0 for that PF.
  5542. * c. Clear the PF enable bit in the PXP.
  5543. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5544. * e. Write zero+valid to all ILT entries (The valid bit must
  5545. * stay set)
  5546. * f. If this is VNIC 3 of a port then also init
  5547. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5548. * to the last enrty in the ILT.
  5549. *
  5550. * Notes:
  5551. * Currently the PF error in the PGLC is non recoverable.
  5552. * In the future the there will be a recovery routine for this error.
  5553. * Currently attention is masked.
  5554. * Having an MCP lock on the load/unload process does not guarantee that
  5555. * there is no Timer disable during Func6/7 enable. This is because the
  5556. * Timers scan is currently being cleared by the MCP on FLR.
  5557. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5558. * there is error before clearing it. But the flow above is simpler and
  5559. * more general.
  5560. * All ILT entries are written by zero+valid and not just PF6/7
  5561. * ILT entries since in the future the ILT entries allocation for
  5562. * PF-s might be dynamic.
  5563. */
  5564. struct ilt_client_info ilt_cli;
  5565. struct bnx2x_ilt ilt;
  5566. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5567. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5568. /* initialize dummy TM client */
  5569. ilt_cli.start = 0;
  5570. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5571. ilt_cli.client_num = ILT_CLIENT_TM;
  5572. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5573. * Step 2: set the timers first/last ilt entry to point
  5574. * to the entire range to prevent ILT range error for 3rd/4th
  5575. * vnic (this code assumes existence of the vnic)
  5576. *
  5577. * both steps performed by call to bnx2x_ilt_client_init_op()
  5578. * with dummy TM client
  5579. *
  5580. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5581. * and his brother are split registers
  5582. */
  5583. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5584. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5585. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5586. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5587. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5588. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5589. }
  5590. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5591. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5592. if (!CHIP_IS_E1x(bp)) {
  5593. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5594. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5595. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5596. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5597. /* let the HW do it's magic ... */
  5598. do {
  5599. msleep(200);
  5600. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5601. } while (factor-- && (val != 1));
  5602. if (val != 1) {
  5603. BNX2X_ERR("ATC_INIT failed\n");
  5604. return -EBUSY;
  5605. }
  5606. }
  5607. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5608. bnx2x_iov_init_dmae(bp);
  5609. /* clean the DMAE memory */
  5610. bp->dmae_ready = 1;
  5611. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5612. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5613. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5614. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5615. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5616. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5617. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5618. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5619. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5620. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5621. /* QM queues pointers table */
  5622. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5623. /* soft reset pulse */
  5624. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5625. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5626. if (CNIC_SUPPORT(bp))
  5627. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5628. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5629. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5630. if (!CHIP_REV_IS_SLOW(bp))
  5631. /* enable hw interrupt from doorbell Q */
  5632. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5633. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5634. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5635. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5636. if (!CHIP_IS_E1(bp))
  5637. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5638. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5639. if (IS_MF_AFEX(bp)) {
  5640. /* configure that VNTag and VLAN headers must be
  5641. * received in afex mode
  5642. */
  5643. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5644. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5645. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5646. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5647. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5648. } else {
  5649. /* Bit-map indicating which L2 hdrs may appear
  5650. * after the basic Ethernet header
  5651. */
  5652. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5653. bp->path_has_ovlan ? 7 : 6);
  5654. }
  5655. }
  5656. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5657. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5658. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5659. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5660. if (!CHIP_IS_E1x(bp)) {
  5661. /* reset VFC memories */
  5662. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5663. VFC_MEMORIES_RST_REG_CAM_RST |
  5664. VFC_MEMORIES_RST_REG_RAM_RST);
  5665. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5666. VFC_MEMORIES_RST_REG_CAM_RST |
  5667. VFC_MEMORIES_RST_REG_RAM_RST);
  5668. msleep(20);
  5669. }
  5670. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5671. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5672. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5673. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5674. /* sync semi rtc */
  5675. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5676. 0x80000000);
  5677. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5678. 0x80000000);
  5679. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5680. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5681. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5682. if (!CHIP_IS_E1x(bp)) {
  5683. if (IS_MF_AFEX(bp)) {
  5684. /* configure that VNTag and VLAN headers must be
  5685. * sent in afex mode
  5686. */
  5687. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5688. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5689. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5690. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5691. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5692. } else {
  5693. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5694. bp->path_has_ovlan ? 7 : 6);
  5695. }
  5696. }
  5697. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5698. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5699. if (CNIC_SUPPORT(bp)) {
  5700. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5701. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5702. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5703. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5704. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5705. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5706. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5707. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5708. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5709. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5710. }
  5711. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5712. if (sizeof(union cdu_context) != 1024)
  5713. /* we currently assume that a context is 1024 bytes */
  5714. dev_alert(&bp->pdev->dev,
  5715. "please adjust the size of cdu_context(%ld)\n",
  5716. (long)sizeof(union cdu_context));
  5717. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5718. val = (4 << 24) + (0 << 12) + 1024;
  5719. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5720. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5721. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5722. /* enable context validation interrupt from CFC */
  5723. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5724. /* set the thresholds to prevent CFC/CDU race */
  5725. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5726. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5727. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5728. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5729. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5730. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5731. /* Reset PCIE errors for debug */
  5732. REG_WR(bp, 0x2814, 0xffffffff);
  5733. REG_WR(bp, 0x3820, 0xffffffff);
  5734. if (!CHIP_IS_E1x(bp)) {
  5735. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5736. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5737. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5738. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5739. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5740. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5741. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5742. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5743. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5744. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5745. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5746. }
  5747. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5748. if (!CHIP_IS_E1(bp)) {
  5749. /* in E3 this done in per-port section */
  5750. if (!CHIP_IS_E3(bp))
  5751. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5752. }
  5753. if (CHIP_IS_E1H(bp))
  5754. /* not applicable for E2 (and above ...) */
  5755. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5756. if (CHIP_REV_IS_SLOW(bp))
  5757. msleep(200);
  5758. /* finish CFC init */
  5759. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5760. if (val != 1) {
  5761. BNX2X_ERR("CFC LL_INIT failed\n");
  5762. return -EBUSY;
  5763. }
  5764. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5765. if (val != 1) {
  5766. BNX2X_ERR("CFC AC_INIT failed\n");
  5767. return -EBUSY;
  5768. }
  5769. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5770. if (val != 1) {
  5771. BNX2X_ERR("CFC CAM_INIT failed\n");
  5772. return -EBUSY;
  5773. }
  5774. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5775. if (CHIP_IS_E1(bp)) {
  5776. /* read NIG statistic
  5777. to see if this is our first up since powerup */
  5778. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5779. val = *bnx2x_sp(bp, wb_data[0]);
  5780. /* do internal memory self test */
  5781. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5782. BNX2X_ERR("internal mem self test failed\n");
  5783. return -EBUSY;
  5784. }
  5785. }
  5786. bnx2x_setup_fan_failure_detection(bp);
  5787. /* clear PXP2 attentions */
  5788. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5789. bnx2x_enable_blocks_attention(bp);
  5790. bnx2x_enable_blocks_parity(bp);
  5791. if (!BP_NOMCP(bp)) {
  5792. if (CHIP_IS_E1x(bp))
  5793. bnx2x__common_init_phy(bp);
  5794. } else
  5795. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5796. return 0;
  5797. }
  5798. /**
  5799. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5800. *
  5801. * @bp: driver handle
  5802. */
  5803. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5804. {
  5805. int rc = bnx2x_init_hw_common(bp);
  5806. if (rc)
  5807. return rc;
  5808. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5809. if (!BP_NOMCP(bp))
  5810. bnx2x__common_init_phy(bp);
  5811. return 0;
  5812. }
  5813. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5814. {
  5815. int port = BP_PORT(bp);
  5816. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5817. u32 low, high;
  5818. u32 val;
  5819. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5820. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5821. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5822. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5823. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5824. /* Timers bug workaround: disables the pf_master bit in pglue at
  5825. * common phase, we need to enable it here before any dmae access are
  5826. * attempted. Therefore we manually added the enable-master to the
  5827. * port phase (it also happens in the function phase)
  5828. */
  5829. if (!CHIP_IS_E1x(bp))
  5830. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5831. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5832. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5833. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5834. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5835. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5836. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5837. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5838. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5839. /* QM cid (connection) count */
  5840. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5841. if (CNIC_SUPPORT(bp)) {
  5842. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5843. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5844. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5845. }
  5846. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5847. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5848. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5849. if (IS_MF(bp))
  5850. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5851. else if (bp->dev->mtu > 4096) {
  5852. if (bp->flags & ONE_PORT_FLAG)
  5853. low = 160;
  5854. else {
  5855. val = bp->dev->mtu;
  5856. /* (24*1024 + val*4)/256 */
  5857. low = 96 + (val/64) +
  5858. ((val % 64) ? 1 : 0);
  5859. }
  5860. } else
  5861. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5862. high = low + 56; /* 14*1024/256 */
  5863. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5864. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5865. }
  5866. if (CHIP_MODE_IS_4_PORT(bp))
  5867. REG_WR(bp, (BP_PORT(bp) ?
  5868. BRB1_REG_MAC_GUARANTIED_1 :
  5869. BRB1_REG_MAC_GUARANTIED_0), 40);
  5870. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5871. if (CHIP_IS_E3B0(bp)) {
  5872. if (IS_MF_AFEX(bp)) {
  5873. /* configure headers for AFEX mode */
  5874. REG_WR(bp, BP_PORT(bp) ?
  5875. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5876. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5877. REG_WR(bp, BP_PORT(bp) ?
  5878. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5879. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5880. REG_WR(bp, BP_PORT(bp) ?
  5881. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5882. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5883. } else {
  5884. /* Ovlan exists only if we are in multi-function +
  5885. * switch-dependent mode, in switch-independent there
  5886. * is no ovlan headers
  5887. */
  5888. REG_WR(bp, BP_PORT(bp) ?
  5889. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5890. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5891. (bp->path_has_ovlan ? 7 : 6));
  5892. }
  5893. }
  5894. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5895. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5896. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5897. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5898. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5899. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5900. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5901. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5902. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5903. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5904. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5905. if (CHIP_IS_E1x(bp)) {
  5906. /* configure PBF to work without PAUSE mtu 9000 */
  5907. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5908. /* update threshold */
  5909. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5910. /* update init credit */
  5911. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5912. /* probe changes */
  5913. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5914. udelay(50);
  5915. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5916. }
  5917. if (CNIC_SUPPORT(bp))
  5918. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5919. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5920. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5921. if (CHIP_IS_E1(bp)) {
  5922. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5923. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5924. }
  5925. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5926. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5927. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5928. /* init aeu_mask_attn_func_0/1:
  5929. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5930. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5931. * bits 4-7 are used for "per vn group attention" */
  5932. val = IS_MF(bp) ? 0xF7 : 0x7;
  5933. /* Enable DCBX attention for all but E1 */
  5934. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5935. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5936. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5937. if (!CHIP_IS_E1x(bp)) {
  5938. /* Bit-map indicating which L2 hdrs may appear after the
  5939. * basic Ethernet header
  5940. */
  5941. if (IS_MF_AFEX(bp))
  5942. REG_WR(bp, BP_PORT(bp) ?
  5943. NIG_REG_P1_HDRS_AFTER_BASIC :
  5944. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5945. else
  5946. REG_WR(bp, BP_PORT(bp) ?
  5947. NIG_REG_P1_HDRS_AFTER_BASIC :
  5948. NIG_REG_P0_HDRS_AFTER_BASIC,
  5949. IS_MF_SD(bp) ? 7 : 6);
  5950. if (CHIP_IS_E3(bp))
  5951. REG_WR(bp, BP_PORT(bp) ?
  5952. NIG_REG_LLH1_MF_MODE :
  5953. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5954. }
  5955. if (!CHIP_IS_E3(bp))
  5956. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5957. if (!CHIP_IS_E1(bp)) {
  5958. /* 0x2 disable mf_ov, 0x1 enable */
  5959. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5960. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5961. if (!CHIP_IS_E1x(bp)) {
  5962. val = 0;
  5963. switch (bp->mf_mode) {
  5964. case MULTI_FUNCTION_SD:
  5965. val = 1;
  5966. break;
  5967. case MULTI_FUNCTION_SI:
  5968. case MULTI_FUNCTION_AFEX:
  5969. val = 2;
  5970. break;
  5971. }
  5972. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5973. NIG_REG_LLH0_CLS_TYPE), val);
  5974. }
  5975. {
  5976. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5977. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5978. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5979. }
  5980. }
  5981. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5982. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5983. if (val & MISC_SPIO_SPIO5) {
  5984. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5985. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5986. val = REG_RD(bp, reg_addr);
  5987. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5988. REG_WR(bp, reg_addr, val);
  5989. }
  5990. return 0;
  5991. }
  5992. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5993. {
  5994. int reg;
  5995. u32 wb_write[2];
  5996. if (CHIP_IS_E1(bp))
  5997. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5998. else
  5999. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6000. wb_write[0] = ONCHIP_ADDR1(addr);
  6001. wb_write[1] = ONCHIP_ADDR2(addr);
  6002. REG_WR_DMAE(bp, reg, wb_write, 2);
  6003. }
  6004. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6005. {
  6006. u32 data, ctl, cnt = 100;
  6007. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6008. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6009. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6010. u32 sb_bit = 1 << (idu_sb_id%32);
  6011. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6012. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6013. /* Not supported in BC mode */
  6014. if (CHIP_INT_MODE_IS_BC(bp))
  6015. return;
  6016. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6017. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6018. IGU_REGULAR_CLEANUP_SET |
  6019. IGU_REGULAR_BCLEANUP;
  6020. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6021. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6022. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6023. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6024. data, igu_addr_data);
  6025. REG_WR(bp, igu_addr_data, data);
  6026. mmiowb();
  6027. barrier();
  6028. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6029. ctl, igu_addr_ctl);
  6030. REG_WR(bp, igu_addr_ctl, ctl);
  6031. mmiowb();
  6032. barrier();
  6033. /* wait for clean up to finish */
  6034. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6035. msleep(20);
  6036. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6037. DP(NETIF_MSG_HW,
  6038. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6039. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6040. }
  6041. }
  6042. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6043. {
  6044. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6045. }
  6046. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6047. {
  6048. u32 i, base = FUNC_ILT_BASE(func);
  6049. for (i = base; i < base + ILT_PER_FUNC; i++)
  6050. bnx2x_ilt_wr(bp, i, 0);
  6051. }
  6052. static void bnx2x_init_searcher(struct bnx2x *bp)
  6053. {
  6054. int port = BP_PORT(bp);
  6055. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6056. /* T1 hash bits value determines the T1 number of entries */
  6057. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6058. }
  6059. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6060. {
  6061. int rc;
  6062. struct bnx2x_func_state_params func_params = {NULL};
  6063. struct bnx2x_func_switch_update_params *switch_update_params =
  6064. &func_params.params.switch_update;
  6065. /* Prepare parameters for function state transitions */
  6066. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6067. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6068. func_params.f_obj = &bp->func_obj;
  6069. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6070. /* Function parameters */
  6071. switch_update_params->suspend = suspend;
  6072. rc = bnx2x_func_state_change(bp, &func_params);
  6073. return rc;
  6074. }
  6075. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6076. {
  6077. int rc, i, port = BP_PORT(bp);
  6078. int vlan_en = 0, mac_en[NUM_MACS];
  6079. /* Close input from network */
  6080. if (bp->mf_mode == SINGLE_FUNCTION) {
  6081. bnx2x_set_rx_filter(&bp->link_params, 0);
  6082. } else {
  6083. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6084. NIG_REG_LLH0_FUNC_EN);
  6085. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6086. NIG_REG_LLH0_FUNC_EN, 0);
  6087. for (i = 0; i < NUM_MACS; i++) {
  6088. mac_en[i] = REG_RD(bp, port ?
  6089. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6090. 4 * i) :
  6091. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6092. 4 * i));
  6093. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6094. 4 * i) :
  6095. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6096. }
  6097. }
  6098. /* Close BMC to host */
  6099. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6100. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6101. /* Suspend Tx switching to the PF. Completion of this ramrod
  6102. * further guarantees that all the packets of that PF / child
  6103. * VFs in BRB were processed by the Parser, so it is safe to
  6104. * change the NIC_MODE register.
  6105. */
  6106. rc = bnx2x_func_switch_update(bp, 1);
  6107. if (rc) {
  6108. BNX2X_ERR("Can't suspend tx-switching!\n");
  6109. return rc;
  6110. }
  6111. /* Change NIC_MODE register */
  6112. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6113. /* Open input from network */
  6114. if (bp->mf_mode == SINGLE_FUNCTION) {
  6115. bnx2x_set_rx_filter(&bp->link_params, 1);
  6116. } else {
  6117. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6118. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6119. for (i = 0; i < NUM_MACS; i++) {
  6120. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6121. 4 * i) :
  6122. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6123. mac_en[i]);
  6124. }
  6125. }
  6126. /* Enable BMC to host */
  6127. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6128. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6129. /* Resume Tx switching to the PF */
  6130. rc = bnx2x_func_switch_update(bp, 0);
  6131. if (rc) {
  6132. BNX2X_ERR("Can't resume tx-switching!\n");
  6133. return rc;
  6134. }
  6135. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6136. return 0;
  6137. }
  6138. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6139. {
  6140. int rc;
  6141. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6142. if (CONFIGURE_NIC_MODE(bp)) {
  6143. /* Configrue searcher as part of function hw init */
  6144. bnx2x_init_searcher(bp);
  6145. /* Reset NIC mode */
  6146. rc = bnx2x_reset_nic_mode(bp);
  6147. if (rc)
  6148. BNX2X_ERR("Can't change NIC mode!\n");
  6149. return rc;
  6150. }
  6151. return 0;
  6152. }
  6153. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6154. {
  6155. int port = BP_PORT(bp);
  6156. int func = BP_FUNC(bp);
  6157. int init_phase = PHASE_PF0 + func;
  6158. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6159. u16 cdu_ilt_start;
  6160. u32 addr, val;
  6161. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6162. int i, main_mem_width, rc;
  6163. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6164. /* FLR cleanup - hmmm */
  6165. if (!CHIP_IS_E1x(bp)) {
  6166. rc = bnx2x_pf_flr_clnup(bp);
  6167. if (rc)
  6168. return rc;
  6169. }
  6170. /* set MSI reconfigure capability */
  6171. if (bp->common.int_block == INT_BLOCK_HC) {
  6172. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6173. val = REG_RD(bp, addr);
  6174. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6175. REG_WR(bp, addr, val);
  6176. }
  6177. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6178. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6179. ilt = BP_ILT(bp);
  6180. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6181. if (IS_SRIOV(bp))
  6182. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6183. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6184. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6185. * those of the VFs, so start line should be reset
  6186. */
  6187. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6188. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6189. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6190. ilt->lines[cdu_ilt_start + i].page_mapping =
  6191. bp->context[i].cxt_mapping;
  6192. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6193. }
  6194. bnx2x_ilt_init_op(bp, INITOP_SET);
  6195. if (!CONFIGURE_NIC_MODE(bp)) {
  6196. bnx2x_init_searcher(bp);
  6197. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6198. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6199. } else {
  6200. /* Set NIC mode */
  6201. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6202. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6203. }
  6204. if (!CHIP_IS_E1x(bp)) {
  6205. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6206. /* Turn on a single ISR mode in IGU if driver is going to use
  6207. * INT#x or MSI
  6208. */
  6209. if (!(bp->flags & USING_MSIX_FLAG))
  6210. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6211. /*
  6212. * Timers workaround bug: function init part.
  6213. * Need to wait 20msec after initializing ILT,
  6214. * needed to make sure there are no requests in
  6215. * one of the PXP internal queues with "old" ILT addresses
  6216. */
  6217. msleep(20);
  6218. /*
  6219. * Master enable - Due to WB DMAE writes performed before this
  6220. * register is re-initialized as part of the regular function
  6221. * init
  6222. */
  6223. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6224. /* Enable the function in IGU */
  6225. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6226. }
  6227. bp->dmae_ready = 1;
  6228. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6229. if (!CHIP_IS_E1x(bp))
  6230. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6231. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6232. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6233. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6234. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6235. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6236. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6237. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6238. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6239. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6240. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6241. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6242. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6243. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6244. if (!CHIP_IS_E1x(bp))
  6245. REG_WR(bp, QM_REG_PF_EN, 1);
  6246. if (!CHIP_IS_E1x(bp)) {
  6247. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6248. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6249. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6250. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6251. }
  6252. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6253. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6254. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6255. bnx2x_iov_init_dq(bp);
  6256. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6257. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6258. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6259. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6260. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6261. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6262. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6263. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6264. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6265. if (!CHIP_IS_E1x(bp))
  6266. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6267. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6268. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6269. if (!CHIP_IS_E1x(bp))
  6270. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6271. if (IS_MF(bp)) {
  6272. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6273. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6274. }
  6275. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6276. /* HC init per function */
  6277. if (bp->common.int_block == INT_BLOCK_HC) {
  6278. if (CHIP_IS_E1H(bp)) {
  6279. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6280. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6281. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6282. }
  6283. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6284. } else {
  6285. int num_segs, sb_idx, prod_offset;
  6286. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6287. if (!CHIP_IS_E1x(bp)) {
  6288. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6289. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6290. }
  6291. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6292. if (!CHIP_IS_E1x(bp)) {
  6293. int dsb_idx = 0;
  6294. /**
  6295. * Producer memory:
  6296. * E2 mode: address 0-135 match to the mapping memory;
  6297. * 136 - PF0 default prod; 137 - PF1 default prod;
  6298. * 138 - PF2 default prod; 139 - PF3 default prod;
  6299. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6300. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6301. * 144-147 reserved.
  6302. *
  6303. * E1.5 mode - In backward compatible mode;
  6304. * for non default SB; each even line in the memory
  6305. * holds the U producer and each odd line hold
  6306. * the C producer. The first 128 producers are for
  6307. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6308. * producers are for the DSB for each PF.
  6309. * Each PF has five segments: (the order inside each
  6310. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6311. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6312. * 144-147 attn prods;
  6313. */
  6314. /* non-default-status-blocks */
  6315. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6316. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6317. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6318. prod_offset = (bp->igu_base_sb + sb_idx) *
  6319. num_segs;
  6320. for (i = 0; i < num_segs; i++) {
  6321. addr = IGU_REG_PROD_CONS_MEMORY +
  6322. (prod_offset + i) * 4;
  6323. REG_WR(bp, addr, 0);
  6324. }
  6325. /* send consumer update with value 0 */
  6326. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6327. USTORM_ID, 0, IGU_INT_NOP, 1);
  6328. bnx2x_igu_clear_sb(bp,
  6329. bp->igu_base_sb + sb_idx);
  6330. }
  6331. /* default-status-blocks */
  6332. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6333. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6334. if (CHIP_MODE_IS_4_PORT(bp))
  6335. dsb_idx = BP_FUNC(bp);
  6336. else
  6337. dsb_idx = BP_VN(bp);
  6338. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6339. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6340. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6341. /*
  6342. * igu prods come in chunks of E1HVN_MAX (4) -
  6343. * does not matters what is the current chip mode
  6344. */
  6345. for (i = 0; i < (num_segs * E1HVN_MAX);
  6346. i += E1HVN_MAX) {
  6347. addr = IGU_REG_PROD_CONS_MEMORY +
  6348. (prod_offset + i)*4;
  6349. REG_WR(bp, addr, 0);
  6350. }
  6351. /* send consumer update with 0 */
  6352. if (CHIP_INT_MODE_IS_BC(bp)) {
  6353. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6354. USTORM_ID, 0, IGU_INT_NOP, 1);
  6355. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6356. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6357. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6358. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6359. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6360. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6361. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6362. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6363. } else {
  6364. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6365. USTORM_ID, 0, IGU_INT_NOP, 1);
  6366. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6367. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6368. }
  6369. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6370. /* !!! these should become driver const once
  6371. rf-tool supports split-68 const */
  6372. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6373. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6374. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6375. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6376. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6377. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6378. }
  6379. }
  6380. /* Reset PCIE errors for debug */
  6381. REG_WR(bp, 0x2114, 0xffffffff);
  6382. REG_WR(bp, 0x2120, 0xffffffff);
  6383. if (CHIP_IS_E1x(bp)) {
  6384. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6385. main_mem_base = HC_REG_MAIN_MEMORY +
  6386. BP_PORT(bp) * (main_mem_size * 4);
  6387. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6388. main_mem_width = 8;
  6389. val = REG_RD(bp, main_mem_prty_clr);
  6390. if (val)
  6391. DP(NETIF_MSG_HW,
  6392. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6393. val);
  6394. /* Clear "false" parity errors in MSI-X table */
  6395. for (i = main_mem_base;
  6396. i < main_mem_base + main_mem_size * 4;
  6397. i += main_mem_width) {
  6398. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6399. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6400. i, main_mem_width / 4);
  6401. }
  6402. /* Clear HC parity attention */
  6403. REG_RD(bp, main_mem_prty_clr);
  6404. }
  6405. #ifdef BNX2X_STOP_ON_ERROR
  6406. /* Enable STORMs SP logging */
  6407. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6408. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6409. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6410. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6411. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6412. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6413. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6414. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6415. #endif
  6416. bnx2x_phy_probe(&bp->link_params);
  6417. return 0;
  6418. }
  6419. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6420. {
  6421. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6422. if (!CHIP_IS_E1x(bp))
  6423. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6424. sizeof(struct host_hc_status_block_e2));
  6425. else
  6426. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6427. sizeof(struct host_hc_status_block_e1x));
  6428. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6429. }
  6430. void bnx2x_free_mem(struct bnx2x *bp)
  6431. {
  6432. int i;
  6433. /* fastpath */
  6434. bnx2x_free_fp_mem(bp);
  6435. /* end of fastpath */
  6436. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6437. sizeof(struct host_sp_status_block));
  6438. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6439. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6440. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6441. sizeof(struct bnx2x_slowpath));
  6442. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6443. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6444. bp->context[i].size);
  6445. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6446. BNX2X_FREE(bp->ilt->lines);
  6447. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6448. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6449. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6450. }
  6451. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6452. {
  6453. if (!CHIP_IS_E1x(bp))
  6454. /* size = the status block + ramrod buffers */
  6455. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6456. sizeof(struct host_hc_status_block_e2));
  6457. else
  6458. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6459. &bp->cnic_sb_mapping,
  6460. sizeof(struct
  6461. host_hc_status_block_e1x));
  6462. if (CONFIGURE_NIC_MODE(bp))
  6463. /* allocate searcher T2 table, as it wan't allocated before */
  6464. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6465. /* write address to which L5 should insert its values */
  6466. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6467. &bp->slowpath->drv_info_to_mcp;
  6468. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6469. goto alloc_mem_err;
  6470. return 0;
  6471. alloc_mem_err:
  6472. bnx2x_free_mem_cnic(bp);
  6473. BNX2X_ERR("Can't allocate memory\n");
  6474. return -ENOMEM;
  6475. }
  6476. int bnx2x_alloc_mem(struct bnx2x *bp)
  6477. {
  6478. int i, allocated, context_size;
  6479. if (!CONFIGURE_NIC_MODE(bp))
  6480. /* allocate searcher T2 table */
  6481. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6482. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6483. sizeof(struct host_sp_status_block));
  6484. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6485. sizeof(struct bnx2x_slowpath));
  6486. /* Allocate memory for CDU context:
  6487. * This memory is allocated separately and not in the generic ILT
  6488. * functions because CDU differs in few aspects:
  6489. * 1. There are multiple entities allocating memory for context -
  6490. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6491. * its own ILT lines.
  6492. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6493. * for the other ILT clients), to be efficient we want to support
  6494. * allocation of sub-page-size in the last entry.
  6495. * 3. Context pointers are used by the driver to pass to FW / update
  6496. * the context (for the other ILT clients the pointers are used just to
  6497. * free the memory during unload).
  6498. */
  6499. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6500. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6501. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6502. (context_size - allocated));
  6503. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6504. &bp->context[i].cxt_mapping,
  6505. bp->context[i].size);
  6506. allocated += bp->context[i].size;
  6507. }
  6508. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6509. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6510. goto alloc_mem_err;
  6511. if (bnx2x_iov_alloc_mem(bp))
  6512. goto alloc_mem_err;
  6513. /* Slow path ring */
  6514. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6515. /* EQ */
  6516. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6517. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6518. return 0;
  6519. alloc_mem_err:
  6520. bnx2x_free_mem(bp);
  6521. BNX2X_ERR("Can't allocate memory\n");
  6522. return -ENOMEM;
  6523. }
  6524. /*
  6525. * Init service functions
  6526. */
  6527. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6528. struct bnx2x_vlan_mac_obj *obj, bool set,
  6529. int mac_type, unsigned long *ramrod_flags)
  6530. {
  6531. int rc;
  6532. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6533. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6534. /* Fill general parameters */
  6535. ramrod_param.vlan_mac_obj = obj;
  6536. ramrod_param.ramrod_flags = *ramrod_flags;
  6537. /* Fill a user request section if needed */
  6538. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6539. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6540. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6541. /* Set the command: ADD or DEL */
  6542. if (set)
  6543. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6544. else
  6545. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6546. }
  6547. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6548. if (rc == -EEXIST) {
  6549. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6550. /* do not treat adding same MAC as error */
  6551. rc = 0;
  6552. } else if (rc < 0)
  6553. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6554. return rc;
  6555. }
  6556. int bnx2x_del_all_macs(struct bnx2x *bp,
  6557. struct bnx2x_vlan_mac_obj *mac_obj,
  6558. int mac_type, bool wait_for_comp)
  6559. {
  6560. int rc;
  6561. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6562. /* Wait for completion of requested */
  6563. if (wait_for_comp)
  6564. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6565. /* Set the mac type of addresses we want to clear */
  6566. __set_bit(mac_type, &vlan_mac_flags);
  6567. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6568. if (rc < 0)
  6569. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6570. return rc;
  6571. }
  6572. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6573. {
  6574. unsigned long ramrod_flags = 0;
  6575. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6576. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6577. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6578. "Ignoring Zero MAC for STORAGE SD mode\n");
  6579. return 0;
  6580. }
  6581. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6582. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6583. /* Eth MAC is set on RSS leading client (fp[0]) */
  6584. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6585. set, BNX2X_ETH_MAC, &ramrod_flags);
  6586. }
  6587. int bnx2x_setup_leading(struct bnx2x *bp)
  6588. {
  6589. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6590. }
  6591. /**
  6592. * bnx2x_set_int_mode - configure interrupt mode
  6593. *
  6594. * @bp: driver handle
  6595. *
  6596. * In case of MSI-X it will also try to enable MSI-X.
  6597. */
  6598. int bnx2x_set_int_mode(struct bnx2x *bp)
  6599. {
  6600. int rc = 0;
  6601. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6602. return -EINVAL;
  6603. switch (int_mode) {
  6604. case BNX2X_INT_MODE_MSIX:
  6605. /* attempt to enable msix */
  6606. rc = bnx2x_enable_msix(bp);
  6607. /* msix attained */
  6608. if (!rc)
  6609. return 0;
  6610. /* vfs use only msix */
  6611. if (rc && IS_VF(bp))
  6612. return rc;
  6613. /* failed to enable multiple MSI-X */
  6614. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6615. bp->num_queues,
  6616. 1 + bp->num_cnic_queues);
  6617. /* falling through... */
  6618. case BNX2X_INT_MODE_MSI:
  6619. bnx2x_enable_msi(bp);
  6620. /* falling through... */
  6621. case BNX2X_INT_MODE_INTX:
  6622. bp->num_ethernet_queues = 1;
  6623. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6624. BNX2X_DEV_INFO("set number of queues to 1\n");
  6625. break;
  6626. default:
  6627. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6628. return -EINVAL;
  6629. }
  6630. return 0;
  6631. }
  6632. /* must be called prior to any HW initializations */
  6633. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6634. {
  6635. if (IS_SRIOV(bp))
  6636. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6637. return L2_ILT_LINES(bp);
  6638. }
  6639. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6640. {
  6641. struct ilt_client_info *ilt_client;
  6642. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6643. u16 line = 0;
  6644. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6645. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6646. /* CDU */
  6647. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6648. ilt_client->client_num = ILT_CLIENT_CDU;
  6649. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6650. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6651. ilt_client->start = line;
  6652. line += bnx2x_cid_ilt_lines(bp);
  6653. if (CNIC_SUPPORT(bp))
  6654. line += CNIC_ILT_LINES;
  6655. ilt_client->end = line - 1;
  6656. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6657. ilt_client->start,
  6658. ilt_client->end,
  6659. ilt_client->page_size,
  6660. ilt_client->flags,
  6661. ilog2(ilt_client->page_size >> 12));
  6662. /* QM */
  6663. if (QM_INIT(bp->qm_cid_count)) {
  6664. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6665. ilt_client->client_num = ILT_CLIENT_QM;
  6666. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6667. ilt_client->flags = 0;
  6668. ilt_client->start = line;
  6669. /* 4 bytes for each cid */
  6670. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6671. QM_ILT_PAGE_SZ);
  6672. ilt_client->end = line - 1;
  6673. DP(NETIF_MSG_IFUP,
  6674. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6675. ilt_client->start,
  6676. ilt_client->end,
  6677. ilt_client->page_size,
  6678. ilt_client->flags,
  6679. ilog2(ilt_client->page_size >> 12));
  6680. }
  6681. if (CNIC_SUPPORT(bp)) {
  6682. /* SRC */
  6683. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6684. ilt_client->client_num = ILT_CLIENT_SRC;
  6685. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6686. ilt_client->flags = 0;
  6687. ilt_client->start = line;
  6688. line += SRC_ILT_LINES;
  6689. ilt_client->end = line - 1;
  6690. DP(NETIF_MSG_IFUP,
  6691. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6692. ilt_client->start,
  6693. ilt_client->end,
  6694. ilt_client->page_size,
  6695. ilt_client->flags,
  6696. ilog2(ilt_client->page_size >> 12));
  6697. /* TM */
  6698. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6699. ilt_client->client_num = ILT_CLIENT_TM;
  6700. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6701. ilt_client->flags = 0;
  6702. ilt_client->start = line;
  6703. line += TM_ILT_LINES;
  6704. ilt_client->end = line - 1;
  6705. DP(NETIF_MSG_IFUP,
  6706. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6707. ilt_client->start,
  6708. ilt_client->end,
  6709. ilt_client->page_size,
  6710. ilt_client->flags,
  6711. ilog2(ilt_client->page_size >> 12));
  6712. }
  6713. BUG_ON(line > ILT_MAX_LINES);
  6714. }
  6715. /**
  6716. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6717. *
  6718. * @bp: driver handle
  6719. * @fp: pointer to fastpath
  6720. * @init_params: pointer to parameters structure
  6721. *
  6722. * parameters configured:
  6723. * - HC configuration
  6724. * - Queue's CDU context
  6725. */
  6726. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6727. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6728. {
  6729. u8 cos;
  6730. int cxt_index, cxt_offset;
  6731. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6732. if (!IS_FCOE_FP(fp)) {
  6733. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6734. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6735. /* If HC is supporterd, enable host coalescing in the transition
  6736. * to INIT state.
  6737. */
  6738. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6739. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6740. /* HC rate */
  6741. init_params->rx.hc_rate = bp->rx_ticks ?
  6742. (1000000 / bp->rx_ticks) : 0;
  6743. init_params->tx.hc_rate = bp->tx_ticks ?
  6744. (1000000 / bp->tx_ticks) : 0;
  6745. /* FW SB ID */
  6746. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6747. fp->fw_sb_id;
  6748. /*
  6749. * CQ index among the SB indices: FCoE clients uses the default
  6750. * SB, therefore it's different.
  6751. */
  6752. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6753. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6754. }
  6755. /* set maximum number of COSs supported by this queue */
  6756. init_params->max_cos = fp->max_cos;
  6757. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6758. fp->index, init_params->max_cos);
  6759. /* set the context pointers queue object */
  6760. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6761. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6762. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6763. ILT_PAGE_CIDS);
  6764. init_params->cxts[cos] =
  6765. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6766. }
  6767. }
  6768. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6769. struct bnx2x_queue_state_params *q_params,
  6770. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6771. int tx_index, bool leading)
  6772. {
  6773. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6774. /* Set the command */
  6775. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6776. /* Set tx-only QUEUE flags: don't zero statistics */
  6777. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6778. /* choose the index of the cid to send the slow path on */
  6779. tx_only_params->cid_index = tx_index;
  6780. /* Set general TX_ONLY_SETUP parameters */
  6781. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6782. /* Set Tx TX_ONLY_SETUP parameters */
  6783. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6784. DP(NETIF_MSG_IFUP,
  6785. "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",
  6786. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6787. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6788. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6789. /* send the ramrod */
  6790. return bnx2x_queue_state_change(bp, q_params);
  6791. }
  6792. /**
  6793. * bnx2x_setup_queue - setup queue
  6794. *
  6795. * @bp: driver handle
  6796. * @fp: pointer to fastpath
  6797. * @leading: is leading
  6798. *
  6799. * This function performs 2 steps in a Queue state machine
  6800. * actually: 1) RESET->INIT 2) INIT->SETUP
  6801. */
  6802. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6803. bool leading)
  6804. {
  6805. struct bnx2x_queue_state_params q_params = {NULL};
  6806. struct bnx2x_queue_setup_params *setup_params =
  6807. &q_params.params.setup;
  6808. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6809. &q_params.params.tx_only;
  6810. int rc;
  6811. u8 tx_index;
  6812. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6813. /* reset IGU state skip FCoE L2 queue */
  6814. if (!IS_FCOE_FP(fp))
  6815. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6816. IGU_INT_ENABLE, 0);
  6817. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6818. /* We want to wait for completion in this context */
  6819. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6820. /* Prepare the INIT parameters */
  6821. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6822. /* Set the command */
  6823. q_params.cmd = BNX2X_Q_CMD_INIT;
  6824. /* Change the state to INIT */
  6825. rc = bnx2x_queue_state_change(bp, &q_params);
  6826. if (rc) {
  6827. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6828. return rc;
  6829. }
  6830. DP(NETIF_MSG_IFUP, "init complete\n");
  6831. /* Now move the Queue to the SETUP state... */
  6832. memset(setup_params, 0, sizeof(*setup_params));
  6833. /* Set QUEUE flags */
  6834. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6835. /* Set general SETUP parameters */
  6836. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6837. FIRST_TX_COS_INDEX);
  6838. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6839. &setup_params->rxq_params);
  6840. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6841. FIRST_TX_COS_INDEX);
  6842. /* Set the command */
  6843. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6844. if (IS_FCOE_FP(fp))
  6845. bp->fcoe_init = true;
  6846. /* Change the state to SETUP */
  6847. rc = bnx2x_queue_state_change(bp, &q_params);
  6848. if (rc) {
  6849. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6850. return rc;
  6851. }
  6852. /* loop through the relevant tx-only indices */
  6853. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6854. tx_index < fp->max_cos;
  6855. tx_index++) {
  6856. /* prepare and send tx-only ramrod*/
  6857. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6858. tx_only_params, tx_index, leading);
  6859. if (rc) {
  6860. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6861. fp->index, tx_index);
  6862. return rc;
  6863. }
  6864. }
  6865. return rc;
  6866. }
  6867. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6868. {
  6869. struct bnx2x_fastpath *fp = &bp->fp[index];
  6870. struct bnx2x_fp_txdata *txdata;
  6871. struct bnx2x_queue_state_params q_params = {NULL};
  6872. int rc, tx_index;
  6873. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6874. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6875. /* We want to wait for completion in this context */
  6876. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6877. /* close tx-only connections */
  6878. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6879. tx_index < fp->max_cos;
  6880. tx_index++){
  6881. /* ascertain this is a normal queue*/
  6882. txdata = fp->txdata_ptr[tx_index];
  6883. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6884. txdata->txq_index);
  6885. /* send halt terminate on tx-only connection */
  6886. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6887. memset(&q_params.params.terminate, 0,
  6888. sizeof(q_params.params.terminate));
  6889. q_params.params.terminate.cid_index = tx_index;
  6890. rc = bnx2x_queue_state_change(bp, &q_params);
  6891. if (rc)
  6892. return rc;
  6893. /* send halt terminate on tx-only connection */
  6894. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6895. memset(&q_params.params.cfc_del, 0,
  6896. sizeof(q_params.params.cfc_del));
  6897. q_params.params.cfc_del.cid_index = tx_index;
  6898. rc = bnx2x_queue_state_change(bp, &q_params);
  6899. if (rc)
  6900. return rc;
  6901. }
  6902. /* Stop the primary connection: */
  6903. /* ...halt the connection */
  6904. q_params.cmd = BNX2X_Q_CMD_HALT;
  6905. rc = bnx2x_queue_state_change(bp, &q_params);
  6906. if (rc)
  6907. return rc;
  6908. /* ...terminate the connection */
  6909. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6910. memset(&q_params.params.terminate, 0,
  6911. sizeof(q_params.params.terminate));
  6912. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6913. rc = bnx2x_queue_state_change(bp, &q_params);
  6914. if (rc)
  6915. return rc;
  6916. /* ...delete cfc entry */
  6917. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6918. memset(&q_params.params.cfc_del, 0,
  6919. sizeof(q_params.params.cfc_del));
  6920. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6921. return bnx2x_queue_state_change(bp, &q_params);
  6922. }
  6923. static void bnx2x_reset_func(struct bnx2x *bp)
  6924. {
  6925. int port = BP_PORT(bp);
  6926. int func = BP_FUNC(bp);
  6927. int i;
  6928. /* Disable the function in the FW */
  6929. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6930. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6931. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6932. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6933. /* FP SBs */
  6934. for_each_eth_queue(bp, i) {
  6935. struct bnx2x_fastpath *fp = &bp->fp[i];
  6936. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6937. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6938. SB_DISABLED);
  6939. }
  6940. if (CNIC_LOADED(bp))
  6941. /* CNIC SB */
  6942. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6943. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6944. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6945. /* SP SB */
  6946. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6947. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6948. SB_DISABLED);
  6949. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6950. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6951. 0);
  6952. /* Configure IGU */
  6953. if (bp->common.int_block == INT_BLOCK_HC) {
  6954. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6955. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6956. } else {
  6957. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6958. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6959. }
  6960. if (CNIC_LOADED(bp)) {
  6961. /* Disable Timer scan */
  6962. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6963. /*
  6964. * Wait for at least 10ms and up to 2 second for the timers
  6965. * scan to complete
  6966. */
  6967. for (i = 0; i < 200; i++) {
  6968. msleep(10);
  6969. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6970. break;
  6971. }
  6972. }
  6973. /* Clear ILT */
  6974. bnx2x_clear_func_ilt(bp, func);
  6975. /* Timers workaround bug for E2: if this is vnic-3,
  6976. * we need to set the entire ilt range for this timers.
  6977. */
  6978. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6979. struct ilt_client_info ilt_cli;
  6980. /* use dummy TM client */
  6981. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6982. ilt_cli.start = 0;
  6983. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6984. ilt_cli.client_num = ILT_CLIENT_TM;
  6985. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6986. }
  6987. /* this assumes that reset_port() called before reset_func()*/
  6988. if (!CHIP_IS_E1x(bp))
  6989. bnx2x_pf_disable(bp);
  6990. bp->dmae_ready = 0;
  6991. }
  6992. static void bnx2x_reset_port(struct bnx2x *bp)
  6993. {
  6994. int port = BP_PORT(bp);
  6995. u32 val;
  6996. /* Reset physical Link */
  6997. bnx2x__link_reset(bp);
  6998. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6999. /* Do not rcv packets to BRB */
  7000. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7001. /* Do not direct rcv packets that are not for MCP to the BRB */
  7002. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7003. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7004. /* Configure AEU */
  7005. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7006. msleep(100);
  7007. /* Check for BRB port occupancy */
  7008. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7009. if (val)
  7010. DP(NETIF_MSG_IFDOWN,
  7011. "BRB1 is not empty %d blocks are occupied\n", val);
  7012. /* TODO: Close Doorbell port? */
  7013. }
  7014. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7015. {
  7016. struct bnx2x_func_state_params func_params = {NULL};
  7017. /* Prepare parameters for function state transitions */
  7018. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7019. func_params.f_obj = &bp->func_obj;
  7020. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7021. func_params.params.hw_init.load_phase = load_code;
  7022. return bnx2x_func_state_change(bp, &func_params);
  7023. }
  7024. static int bnx2x_func_stop(struct bnx2x *bp)
  7025. {
  7026. struct bnx2x_func_state_params func_params = {NULL};
  7027. int rc;
  7028. /* Prepare parameters for function state transitions */
  7029. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7030. func_params.f_obj = &bp->func_obj;
  7031. func_params.cmd = BNX2X_F_CMD_STOP;
  7032. /*
  7033. * Try to stop the function the 'good way'. If fails (in case
  7034. * of a parity error during bnx2x_chip_cleanup()) and we are
  7035. * not in a debug mode, perform a state transaction in order to
  7036. * enable further HW_RESET transaction.
  7037. */
  7038. rc = bnx2x_func_state_change(bp, &func_params);
  7039. if (rc) {
  7040. #ifdef BNX2X_STOP_ON_ERROR
  7041. return rc;
  7042. #else
  7043. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7044. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7045. return bnx2x_func_state_change(bp, &func_params);
  7046. #endif
  7047. }
  7048. return 0;
  7049. }
  7050. /**
  7051. * bnx2x_send_unload_req - request unload mode from the MCP.
  7052. *
  7053. * @bp: driver handle
  7054. * @unload_mode: requested function's unload mode
  7055. *
  7056. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7057. */
  7058. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7059. {
  7060. u32 reset_code = 0;
  7061. int port = BP_PORT(bp);
  7062. /* Select the UNLOAD request mode */
  7063. if (unload_mode == UNLOAD_NORMAL)
  7064. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7065. else if (bp->flags & NO_WOL_FLAG)
  7066. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7067. else if (bp->wol) {
  7068. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7069. u8 *mac_addr = bp->dev->dev_addr;
  7070. u32 val;
  7071. u16 pmc;
  7072. /* The mac address is written to entries 1-4 to
  7073. * preserve entry 0 which is used by the PMF
  7074. */
  7075. u8 entry = (BP_VN(bp) + 1)*8;
  7076. val = (mac_addr[0] << 8) | mac_addr[1];
  7077. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7078. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7079. (mac_addr[4] << 8) | mac_addr[5];
  7080. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7081. /* Enable the PME and clear the status */
  7082. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7083. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7084. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7085. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7086. } else
  7087. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7088. /* Send the request to the MCP */
  7089. if (!BP_NOMCP(bp))
  7090. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7091. else {
  7092. int path = BP_PATH(bp);
  7093. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7094. path, load_count[path][0], load_count[path][1],
  7095. load_count[path][2]);
  7096. load_count[path][0]--;
  7097. load_count[path][1 + port]--;
  7098. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7099. path, load_count[path][0], load_count[path][1],
  7100. load_count[path][2]);
  7101. if (load_count[path][0] == 0)
  7102. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7103. else if (load_count[path][1 + port] == 0)
  7104. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7105. else
  7106. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7107. }
  7108. return reset_code;
  7109. }
  7110. /**
  7111. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7112. *
  7113. * @bp: driver handle
  7114. * @keep_link: true iff link should be kept up
  7115. */
  7116. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7117. {
  7118. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7119. /* Report UNLOAD_DONE to MCP */
  7120. if (!BP_NOMCP(bp))
  7121. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7122. }
  7123. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7124. {
  7125. int tout = 50;
  7126. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7127. if (!bp->port.pmf)
  7128. return 0;
  7129. /*
  7130. * (assumption: No Attention from MCP at this stage)
  7131. * PMF probably in the middle of TXdisable/enable transaction
  7132. * 1. Sync IRS for default SB
  7133. * 2. Sync SP queue - this guarantes us that attention handling started
  7134. * 3. Wait, that TXdisable/enable transaction completes
  7135. *
  7136. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7137. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7138. * received complettion for the transaction the state is TX_STOPPED.
  7139. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7140. * transaction.
  7141. */
  7142. /* make sure default SB ISR is done */
  7143. if (msix)
  7144. synchronize_irq(bp->msix_table[0].vector);
  7145. else
  7146. synchronize_irq(bp->pdev->irq);
  7147. flush_workqueue(bnx2x_wq);
  7148. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7149. BNX2X_F_STATE_STARTED && tout--)
  7150. msleep(20);
  7151. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7152. BNX2X_F_STATE_STARTED) {
  7153. #ifdef BNX2X_STOP_ON_ERROR
  7154. BNX2X_ERR("Wrong function state\n");
  7155. return -EBUSY;
  7156. #else
  7157. /*
  7158. * Failed to complete the transaction in a "good way"
  7159. * Force both transactions with CLR bit
  7160. */
  7161. struct bnx2x_func_state_params func_params = {NULL};
  7162. DP(NETIF_MSG_IFDOWN,
  7163. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7164. func_params.f_obj = &bp->func_obj;
  7165. __set_bit(RAMROD_DRV_CLR_ONLY,
  7166. &func_params.ramrod_flags);
  7167. /* STARTED-->TX_ST0PPED */
  7168. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7169. bnx2x_func_state_change(bp, &func_params);
  7170. /* TX_ST0PPED-->STARTED */
  7171. func_params.cmd = BNX2X_F_CMD_TX_START;
  7172. return bnx2x_func_state_change(bp, &func_params);
  7173. #endif
  7174. }
  7175. return 0;
  7176. }
  7177. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7178. {
  7179. int port = BP_PORT(bp);
  7180. int i, rc = 0;
  7181. u8 cos;
  7182. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7183. u32 reset_code;
  7184. /* Wait until tx fastpath tasks complete */
  7185. for_each_tx_queue(bp, i) {
  7186. struct bnx2x_fastpath *fp = &bp->fp[i];
  7187. for_each_cos_in_tx_queue(fp, cos)
  7188. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7189. #ifdef BNX2X_STOP_ON_ERROR
  7190. if (rc)
  7191. return;
  7192. #endif
  7193. }
  7194. /* Give HW time to discard old tx messages */
  7195. usleep_range(1000, 1000);
  7196. /* Clean all ETH MACs */
  7197. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7198. false);
  7199. if (rc < 0)
  7200. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7201. /* Clean up UC list */
  7202. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7203. true);
  7204. if (rc < 0)
  7205. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7206. rc);
  7207. /* Disable LLH */
  7208. if (!CHIP_IS_E1(bp))
  7209. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7210. /* Set "drop all" (stop Rx).
  7211. * We need to take a netif_addr_lock() here in order to prevent
  7212. * a race between the completion code and this code.
  7213. */
  7214. netif_addr_lock_bh(bp->dev);
  7215. /* Schedule the rx_mode command */
  7216. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7217. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7218. else
  7219. bnx2x_set_storm_rx_mode(bp);
  7220. /* Cleanup multicast configuration */
  7221. rparam.mcast_obj = &bp->mcast_obj;
  7222. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7223. if (rc < 0)
  7224. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7225. netif_addr_unlock_bh(bp->dev);
  7226. bnx2x_iov_chip_cleanup(bp);
  7227. /*
  7228. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7229. * this function should perform FUNC, PORT or COMMON HW
  7230. * reset.
  7231. */
  7232. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7233. /*
  7234. * (assumption: No Attention from MCP at this stage)
  7235. * PMF probably in the middle of TXdisable/enable transaction
  7236. */
  7237. rc = bnx2x_func_wait_started(bp);
  7238. if (rc) {
  7239. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7240. #ifdef BNX2X_STOP_ON_ERROR
  7241. return;
  7242. #endif
  7243. }
  7244. /* Close multi and leading connections
  7245. * Completions for ramrods are collected in a synchronous way
  7246. */
  7247. for_each_eth_queue(bp, i)
  7248. if (bnx2x_stop_queue(bp, i))
  7249. #ifdef BNX2X_STOP_ON_ERROR
  7250. return;
  7251. #else
  7252. goto unload_error;
  7253. #endif
  7254. if (CNIC_LOADED(bp)) {
  7255. for_each_cnic_queue(bp, i)
  7256. if (bnx2x_stop_queue(bp, i))
  7257. #ifdef BNX2X_STOP_ON_ERROR
  7258. return;
  7259. #else
  7260. goto unload_error;
  7261. #endif
  7262. }
  7263. /* If SP settings didn't get completed so far - something
  7264. * very wrong has happen.
  7265. */
  7266. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7267. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7268. #ifndef BNX2X_STOP_ON_ERROR
  7269. unload_error:
  7270. #endif
  7271. rc = bnx2x_func_stop(bp);
  7272. if (rc) {
  7273. BNX2X_ERR("Function stop failed!\n");
  7274. #ifdef BNX2X_STOP_ON_ERROR
  7275. return;
  7276. #endif
  7277. }
  7278. /* Disable HW interrupts, NAPI */
  7279. bnx2x_netif_stop(bp, 1);
  7280. /* Delete all NAPI objects */
  7281. bnx2x_del_all_napi(bp);
  7282. if (CNIC_LOADED(bp))
  7283. bnx2x_del_all_napi_cnic(bp);
  7284. /* Release IRQs */
  7285. bnx2x_free_irq(bp);
  7286. /* Reset the chip */
  7287. rc = bnx2x_reset_hw(bp, reset_code);
  7288. if (rc)
  7289. BNX2X_ERR("HW_RESET failed\n");
  7290. /* Report UNLOAD_DONE to MCP */
  7291. bnx2x_send_unload_done(bp, keep_link);
  7292. }
  7293. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7294. {
  7295. u32 val;
  7296. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7297. if (CHIP_IS_E1(bp)) {
  7298. int port = BP_PORT(bp);
  7299. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7300. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7301. val = REG_RD(bp, addr);
  7302. val &= ~(0x300);
  7303. REG_WR(bp, addr, val);
  7304. } else {
  7305. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7306. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7307. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7308. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7309. }
  7310. }
  7311. /* Close gates #2, #3 and #4: */
  7312. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7313. {
  7314. u32 val;
  7315. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7316. if (!CHIP_IS_E1(bp)) {
  7317. /* #4 */
  7318. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7319. /* #2 */
  7320. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7321. }
  7322. /* #3 */
  7323. if (CHIP_IS_E1x(bp)) {
  7324. /* Prevent interrupts from HC on both ports */
  7325. val = REG_RD(bp, HC_REG_CONFIG_1);
  7326. REG_WR(bp, HC_REG_CONFIG_1,
  7327. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7328. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7329. val = REG_RD(bp, HC_REG_CONFIG_0);
  7330. REG_WR(bp, HC_REG_CONFIG_0,
  7331. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7332. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7333. } else {
  7334. /* Prevent incomming interrupts in IGU */
  7335. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7336. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7337. (!close) ?
  7338. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7339. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7340. }
  7341. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7342. close ? "closing" : "opening");
  7343. mmiowb();
  7344. }
  7345. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7346. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7347. {
  7348. /* Do some magic... */
  7349. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7350. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7351. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7352. }
  7353. /**
  7354. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7355. *
  7356. * @bp: driver handle
  7357. * @magic_val: old value of the `magic' bit.
  7358. */
  7359. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7360. {
  7361. /* Restore the `magic' bit value... */
  7362. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7363. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7364. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7365. }
  7366. /**
  7367. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7368. *
  7369. * @bp: driver handle
  7370. * @magic_val: old value of 'magic' bit.
  7371. *
  7372. * Takes care of CLP configurations.
  7373. */
  7374. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7375. {
  7376. u32 shmem;
  7377. u32 validity_offset;
  7378. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7379. /* Set `magic' bit in order to save MF config */
  7380. if (!CHIP_IS_E1(bp))
  7381. bnx2x_clp_reset_prep(bp, magic_val);
  7382. /* Get shmem offset */
  7383. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7384. validity_offset =
  7385. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7386. /* Clear validity map flags */
  7387. if (shmem > 0)
  7388. REG_WR(bp, shmem + validity_offset, 0);
  7389. }
  7390. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7391. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7392. /**
  7393. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7394. *
  7395. * @bp: driver handle
  7396. */
  7397. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7398. {
  7399. /* special handling for emulation and FPGA,
  7400. wait 10 times longer */
  7401. if (CHIP_REV_IS_SLOW(bp))
  7402. msleep(MCP_ONE_TIMEOUT*10);
  7403. else
  7404. msleep(MCP_ONE_TIMEOUT);
  7405. }
  7406. /*
  7407. * initializes bp->common.shmem_base and waits for validity signature to appear
  7408. */
  7409. static int bnx2x_init_shmem(struct bnx2x *bp)
  7410. {
  7411. int cnt = 0;
  7412. u32 val = 0;
  7413. do {
  7414. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7415. if (bp->common.shmem_base) {
  7416. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7417. if (val & SHR_MEM_VALIDITY_MB)
  7418. return 0;
  7419. }
  7420. bnx2x_mcp_wait_one(bp);
  7421. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7422. BNX2X_ERR("BAD MCP validity signature\n");
  7423. return -ENODEV;
  7424. }
  7425. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7426. {
  7427. int rc = bnx2x_init_shmem(bp);
  7428. /* Restore the `magic' bit value */
  7429. if (!CHIP_IS_E1(bp))
  7430. bnx2x_clp_reset_done(bp, magic_val);
  7431. return rc;
  7432. }
  7433. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7434. {
  7435. if (!CHIP_IS_E1(bp)) {
  7436. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7437. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7438. mmiowb();
  7439. }
  7440. }
  7441. /*
  7442. * Reset the whole chip except for:
  7443. * - PCIE core
  7444. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7445. * one reset bit)
  7446. * - IGU
  7447. * - MISC (including AEU)
  7448. * - GRC
  7449. * - RBCN, RBCP
  7450. */
  7451. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7452. {
  7453. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7454. u32 global_bits2, stay_reset2;
  7455. /*
  7456. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7457. * (per chip) blocks.
  7458. */
  7459. global_bits2 =
  7460. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7461. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7462. /* Don't reset the following blocks.
  7463. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7464. * reset, as in 4 port device they might still be owned
  7465. * by the MCP (there is only one leader per path).
  7466. */
  7467. not_reset_mask1 =
  7468. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7469. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7470. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7471. not_reset_mask2 =
  7472. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7473. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7474. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7475. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7476. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7477. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7478. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7479. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7480. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7481. MISC_REGISTERS_RESET_REG_2_PGLC |
  7482. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7483. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7484. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7485. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7486. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7487. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7488. /*
  7489. * Keep the following blocks in reset:
  7490. * - all xxMACs are handled by the bnx2x_link code.
  7491. */
  7492. stay_reset2 =
  7493. MISC_REGISTERS_RESET_REG_2_XMAC |
  7494. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7495. /* Full reset masks according to the chip */
  7496. reset_mask1 = 0xffffffff;
  7497. if (CHIP_IS_E1(bp))
  7498. reset_mask2 = 0xffff;
  7499. else if (CHIP_IS_E1H(bp))
  7500. reset_mask2 = 0x1ffff;
  7501. else if (CHIP_IS_E2(bp))
  7502. reset_mask2 = 0xfffff;
  7503. else /* CHIP_IS_E3 */
  7504. reset_mask2 = 0x3ffffff;
  7505. /* Don't reset global blocks unless we need to */
  7506. if (!global)
  7507. reset_mask2 &= ~global_bits2;
  7508. /*
  7509. * In case of attention in the QM, we need to reset PXP
  7510. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7511. * because otherwise QM reset would release 'close the gates' shortly
  7512. * before resetting the PXP, then the PSWRQ would send a write
  7513. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7514. * read the payload data from PSWWR, but PSWWR would not
  7515. * respond. The write queue in PGLUE would stuck, dmae commands
  7516. * would not return. Therefore it's important to reset the second
  7517. * reset register (containing the
  7518. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7519. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7520. * bit).
  7521. */
  7522. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7523. reset_mask2 & (~not_reset_mask2));
  7524. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7525. reset_mask1 & (~not_reset_mask1));
  7526. barrier();
  7527. mmiowb();
  7528. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7529. reset_mask2 & (~stay_reset2));
  7530. barrier();
  7531. mmiowb();
  7532. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7533. mmiowb();
  7534. }
  7535. /**
  7536. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7537. * It should get cleared in no more than 1s.
  7538. *
  7539. * @bp: driver handle
  7540. *
  7541. * It should get cleared in no more than 1s. Returns 0 if
  7542. * pending writes bit gets cleared.
  7543. */
  7544. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7545. {
  7546. u32 cnt = 1000;
  7547. u32 pend_bits = 0;
  7548. do {
  7549. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7550. if (pend_bits == 0)
  7551. break;
  7552. usleep_range(1000, 1000);
  7553. } while (cnt-- > 0);
  7554. if (cnt <= 0) {
  7555. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7556. pend_bits);
  7557. return -EBUSY;
  7558. }
  7559. return 0;
  7560. }
  7561. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7562. {
  7563. int cnt = 1000;
  7564. u32 val = 0;
  7565. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7566. u32 tags_63_32 = 0;
  7567. /* Empty the Tetris buffer, wait for 1s */
  7568. do {
  7569. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7570. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7571. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7572. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7573. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7574. if (CHIP_IS_E3(bp))
  7575. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7576. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7577. ((port_is_idle_0 & 0x1) == 0x1) &&
  7578. ((port_is_idle_1 & 0x1) == 0x1) &&
  7579. (pgl_exp_rom2 == 0xffffffff) &&
  7580. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7581. break;
  7582. usleep_range(1000, 1000);
  7583. } while (cnt-- > 0);
  7584. if (cnt <= 0) {
  7585. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7586. 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",
  7587. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7588. pgl_exp_rom2);
  7589. return -EAGAIN;
  7590. }
  7591. barrier();
  7592. /* Close gates #2, #3 and #4 */
  7593. bnx2x_set_234_gates(bp, true);
  7594. /* Poll for IGU VQs for 57712 and newer chips */
  7595. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7596. return -EAGAIN;
  7597. /* TBD: Indicate that "process kill" is in progress to MCP */
  7598. /* Clear "unprepared" bit */
  7599. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7600. barrier();
  7601. /* Make sure all is written to the chip before the reset */
  7602. mmiowb();
  7603. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7604. * PSWHST, GRC and PSWRD Tetris buffer.
  7605. */
  7606. usleep_range(1000, 1000);
  7607. /* Prepare to chip reset: */
  7608. /* MCP */
  7609. if (global)
  7610. bnx2x_reset_mcp_prep(bp, &val);
  7611. /* PXP */
  7612. bnx2x_pxp_prep(bp);
  7613. barrier();
  7614. /* reset the chip */
  7615. bnx2x_process_kill_chip_reset(bp, global);
  7616. barrier();
  7617. /* Recover after reset: */
  7618. /* MCP */
  7619. if (global && bnx2x_reset_mcp_comp(bp, val))
  7620. return -EAGAIN;
  7621. /* TBD: Add resetting the NO_MCP mode DB here */
  7622. /* Open the gates #2, #3 and #4 */
  7623. bnx2x_set_234_gates(bp, false);
  7624. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7625. * reset state, re-enable attentions. */
  7626. return 0;
  7627. }
  7628. static int bnx2x_leader_reset(struct bnx2x *bp)
  7629. {
  7630. int rc = 0;
  7631. bool global = bnx2x_reset_is_global(bp);
  7632. u32 load_code;
  7633. /* if not going to reset MCP - load "fake" driver to reset HW while
  7634. * driver is owner of the HW
  7635. */
  7636. if (!global && !BP_NOMCP(bp)) {
  7637. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7638. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7639. if (!load_code) {
  7640. BNX2X_ERR("MCP response failure, aborting\n");
  7641. rc = -EAGAIN;
  7642. goto exit_leader_reset;
  7643. }
  7644. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7645. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7646. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7647. rc = -EAGAIN;
  7648. goto exit_leader_reset2;
  7649. }
  7650. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7651. if (!load_code) {
  7652. BNX2X_ERR("MCP response failure, aborting\n");
  7653. rc = -EAGAIN;
  7654. goto exit_leader_reset2;
  7655. }
  7656. }
  7657. /* Try to recover after the failure */
  7658. if (bnx2x_process_kill(bp, global)) {
  7659. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7660. BP_PATH(bp));
  7661. rc = -EAGAIN;
  7662. goto exit_leader_reset2;
  7663. }
  7664. /*
  7665. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7666. * state.
  7667. */
  7668. bnx2x_set_reset_done(bp);
  7669. if (global)
  7670. bnx2x_clear_reset_global(bp);
  7671. exit_leader_reset2:
  7672. /* unload "fake driver" if it was loaded */
  7673. if (!global && !BP_NOMCP(bp)) {
  7674. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7675. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7676. }
  7677. exit_leader_reset:
  7678. bp->is_leader = 0;
  7679. bnx2x_release_leader_lock(bp);
  7680. smp_mb();
  7681. return rc;
  7682. }
  7683. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7684. {
  7685. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7686. /* Disconnect this device */
  7687. netif_device_detach(bp->dev);
  7688. /*
  7689. * Block ifup for all function on this engine until "process kill"
  7690. * or power cycle.
  7691. */
  7692. bnx2x_set_reset_in_progress(bp);
  7693. /* Shut down the power */
  7694. bnx2x_set_power_state(bp, PCI_D3hot);
  7695. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7696. smp_mb();
  7697. }
  7698. /*
  7699. * Assumption: runs under rtnl lock. This together with the fact
  7700. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7701. * will never be called when netif_running(bp->dev) is false.
  7702. */
  7703. static void bnx2x_parity_recover(struct bnx2x *bp)
  7704. {
  7705. bool global = false;
  7706. u32 error_recovered, error_unrecovered;
  7707. bool is_parity;
  7708. DP(NETIF_MSG_HW, "Handling parity\n");
  7709. while (1) {
  7710. switch (bp->recovery_state) {
  7711. case BNX2X_RECOVERY_INIT:
  7712. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7713. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7714. WARN_ON(!is_parity);
  7715. /* Try to get a LEADER_LOCK HW lock */
  7716. if (bnx2x_trylock_leader_lock(bp)) {
  7717. bnx2x_set_reset_in_progress(bp);
  7718. /*
  7719. * Check if there is a global attention and if
  7720. * there was a global attention, set the global
  7721. * reset bit.
  7722. */
  7723. if (global)
  7724. bnx2x_set_reset_global(bp);
  7725. bp->is_leader = 1;
  7726. }
  7727. /* Stop the driver */
  7728. /* If interface has been removed - break */
  7729. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7730. return;
  7731. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7732. /* Ensure "is_leader", MCP command sequence and
  7733. * "recovery_state" update values are seen on other
  7734. * CPUs.
  7735. */
  7736. smp_mb();
  7737. break;
  7738. case BNX2X_RECOVERY_WAIT:
  7739. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7740. if (bp->is_leader) {
  7741. int other_engine = BP_PATH(bp) ? 0 : 1;
  7742. bool other_load_status =
  7743. bnx2x_get_load_status(bp, other_engine);
  7744. bool load_status =
  7745. bnx2x_get_load_status(bp, BP_PATH(bp));
  7746. global = bnx2x_reset_is_global(bp);
  7747. /*
  7748. * In case of a parity in a global block, let
  7749. * the first leader that performs a
  7750. * leader_reset() reset the global blocks in
  7751. * order to clear global attentions. Otherwise
  7752. * the the gates will remain closed for that
  7753. * engine.
  7754. */
  7755. if (load_status ||
  7756. (global && other_load_status)) {
  7757. /* Wait until all other functions get
  7758. * down.
  7759. */
  7760. schedule_delayed_work(&bp->sp_rtnl_task,
  7761. HZ/10);
  7762. return;
  7763. } else {
  7764. /* If all other functions got down -
  7765. * try to bring the chip back to
  7766. * normal. In any case it's an exit
  7767. * point for a leader.
  7768. */
  7769. if (bnx2x_leader_reset(bp)) {
  7770. bnx2x_recovery_failed(bp);
  7771. return;
  7772. }
  7773. /* If we are here, means that the
  7774. * leader has succeeded and doesn't
  7775. * want to be a leader any more. Try
  7776. * to continue as a none-leader.
  7777. */
  7778. break;
  7779. }
  7780. } else { /* non-leader */
  7781. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7782. /* Try to get a LEADER_LOCK HW lock as
  7783. * long as a former leader may have
  7784. * been unloaded by the user or
  7785. * released a leadership by another
  7786. * reason.
  7787. */
  7788. if (bnx2x_trylock_leader_lock(bp)) {
  7789. /* I'm a leader now! Restart a
  7790. * switch case.
  7791. */
  7792. bp->is_leader = 1;
  7793. break;
  7794. }
  7795. schedule_delayed_work(&bp->sp_rtnl_task,
  7796. HZ/10);
  7797. return;
  7798. } else {
  7799. /*
  7800. * If there was a global attention, wait
  7801. * for it to be cleared.
  7802. */
  7803. if (bnx2x_reset_is_global(bp)) {
  7804. schedule_delayed_work(
  7805. &bp->sp_rtnl_task,
  7806. HZ/10);
  7807. return;
  7808. }
  7809. error_recovered =
  7810. bp->eth_stats.recoverable_error;
  7811. error_unrecovered =
  7812. bp->eth_stats.unrecoverable_error;
  7813. bp->recovery_state =
  7814. BNX2X_RECOVERY_NIC_LOADING;
  7815. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7816. error_unrecovered++;
  7817. netdev_err(bp->dev,
  7818. "Recovery failed. Power cycle needed\n");
  7819. /* Disconnect this device */
  7820. netif_device_detach(bp->dev);
  7821. /* Shut down the power */
  7822. bnx2x_set_power_state(
  7823. bp, PCI_D3hot);
  7824. smp_mb();
  7825. } else {
  7826. bp->recovery_state =
  7827. BNX2X_RECOVERY_DONE;
  7828. error_recovered++;
  7829. smp_mb();
  7830. }
  7831. bp->eth_stats.recoverable_error =
  7832. error_recovered;
  7833. bp->eth_stats.unrecoverable_error =
  7834. error_unrecovered;
  7835. return;
  7836. }
  7837. }
  7838. default:
  7839. return;
  7840. }
  7841. }
  7842. }
  7843. static int bnx2x_close(struct net_device *dev);
  7844. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7845. * scheduled on a general queue in order to prevent a dead lock.
  7846. */
  7847. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7848. {
  7849. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7850. rtnl_lock();
  7851. if (!netif_running(bp->dev)) {
  7852. rtnl_unlock();
  7853. return;
  7854. }
  7855. /* if stop on error is defined no recovery flows should be executed */
  7856. #ifdef BNX2X_STOP_ON_ERROR
  7857. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7858. "you will need to reboot when done\n");
  7859. goto sp_rtnl_not_reset;
  7860. #endif
  7861. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7862. /*
  7863. * Clear all pending SP commands as we are going to reset the
  7864. * function anyway.
  7865. */
  7866. bp->sp_rtnl_state = 0;
  7867. smp_mb();
  7868. bnx2x_parity_recover(bp);
  7869. rtnl_unlock();
  7870. return;
  7871. }
  7872. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7873. /*
  7874. * Clear all pending SP commands as we are going to reset the
  7875. * function anyway.
  7876. */
  7877. bp->sp_rtnl_state = 0;
  7878. smp_mb();
  7879. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7880. bnx2x_nic_load(bp, LOAD_NORMAL);
  7881. rtnl_unlock();
  7882. return;
  7883. }
  7884. #ifdef BNX2X_STOP_ON_ERROR
  7885. sp_rtnl_not_reset:
  7886. #endif
  7887. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7888. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7889. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7890. bnx2x_after_function_update(bp);
  7891. /*
  7892. * in case of fan failure we need to reset id if the "stop on error"
  7893. * debug flag is set, since we trying to prevent permanent overheating
  7894. * damage
  7895. */
  7896. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7897. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7898. netif_device_detach(bp->dev);
  7899. bnx2x_close(bp->dev);
  7900. rtnl_unlock();
  7901. return;
  7902. }
  7903. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7904. DP(BNX2X_MSG_SP,
  7905. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7906. bnx2x_vfpf_set_mcast(bp->dev);
  7907. }
  7908. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7909. &bp->sp_rtnl_state)) {
  7910. DP(BNX2X_MSG_SP,
  7911. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7912. bnx2x_vfpf_storm_rx_mode(bp);
  7913. }
  7914. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  7915. * can be called from other contexts as well)
  7916. */
  7917. rtnl_unlock();
  7918. /* enable SR-IOV if applicable */
  7919. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  7920. &bp->sp_rtnl_state))
  7921. bnx2x_enable_sriov(bp);
  7922. }
  7923. static void bnx2x_period_task(struct work_struct *work)
  7924. {
  7925. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7926. if (!netif_running(bp->dev))
  7927. goto period_task_exit;
  7928. if (CHIP_REV_IS_SLOW(bp)) {
  7929. BNX2X_ERR("period task called on emulation, ignoring\n");
  7930. goto period_task_exit;
  7931. }
  7932. bnx2x_acquire_phy_lock(bp);
  7933. /*
  7934. * The barrier is needed to ensure the ordering between the writing to
  7935. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7936. * the reading here.
  7937. */
  7938. smp_mb();
  7939. if (bp->port.pmf) {
  7940. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7941. /* Re-queue task in 1 sec */
  7942. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7943. }
  7944. bnx2x_release_phy_lock(bp);
  7945. period_task_exit:
  7946. return;
  7947. }
  7948. /*
  7949. * Init service functions
  7950. */
  7951. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7952. {
  7953. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7954. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7955. return base + (BP_ABS_FUNC(bp)) * stride;
  7956. }
  7957. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7958. {
  7959. u32 reg = bnx2x_get_pretend_reg(bp);
  7960. /* Flush all outstanding writes */
  7961. mmiowb();
  7962. /* Pretend to be function 0 */
  7963. REG_WR(bp, reg, 0);
  7964. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7965. /* From now we are in the "like-E1" mode */
  7966. bnx2x_int_disable(bp);
  7967. /* Flush all outstanding writes */
  7968. mmiowb();
  7969. /* Restore the original function */
  7970. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7971. REG_RD(bp, reg);
  7972. }
  7973. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7974. {
  7975. if (CHIP_IS_E1(bp))
  7976. bnx2x_int_disable(bp);
  7977. else
  7978. bnx2x_undi_int_disable_e1h(bp);
  7979. }
  7980. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  7981. struct bnx2x_mac_vals *vals)
  7982. {
  7983. u32 val, base_addr, offset, mask, reset_reg;
  7984. bool mac_stopped = false;
  7985. u8 port = BP_PORT(bp);
  7986. /* reset addresses as they also mark which values were changed */
  7987. vals->bmac_addr = 0;
  7988. vals->umac_addr = 0;
  7989. vals->xmac_addr = 0;
  7990. vals->emac_addr = 0;
  7991. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7992. if (!CHIP_IS_E3(bp)) {
  7993. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7994. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7995. if ((mask & reset_reg) && val) {
  7996. u32 wb_data[2];
  7997. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7998. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7999. : NIG_REG_INGRESS_BMAC0_MEM;
  8000. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8001. : BIGMAC_REGISTER_BMAC_CONTROL;
  8002. /*
  8003. * use rd/wr since we cannot use dmae. This is safe
  8004. * since MCP won't access the bus due to the request
  8005. * to unload, and no function on the path can be
  8006. * loaded at this time.
  8007. */
  8008. wb_data[0] = REG_RD(bp, base_addr + offset);
  8009. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8010. vals->bmac_addr = base_addr + offset;
  8011. vals->bmac_val[0] = wb_data[0];
  8012. vals->bmac_val[1] = wb_data[1];
  8013. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8014. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8015. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8016. }
  8017. BNX2X_DEV_INFO("Disable emac Rx\n");
  8018. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8019. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8020. REG_WR(bp, vals->emac_addr, 0);
  8021. mac_stopped = true;
  8022. } else {
  8023. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8024. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8025. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8026. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8027. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8028. val & ~(1 << 1));
  8029. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8030. val | (1 << 1));
  8031. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8032. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8033. REG_WR(bp, vals->xmac_addr, 0);
  8034. mac_stopped = true;
  8035. }
  8036. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8037. if (mask & reset_reg) {
  8038. BNX2X_DEV_INFO("Disable umac Rx\n");
  8039. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8040. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8041. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8042. REG_WR(bp, vals->umac_addr, 0);
  8043. mac_stopped = true;
  8044. }
  8045. }
  8046. if (mac_stopped)
  8047. msleep(20);
  8048. }
  8049. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8050. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8051. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8052. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8053. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8054. {
  8055. u16 rcq, bd;
  8056. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8057. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8058. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8059. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8060. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8061. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8062. port, bd, rcq);
  8063. }
  8064. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8065. {
  8066. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8067. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8068. if (!rc) {
  8069. BNX2X_ERR("MCP response failure, aborting\n");
  8070. return -EBUSY;
  8071. }
  8072. return 0;
  8073. }
  8074. static struct bnx2x_prev_path_list *
  8075. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8076. {
  8077. struct bnx2x_prev_path_list *tmp_list;
  8078. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8079. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8080. bp->pdev->bus->number == tmp_list->bus &&
  8081. BP_PATH(bp) == tmp_list->path)
  8082. return tmp_list;
  8083. return NULL;
  8084. }
  8085. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8086. {
  8087. struct bnx2x_prev_path_list *tmp_list;
  8088. int rc = false;
  8089. if (down_trylock(&bnx2x_prev_sem))
  8090. return false;
  8091. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  8092. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8093. bp->pdev->bus->number == tmp_list->bus &&
  8094. BP_PATH(bp) == tmp_list->path) {
  8095. rc = true;
  8096. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8097. BP_PATH(bp));
  8098. break;
  8099. }
  8100. }
  8101. up(&bnx2x_prev_sem);
  8102. return rc;
  8103. }
  8104. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8105. {
  8106. struct bnx2x_prev_path_list *tmp_list;
  8107. int rc;
  8108. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8109. if (!tmp_list) {
  8110. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8111. return -ENOMEM;
  8112. }
  8113. tmp_list->bus = bp->pdev->bus->number;
  8114. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8115. tmp_list->path = BP_PATH(bp);
  8116. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8117. rc = down_interruptible(&bnx2x_prev_sem);
  8118. if (rc) {
  8119. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8120. kfree(tmp_list);
  8121. } else {
  8122. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  8123. BP_PATH(bp));
  8124. list_add(&tmp_list->list, &bnx2x_prev_list);
  8125. up(&bnx2x_prev_sem);
  8126. }
  8127. return rc;
  8128. }
  8129. static int bnx2x_do_flr(struct bnx2x *bp)
  8130. {
  8131. int i;
  8132. u16 status;
  8133. struct pci_dev *dev = bp->pdev;
  8134. if (CHIP_IS_E1x(bp)) {
  8135. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8136. return -EINVAL;
  8137. }
  8138. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8139. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8140. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8141. bp->common.bc_ver);
  8142. return -EINVAL;
  8143. }
  8144. /* Wait for Transaction Pending bit clean */
  8145. for (i = 0; i < 4; i++) {
  8146. if (i)
  8147. msleep((1 << (i - 1)) * 100);
  8148. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8149. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8150. goto clear;
  8151. }
  8152. dev_err(&dev->dev,
  8153. "transaction is not cleared; proceeding with reset anyway\n");
  8154. clear:
  8155. BNX2X_DEV_INFO("Initiating FLR\n");
  8156. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8157. return 0;
  8158. }
  8159. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8160. {
  8161. int rc;
  8162. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8163. /* Test if previous unload process was already finished for this path */
  8164. if (bnx2x_prev_is_path_marked(bp))
  8165. return bnx2x_prev_mcp_done(bp);
  8166. /* If function has FLR capabilities, and existing FW version matches
  8167. * the one required, then FLR will be sufficient to clean any residue
  8168. * left by previous driver
  8169. */
  8170. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8171. if (!rc) {
  8172. /* fw version is good */
  8173. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8174. rc = bnx2x_do_flr(bp);
  8175. }
  8176. if (!rc) {
  8177. /* FLR was performed */
  8178. BNX2X_DEV_INFO("FLR successful\n");
  8179. return 0;
  8180. }
  8181. BNX2X_DEV_INFO("Could not FLR\n");
  8182. /* Close the MCP request, return failure*/
  8183. rc = bnx2x_prev_mcp_done(bp);
  8184. if (!rc)
  8185. rc = BNX2X_PREV_WAIT_NEEDED;
  8186. return rc;
  8187. }
  8188. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8189. {
  8190. u32 reset_reg, tmp_reg = 0, rc;
  8191. bool prev_undi = false;
  8192. struct bnx2x_mac_vals mac_vals;
  8193. /* It is possible a previous function received 'common' answer,
  8194. * but hasn't loaded yet, therefore creating a scenario of
  8195. * multiple functions receiving 'common' on the same path.
  8196. */
  8197. BNX2X_DEV_INFO("Common unload Flow\n");
  8198. memset(&mac_vals, 0, sizeof(mac_vals));
  8199. if (bnx2x_prev_is_path_marked(bp))
  8200. return bnx2x_prev_mcp_done(bp);
  8201. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8202. /* Reset should be performed after BRB is emptied */
  8203. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8204. u32 timer_count = 1000;
  8205. /* Close the MAC Rx to prevent BRB from filling up */
  8206. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8207. /* close LLH filters towards the BRB */
  8208. bnx2x_set_rx_filter(&bp->link_params, 0);
  8209. /* Check if the UNDI driver was previously loaded
  8210. * UNDI driver initializes CID offset for normal bell to 0x7
  8211. */
  8212. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8213. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8214. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8215. if (tmp_reg == 0x7) {
  8216. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8217. prev_undi = true;
  8218. /* clear the UNDI indication */
  8219. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8220. /* clear possible idle check errors */
  8221. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8222. }
  8223. }
  8224. /* wait until BRB is empty */
  8225. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8226. while (timer_count) {
  8227. u32 prev_brb = tmp_reg;
  8228. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8229. if (!tmp_reg)
  8230. break;
  8231. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8232. /* reset timer as long as BRB actually gets emptied */
  8233. if (prev_brb > tmp_reg)
  8234. timer_count = 1000;
  8235. else
  8236. timer_count--;
  8237. /* If UNDI resides in memory, manually increment it */
  8238. if (prev_undi)
  8239. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8240. udelay(10);
  8241. }
  8242. if (!timer_count)
  8243. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8244. }
  8245. /* No packets are in the pipeline, path is ready for reset */
  8246. bnx2x_reset_common(bp);
  8247. if (mac_vals.xmac_addr)
  8248. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8249. if (mac_vals.umac_addr)
  8250. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8251. if (mac_vals.emac_addr)
  8252. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8253. if (mac_vals.bmac_addr) {
  8254. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8255. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8256. }
  8257. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8258. if (rc) {
  8259. bnx2x_prev_mcp_done(bp);
  8260. return rc;
  8261. }
  8262. return bnx2x_prev_mcp_done(bp);
  8263. }
  8264. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8265. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8266. * the addresses of the transaction, resulting in was-error bit set in the pci
  8267. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8268. * to clear the interrupt which detected this from the pglueb and the was done
  8269. * bit
  8270. */
  8271. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8272. {
  8273. if (!CHIP_IS_E1x(bp)) {
  8274. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8275. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8276. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  8277. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8278. 1 << BP_FUNC(bp));
  8279. }
  8280. }
  8281. }
  8282. static int bnx2x_prev_unload(struct bnx2x *bp)
  8283. {
  8284. int time_counter = 10;
  8285. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8286. struct bnx2x_prev_path_list *prev_list;
  8287. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8288. /* clear hw from errors which may have resulted from an interrupted
  8289. * dmae transaction.
  8290. */
  8291. bnx2x_prev_interrupted_dmae(bp);
  8292. /* Release previously held locks */
  8293. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8294. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8295. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8296. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8297. if (hw_lock_val) {
  8298. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8299. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8300. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8301. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8302. }
  8303. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8304. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8305. } else
  8306. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8307. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8308. BNX2X_DEV_INFO("Release previously held alr\n");
  8309. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8310. }
  8311. do {
  8312. /* Lock MCP using an unload request */
  8313. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8314. if (!fw) {
  8315. BNX2X_ERR("MCP response failure, aborting\n");
  8316. rc = -EBUSY;
  8317. break;
  8318. }
  8319. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8320. rc = bnx2x_prev_unload_common(bp);
  8321. break;
  8322. }
  8323. /* non-common reply from MCP night require looping */
  8324. rc = bnx2x_prev_unload_uncommon(bp);
  8325. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8326. break;
  8327. msleep(20);
  8328. } while (--time_counter);
  8329. if (!time_counter || rc) {
  8330. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8331. rc = -EBUSY;
  8332. }
  8333. /* Mark function if its port was used to boot from SAN */
  8334. prev_list = bnx2x_prev_path_get_entry(bp);
  8335. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8336. bp->link_params.feature_config_flags |=
  8337. FEATURE_CONFIG_BOOT_FROM_SAN;
  8338. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8339. return rc;
  8340. }
  8341. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8342. {
  8343. u32 val, val2, val3, val4, id, boot_mode;
  8344. u16 pmc;
  8345. /* Get the chip revision id and number. */
  8346. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8347. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8348. id = ((val & 0xffff) << 16);
  8349. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8350. id |= ((val & 0xf) << 12);
  8351. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8352. id |= ((val & 0xff) << 4);
  8353. val = REG_RD(bp, MISC_REG_BOND_ID);
  8354. id |= (val & 0xf);
  8355. bp->common.chip_id = id;
  8356. /* force 57811 according to MISC register */
  8357. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8358. if (CHIP_IS_57810(bp))
  8359. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8360. (bp->common.chip_id & 0x0000FFFF);
  8361. else if (CHIP_IS_57810_MF(bp))
  8362. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8363. (bp->common.chip_id & 0x0000FFFF);
  8364. bp->common.chip_id |= 0x1;
  8365. }
  8366. /* Set doorbell size */
  8367. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8368. if (!CHIP_IS_E1x(bp)) {
  8369. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8370. if ((val & 1) == 0)
  8371. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8372. else
  8373. val = (val >> 1) & 1;
  8374. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8375. "2_PORT_MODE");
  8376. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8377. CHIP_2_PORT_MODE;
  8378. if (CHIP_MODE_IS_4_PORT(bp))
  8379. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8380. else
  8381. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8382. } else {
  8383. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8384. bp->pfid = bp->pf_num; /* 0..7 */
  8385. }
  8386. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8387. bp->link_params.chip_id = bp->common.chip_id;
  8388. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8389. val = (REG_RD(bp, 0x2874) & 0x55);
  8390. if ((bp->common.chip_id & 0x1) ||
  8391. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8392. bp->flags |= ONE_PORT_FLAG;
  8393. BNX2X_DEV_INFO("single port device\n");
  8394. }
  8395. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8396. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8397. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8398. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8399. bp->common.flash_size, bp->common.flash_size);
  8400. bnx2x_init_shmem(bp);
  8401. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8402. MISC_REG_GENERIC_CR_1 :
  8403. MISC_REG_GENERIC_CR_0));
  8404. bp->link_params.shmem_base = bp->common.shmem_base;
  8405. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8406. if (SHMEM2_RD(bp, size) >
  8407. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8408. bp->link_params.lfa_base =
  8409. REG_RD(bp, bp->common.shmem2_base +
  8410. (u32)offsetof(struct shmem2_region,
  8411. lfa_host_addr[BP_PORT(bp)]));
  8412. else
  8413. bp->link_params.lfa_base = 0;
  8414. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8415. bp->common.shmem_base, bp->common.shmem2_base);
  8416. if (!bp->common.shmem_base) {
  8417. BNX2X_DEV_INFO("MCP not active\n");
  8418. bp->flags |= NO_MCP_FLAG;
  8419. return;
  8420. }
  8421. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8422. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8423. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8424. SHARED_HW_CFG_LED_MODE_MASK) >>
  8425. SHARED_HW_CFG_LED_MODE_SHIFT);
  8426. bp->link_params.feature_config_flags = 0;
  8427. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8428. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8429. bp->link_params.feature_config_flags |=
  8430. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8431. else
  8432. bp->link_params.feature_config_flags &=
  8433. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8434. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8435. bp->common.bc_ver = val;
  8436. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8437. if (val < BNX2X_BC_VER) {
  8438. /* for now only warn
  8439. * later we might need to enforce this */
  8440. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8441. BNX2X_BC_VER, val);
  8442. }
  8443. bp->link_params.feature_config_flags |=
  8444. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8445. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8446. bp->link_params.feature_config_flags |=
  8447. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8448. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8449. bp->link_params.feature_config_flags |=
  8450. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8451. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8452. bp->link_params.feature_config_flags |=
  8453. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8454. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8455. bp->link_params.feature_config_flags |=
  8456. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8457. FEATURE_CONFIG_MT_SUPPORT : 0;
  8458. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8459. BC_SUPPORTS_PFC_STATS : 0;
  8460. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8461. BC_SUPPORTS_FCOE_FEATURES : 0;
  8462. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8463. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8464. boot_mode = SHMEM_RD(bp,
  8465. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8466. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8467. switch (boot_mode) {
  8468. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8469. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8470. break;
  8471. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8472. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8473. break;
  8474. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8475. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8476. break;
  8477. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8478. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8479. break;
  8480. }
  8481. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8482. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8483. BNX2X_DEV_INFO("%sWoL capable\n",
  8484. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8485. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8486. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8487. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8488. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8489. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8490. val, val2, val3, val4);
  8491. }
  8492. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8493. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8494. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8495. {
  8496. int pfid = BP_FUNC(bp);
  8497. int igu_sb_id;
  8498. u32 val;
  8499. u8 fid, igu_sb_cnt = 0;
  8500. bp->igu_base_sb = 0xff;
  8501. if (CHIP_INT_MODE_IS_BC(bp)) {
  8502. int vn = BP_VN(bp);
  8503. igu_sb_cnt = bp->igu_sb_cnt;
  8504. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8505. FP_SB_MAX_E1x;
  8506. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8507. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8508. return 0;
  8509. }
  8510. /* IGU in normal mode - read CAM */
  8511. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8512. igu_sb_id++) {
  8513. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8514. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8515. continue;
  8516. fid = IGU_FID(val);
  8517. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8518. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8519. continue;
  8520. if (IGU_VEC(val) == 0)
  8521. /* default status block */
  8522. bp->igu_dsb_id = igu_sb_id;
  8523. else {
  8524. if (bp->igu_base_sb == 0xff)
  8525. bp->igu_base_sb = igu_sb_id;
  8526. igu_sb_cnt++;
  8527. }
  8528. }
  8529. }
  8530. #ifdef CONFIG_PCI_MSI
  8531. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8532. * optional that number of CAM entries will not be equal to the value
  8533. * advertised in PCI.
  8534. * Driver should use the minimal value of both as the actual status
  8535. * block count
  8536. */
  8537. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8538. #endif
  8539. if (igu_sb_cnt == 0) {
  8540. BNX2X_ERR("CAM configuration error\n");
  8541. return -EINVAL;
  8542. }
  8543. return 0;
  8544. }
  8545. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8546. {
  8547. int cfg_size = 0, idx, port = BP_PORT(bp);
  8548. /* Aggregation of supported attributes of all external phys */
  8549. bp->port.supported[0] = 0;
  8550. bp->port.supported[1] = 0;
  8551. switch (bp->link_params.num_phys) {
  8552. case 1:
  8553. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8554. cfg_size = 1;
  8555. break;
  8556. case 2:
  8557. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8558. cfg_size = 1;
  8559. break;
  8560. case 3:
  8561. if (bp->link_params.multi_phy_config &
  8562. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8563. bp->port.supported[1] =
  8564. bp->link_params.phy[EXT_PHY1].supported;
  8565. bp->port.supported[0] =
  8566. bp->link_params.phy[EXT_PHY2].supported;
  8567. } else {
  8568. bp->port.supported[0] =
  8569. bp->link_params.phy[EXT_PHY1].supported;
  8570. bp->port.supported[1] =
  8571. bp->link_params.phy[EXT_PHY2].supported;
  8572. }
  8573. cfg_size = 2;
  8574. break;
  8575. }
  8576. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8577. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8578. SHMEM_RD(bp,
  8579. dev_info.port_hw_config[port].external_phy_config),
  8580. SHMEM_RD(bp,
  8581. dev_info.port_hw_config[port].external_phy_config2));
  8582. return;
  8583. }
  8584. if (CHIP_IS_E3(bp))
  8585. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8586. else {
  8587. switch (switch_cfg) {
  8588. case SWITCH_CFG_1G:
  8589. bp->port.phy_addr = REG_RD(
  8590. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8591. break;
  8592. case SWITCH_CFG_10G:
  8593. bp->port.phy_addr = REG_RD(
  8594. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8595. break;
  8596. default:
  8597. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8598. bp->port.link_config[0]);
  8599. return;
  8600. }
  8601. }
  8602. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8603. /* mask what we support according to speed_cap_mask per configuration */
  8604. for (idx = 0; idx < cfg_size; idx++) {
  8605. if (!(bp->link_params.speed_cap_mask[idx] &
  8606. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8607. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8608. if (!(bp->link_params.speed_cap_mask[idx] &
  8609. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8610. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8611. if (!(bp->link_params.speed_cap_mask[idx] &
  8612. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8613. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8614. if (!(bp->link_params.speed_cap_mask[idx] &
  8615. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8616. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8617. if (!(bp->link_params.speed_cap_mask[idx] &
  8618. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8619. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8620. SUPPORTED_1000baseT_Full);
  8621. if (!(bp->link_params.speed_cap_mask[idx] &
  8622. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8623. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8624. if (!(bp->link_params.speed_cap_mask[idx] &
  8625. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8626. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8627. }
  8628. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8629. bp->port.supported[1]);
  8630. }
  8631. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8632. {
  8633. u32 link_config, idx, cfg_size = 0;
  8634. bp->port.advertising[0] = 0;
  8635. bp->port.advertising[1] = 0;
  8636. switch (bp->link_params.num_phys) {
  8637. case 1:
  8638. case 2:
  8639. cfg_size = 1;
  8640. break;
  8641. case 3:
  8642. cfg_size = 2;
  8643. break;
  8644. }
  8645. for (idx = 0; idx < cfg_size; idx++) {
  8646. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8647. link_config = bp->port.link_config[idx];
  8648. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8649. case PORT_FEATURE_LINK_SPEED_AUTO:
  8650. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8651. bp->link_params.req_line_speed[idx] =
  8652. SPEED_AUTO_NEG;
  8653. bp->port.advertising[idx] |=
  8654. bp->port.supported[idx];
  8655. if (bp->link_params.phy[EXT_PHY1].type ==
  8656. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8657. bp->port.advertising[idx] |=
  8658. (SUPPORTED_100baseT_Half |
  8659. SUPPORTED_100baseT_Full);
  8660. } else {
  8661. /* force 10G, no AN */
  8662. bp->link_params.req_line_speed[idx] =
  8663. SPEED_10000;
  8664. bp->port.advertising[idx] |=
  8665. (ADVERTISED_10000baseT_Full |
  8666. ADVERTISED_FIBRE);
  8667. continue;
  8668. }
  8669. break;
  8670. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8671. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8672. bp->link_params.req_line_speed[idx] =
  8673. SPEED_10;
  8674. bp->port.advertising[idx] |=
  8675. (ADVERTISED_10baseT_Full |
  8676. ADVERTISED_TP);
  8677. } else {
  8678. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8679. link_config,
  8680. bp->link_params.speed_cap_mask[idx]);
  8681. return;
  8682. }
  8683. break;
  8684. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8685. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8686. bp->link_params.req_line_speed[idx] =
  8687. SPEED_10;
  8688. bp->link_params.req_duplex[idx] =
  8689. DUPLEX_HALF;
  8690. bp->port.advertising[idx] |=
  8691. (ADVERTISED_10baseT_Half |
  8692. ADVERTISED_TP);
  8693. } else {
  8694. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8695. link_config,
  8696. bp->link_params.speed_cap_mask[idx]);
  8697. return;
  8698. }
  8699. break;
  8700. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8701. if (bp->port.supported[idx] &
  8702. SUPPORTED_100baseT_Full) {
  8703. bp->link_params.req_line_speed[idx] =
  8704. SPEED_100;
  8705. bp->port.advertising[idx] |=
  8706. (ADVERTISED_100baseT_Full |
  8707. ADVERTISED_TP);
  8708. } else {
  8709. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8710. link_config,
  8711. bp->link_params.speed_cap_mask[idx]);
  8712. return;
  8713. }
  8714. break;
  8715. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8716. if (bp->port.supported[idx] &
  8717. SUPPORTED_100baseT_Half) {
  8718. bp->link_params.req_line_speed[idx] =
  8719. SPEED_100;
  8720. bp->link_params.req_duplex[idx] =
  8721. DUPLEX_HALF;
  8722. bp->port.advertising[idx] |=
  8723. (ADVERTISED_100baseT_Half |
  8724. ADVERTISED_TP);
  8725. } else {
  8726. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8727. link_config,
  8728. bp->link_params.speed_cap_mask[idx]);
  8729. return;
  8730. }
  8731. break;
  8732. case PORT_FEATURE_LINK_SPEED_1G:
  8733. if (bp->port.supported[idx] &
  8734. SUPPORTED_1000baseT_Full) {
  8735. bp->link_params.req_line_speed[idx] =
  8736. SPEED_1000;
  8737. bp->port.advertising[idx] |=
  8738. (ADVERTISED_1000baseT_Full |
  8739. ADVERTISED_TP);
  8740. } else {
  8741. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8742. link_config,
  8743. bp->link_params.speed_cap_mask[idx]);
  8744. return;
  8745. }
  8746. break;
  8747. case PORT_FEATURE_LINK_SPEED_2_5G:
  8748. if (bp->port.supported[idx] &
  8749. SUPPORTED_2500baseX_Full) {
  8750. bp->link_params.req_line_speed[idx] =
  8751. SPEED_2500;
  8752. bp->port.advertising[idx] |=
  8753. (ADVERTISED_2500baseX_Full |
  8754. ADVERTISED_TP);
  8755. } else {
  8756. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8757. link_config,
  8758. bp->link_params.speed_cap_mask[idx]);
  8759. return;
  8760. }
  8761. break;
  8762. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8763. if (bp->port.supported[idx] &
  8764. SUPPORTED_10000baseT_Full) {
  8765. bp->link_params.req_line_speed[idx] =
  8766. SPEED_10000;
  8767. bp->port.advertising[idx] |=
  8768. (ADVERTISED_10000baseT_Full |
  8769. ADVERTISED_FIBRE);
  8770. } else {
  8771. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8772. link_config,
  8773. bp->link_params.speed_cap_mask[idx]);
  8774. return;
  8775. }
  8776. break;
  8777. case PORT_FEATURE_LINK_SPEED_20G:
  8778. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8779. break;
  8780. default:
  8781. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8782. link_config);
  8783. bp->link_params.req_line_speed[idx] =
  8784. SPEED_AUTO_NEG;
  8785. bp->port.advertising[idx] =
  8786. bp->port.supported[idx];
  8787. break;
  8788. }
  8789. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8790. PORT_FEATURE_FLOW_CONTROL_MASK);
  8791. if (bp->link_params.req_flow_ctrl[idx] ==
  8792. BNX2X_FLOW_CTRL_AUTO) {
  8793. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8794. bp->link_params.req_flow_ctrl[idx] =
  8795. BNX2X_FLOW_CTRL_NONE;
  8796. else
  8797. bnx2x_set_requested_fc(bp);
  8798. }
  8799. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8800. bp->link_params.req_line_speed[idx],
  8801. bp->link_params.req_duplex[idx],
  8802. bp->link_params.req_flow_ctrl[idx],
  8803. bp->port.advertising[idx]);
  8804. }
  8805. }
  8806. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8807. {
  8808. mac_hi = cpu_to_be16(mac_hi);
  8809. mac_lo = cpu_to_be32(mac_lo);
  8810. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8811. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8812. }
  8813. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8814. {
  8815. int port = BP_PORT(bp);
  8816. u32 config;
  8817. u32 ext_phy_type, ext_phy_config, eee_mode;
  8818. bp->link_params.bp = bp;
  8819. bp->link_params.port = port;
  8820. bp->link_params.lane_config =
  8821. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8822. bp->link_params.speed_cap_mask[0] =
  8823. SHMEM_RD(bp,
  8824. dev_info.port_hw_config[port].speed_capability_mask);
  8825. bp->link_params.speed_cap_mask[1] =
  8826. SHMEM_RD(bp,
  8827. dev_info.port_hw_config[port].speed_capability_mask2);
  8828. bp->port.link_config[0] =
  8829. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8830. bp->port.link_config[1] =
  8831. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8832. bp->link_params.multi_phy_config =
  8833. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8834. /* If the device is capable of WoL, set the default state according
  8835. * to the HW
  8836. */
  8837. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8838. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8839. (config & PORT_FEATURE_WOL_ENABLED));
  8840. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8841. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  8842. bp->flags |= NO_ISCSI_FLAG;
  8843. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8844. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  8845. bp->flags |= NO_FCOE_FLAG;
  8846. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8847. bp->link_params.lane_config,
  8848. bp->link_params.speed_cap_mask[0],
  8849. bp->port.link_config[0]);
  8850. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8851. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8852. bnx2x_phy_probe(&bp->link_params);
  8853. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8854. bnx2x_link_settings_requested(bp);
  8855. /*
  8856. * If connected directly, work with the internal PHY, otherwise, work
  8857. * with the external PHY
  8858. */
  8859. ext_phy_config =
  8860. SHMEM_RD(bp,
  8861. dev_info.port_hw_config[port].external_phy_config);
  8862. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8863. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8864. bp->mdio.prtad = bp->port.phy_addr;
  8865. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8866. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8867. bp->mdio.prtad =
  8868. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8869. /* Configure link feature according to nvram value */
  8870. eee_mode = (((SHMEM_RD(bp, dev_info.
  8871. port_feature_config[port].eee_power_mode)) &
  8872. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8873. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8874. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8875. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8876. EEE_MODE_ENABLE_LPI |
  8877. EEE_MODE_OUTPUT_TIME;
  8878. } else {
  8879. bp->link_params.eee_mode = 0;
  8880. }
  8881. }
  8882. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8883. {
  8884. u32 no_flags = NO_ISCSI_FLAG;
  8885. int port = BP_PORT(bp);
  8886. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8887. drv_lic_key[port].max_iscsi_conn);
  8888. if (!CNIC_SUPPORT(bp)) {
  8889. bp->flags |= no_flags;
  8890. return;
  8891. }
  8892. /* Get the number of maximum allowed iSCSI connections */
  8893. bp->cnic_eth_dev.max_iscsi_conn =
  8894. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8895. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8896. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8897. bp->cnic_eth_dev.max_iscsi_conn);
  8898. /*
  8899. * If maximum allowed number of connections is zero -
  8900. * disable the feature.
  8901. */
  8902. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8903. bp->flags |= no_flags;
  8904. }
  8905. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8906. {
  8907. /* Port info */
  8908. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8909. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8910. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8911. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8912. /* Node info */
  8913. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8914. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8915. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8916. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8917. }
  8918. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8919. {
  8920. int port = BP_PORT(bp);
  8921. int func = BP_ABS_FUNC(bp);
  8922. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8923. drv_lic_key[port].max_fcoe_conn);
  8924. if (!CNIC_SUPPORT(bp)) {
  8925. bp->flags |= NO_FCOE_FLAG;
  8926. return;
  8927. }
  8928. /* Get the number of maximum allowed FCoE connections */
  8929. bp->cnic_eth_dev.max_fcoe_conn =
  8930. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8931. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8932. /* Read the WWN: */
  8933. if (!IS_MF(bp)) {
  8934. /* Port info */
  8935. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8936. SHMEM_RD(bp,
  8937. dev_info.port_hw_config[port].
  8938. fcoe_wwn_port_name_upper);
  8939. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8940. SHMEM_RD(bp,
  8941. dev_info.port_hw_config[port].
  8942. fcoe_wwn_port_name_lower);
  8943. /* Node info */
  8944. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8945. SHMEM_RD(bp,
  8946. dev_info.port_hw_config[port].
  8947. fcoe_wwn_node_name_upper);
  8948. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8949. SHMEM_RD(bp,
  8950. dev_info.port_hw_config[port].
  8951. fcoe_wwn_node_name_lower);
  8952. } else if (!IS_MF_SD(bp)) {
  8953. /*
  8954. * Read the WWN info only if the FCoE feature is enabled for
  8955. * this function.
  8956. */
  8957. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8958. bnx2x_get_ext_wwn_info(bp, func);
  8959. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8960. bnx2x_get_ext_wwn_info(bp, func);
  8961. }
  8962. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8963. /*
  8964. * If maximum allowed number of connections is zero -
  8965. * disable the feature.
  8966. */
  8967. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8968. bp->flags |= NO_FCOE_FLAG;
  8969. }
  8970. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  8971. {
  8972. /*
  8973. * iSCSI may be dynamically disabled but reading
  8974. * info here we will decrease memory usage by driver
  8975. * if the feature is disabled for good
  8976. */
  8977. bnx2x_get_iscsi_info(bp);
  8978. bnx2x_get_fcoe_info(bp);
  8979. }
  8980. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8981. {
  8982. u32 val, val2;
  8983. int func = BP_ABS_FUNC(bp);
  8984. int port = BP_PORT(bp);
  8985. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8986. u8 *fip_mac = bp->fip_mac;
  8987. if (IS_MF(bp)) {
  8988. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8989. * FCoE MAC then the appropriate feature should be disabled.
  8990. * In non SD mode features configuration comes from struct
  8991. * func_ext_config.
  8992. */
  8993. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  8994. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8995. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8996. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8997. iscsi_mac_addr_upper);
  8998. val = MF_CFG_RD(bp, func_ext_config[func].
  8999. iscsi_mac_addr_lower);
  9000. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9001. BNX2X_DEV_INFO
  9002. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9003. } else {
  9004. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9005. }
  9006. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9007. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9008. fcoe_mac_addr_upper);
  9009. val = MF_CFG_RD(bp, func_ext_config[func].
  9010. fcoe_mac_addr_lower);
  9011. bnx2x_set_mac_buf(fip_mac, val, val2);
  9012. BNX2X_DEV_INFO
  9013. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9014. } else {
  9015. bp->flags |= NO_FCOE_FLAG;
  9016. }
  9017. bp->mf_ext_config = cfg;
  9018. } else { /* SD MODE */
  9019. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9020. /* use primary mac as iscsi mac */
  9021. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9022. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9023. BNX2X_DEV_INFO
  9024. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9025. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9026. /* use primary mac as fip mac */
  9027. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9028. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9029. BNX2X_DEV_INFO
  9030. ("Read FIP MAC: %pM\n", fip_mac);
  9031. }
  9032. }
  9033. if (IS_MF_STORAGE_SD(bp))
  9034. /* Zero primary MAC configuration */
  9035. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9036. if (IS_MF_FCOE_AFEX(bp) || IS_MF_FCOE_SD(bp))
  9037. /* use FIP MAC as primary MAC */
  9038. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9039. } else {
  9040. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9041. iscsi_mac_upper);
  9042. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9043. iscsi_mac_lower);
  9044. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9045. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9046. fcoe_fip_mac_upper);
  9047. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9048. fcoe_fip_mac_lower);
  9049. bnx2x_set_mac_buf(fip_mac, val, val2);
  9050. }
  9051. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9052. if (!is_valid_ether_addr(iscsi_mac)) {
  9053. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9054. memset(iscsi_mac, 0, ETH_ALEN);
  9055. }
  9056. /* Disable FCoE if MAC configuration is invalid. */
  9057. if (!is_valid_ether_addr(fip_mac)) {
  9058. bp->flags |= NO_FCOE_FLAG;
  9059. memset(bp->fip_mac, 0, ETH_ALEN);
  9060. }
  9061. }
  9062. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9063. {
  9064. u32 val, val2;
  9065. int func = BP_ABS_FUNC(bp);
  9066. int port = BP_PORT(bp);
  9067. /* Zero primary MAC configuration */
  9068. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9069. if (BP_NOMCP(bp)) {
  9070. BNX2X_ERROR("warning: random MAC workaround active\n");
  9071. eth_hw_addr_random(bp->dev);
  9072. } else if (IS_MF(bp)) {
  9073. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9074. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9075. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9076. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9077. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9078. if (CNIC_SUPPORT(bp))
  9079. bnx2x_get_cnic_mac_hwinfo(bp);
  9080. } else {
  9081. /* in SF read MACs from port configuration */
  9082. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9083. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9084. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9085. if (CNIC_SUPPORT(bp))
  9086. bnx2x_get_cnic_mac_hwinfo(bp);
  9087. }
  9088. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9089. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9090. dev_err(&bp->pdev->dev,
  9091. "bad Ethernet MAC address configuration: %pM\n"
  9092. "change it manually before bringing up the appropriate network interface\n",
  9093. bp->dev->dev_addr);
  9094. }
  9095. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9096. {
  9097. int tmp;
  9098. u32 cfg;
  9099. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9100. /* Take function: tmp = func */
  9101. tmp = BP_ABS_FUNC(bp);
  9102. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9103. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9104. } else {
  9105. /* Take port: tmp = port */
  9106. tmp = BP_PORT(bp);
  9107. cfg = SHMEM_RD(bp,
  9108. dev_info.port_hw_config[tmp].generic_features);
  9109. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9110. }
  9111. return cfg;
  9112. }
  9113. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9114. {
  9115. int /*abs*/func = BP_ABS_FUNC(bp);
  9116. int vn;
  9117. u32 val = 0;
  9118. int rc = 0;
  9119. bnx2x_get_common_hwinfo(bp);
  9120. /*
  9121. * initialize IGU parameters
  9122. */
  9123. if (CHIP_IS_E1x(bp)) {
  9124. bp->common.int_block = INT_BLOCK_HC;
  9125. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9126. bp->igu_base_sb = 0;
  9127. } else {
  9128. bp->common.int_block = INT_BLOCK_IGU;
  9129. /* do not allow device reset during IGU info preocessing */
  9130. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9131. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9132. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9133. int tout = 5000;
  9134. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9135. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9136. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9137. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9138. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9139. tout--;
  9140. usleep_range(1000, 1000);
  9141. }
  9142. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9143. dev_err(&bp->pdev->dev,
  9144. "FORCING Normal Mode failed!!!\n");
  9145. bnx2x_release_hw_lock(bp,
  9146. HW_LOCK_RESOURCE_RESET);
  9147. return -EPERM;
  9148. }
  9149. }
  9150. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9151. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9152. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9153. } else
  9154. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9155. rc = bnx2x_get_igu_cam_info(bp);
  9156. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9157. if (rc)
  9158. return rc;
  9159. }
  9160. /*
  9161. * set base FW non-default (fast path) status block id, this value is
  9162. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9163. * determine the id used by the FW.
  9164. */
  9165. if (CHIP_IS_E1x(bp))
  9166. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9167. else /*
  9168. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9169. * the same queue are indicated on the same IGU SB). So we prefer
  9170. * FW and IGU SBs to be the same value.
  9171. */
  9172. bp->base_fw_ndsb = bp->igu_base_sb;
  9173. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9174. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9175. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9176. /*
  9177. * Initialize MF configuration
  9178. */
  9179. bp->mf_ov = 0;
  9180. bp->mf_mode = 0;
  9181. vn = BP_VN(bp);
  9182. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9183. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9184. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9185. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9186. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9187. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9188. else
  9189. bp->common.mf_cfg_base = bp->common.shmem_base +
  9190. offsetof(struct shmem_region, func_mb) +
  9191. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9192. /*
  9193. * get mf configuration:
  9194. * 1. existence of MF configuration
  9195. * 2. MAC address must be legal (check only upper bytes)
  9196. * for Switch-Independent mode;
  9197. * OVLAN must be legal for Switch-Dependent mode
  9198. * 3. SF_MODE configures specific MF mode
  9199. */
  9200. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9201. /* get mf configuration */
  9202. val = SHMEM_RD(bp,
  9203. dev_info.shared_feature_config.config);
  9204. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9205. switch (val) {
  9206. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9207. val = MF_CFG_RD(bp, func_mf_config[func].
  9208. mac_upper);
  9209. /* check for legal mac (upper bytes)*/
  9210. if (val != 0xffff) {
  9211. bp->mf_mode = MULTI_FUNCTION_SI;
  9212. bp->mf_config[vn] = MF_CFG_RD(bp,
  9213. func_mf_config[func].config);
  9214. } else
  9215. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9216. break;
  9217. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9218. if ((!CHIP_IS_E1x(bp)) &&
  9219. (MF_CFG_RD(bp, func_mf_config[func].
  9220. mac_upper) != 0xffff) &&
  9221. (SHMEM2_HAS(bp,
  9222. afex_driver_support))) {
  9223. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9224. bp->mf_config[vn] = MF_CFG_RD(bp,
  9225. func_mf_config[func].config);
  9226. } else {
  9227. BNX2X_DEV_INFO("can not configure afex mode\n");
  9228. }
  9229. break;
  9230. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9231. /* get OV configuration */
  9232. val = MF_CFG_RD(bp,
  9233. func_mf_config[FUNC_0].e1hov_tag);
  9234. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9235. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9236. bp->mf_mode = MULTI_FUNCTION_SD;
  9237. bp->mf_config[vn] = MF_CFG_RD(bp,
  9238. func_mf_config[func].config);
  9239. } else
  9240. BNX2X_DEV_INFO("illegal OV for SD\n");
  9241. break;
  9242. default:
  9243. /* Unknown configuration: reset mf_config */
  9244. bp->mf_config[vn] = 0;
  9245. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9246. }
  9247. }
  9248. BNX2X_DEV_INFO("%s function mode\n",
  9249. IS_MF(bp) ? "multi" : "single");
  9250. switch (bp->mf_mode) {
  9251. case MULTI_FUNCTION_SD:
  9252. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9253. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9254. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9255. bp->mf_ov = val;
  9256. bp->path_has_ovlan = true;
  9257. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9258. func, bp->mf_ov, bp->mf_ov);
  9259. } else {
  9260. dev_err(&bp->pdev->dev,
  9261. "No valid MF OV for func %d, aborting\n",
  9262. func);
  9263. return -EPERM;
  9264. }
  9265. break;
  9266. case MULTI_FUNCTION_AFEX:
  9267. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9268. break;
  9269. case MULTI_FUNCTION_SI:
  9270. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9271. func);
  9272. break;
  9273. default:
  9274. if (vn) {
  9275. dev_err(&bp->pdev->dev,
  9276. "VN %d is in a single function mode, aborting\n",
  9277. vn);
  9278. return -EPERM;
  9279. }
  9280. break;
  9281. }
  9282. /* check if other port on the path needs ovlan:
  9283. * Since MF configuration is shared between ports
  9284. * Possible mixed modes are only
  9285. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9286. */
  9287. if (CHIP_MODE_IS_4_PORT(bp) &&
  9288. !bp->path_has_ovlan &&
  9289. !IS_MF(bp) &&
  9290. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9291. u8 other_port = !BP_PORT(bp);
  9292. u8 other_func = BP_PATH(bp) + 2*other_port;
  9293. val = MF_CFG_RD(bp,
  9294. func_mf_config[other_func].e1hov_tag);
  9295. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9296. bp->path_has_ovlan = true;
  9297. }
  9298. }
  9299. /* adjust igu_sb_cnt to MF for E1x */
  9300. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9301. bp->igu_sb_cnt /= E1HVN_MAX;
  9302. /* port info */
  9303. bnx2x_get_port_hwinfo(bp);
  9304. /* Get MAC addresses */
  9305. bnx2x_get_mac_hwinfo(bp);
  9306. bnx2x_get_cnic_info(bp);
  9307. return rc;
  9308. }
  9309. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9310. {
  9311. int cnt, i, block_end, rodi;
  9312. char vpd_start[BNX2X_VPD_LEN+1];
  9313. char str_id_reg[VENDOR_ID_LEN+1];
  9314. char str_id_cap[VENDOR_ID_LEN+1];
  9315. char *vpd_data;
  9316. char *vpd_extended_data = NULL;
  9317. u8 len;
  9318. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9319. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9320. if (cnt < BNX2X_VPD_LEN)
  9321. goto out_not_found;
  9322. /* VPD RO tag should be first tag after identifier string, hence
  9323. * we should be able to find it in first BNX2X_VPD_LEN chars
  9324. */
  9325. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9326. PCI_VPD_LRDT_RO_DATA);
  9327. if (i < 0)
  9328. goto out_not_found;
  9329. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9330. pci_vpd_lrdt_size(&vpd_start[i]);
  9331. i += PCI_VPD_LRDT_TAG_SIZE;
  9332. if (block_end > BNX2X_VPD_LEN) {
  9333. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9334. if (vpd_extended_data == NULL)
  9335. goto out_not_found;
  9336. /* read rest of vpd image into vpd_extended_data */
  9337. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9338. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9339. block_end - BNX2X_VPD_LEN,
  9340. vpd_extended_data + BNX2X_VPD_LEN);
  9341. if (cnt < (block_end - BNX2X_VPD_LEN))
  9342. goto out_not_found;
  9343. vpd_data = vpd_extended_data;
  9344. } else
  9345. vpd_data = vpd_start;
  9346. /* now vpd_data holds full vpd content in both cases */
  9347. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9348. PCI_VPD_RO_KEYWORD_MFR_ID);
  9349. if (rodi < 0)
  9350. goto out_not_found;
  9351. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9352. if (len != VENDOR_ID_LEN)
  9353. goto out_not_found;
  9354. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9355. /* vendor specific info */
  9356. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9357. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9358. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9359. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9360. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9361. PCI_VPD_RO_KEYWORD_VENDOR0);
  9362. if (rodi >= 0) {
  9363. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9364. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9365. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9366. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9367. bp->fw_ver[len] = ' ';
  9368. }
  9369. }
  9370. kfree(vpd_extended_data);
  9371. return;
  9372. }
  9373. out_not_found:
  9374. kfree(vpd_extended_data);
  9375. return;
  9376. }
  9377. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9378. {
  9379. u32 flags = 0;
  9380. if (CHIP_REV_IS_FPGA(bp))
  9381. SET_FLAGS(flags, MODE_FPGA);
  9382. else if (CHIP_REV_IS_EMUL(bp))
  9383. SET_FLAGS(flags, MODE_EMUL);
  9384. else
  9385. SET_FLAGS(flags, MODE_ASIC);
  9386. if (CHIP_MODE_IS_4_PORT(bp))
  9387. SET_FLAGS(flags, MODE_PORT4);
  9388. else
  9389. SET_FLAGS(flags, MODE_PORT2);
  9390. if (CHIP_IS_E2(bp))
  9391. SET_FLAGS(flags, MODE_E2);
  9392. else if (CHIP_IS_E3(bp)) {
  9393. SET_FLAGS(flags, MODE_E3);
  9394. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9395. SET_FLAGS(flags, MODE_E3_A0);
  9396. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9397. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9398. }
  9399. if (IS_MF(bp)) {
  9400. SET_FLAGS(flags, MODE_MF);
  9401. switch (bp->mf_mode) {
  9402. case MULTI_FUNCTION_SD:
  9403. SET_FLAGS(flags, MODE_MF_SD);
  9404. break;
  9405. case MULTI_FUNCTION_SI:
  9406. SET_FLAGS(flags, MODE_MF_SI);
  9407. break;
  9408. case MULTI_FUNCTION_AFEX:
  9409. SET_FLAGS(flags, MODE_MF_AFEX);
  9410. break;
  9411. }
  9412. } else
  9413. SET_FLAGS(flags, MODE_SF);
  9414. #if defined(__LITTLE_ENDIAN)
  9415. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9416. #else /*(__BIG_ENDIAN)*/
  9417. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9418. #endif
  9419. INIT_MODE_FLAGS(bp) = flags;
  9420. }
  9421. static int bnx2x_init_bp(struct bnx2x *bp)
  9422. {
  9423. int func;
  9424. int rc;
  9425. mutex_init(&bp->port.phy_mutex);
  9426. mutex_init(&bp->fw_mb_mutex);
  9427. spin_lock_init(&bp->stats_lock);
  9428. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9429. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9430. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9431. if (IS_PF(bp)) {
  9432. rc = bnx2x_get_hwinfo(bp);
  9433. if (rc)
  9434. return rc;
  9435. } else {
  9436. random_ether_addr(bp->dev->dev_addr);
  9437. }
  9438. bnx2x_set_modes_bitmap(bp);
  9439. rc = bnx2x_alloc_mem_bp(bp);
  9440. if (rc)
  9441. return rc;
  9442. bnx2x_read_fwinfo(bp);
  9443. func = BP_FUNC(bp);
  9444. /* need to reset chip if undi was active */
  9445. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9446. /* init fw_seq */
  9447. bp->fw_seq =
  9448. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9449. DRV_MSG_SEQ_NUMBER_MASK;
  9450. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9451. bnx2x_prev_unload(bp);
  9452. }
  9453. if (CHIP_REV_IS_FPGA(bp))
  9454. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9455. if (BP_NOMCP(bp) && (func == 0))
  9456. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9457. bp->disable_tpa = disable_tpa;
  9458. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9459. /* Set TPA flags */
  9460. if (bp->disable_tpa) {
  9461. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9462. bp->dev->features &= ~NETIF_F_LRO;
  9463. } else {
  9464. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9465. bp->dev->features |= NETIF_F_LRO;
  9466. }
  9467. if (CHIP_IS_E1(bp))
  9468. bp->dropless_fc = 0;
  9469. else
  9470. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9471. bp->mrrs = mrrs;
  9472. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9473. if (IS_VF(bp))
  9474. bp->rx_ring_size = MAX_RX_AVAIL;
  9475. /* make sure that the numbers are in the right granularity */
  9476. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9477. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9478. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9479. init_timer(&bp->timer);
  9480. bp->timer.expires = jiffies + bp->current_interval;
  9481. bp->timer.data = (unsigned long) bp;
  9482. bp->timer.function = bnx2x_timer;
  9483. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9484. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9485. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9486. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9487. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9488. bnx2x_dcbx_init_params(bp);
  9489. } else {
  9490. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9491. }
  9492. if (CHIP_IS_E1x(bp))
  9493. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9494. else
  9495. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9496. /* multiple tx priority */
  9497. if (IS_VF(bp))
  9498. bp->max_cos = 1;
  9499. else if (CHIP_IS_E1x(bp))
  9500. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9501. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9502. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9503. else if (CHIP_IS_E3B0(bp))
  9504. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9505. else
  9506. BNX2X_ERR("unknown chip %x revision %x\n",
  9507. CHIP_NUM(bp), CHIP_REV(bp));
  9508. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9509. /* We need at least one default status block for slow-path events,
  9510. * second status block for the L2 queue, and a third status block for
  9511. * CNIC if supproted.
  9512. */
  9513. if (CNIC_SUPPORT(bp))
  9514. bp->min_msix_vec_cnt = 3;
  9515. else
  9516. bp->min_msix_vec_cnt = 2;
  9517. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9518. return rc;
  9519. }
  9520. /****************************************************************************
  9521. * General service functions
  9522. ****************************************************************************/
  9523. /*
  9524. * net_device service functions
  9525. */
  9526. static int bnx2x_open_epilog(struct bnx2x *bp)
  9527. {
  9528. /* Enable sriov via delayed work. This must be done via delayed work
  9529. * because it causes the probe of the vf devices to be run, which invoke
  9530. * register_netdevice which must have rtnl lock taken. As we are holding
  9531. * the lock right now, that could only work if the probe would not take
  9532. * the lock. However, as the probe of the vf may be called from other
  9533. * contexts as well (such as passthrough to vm failes) it can't assume
  9534. * the lock is being held for it. Using delayed work here allows the
  9535. * probe code to simply take the lock (i.e. wait for it to be released
  9536. * if it is being held).
  9537. */
  9538. smp_mb__before_clear_bit();
  9539. set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, &bp->sp_rtnl_state);
  9540. smp_mb__after_clear_bit();
  9541. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9542. return 0;
  9543. }
  9544. /* called with rtnl_lock */
  9545. static int bnx2x_open(struct net_device *dev)
  9546. {
  9547. struct bnx2x *bp = netdev_priv(dev);
  9548. bool global = false;
  9549. int other_engine = BP_PATH(bp) ? 0 : 1;
  9550. bool other_load_status, load_status;
  9551. int rc;
  9552. bp->stats_init = true;
  9553. netif_carrier_off(dev);
  9554. bnx2x_set_power_state(bp, PCI_D0);
  9555. /* If parity had happen during the unload, then attentions
  9556. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9557. * want the first function loaded on the current engine to
  9558. * complete the recovery.
  9559. * Parity recovery is only relevant for PF driver.
  9560. */
  9561. if (IS_PF(bp)) {
  9562. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9563. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9564. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9565. bnx2x_chk_parity_attn(bp, &global, true)) {
  9566. do {
  9567. /* If there are attentions and they are in a
  9568. * global blocks, set the GLOBAL_RESET bit
  9569. * regardless whether it will be this function
  9570. * that will complete the recovery or not.
  9571. */
  9572. if (global)
  9573. bnx2x_set_reset_global(bp);
  9574. /* Only the first function on the current
  9575. * engine should try to recover in open. In case
  9576. * of attentions in global blocks only the first
  9577. * in the chip should try to recover.
  9578. */
  9579. if ((!load_status &&
  9580. (!global || !other_load_status)) &&
  9581. bnx2x_trylock_leader_lock(bp) &&
  9582. !bnx2x_leader_reset(bp)) {
  9583. netdev_info(bp->dev,
  9584. "Recovered in open\n");
  9585. break;
  9586. }
  9587. /* recovery has failed... */
  9588. bnx2x_set_power_state(bp, PCI_D3hot);
  9589. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9590. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9591. "If you still see this message after a few retries then power cycle is required.\n");
  9592. return -EAGAIN;
  9593. } while (0);
  9594. }
  9595. }
  9596. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9597. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9598. if (rc)
  9599. return rc;
  9600. return bnx2x_open_epilog(bp);
  9601. }
  9602. /* called with rtnl_lock */
  9603. static int bnx2x_close(struct net_device *dev)
  9604. {
  9605. struct bnx2x *bp = netdev_priv(dev);
  9606. /* Unload the driver, release IRQs */
  9607. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9608. /* Power off */
  9609. bnx2x_set_power_state(bp, PCI_D3hot);
  9610. return 0;
  9611. }
  9612. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9613. struct bnx2x_mcast_ramrod_params *p)
  9614. {
  9615. int mc_count = netdev_mc_count(bp->dev);
  9616. struct bnx2x_mcast_list_elem *mc_mac =
  9617. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9618. struct netdev_hw_addr *ha;
  9619. if (!mc_mac)
  9620. return -ENOMEM;
  9621. INIT_LIST_HEAD(&p->mcast_list);
  9622. netdev_for_each_mc_addr(ha, bp->dev) {
  9623. mc_mac->mac = bnx2x_mc_addr(ha);
  9624. list_add_tail(&mc_mac->link, &p->mcast_list);
  9625. mc_mac++;
  9626. }
  9627. p->mcast_list_len = mc_count;
  9628. return 0;
  9629. }
  9630. static void bnx2x_free_mcast_macs_list(
  9631. struct bnx2x_mcast_ramrod_params *p)
  9632. {
  9633. struct bnx2x_mcast_list_elem *mc_mac =
  9634. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9635. link);
  9636. WARN_ON(!mc_mac);
  9637. kfree(mc_mac);
  9638. }
  9639. /**
  9640. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9641. *
  9642. * @bp: driver handle
  9643. *
  9644. * We will use zero (0) as a MAC type for these MACs.
  9645. */
  9646. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9647. {
  9648. int rc;
  9649. struct net_device *dev = bp->dev;
  9650. struct netdev_hw_addr *ha;
  9651. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9652. unsigned long ramrod_flags = 0;
  9653. /* First schedule a cleanup up of old configuration */
  9654. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9655. if (rc < 0) {
  9656. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9657. return rc;
  9658. }
  9659. netdev_for_each_uc_addr(ha, dev) {
  9660. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9661. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9662. if (rc == -EEXIST) {
  9663. DP(BNX2X_MSG_SP,
  9664. "Failed to schedule ADD operations: %d\n", rc);
  9665. /* do not treat adding same MAC as error */
  9666. rc = 0;
  9667. } else if (rc < 0) {
  9668. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9669. rc);
  9670. return rc;
  9671. }
  9672. }
  9673. /* Execute the pending commands */
  9674. __set_bit(RAMROD_CONT, &ramrod_flags);
  9675. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9676. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9677. }
  9678. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9679. {
  9680. struct net_device *dev = bp->dev;
  9681. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9682. int rc = 0;
  9683. rparam.mcast_obj = &bp->mcast_obj;
  9684. /* first, clear all configured multicast MACs */
  9685. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9686. if (rc < 0) {
  9687. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9688. return rc;
  9689. }
  9690. /* then, configure a new MACs list */
  9691. if (netdev_mc_count(dev)) {
  9692. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9693. if (rc) {
  9694. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9695. rc);
  9696. return rc;
  9697. }
  9698. /* Now add the new MACs */
  9699. rc = bnx2x_config_mcast(bp, &rparam,
  9700. BNX2X_MCAST_CMD_ADD);
  9701. if (rc < 0)
  9702. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9703. rc);
  9704. bnx2x_free_mcast_macs_list(&rparam);
  9705. }
  9706. return rc;
  9707. }
  9708. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9709. void bnx2x_set_rx_mode(struct net_device *dev)
  9710. {
  9711. struct bnx2x *bp = netdev_priv(dev);
  9712. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9713. if (bp->state != BNX2X_STATE_OPEN) {
  9714. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9715. return;
  9716. }
  9717. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9718. if (dev->flags & IFF_PROMISC)
  9719. rx_mode = BNX2X_RX_MODE_PROMISC;
  9720. else if ((dev->flags & IFF_ALLMULTI) ||
  9721. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9722. CHIP_IS_E1(bp)))
  9723. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9724. else {
  9725. if (IS_PF(bp)) {
  9726. /* some multicasts */
  9727. if (bnx2x_set_mc_list(bp) < 0)
  9728. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9729. if (bnx2x_set_uc_list(bp) < 0)
  9730. rx_mode = BNX2X_RX_MODE_PROMISC;
  9731. } else {
  9732. /* configuring mcast to a vf involves sleeping (when we
  9733. * wait for the pf's response). Since this function is
  9734. * called from non sleepable context we must schedule
  9735. * a work item for this purpose
  9736. */
  9737. smp_mb__before_clear_bit();
  9738. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9739. &bp->sp_rtnl_state);
  9740. smp_mb__after_clear_bit();
  9741. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9742. }
  9743. }
  9744. bp->rx_mode = rx_mode;
  9745. /* handle ISCSI SD mode */
  9746. if (IS_MF_ISCSI_SD(bp))
  9747. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9748. /* Schedule the rx_mode command */
  9749. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9750. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9751. return;
  9752. }
  9753. if (IS_PF(bp)) {
  9754. bnx2x_set_storm_rx_mode(bp);
  9755. } else {
  9756. /* configuring rx mode to storms in a vf involves sleeping (when
  9757. * we wait for the pf's response). Since this function is
  9758. * called from non sleepable context we must schedule
  9759. * a work item for this purpose
  9760. */
  9761. smp_mb__before_clear_bit();
  9762. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9763. &bp->sp_rtnl_state);
  9764. smp_mb__after_clear_bit();
  9765. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9766. }
  9767. }
  9768. /* called with rtnl_lock */
  9769. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9770. int devad, u16 addr)
  9771. {
  9772. struct bnx2x *bp = netdev_priv(netdev);
  9773. u16 value;
  9774. int rc;
  9775. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9776. prtad, devad, addr);
  9777. /* The HW expects different devad if CL22 is used */
  9778. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9779. bnx2x_acquire_phy_lock(bp);
  9780. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9781. bnx2x_release_phy_lock(bp);
  9782. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9783. if (!rc)
  9784. rc = value;
  9785. return rc;
  9786. }
  9787. /* called with rtnl_lock */
  9788. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9789. u16 addr, u16 value)
  9790. {
  9791. struct bnx2x *bp = netdev_priv(netdev);
  9792. int rc;
  9793. DP(NETIF_MSG_LINK,
  9794. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9795. prtad, devad, addr, value);
  9796. /* The HW expects different devad if CL22 is used */
  9797. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9798. bnx2x_acquire_phy_lock(bp);
  9799. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9800. bnx2x_release_phy_lock(bp);
  9801. return rc;
  9802. }
  9803. /* called with rtnl_lock */
  9804. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9805. {
  9806. struct bnx2x *bp = netdev_priv(dev);
  9807. struct mii_ioctl_data *mdio = if_mii(ifr);
  9808. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9809. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9810. if (!netif_running(dev))
  9811. return -EAGAIN;
  9812. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9813. }
  9814. #ifdef CONFIG_NET_POLL_CONTROLLER
  9815. static void poll_bnx2x(struct net_device *dev)
  9816. {
  9817. struct bnx2x *bp = netdev_priv(dev);
  9818. int i;
  9819. for_each_eth_queue(bp, i) {
  9820. struct bnx2x_fastpath *fp = &bp->fp[i];
  9821. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9822. }
  9823. }
  9824. #endif
  9825. static int bnx2x_validate_addr(struct net_device *dev)
  9826. {
  9827. struct bnx2x *bp = netdev_priv(dev);
  9828. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9829. BNX2X_ERR("Non-valid Ethernet address\n");
  9830. return -EADDRNOTAVAIL;
  9831. }
  9832. return 0;
  9833. }
  9834. static const struct net_device_ops bnx2x_netdev_ops = {
  9835. .ndo_open = bnx2x_open,
  9836. .ndo_stop = bnx2x_close,
  9837. .ndo_start_xmit = bnx2x_start_xmit,
  9838. .ndo_select_queue = bnx2x_select_queue,
  9839. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9840. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9841. .ndo_validate_addr = bnx2x_validate_addr,
  9842. .ndo_do_ioctl = bnx2x_ioctl,
  9843. .ndo_change_mtu = bnx2x_change_mtu,
  9844. .ndo_fix_features = bnx2x_fix_features,
  9845. .ndo_set_features = bnx2x_set_features,
  9846. .ndo_tx_timeout = bnx2x_tx_timeout,
  9847. #ifdef CONFIG_NET_POLL_CONTROLLER
  9848. .ndo_poll_controller = poll_bnx2x,
  9849. #endif
  9850. .ndo_setup_tc = bnx2x_setup_tc,
  9851. #ifdef CONFIG_BNX2X_SRIOV
  9852. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  9853. #endif
  9854. #ifdef NETDEV_FCOE_WWNN
  9855. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9856. #endif
  9857. };
  9858. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9859. {
  9860. struct device *dev = &bp->pdev->dev;
  9861. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9862. bp->flags |= USING_DAC_FLAG;
  9863. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9864. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9865. return -EIO;
  9866. }
  9867. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9868. dev_err(dev, "System does not support DMA, aborting\n");
  9869. return -EIO;
  9870. }
  9871. return 0;
  9872. }
  9873. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9874. struct net_device *dev, unsigned long board_type)
  9875. {
  9876. int rc;
  9877. u32 pci_cfg_dword;
  9878. bool chip_is_e1x = (board_type == BCM57710 ||
  9879. board_type == BCM57711 ||
  9880. board_type == BCM57711E);
  9881. SET_NETDEV_DEV(dev, &pdev->dev);
  9882. bp->dev = dev;
  9883. bp->pdev = pdev;
  9884. rc = pci_enable_device(pdev);
  9885. if (rc) {
  9886. dev_err(&bp->pdev->dev,
  9887. "Cannot enable PCI device, aborting\n");
  9888. goto err_out;
  9889. }
  9890. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9891. dev_err(&bp->pdev->dev,
  9892. "Cannot find PCI device base address, aborting\n");
  9893. rc = -ENODEV;
  9894. goto err_out_disable;
  9895. }
  9896. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9897. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9898. rc = -ENODEV;
  9899. goto err_out_disable;
  9900. }
  9901. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9902. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9903. PCICFG_REVESION_ID_ERROR_VAL) {
  9904. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9905. rc = -ENODEV;
  9906. goto err_out_disable;
  9907. }
  9908. if (atomic_read(&pdev->enable_cnt) == 1) {
  9909. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9910. if (rc) {
  9911. dev_err(&bp->pdev->dev,
  9912. "Cannot obtain PCI resources, aborting\n");
  9913. goto err_out_disable;
  9914. }
  9915. pci_set_master(pdev);
  9916. pci_save_state(pdev);
  9917. }
  9918. if (IS_PF(bp)) {
  9919. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9920. if (bp->pm_cap == 0) {
  9921. dev_err(&bp->pdev->dev,
  9922. "Cannot find power management capability, aborting\n");
  9923. rc = -EIO;
  9924. goto err_out_release;
  9925. }
  9926. }
  9927. if (!pci_is_pcie(pdev)) {
  9928. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9929. rc = -EIO;
  9930. goto err_out_release;
  9931. }
  9932. rc = bnx2x_set_coherency_mask(bp);
  9933. if (rc)
  9934. goto err_out_release;
  9935. dev->mem_start = pci_resource_start(pdev, 0);
  9936. dev->base_addr = dev->mem_start;
  9937. dev->mem_end = pci_resource_end(pdev, 0);
  9938. dev->irq = pdev->irq;
  9939. bp->regview = pci_ioremap_bar(pdev, 0);
  9940. if (!bp->regview) {
  9941. dev_err(&bp->pdev->dev,
  9942. "Cannot map register space, aborting\n");
  9943. rc = -ENOMEM;
  9944. goto err_out_release;
  9945. }
  9946. /* In E1/E1H use pci device function given by kernel.
  9947. * In E2/E3 read physical function from ME register since these chips
  9948. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9949. * (depending on hypervisor).
  9950. */
  9951. if (chip_is_e1x) {
  9952. bp->pf_num = PCI_FUNC(pdev->devfn);
  9953. } else {
  9954. /* chip is E2/3*/
  9955. pci_read_config_dword(bp->pdev,
  9956. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9957. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9958. ME_REG_ABS_PF_NUM_SHIFT);
  9959. }
  9960. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9961. bnx2x_set_power_state(bp, PCI_D0);
  9962. /* clean indirect addresses */
  9963. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9964. PCICFG_VENDOR_ID_OFFSET);
  9965. /*
  9966. * Clean the following indirect addresses for all functions since it
  9967. * is not used by the driver.
  9968. */
  9969. if (IS_PF(bp)) {
  9970. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9971. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9972. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9973. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9974. if (chip_is_e1x) {
  9975. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9976. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9977. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9978. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9979. }
  9980. /* Enable internal target-read (in case we are probed after PF
  9981. * FLR). Must be done prior to any BAR read access. Only for
  9982. * 57712 and up
  9983. */
  9984. if (!chip_is_e1x)
  9985. REG_WR(bp,
  9986. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9987. }
  9988. dev->watchdog_timeo = TX_TIMEOUT;
  9989. dev->netdev_ops = &bnx2x_netdev_ops;
  9990. bnx2x_set_ethtool_ops(dev);
  9991. dev->priv_flags |= IFF_UNICAST_FLT;
  9992. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9993. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9994. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9995. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9996. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9997. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9998. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9999. if (bp->flags & USING_DAC_FLAG)
  10000. dev->features |= NETIF_F_HIGHDMA;
  10001. /* Add Loopback capability to the device */
  10002. dev->hw_features |= NETIF_F_LOOPBACK;
  10003. #ifdef BCM_DCBNL
  10004. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10005. #endif
  10006. /* get_port_hwinfo() will set prtad and mmds properly */
  10007. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10008. bp->mdio.mmds = 0;
  10009. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10010. bp->mdio.dev = dev;
  10011. bp->mdio.mdio_read = bnx2x_mdio_read;
  10012. bp->mdio.mdio_write = bnx2x_mdio_write;
  10013. return 0;
  10014. err_out_release:
  10015. if (atomic_read(&pdev->enable_cnt) == 1)
  10016. pci_release_regions(pdev);
  10017. err_out_disable:
  10018. pci_disable_device(pdev);
  10019. pci_set_drvdata(pdev, NULL);
  10020. err_out:
  10021. return rc;
  10022. }
  10023. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  10024. {
  10025. u32 val = 0;
  10026. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10027. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10028. /* return value of 1=2.5GHz 2=5GHz */
  10029. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10030. }
  10031. static int bnx2x_check_firmware(struct bnx2x *bp)
  10032. {
  10033. const struct firmware *firmware = bp->firmware;
  10034. struct bnx2x_fw_file_hdr *fw_hdr;
  10035. struct bnx2x_fw_file_section *sections;
  10036. u32 offset, len, num_ops;
  10037. u16 *ops_offsets;
  10038. int i;
  10039. const u8 *fw_ver;
  10040. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10041. BNX2X_ERR("Wrong FW size\n");
  10042. return -EINVAL;
  10043. }
  10044. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10045. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10046. /* Make sure none of the offsets and sizes make us read beyond
  10047. * the end of the firmware data */
  10048. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10049. offset = be32_to_cpu(sections[i].offset);
  10050. len = be32_to_cpu(sections[i].len);
  10051. if (offset + len > firmware->size) {
  10052. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10053. return -EINVAL;
  10054. }
  10055. }
  10056. /* Likewise for the init_ops offsets */
  10057. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10058. ops_offsets = (u16 *)(firmware->data + offset);
  10059. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10060. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10061. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10062. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10063. return -EINVAL;
  10064. }
  10065. }
  10066. /* Check FW version */
  10067. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10068. fw_ver = firmware->data + offset;
  10069. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10070. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10071. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10072. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10073. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10074. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10075. BCM_5710_FW_MAJOR_VERSION,
  10076. BCM_5710_FW_MINOR_VERSION,
  10077. BCM_5710_FW_REVISION_VERSION,
  10078. BCM_5710_FW_ENGINEERING_VERSION);
  10079. return -EINVAL;
  10080. }
  10081. return 0;
  10082. }
  10083. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10084. {
  10085. const __be32 *source = (const __be32 *)_source;
  10086. u32 *target = (u32 *)_target;
  10087. u32 i;
  10088. for (i = 0; i < n/4; i++)
  10089. target[i] = be32_to_cpu(source[i]);
  10090. }
  10091. /*
  10092. Ops array is stored in the following format:
  10093. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10094. */
  10095. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10096. {
  10097. const __be32 *source = (const __be32 *)_source;
  10098. struct raw_op *target = (struct raw_op *)_target;
  10099. u32 i, j, tmp;
  10100. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10101. tmp = be32_to_cpu(source[j]);
  10102. target[i].op = (tmp >> 24) & 0xff;
  10103. target[i].offset = tmp & 0xffffff;
  10104. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10105. }
  10106. }
  10107. /* IRO array is stored in the following format:
  10108. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10109. */
  10110. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10111. {
  10112. const __be32 *source = (const __be32 *)_source;
  10113. struct iro *target = (struct iro *)_target;
  10114. u32 i, j, tmp;
  10115. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10116. target[i].base = be32_to_cpu(source[j]);
  10117. j++;
  10118. tmp = be32_to_cpu(source[j]);
  10119. target[i].m1 = (tmp >> 16) & 0xffff;
  10120. target[i].m2 = tmp & 0xffff;
  10121. j++;
  10122. tmp = be32_to_cpu(source[j]);
  10123. target[i].m3 = (tmp >> 16) & 0xffff;
  10124. target[i].size = tmp & 0xffff;
  10125. j++;
  10126. }
  10127. }
  10128. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10129. {
  10130. const __be16 *source = (const __be16 *)_source;
  10131. u16 *target = (u16 *)_target;
  10132. u32 i;
  10133. for (i = 0; i < n/2; i++)
  10134. target[i] = be16_to_cpu(source[i]);
  10135. }
  10136. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10137. do { \
  10138. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10139. bp->arr = kmalloc(len, GFP_KERNEL); \
  10140. if (!bp->arr) \
  10141. goto lbl; \
  10142. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10143. (u8 *)bp->arr, len); \
  10144. } while (0)
  10145. static int bnx2x_init_firmware(struct bnx2x *bp)
  10146. {
  10147. const char *fw_file_name;
  10148. struct bnx2x_fw_file_hdr *fw_hdr;
  10149. int rc;
  10150. if (bp->firmware)
  10151. return 0;
  10152. if (CHIP_IS_E1(bp))
  10153. fw_file_name = FW_FILE_NAME_E1;
  10154. else if (CHIP_IS_E1H(bp))
  10155. fw_file_name = FW_FILE_NAME_E1H;
  10156. else if (!CHIP_IS_E1x(bp))
  10157. fw_file_name = FW_FILE_NAME_E2;
  10158. else {
  10159. BNX2X_ERR("Unsupported chip revision\n");
  10160. return -EINVAL;
  10161. }
  10162. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10163. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10164. if (rc) {
  10165. BNX2X_ERR("Can't load firmware file %s\n",
  10166. fw_file_name);
  10167. goto request_firmware_exit;
  10168. }
  10169. rc = bnx2x_check_firmware(bp);
  10170. if (rc) {
  10171. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10172. goto request_firmware_exit;
  10173. }
  10174. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10175. /* Initialize the pointers to the init arrays */
  10176. /* Blob */
  10177. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10178. /* Opcodes */
  10179. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10180. /* Offsets */
  10181. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10182. be16_to_cpu_n);
  10183. /* STORMs firmware */
  10184. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10185. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10186. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10187. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10188. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10189. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10190. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10191. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10192. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10193. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10194. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10195. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10196. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10197. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10198. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10199. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10200. /* IRO */
  10201. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10202. return 0;
  10203. iro_alloc_err:
  10204. kfree(bp->init_ops_offsets);
  10205. init_offsets_alloc_err:
  10206. kfree(bp->init_ops);
  10207. init_ops_alloc_err:
  10208. kfree(bp->init_data);
  10209. request_firmware_exit:
  10210. release_firmware(bp->firmware);
  10211. bp->firmware = NULL;
  10212. return rc;
  10213. }
  10214. static void bnx2x_release_firmware(struct bnx2x *bp)
  10215. {
  10216. kfree(bp->init_ops_offsets);
  10217. kfree(bp->init_ops);
  10218. kfree(bp->init_data);
  10219. release_firmware(bp->firmware);
  10220. bp->firmware = NULL;
  10221. }
  10222. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10223. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10224. .init_hw_cmn = bnx2x_init_hw_common,
  10225. .init_hw_port = bnx2x_init_hw_port,
  10226. .init_hw_func = bnx2x_init_hw_func,
  10227. .reset_hw_cmn = bnx2x_reset_common,
  10228. .reset_hw_port = bnx2x_reset_port,
  10229. .reset_hw_func = bnx2x_reset_func,
  10230. .gunzip_init = bnx2x_gunzip_init,
  10231. .gunzip_end = bnx2x_gunzip_end,
  10232. .init_fw = bnx2x_init_firmware,
  10233. .release_fw = bnx2x_release_firmware,
  10234. };
  10235. void bnx2x__init_func_obj(struct bnx2x *bp)
  10236. {
  10237. /* Prepare DMAE related driver resources */
  10238. bnx2x_setup_dmae(bp);
  10239. bnx2x_init_func_obj(bp, &bp->func_obj,
  10240. bnx2x_sp(bp, func_rdata),
  10241. bnx2x_sp_mapping(bp, func_rdata),
  10242. bnx2x_sp(bp, func_afex_rdata),
  10243. bnx2x_sp_mapping(bp, func_afex_rdata),
  10244. &bnx2x_func_sp_drv);
  10245. }
  10246. /* must be called after sriov-enable */
  10247. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10248. {
  10249. int cid_count = BNX2X_L2_MAX_CID(bp);
  10250. if (IS_SRIOV(bp))
  10251. cid_count += BNX2X_VF_CIDS;
  10252. if (CNIC_SUPPORT(bp))
  10253. cid_count += CNIC_CID_MAX;
  10254. return roundup(cid_count, QM_CID_ROUND);
  10255. }
  10256. /**
  10257. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10258. *
  10259. * @dev: pci device
  10260. *
  10261. */
  10262. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10263. int cnic_cnt, bool is_vf)
  10264. {
  10265. int pos, index;
  10266. u16 control = 0;
  10267. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10268. /*
  10269. * If MSI-X is not supported - return number of SBs needed to support
  10270. * one fast path queue: one FP queue + SB for CNIC
  10271. */
  10272. if (!pos) {
  10273. dev_info(&pdev->dev, "no msix capability found\n");
  10274. return 1 + cnic_cnt;
  10275. }
  10276. dev_info(&pdev->dev, "msix capability found\n");
  10277. /*
  10278. * The value in the PCI configuration space is the index of the last
  10279. * entry, namely one less than the actual size of the table, which is
  10280. * exactly what we want to return from this function: number of all SBs
  10281. * without the default SB.
  10282. * For VFs there is no default SB, then we return (index+1).
  10283. */
  10284. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10285. index = control & PCI_MSIX_FLAGS_QSIZE;
  10286. return is_vf ? index + 1 : index;
  10287. }
  10288. static int set_max_cos_est(int chip_id)
  10289. {
  10290. switch (chip_id) {
  10291. case BCM57710:
  10292. case BCM57711:
  10293. case BCM57711E:
  10294. return BNX2X_MULTI_TX_COS_E1X;
  10295. case BCM57712:
  10296. case BCM57712_MF:
  10297. case BCM57712_VF:
  10298. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10299. case BCM57800:
  10300. case BCM57800_MF:
  10301. case BCM57800_VF:
  10302. case BCM57810:
  10303. case BCM57810_MF:
  10304. case BCM57840_4_10:
  10305. case BCM57840_2_20:
  10306. case BCM57840_O:
  10307. case BCM57840_MFO:
  10308. case BCM57810_VF:
  10309. case BCM57840_MF:
  10310. case BCM57840_VF:
  10311. case BCM57811:
  10312. case BCM57811_MF:
  10313. case BCM57811_VF:
  10314. return BNX2X_MULTI_TX_COS_E3B0;
  10315. return 1;
  10316. default:
  10317. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10318. return -ENODEV;
  10319. }
  10320. }
  10321. static int set_is_vf(int chip_id)
  10322. {
  10323. switch (chip_id) {
  10324. case BCM57712_VF:
  10325. case BCM57800_VF:
  10326. case BCM57810_VF:
  10327. case BCM57840_VF:
  10328. case BCM57811_VF:
  10329. return true;
  10330. default:
  10331. return false;
  10332. }
  10333. }
  10334. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10335. static int bnx2x_init_one(struct pci_dev *pdev,
  10336. const struct pci_device_id *ent)
  10337. {
  10338. struct net_device *dev = NULL;
  10339. struct bnx2x *bp;
  10340. int pcie_width, pcie_speed;
  10341. int rc, max_non_def_sbs;
  10342. int rx_count, tx_count, rss_count, doorbell_size;
  10343. int max_cos_est;
  10344. bool is_vf;
  10345. int cnic_cnt;
  10346. /* An estimated maximum supported CoS number according to the chip
  10347. * version.
  10348. * We will try to roughly estimate the maximum number of CoSes this chip
  10349. * may support in order to minimize the memory allocated for Tx
  10350. * netdev_queue's. This number will be accurately calculated during the
  10351. * initialization of bp->max_cos based on the chip versions AND chip
  10352. * revision in the bnx2x_init_bp().
  10353. */
  10354. max_cos_est = set_max_cos_est(ent->driver_data);
  10355. if (max_cos_est < 0)
  10356. return max_cos_est;
  10357. is_vf = set_is_vf(ent->driver_data);
  10358. cnic_cnt = is_vf ? 0 : 1;
  10359. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10360. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10361. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10362. if (rss_count < 1)
  10363. return -EINVAL;
  10364. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10365. rx_count = rss_count + cnic_cnt;
  10366. /* Maximum number of netdev Tx queues:
  10367. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10368. */
  10369. tx_count = rss_count * max_cos_est + cnic_cnt;
  10370. /* dev zeroed in init_etherdev */
  10371. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10372. if (!dev)
  10373. return -ENOMEM;
  10374. bp = netdev_priv(dev);
  10375. bp->flags = 0;
  10376. if (is_vf)
  10377. bp->flags |= IS_VF_FLAG;
  10378. bp->igu_sb_cnt = max_non_def_sbs;
  10379. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10380. bp->msg_enable = debug;
  10381. bp->cnic_support = cnic_cnt;
  10382. bp->cnic_probe = bnx2x_cnic_probe;
  10383. pci_set_drvdata(pdev, dev);
  10384. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10385. if (rc < 0) {
  10386. free_netdev(dev);
  10387. return rc;
  10388. }
  10389. BNX2X_DEV_INFO("This is a %s function\n",
  10390. IS_PF(bp) ? "physical" : "virtual");
  10391. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10392. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10393. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10394. tx_count, rx_count);
  10395. rc = bnx2x_init_bp(bp);
  10396. if (rc)
  10397. goto init_one_exit;
  10398. /* Map doorbells here as we need the real value of bp->max_cos which
  10399. * is initialized in bnx2x_init_bp() to determine the number of
  10400. * l2 connections.
  10401. */
  10402. if (IS_VF(bp)) {
  10403. bnx2x_vf_map_doorbells(bp);
  10404. rc = bnx2x_vf_pci_alloc(bp);
  10405. if (rc)
  10406. goto init_one_exit;
  10407. } else {
  10408. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10409. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10410. dev_err(&bp->pdev->dev,
  10411. "Cannot map doorbells, bar size too small, aborting\n");
  10412. rc = -ENOMEM;
  10413. goto init_one_exit;
  10414. }
  10415. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10416. doorbell_size);
  10417. }
  10418. if (!bp->doorbells) {
  10419. dev_err(&bp->pdev->dev,
  10420. "Cannot map doorbell space, aborting\n");
  10421. rc = -ENOMEM;
  10422. goto init_one_exit;
  10423. }
  10424. if (IS_VF(bp)) {
  10425. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10426. if (rc)
  10427. goto init_one_exit;
  10428. }
  10429. /* Enable SRIOV if capability found in configuration space.
  10430. * Once the generic SR-IOV framework makes it in from the
  10431. * pci tree this will be revised, to allow dynamic control
  10432. * over the number of VFs. Right now, change the num of vfs
  10433. * param below to enable SR-IOV.
  10434. */
  10435. rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/);
  10436. if (rc)
  10437. goto init_one_exit;
  10438. /* calc qm_cid_count */
  10439. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10440. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10441. /* disable FCOE L2 queue for E1x*/
  10442. if (CHIP_IS_E1x(bp))
  10443. bp->flags |= NO_FCOE_FLAG;
  10444. /* disable FCOE for 57840 device, until FW supports it */
  10445. switch (ent->driver_data) {
  10446. case BCM57840_O:
  10447. case BCM57840_4_10:
  10448. case BCM57840_2_20:
  10449. case BCM57840_MFO:
  10450. case BCM57840_MF:
  10451. bp->flags |= NO_FCOE_FLAG;
  10452. }
  10453. /* Set bp->num_queues for MSI-X mode*/
  10454. bnx2x_set_num_queues(bp);
  10455. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10456. * needed.
  10457. */
  10458. rc = bnx2x_set_int_mode(bp);
  10459. if (rc) {
  10460. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10461. goto init_one_exit;
  10462. }
  10463. /* register the net device */
  10464. rc = register_netdev(dev);
  10465. if (rc) {
  10466. dev_err(&pdev->dev, "Cannot register net device\n");
  10467. goto init_one_exit;
  10468. }
  10469. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10470. if (!NO_FCOE(bp)) {
  10471. /* Add storage MAC address */
  10472. rtnl_lock();
  10473. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10474. rtnl_unlock();
  10475. }
  10476. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10477. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10478. pcie_width, pcie_speed);
  10479. BNX2X_DEV_INFO(
  10480. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10481. board_info[ent->driver_data].name,
  10482. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10483. pcie_width,
  10484. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10485. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10486. "5GHz (Gen2)" : "2.5GHz",
  10487. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10488. return 0;
  10489. init_one_exit:
  10490. if (bp->regview)
  10491. iounmap(bp->regview);
  10492. if (IS_PF(bp) && bp->doorbells)
  10493. iounmap(bp->doorbells);
  10494. free_netdev(dev);
  10495. if (atomic_read(&pdev->enable_cnt) == 1)
  10496. pci_release_regions(pdev);
  10497. pci_disable_device(pdev);
  10498. pci_set_drvdata(pdev, NULL);
  10499. return rc;
  10500. }
  10501. static void bnx2x_remove_one(struct pci_dev *pdev)
  10502. {
  10503. struct net_device *dev = pci_get_drvdata(pdev);
  10504. struct bnx2x *bp;
  10505. if (!dev) {
  10506. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10507. return;
  10508. }
  10509. bp = netdev_priv(dev);
  10510. /* Delete storage MAC address */
  10511. if (!NO_FCOE(bp)) {
  10512. rtnl_lock();
  10513. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10514. rtnl_unlock();
  10515. }
  10516. #ifdef BCM_DCBNL
  10517. /* Delete app tlvs from dcbnl */
  10518. bnx2x_dcbnl_update_applist(bp, true);
  10519. #endif
  10520. unregister_netdev(dev);
  10521. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10522. if (IS_PF(bp))
  10523. bnx2x_set_power_state(bp, PCI_D0);
  10524. /* Disable MSI/MSI-X */
  10525. bnx2x_disable_msi(bp);
  10526. /* Power off */
  10527. if (IS_PF(bp))
  10528. bnx2x_set_power_state(bp, PCI_D3hot);
  10529. /* Make sure RESET task is not scheduled before continuing */
  10530. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10531. bnx2x_iov_remove_one(bp);
  10532. /* send message via vfpf channel to release the resources of this vf */
  10533. if (IS_VF(bp))
  10534. bnx2x_vfpf_release(bp);
  10535. if (bp->regview)
  10536. iounmap(bp->regview);
  10537. /* for vf doorbells are part of the regview and were unmapped along with
  10538. * it. FW is only loaded by PF.
  10539. */
  10540. if (IS_PF(bp)) {
  10541. if (bp->doorbells)
  10542. iounmap(bp->doorbells);
  10543. bnx2x_release_firmware(bp);
  10544. }
  10545. bnx2x_free_mem_bp(bp);
  10546. free_netdev(dev);
  10547. if (atomic_read(&pdev->enable_cnt) == 1)
  10548. pci_release_regions(pdev);
  10549. pci_disable_device(pdev);
  10550. pci_set_drvdata(pdev, NULL);
  10551. }
  10552. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10553. {
  10554. int i;
  10555. bp->state = BNX2X_STATE_ERROR;
  10556. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10557. if (CNIC_LOADED(bp))
  10558. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10559. /* Stop Tx */
  10560. bnx2x_tx_disable(bp);
  10561. bnx2x_netif_stop(bp, 0);
  10562. /* Delete all NAPI objects */
  10563. bnx2x_del_all_napi(bp);
  10564. if (CNIC_LOADED(bp))
  10565. bnx2x_del_all_napi_cnic(bp);
  10566. del_timer_sync(&bp->timer);
  10567. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10568. /* Release IRQs */
  10569. bnx2x_free_irq(bp);
  10570. /* Free SKBs, SGEs, TPA pool and driver internals */
  10571. bnx2x_free_skbs(bp);
  10572. for_each_rx_queue(bp, i)
  10573. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10574. bnx2x_free_mem(bp);
  10575. bp->state = BNX2X_STATE_CLOSED;
  10576. netif_carrier_off(bp->dev);
  10577. return 0;
  10578. }
  10579. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10580. {
  10581. u32 val;
  10582. mutex_init(&bp->port.phy_mutex);
  10583. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10584. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10585. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10586. BNX2X_ERR("BAD MCP validity signature\n");
  10587. }
  10588. /**
  10589. * bnx2x_io_error_detected - called when PCI error is detected
  10590. * @pdev: Pointer to PCI device
  10591. * @state: The current pci connection state
  10592. *
  10593. * This function is called after a PCI bus error affecting
  10594. * this device has been detected.
  10595. */
  10596. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10597. pci_channel_state_t state)
  10598. {
  10599. struct net_device *dev = pci_get_drvdata(pdev);
  10600. struct bnx2x *bp = netdev_priv(dev);
  10601. rtnl_lock();
  10602. netif_device_detach(dev);
  10603. if (state == pci_channel_io_perm_failure) {
  10604. rtnl_unlock();
  10605. return PCI_ERS_RESULT_DISCONNECT;
  10606. }
  10607. if (netif_running(dev))
  10608. bnx2x_eeh_nic_unload(bp);
  10609. pci_disable_device(pdev);
  10610. rtnl_unlock();
  10611. /* Request a slot reset */
  10612. return PCI_ERS_RESULT_NEED_RESET;
  10613. }
  10614. /**
  10615. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10616. * @pdev: Pointer to PCI device
  10617. *
  10618. * Restart the card from scratch, as if from a cold-boot.
  10619. */
  10620. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10621. {
  10622. struct net_device *dev = pci_get_drvdata(pdev);
  10623. struct bnx2x *bp = netdev_priv(dev);
  10624. rtnl_lock();
  10625. if (pci_enable_device(pdev)) {
  10626. dev_err(&pdev->dev,
  10627. "Cannot re-enable PCI device after reset\n");
  10628. rtnl_unlock();
  10629. return PCI_ERS_RESULT_DISCONNECT;
  10630. }
  10631. pci_set_master(pdev);
  10632. pci_restore_state(pdev);
  10633. if (netif_running(dev))
  10634. bnx2x_set_power_state(bp, PCI_D0);
  10635. rtnl_unlock();
  10636. return PCI_ERS_RESULT_RECOVERED;
  10637. }
  10638. /**
  10639. * bnx2x_io_resume - called when traffic can start flowing again
  10640. * @pdev: Pointer to PCI device
  10641. *
  10642. * This callback is called when the error recovery driver tells us that
  10643. * its OK to resume normal operation.
  10644. */
  10645. static void bnx2x_io_resume(struct pci_dev *pdev)
  10646. {
  10647. struct net_device *dev = pci_get_drvdata(pdev);
  10648. struct bnx2x *bp = netdev_priv(dev);
  10649. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10650. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10651. return;
  10652. }
  10653. rtnl_lock();
  10654. bnx2x_eeh_recover(bp);
  10655. if (netif_running(dev))
  10656. bnx2x_nic_load(bp, LOAD_NORMAL);
  10657. netif_device_attach(dev);
  10658. rtnl_unlock();
  10659. }
  10660. static const struct pci_error_handlers bnx2x_err_handler = {
  10661. .error_detected = bnx2x_io_error_detected,
  10662. .slot_reset = bnx2x_io_slot_reset,
  10663. .resume = bnx2x_io_resume,
  10664. };
  10665. static struct pci_driver bnx2x_pci_driver = {
  10666. .name = DRV_MODULE_NAME,
  10667. .id_table = bnx2x_pci_tbl,
  10668. .probe = bnx2x_init_one,
  10669. .remove = bnx2x_remove_one,
  10670. .suspend = bnx2x_suspend,
  10671. .resume = bnx2x_resume,
  10672. .err_handler = &bnx2x_err_handler,
  10673. };
  10674. static int __init bnx2x_init(void)
  10675. {
  10676. int ret;
  10677. pr_info("%s", version);
  10678. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10679. if (bnx2x_wq == NULL) {
  10680. pr_err("Cannot create workqueue\n");
  10681. return -ENOMEM;
  10682. }
  10683. ret = pci_register_driver(&bnx2x_pci_driver);
  10684. if (ret) {
  10685. pr_err("Cannot register driver\n");
  10686. destroy_workqueue(bnx2x_wq);
  10687. }
  10688. return ret;
  10689. }
  10690. static void __exit bnx2x_cleanup(void)
  10691. {
  10692. struct list_head *pos, *q;
  10693. pci_unregister_driver(&bnx2x_pci_driver);
  10694. destroy_workqueue(bnx2x_wq);
  10695. /* Free globablly allocated resources */
  10696. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10697. struct bnx2x_prev_path_list *tmp =
  10698. list_entry(pos, struct bnx2x_prev_path_list, list);
  10699. list_del(pos);
  10700. kfree(tmp);
  10701. }
  10702. }
  10703. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10704. {
  10705. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10706. }
  10707. module_init(bnx2x_init);
  10708. module_exit(bnx2x_cleanup);
  10709. /**
  10710. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10711. *
  10712. * @bp: driver handle
  10713. * @set: set or clear the CAM entry
  10714. *
  10715. * This function will wait until the ramdord completion returns.
  10716. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10717. */
  10718. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10719. {
  10720. unsigned long ramrod_flags = 0;
  10721. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10722. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10723. &bp->iscsi_l2_mac_obj, true,
  10724. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10725. }
  10726. /* count denotes the number of new completions we have seen */
  10727. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10728. {
  10729. struct eth_spe *spe;
  10730. int cxt_index, cxt_offset;
  10731. #ifdef BNX2X_STOP_ON_ERROR
  10732. if (unlikely(bp->panic))
  10733. return;
  10734. #endif
  10735. spin_lock_bh(&bp->spq_lock);
  10736. BUG_ON(bp->cnic_spq_pending < count);
  10737. bp->cnic_spq_pending -= count;
  10738. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10739. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10740. & SPE_HDR_CONN_TYPE) >>
  10741. SPE_HDR_CONN_TYPE_SHIFT;
  10742. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10743. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10744. /* Set validation for iSCSI L2 client before sending SETUP
  10745. * ramrod
  10746. */
  10747. if (type == ETH_CONNECTION_TYPE) {
  10748. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10749. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10750. ILT_PAGE_CIDS;
  10751. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10752. (cxt_index * ILT_PAGE_CIDS);
  10753. bnx2x_set_ctx_validation(bp,
  10754. &bp->context[cxt_index].
  10755. vcxt[cxt_offset].eth,
  10756. BNX2X_ISCSI_ETH_CID(bp));
  10757. }
  10758. }
  10759. /*
  10760. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10761. * and in the air. We also check that number of outstanding
  10762. * COMMON ramrods is not more than the EQ and SPQ can
  10763. * accommodate.
  10764. */
  10765. if (type == ETH_CONNECTION_TYPE) {
  10766. if (!atomic_read(&bp->cq_spq_left))
  10767. break;
  10768. else
  10769. atomic_dec(&bp->cq_spq_left);
  10770. } else if (type == NONE_CONNECTION_TYPE) {
  10771. if (!atomic_read(&bp->eq_spq_left))
  10772. break;
  10773. else
  10774. atomic_dec(&bp->eq_spq_left);
  10775. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10776. (type == FCOE_CONNECTION_TYPE)) {
  10777. if (bp->cnic_spq_pending >=
  10778. bp->cnic_eth_dev.max_kwqe_pending)
  10779. break;
  10780. else
  10781. bp->cnic_spq_pending++;
  10782. } else {
  10783. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10784. bnx2x_panic();
  10785. break;
  10786. }
  10787. spe = bnx2x_sp_get_next(bp);
  10788. *spe = *bp->cnic_kwq_cons;
  10789. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10790. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10791. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10792. bp->cnic_kwq_cons = bp->cnic_kwq;
  10793. else
  10794. bp->cnic_kwq_cons++;
  10795. }
  10796. bnx2x_sp_prod_update(bp);
  10797. spin_unlock_bh(&bp->spq_lock);
  10798. }
  10799. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10800. struct kwqe_16 *kwqes[], u32 count)
  10801. {
  10802. struct bnx2x *bp = netdev_priv(dev);
  10803. int i;
  10804. #ifdef BNX2X_STOP_ON_ERROR
  10805. if (unlikely(bp->panic)) {
  10806. BNX2X_ERR("Can't post to SP queue while panic\n");
  10807. return -EIO;
  10808. }
  10809. #endif
  10810. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10811. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10812. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10813. return -EAGAIN;
  10814. }
  10815. spin_lock_bh(&bp->spq_lock);
  10816. for (i = 0; i < count; i++) {
  10817. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10818. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10819. break;
  10820. *bp->cnic_kwq_prod = *spe;
  10821. bp->cnic_kwq_pending++;
  10822. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10823. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10824. spe->data.update_data_addr.hi,
  10825. spe->data.update_data_addr.lo,
  10826. bp->cnic_kwq_pending);
  10827. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10828. bp->cnic_kwq_prod = bp->cnic_kwq;
  10829. else
  10830. bp->cnic_kwq_prod++;
  10831. }
  10832. spin_unlock_bh(&bp->spq_lock);
  10833. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10834. bnx2x_cnic_sp_post(bp, 0);
  10835. return i;
  10836. }
  10837. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10838. {
  10839. struct cnic_ops *c_ops;
  10840. int rc = 0;
  10841. mutex_lock(&bp->cnic_mutex);
  10842. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10843. lockdep_is_held(&bp->cnic_mutex));
  10844. if (c_ops)
  10845. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10846. mutex_unlock(&bp->cnic_mutex);
  10847. return rc;
  10848. }
  10849. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10850. {
  10851. struct cnic_ops *c_ops;
  10852. int rc = 0;
  10853. rcu_read_lock();
  10854. c_ops = rcu_dereference(bp->cnic_ops);
  10855. if (c_ops)
  10856. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10857. rcu_read_unlock();
  10858. return rc;
  10859. }
  10860. /*
  10861. * for commands that have no data
  10862. */
  10863. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10864. {
  10865. struct cnic_ctl_info ctl = {0};
  10866. ctl.cmd = cmd;
  10867. return bnx2x_cnic_ctl_send(bp, &ctl);
  10868. }
  10869. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10870. {
  10871. struct cnic_ctl_info ctl = {0};
  10872. /* first we tell CNIC and only then we count this as a completion */
  10873. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10874. ctl.data.comp.cid = cid;
  10875. ctl.data.comp.error = err;
  10876. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10877. bnx2x_cnic_sp_post(bp, 0);
  10878. }
  10879. /* Called with netif_addr_lock_bh() taken.
  10880. * Sets an rx_mode config for an iSCSI ETH client.
  10881. * Doesn't block.
  10882. * Completion should be checked outside.
  10883. */
  10884. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10885. {
  10886. unsigned long accept_flags = 0, ramrod_flags = 0;
  10887. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10888. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10889. if (start) {
  10890. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10891. * because it's the only way for UIO Queue to accept
  10892. * multicasts (in non-promiscuous mode only one Queue per
  10893. * function will receive multicast packets (leading in our
  10894. * case).
  10895. */
  10896. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10897. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10898. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10899. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10900. /* Clear STOP_PENDING bit if START is requested */
  10901. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10902. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10903. } else
  10904. /* Clear START_PENDING bit if STOP is requested */
  10905. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10906. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10907. set_bit(sched_state, &bp->sp_state);
  10908. else {
  10909. __set_bit(RAMROD_RX, &ramrod_flags);
  10910. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10911. ramrod_flags);
  10912. }
  10913. }
  10914. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10915. {
  10916. struct bnx2x *bp = netdev_priv(dev);
  10917. int rc = 0;
  10918. switch (ctl->cmd) {
  10919. case DRV_CTL_CTXTBL_WR_CMD: {
  10920. u32 index = ctl->data.io.offset;
  10921. dma_addr_t addr = ctl->data.io.dma_addr;
  10922. bnx2x_ilt_wr(bp, index, addr);
  10923. break;
  10924. }
  10925. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10926. int count = ctl->data.credit.credit_count;
  10927. bnx2x_cnic_sp_post(bp, count);
  10928. break;
  10929. }
  10930. /* rtnl_lock is held. */
  10931. case DRV_CTL_START_L2_CMD: {
  10932. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10933. unsigned long sp_bits = 0;
  10934. /* Configure the iSCSI classification object */
  10935. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10936. cp->iscsi_l2_client_id,
  10937. cp->iscsi_l2_cid, BP_FUNC(bp),
  10938. bnx2x_sp(bp, mac_rdata),
  10939. bnx2x_sp_mapping(bp, mac_rdata),
  10940. BNX2X_FILTER_MAC_PENDING,
  10941. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10942. &bp->macs_pool);
  10943. /* Set iSCSI MAC address */
  10944. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10945. if (rc)
  10946. break;
  10947. mmiowb();
  10948. barrier();
  10949. /* Start accepting on iSCSI L2 ring */
  10950. netif_addr_lock_bh(dev);
  10951. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10952. netif_addr_unlock_bh(dev);
  10953. /* bits to wait on */
  10954. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10955. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10956. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10957. BNX2X_ERR("rx_mode completion timed out!\n");
  10958. break;
  10959. }
  10960. /* rtnl_lock is held. */
  10961. case DRV_CTL_STOP_L2_CMD: {
  10962. unsigned long sp_bits = 0;
  10963. /* Stop accepting on iSCSI L2 ring */
  10964. netif_addr_lock_bh(dev);
  10965. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10966. netif_addr_unlock_bh(dev);
  10967. /* bits to wait on */
  10968. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10969. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10970. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10971. BNX2X_ERR("rx_mode completion timed out!\n");
  10972. mmiowb();
  10973. barrier();
  10974. /* Unset iSCSI L2 MAC */
  10975. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10976. BNX2X_ISCSI_ETH_MAC, true);
  10977. break;
  10978. }
  10979. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10980. int count = ctl->data.credit.credit_count;
  10981. smp_mb__before_atomic_inc();
  10982. atomic_add(count, &bp->cq_spq_left);
  10983. smp_mb__after_atomic_inc();
  10984. break;
  10985. }
  10986. case DRV_CTL_ULP_REGISTER_CMD: {
  10987. int ulp_type = ctl->data.register_data.ulp_type;
  10988. if (CHIP_IS_E3(bp)) {
  10989. int idx = BP_FW_MB_IDX(bp);
  10990. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10991. int path = BP_PATH(bp);
  10992. int port = BP_PORT(bp);
  10993. int i;
  10994. u32 scratch_offset;
  10995. u32 *host_addr;
  10996. /* first write capability to shmem2 */
  10997. if (ulp_type == CNIC_ULP_ISCSI)
  10998. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10999. else if (ulp_type == CNIC_ULP_FCOE)
  11000. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11001. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11002. if ((ulp_type != CNIC_ULP_FCOE) ||
  11003. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11004. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11005. break;
  11006. /* if reached here - should write fcoe capabilities */
  11007. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11008. if (!scratch_offset)
  11009. break;
  11010. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11011. fcoe_features[path][port]);
  11012. host_addr = (u32 *) &(ctl->data.register_data.
  11013. fcoe_features);
  11014. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11015. i += 4)
  11016. REG_WR(bp, scratch_offset + i,
  11017. *(host_addr + i/4));
  11018. }
  11019. break;
  11020. }
  11021. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11022. int ulp_type = ctl->data.ulp_type;
  11023. if (CHIP_IS_E3(bp)) {
  11024. int idx = BP_FW_MB_IDX(bp);
  11025. u32 cap;
  11026. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11027. if (ulp_type == CNIC_ULP_ISCSI)
  11028. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11029. else if (ulp_type == CNIC_ULP_FCOE)
  11030. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11031. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11032. }
  11033. break;
  11034. }
  11035. default:
  11036. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11037. rc = -EINVAL;
  11038. }
  11039. return rc;
  11040. }
  11041. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11042. {
  11043. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11044. if (bp->flags & USING_MSIX_FLAG) {
  11045. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11046. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11047. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11048. } else {
  11049. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11050. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11051. }
  11052. if (!CHIP_IS_E1x(bp))
  11053. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11054. else
  11055. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11056. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11057. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11058. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11059. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11060. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11061. cp->num_irq = 2;
  11062. }
  11063. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11064. {
  11065. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11066. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11067. bnx2x_cid_ilt_lines(bp);
  11068. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11069. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11070. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11071. if (NO_ISCSI_OOO(bp))
  11072. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11073. }
  11074. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11075. void *data)
  11076. {
  11077. struct bnx2x *bp = netdev_priv(dev);
  11078. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11079. int rc;
  11080. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11081. if (ops == NULL) {
  11082. BNX2X_ERR("NULL ops received\n");
  11083. return -EINVAL;
  11084. }
  11085. if (!CNIC_SUPPORT(bp)) {
  11086. BNX2X_ERR("Can't register CNIC when not supported\n");
  11087. return -EOPNOTSUPP;
  11088. }
  11089. if (!CNIC_LOADED(bp)) {
  11090. rc = bnx2x_load_cnic(bp);
  11091. if (rc) {
  11092. BNX2X_ERR("CNIC-related load failed\n");
  11093. return rc;
  11094. }
  11095. }
  11096. bp->cnic_enabled = true;
  11097. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11098. if (!bp->cnic_kwq)
  11099. return -ENOMEM;
  11100. bp->cnic_kwq_cons = bp->cnic_kwq;
  11101. bp->cnic_kwq_prod = bp->cnic_kwq;
  11102. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11103. bp->cnic_spq_pending = 0;
  11104. bp->cnic_kwq_pending = 0;
  11105. bp->cnic_data = data;
  11106. cp->num_irq = 0;
  11107. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11108. cp->iro_arr = bp->iro_arr;
  11109. bnx2x_setup_cnic_irq_info(bp);
  11110. rcu_assign_pointer(bp->cnic_ops, ops);
  11111. return 0;
  11112. }
  11113. static int bnx2x_unregister_cnic(struct net_device *dev)
  11114. {
  11115. struct bnx2x *bp = netdev_priv(dev);
  11116. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11117. mutex_lock(&bp->cnic_mutex);
  11118. cp->drv_state = 0;
  11119. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11120. mutex_unlock(&bp->cnic_mutex);
  11121. synchronize_rcu();
  11122. kfree(bp->cnic_kwq);
  11123. bp->cnic_kwq = NULL;
  11124. return 0;
  11125. }
  11126. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11127. {
  11128. struct bnx2x *bp = netdev_priv(dev);
  11129. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11130. /* If both iSCSI and FCoE are disabled - return NULL in
  11131. * order to indicate CNIC that it should not try to work
  11132. * with this device.
  11133. */
  11134. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11135. return NULL;
  11136. cp->drv_owner = THIS_MODULE;
  11137. cp->chip_id = CHIP_ID(bp);
  11138. cp->pdev = bp->pdev;
  11139. cp->io_base = bp->regview;
  11140. cp->io_base2 = bp->doorbells;
  11141. cp->max_kwqe_pending = 8;
  11142. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11143. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11144. bnx2x_cid_ilt_lines(bp);
  11145. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11146. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11147. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11148. cp->drv_ctl = bnx2x_drv_ctl;
  11149. cp->drv_register_cnic = bnx2x_register_cnic;
  11150. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11151. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11152. cp->iscsi_l2_client_id =
  11153. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11154. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11155. if (NO_ISCSI_OOO(bp))
  11156. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11157. if (NO_ISCSI(bp))
  11158. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11159. if (NO_FCOE(bp))
  11160. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11161. BNX2X_DEV_INFO(
  11162. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11163. cp->ctx_blk_size,
  11164. cp->ctx_tbl_offset,
  11165. cp->ctx_tbl_len,
  11166. cp->starting_cid);
  11167. return cp;
  11168. }
  11169. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11170. {
  11171. struct bnx2x *bp = fp->bp;
  11172. u32 offset = BAR_USTRORM_INTMEM;
  11173. if (IS_VF(bp))
  11174. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11175. else if (!CHIP_IS_E1x(bp))
  11176. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11177. else
  11178. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11179. return offset;
  11180. }
  11181. /* called only on E1H or E2.
  11182. * When pretending to be PF, the pretend value is the function number 0...7
  11183. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11184. * combination
  11185. */
  11186. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11187. {
  11188. u32 pretend_reg;
  11189. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11190. return -1;
  11191. /* get my own pretend register */
  11192. pretend_reg = bnx2x_get_pretend_reg(bp);
  11193. REG_WR(bp, pretend_reg, pretend_func_val);
  11194. REG_RD(bp, pretend_reg);
  11195. return 0;
  11196. }