bnx2x_main.c 368 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/ipv6.h>
  43. #include <net/tcp.h>
  44. #include <net/checksum.h>
  45. #include <net/ip6_checksum.h>
  46. #include <linux/workqueue.h>
  47. #include <linux/crc32.h>
  48. #include <linux/crc32c.h>
  49. #include <linux/prefetch.h>
  50. #include <linux/zlib.h>
  51. #include <linux/io.h>
  52. #include <linux/semaphore.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_vfpf.h"
  60. #include "bnx2x_dcb.h"
  61. #include "bnx2x_sp.h"
  62. #include <linux/firmware.h>
  63. #include "bnx2x_fw_file_hdr.h"
  64. /* FW files */
  65. #define FW_FILE_VERSION \
  66. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  69. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  70. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  73. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] =
  76. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  77. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  78. MODULE_AUTHOR("Eliezer Tamir");
  79. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  80. "BCM57710/57711/57711E/"
  81. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  82. "57840/57840_MF Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_MODULE_VERSION);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues,
  91. " Set number of queues (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. int int_mode;
  96. module_param(int_mode, int, 0);
  97. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  98. "(1 INT#x; 2 MSI)");
  99. static int dropless_fc;
  100. module_param(dropless_fc, int, 0);
  101. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  102. static int mrrs = -1;
  103. module_param(mrrs, int, 0);
  104. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  105. static int debug;
  106. module_param(debug, int, 0);
  107. MODULE_PARM_DESC(debug, " Default debug msglevel");
  108. struct workqueue_struct *bnx2x_wq;
  109. struct bnx2x_mac_vals {
  110. u32 xmac_addr;
  111. u32 xmac_val;
  112. u32 emac_addr;
  113. u32 emac_val;
  114. u32 umac_addr;
  115. u32 umac_val;
  116. u32 bmac_addr;
  117. u32 bmac_val[2];
  118. };
  119. enum bnx2x_board_type {
  120. BCM57710 = 0,
  121. BCM57711,
  122. BCM57711E,
  123. BCM57712,
  124. BCM57712_MF,
  125. BCM57712_VF,
  126. BCM57800,
  127. BCM57800_MF,
  128. BCM57800_VF,
  129. BCM57810,
  130. BCM57810_MF,
  131. BCM57810_VF,
  132. BCM57840_4_10,
  133. BCM57840_2_20,
  134. BCM57840_MF,
  135. BCM57840_VF,
  136. BCM57811,
  137. BCM57811_MF,
  138. BCM57840_O,
  139. BCM57840_MFO,
  140. BCM57811_VF
  141. };
  142. /* indexed by board_type, above */
  143. static struct {
  144. char *name;
  145. } board_info[] = {
  146. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  147. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  148. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  149. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  150. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  151. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  152. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  153. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  154. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  156. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  157. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  159. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  160. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  161. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  162. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  163. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  164. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  165. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  166. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  167. };
  168. #ifndef PCI_DEVICE_ID_NX2_57710
  169. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57711
  172. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711E
  175. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57712
  178. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  181. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  184. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57800
  187. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  190. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  193. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57810
  196. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  199. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57840_O
  202. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  205. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  208. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  211. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  214. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  217. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  220. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57811
  223. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  226. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  229. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  230. #endif
  231. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  232. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  233. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  253. { 0 }
  254. };
  255. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  256. /* Global resources for unloading a previously loaded device */
  257. #define BNX2X_PREV_WAIT_NEEDED 1
  258. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  259. static LIST_HEAD(bnx2x_prev_list);
  260. /****************************************************************************
  261. * General service functions
  262. ****************************************************************************/
  263. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  264. u32 addr, dma_addr_t mapping)
  265. {
  266. REG_WR(bp, addr, U64_LO(mapping));
  267. REG_WR(bp, addr + 4, U64_HI(mapping));
  268. }
  269. static void storm_memset_spq_addr(struct bnx2x *bp,
  270. dma_addr_t mapping, u16 abs_fid)
  271. {
  272. u32 addr = XSEM_REG_FAST_MEMORY +
  273. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  274. __storm_memset_dma_mapping(bp, addr, mapping);
  275. }
  276. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  277. u16 pf_id)
  278. {
  279. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  280. pf_id);
  281. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  282. pf_id);
  283. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  284. pf_id);
  285. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. }
  288. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  289. u8 enable)
  290. {
  291. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  292. enable);
  293. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  294. enable);
  295. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  296. enable);
  297. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. }
  300. static void storm_memset_eq_data(struct bnx2x *bp,
  301. struct event_ring_data *eq_data,
  302. u16 pfid)
  303. {
  304. size_t size = sizeof(struct event_ring_data);
  305. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  306. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  307. }
  308. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  309. u16 pfid)
  310. {
  311. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  312. REG_WR16(bp, addr, eq_prod);
  313. }
  314. /* used only at init
  315. * locking is done by mcp
  316. */
  317. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  318. {
  319. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  320. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  321. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  322. PCICFG_VENDOR_ID_OFFSET);
  323. }
  324. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  325. {
  326. u32 val;
  327. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  328. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  330. PCICFG_VENDOR_ID_OFFSET);
  331. return val;
  332. }
  333. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  334. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  335. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  336. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  337. #define DMAE_DP_DST_NONE "dst_addr [none]"
  338. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  339. {
  340. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  341. switch (dmae->opcode & DMAE_COMMAND_DST) {
  342. case DMAE_CMD_DST_PCI:
  343. if (src_type == DMAE_CMD_SRC_PCI)
  344. DP(msglvl, "DMAE: opcode 0x%08x\n"
  345. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  346. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  347. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  348. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  349. dmae->comp_addr_hi, dmae->comp_addr_lo,
  350. dmae->comp_val);
  351. else
  352. DP(msglvl, "DMAE: opcode 0x%08x\n"
  353. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  354. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  355. dmae->opcode, dmae->src_addr_lo >> 2,
  356. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  357. dmae->comp_addr_hi, dmae->comp_addr_lo,
  358. dmae->comp_val);
  359. break;
  360. case DMAE_CMD_DST_GRC:
  361. if (src_type == DMAE_CMD_SRC_PCI)
  362. DP(msglvl, "DMAE: opcode 0x%08x\n"
  363. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  364. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  365. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  366. dmae->len, dmae->dst_addr_lo >> 2,
  367. dmae->comp_addr_hi, dmae->comp_addr_lo,
  368. dmae->comp_val);
  369. else
  370. DP(msglvl, "DMAE: opcode 0x%08x\n"
  371. "src [%08x], len [%d*4], dst [%08x]\n"
  372. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  373. dmae->opcode, dmae->src_addr_lo >> 2,
  374. dmae->len, dmae->dst_addr_lo >> 2,
  375. dmae->comp_addr_hi, dmae->comp_addr_lo,
  376. dmae->comp_val);
  377. break;
  378. default:
  379. if (src_type == DMAE_CMD_SRC_PCI)
  380. DP(msglvl, "DMAE: opcode 0x%08x\n"
  381. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  382. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  383. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  384. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  385. dmae->comp_val);
  386. else
  387. DP(msglvl, "DMAE: opcode 0x%08x\n"
  388. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  389. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  390. dmae->opcode, dmae->src_addr_lo >> 2,
  391. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  392. dmae->comp_val);
  393. break;
  394. }
  395. }
  396. /* copy command into DMAE command memory and set DMAE command go */
  397. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  398. {
  399. u32 cmd_offset;
  400. int i;
  401. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  402. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  403. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  404. }
  405. REG_WR(bp, dmae_reg_go_c[idx], 1);
  406. }
  407. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  408. {
  409. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  410. DMAE_CMD_C_ENABLE);
  411. }
  412. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  413. {
  414. return opcode & ~DMAE_CMD_SRC_RESET;
  415. }
  416. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  417. bool with_comp, u8 comp_type)
  418. {
  419. u32 opcode = 0;
  420. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  421. (dst_type << DMAE_COMMAND_DST_SHIFT));
  422. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  423. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  424. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  425. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  426. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  427. #ifdef __BIG_ENDIAN
  428. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  429. #else
  430. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  431. #endif
  432. if (with_comp)
  433. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  434. return opcode;
  435. }
  436. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  437. struct dmae_command *dmae,
  438. u8 src_type, u8 dst_type)
  439. {
  440. memset(dmae, 0, sizeof(struct dmae_command));
  441. /* set the opcode */
  442. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  443. true, DMAE_COMP_PCI);
  444. /* fill in the completion parameters */
  445. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  446. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  447. dmae->comp_val = DMAE_COMP_VAL;
  448. }
  449. /* issue a dmae command over the init-channel and wait for completion */
  450. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  451. {
  452. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  453. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  454. int rc = 0;
  455. /*
  456. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  457. * as long as this code is called both from syscall context and
  458. * from ndo_set_rx_mode() flow that may be called from BH.
  459. */
  460. spin_lock_bh(&bp->dmae_lock);
  461. /* reset completion */
  462. *wb_comp = 0;
  463. /* post the command on the channel used for initializations */
  464. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  465. /* wait for completion */
  466. udelay(5);
  467. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  468. if (!cnt ||
  469. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  470. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  471. BNX2X_ERR("DMAE timeout!\n");
  472. rc = DMAE_TIMEOUT;
  473. goto unlock;
  474. }
  475. cnt--;
  476. udelay(50);
  477. }
  478. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  479. BNX2X_ERR("DMAE PCI error!\n");
  480. rc = DMAE_PCI_ERROR;
  481. }
  482. unlock:
  483. spin_unlock_bh(&bp->dmae_lock);
  484. return rc;
  485. }
  486. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  487. u32 len32)
  488. {
  489. struct dmae_command dmae;
  490. if (!bp->dmae_ready) {
  491. u32 *data = bnx2x_sp(bp, wb_data[0]);
  492. if (CHIP_IS_E1(bp))
  493. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  494. else
  495. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  496. return;
  497. }
  498. /* set opcode and fixed command fields */
  499. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  500. /* fill in addresses and len */
  501. dmae.src_addr_lo = U64_LO(dma_addr);
  502. dmae.src_addr_hi = U64_HI(dma_addr);
  503. dmae.dst_addr_lo = dst_addr >> 2;
  504. dmae.dst_addr_hi = 0;
  505. dmae.len = len32;
  506. /* issue the command and wait for completion */
  507. bnx2x_issue_dmae_with_comp(bp, &dmae);
  508. }
  509. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  510. {
  511. struct dmae_command dmae;
  512. if (!bp->dmae_ready) {
  513. u32 *data = bnx2x_sp(bp, wb_data[0]);
  514. int i;
  515. if (CHIP_IS_E1(bp))
  516. for (i = 0; i < len32; i++)
  517. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  518. else
  519. for (i = 0; i < len32; i++)
  520. data[i] = REG_RD(bp, src_addr + i*4);
  521. return;
  522. }
  523. /* set opcode and fixed command fields */
  524. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  525. /* fill in addresses and len */
  526. dmae.src_addr_lo = src_addr >> 2;
  527. dmae.src_addr_hi = 0;
  528. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  529. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  530. dmae.len = len32;
  531. /* issue the command and wait for completion */
  532. bnx2x_issue_dmae_with_comp(bp, &dmae);
  533. }
  534. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  535. u32 addr, u32 len)
  536. {
  537. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  538. int offset = 0;
  539. while (len > dmae_wr_max) {
  540. bnx2x_write_dmae(bp, phys_addr + offset,
  541. addr + offset, dmae_wr_max);
  542. offset += dmae_wr_max * 4;
  543. len -= dmae_wr_max;
  544. }
  545. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  546. }
  547. static int bnx2x_mc_assert(struct bnx2x *bp)
  548. {
  549. char last_idx;
  550. int i, rc = 0;
  551. u32 row0, row1, row2, row3;
  552. /* XSTORM */
  553. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  554. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  555. if (last_idx)
  556. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  557. /* print the asserts */
  558. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  559. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  560. XSTORM_ASSERT_LIST_OFFSET(i));
  561. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  562. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  563. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  564. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  565. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  566. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  567. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  568. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  569. i, row3, row2, row1, row0);
  570. rc++;
  571. } else {
  572. break;
  573. }
  574. }
  575. /* TSTORM */
  576. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  577. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  578. if (last_idx)
  579. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  580. /* print the asserts */
  581. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  582. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  583. TSTORM_ASSERT_LIST_OFFSET(i));
  584. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  585. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  586. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  587. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  588. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  589. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  590. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  591. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  592. i, row3, row2, row1, row0);
  593. rc++;
  594. } else {
  595. break;
  596. }
  597. }
  598. /* CSTORM */
  599. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  600. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  601. if (last_idx)
  602. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  603. /* print the asserts */
  604. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  605. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  606. CSTORM_ASSERT_LIST_OFFSET(i));
  607. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  608. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  609. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  610. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  611. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  612. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  613. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  614. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  615. i, row3, row2, row1, row0);
  616. rc++;
  617. } else {
  618. break;
  619. }
  620. }
  621. /* USTORM */
  622. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  623. USTORM_ASSERT_LIST_INDEX_OFFSET);
  624. if (last_idx)
  625. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  626. /* print the asserts */
  627. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  628. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  629. USTORM_ASSERT_LIST_OFFSET(i));
  630. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  631. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  632. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  633. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  634. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  635. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  636. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  637. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  638. i, row3, row2, row1, row0);
  639. rc++;
  640. } else {
  641. break;
  642. }
  643. }
  644. return rc;
  645. }
  646. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  647. {
  648. u32 addr, val;
  649. u32 mark, offset;
  650. __be32 data[9];
  651. int word;
  652. u32 trace_shmem_base;
  653. if (BP_NOMCP(bp)) {
  654. BNX2X_ERR("NO MCP - can not dump\n");
  655. return;
  656. }
  657. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  658. (bp->common.bc_ver & 0xff0000) >> 16,
  659. (bp->common.bc_ver & 0xff00) >> 8,
  660. (bp->common.bc_ver & 0xff));
  661. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  662. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  663. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  664. if (BP_PATH(bp) == 0)
  665. trace_shmem_base = bp->common.shmem_base;
  666. else
  667. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  668. addr = trace_shmem_base - 0x800;
  669. /* validate TRCB signature */
  670. mark = REG_RD(bp, addr);
  671. if (mark != MFW_TRACE_SIGNATURE) {
  672. BNX2X_ERR("Trace buffer signature is missing.");
  673. return ;
  674. }
  675. /* read cyclic buffer pointer */
  676. addr += 4;
  677. mark = REG_RD(bp, addr);
  678. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  679. + ((mark + 0x3) & ~0x3) - 0x08000000;
  680. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  681. printk("%s", lvl);
  682. /* dump buffer after the mark */
  683. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  684. for (word = 0; word < 8; word++)
  685. data[word] = htonl(REG_RD(bp, offset + 4*word));
  686. data[8] = 0x0;
  687. pr_cont("%s", (char *)data);
  688. }
  689. /* dump buffer before the mark */
  690. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  691. for (word = 0; word < 8; word++)
  692. data[word] = htonl(REG_RD(bp, offset + 4*word));
  693. data[8] = 0x0;
  694. pr_cont("%s", (char *)data);
  695. }
  696. printk("%s" "end of fw dump\n", lvl);
  697. }
  698. static void bnx2x_fw_dump(struct bnx2x *bp)
  699. {
  700. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  701. }
  702. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  703. {
  704. int port = BP_PORT(bp);
  705. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  706. u32 val = REG_RD(bp, addr);
  707. /* in E1 we must use only PCI configuration space to disable
  708. * MSI/MSIX capability
  709. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  710. */
  711. if (CHIP_IS_E1(bp)) {
  712. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  713. * Use mask register to prevent from HC sending interrupts
  714. * after we exit the function
  715. */
  716. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  717. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  718. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  719. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  720. } else
  721. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  722. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  723. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  724. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  725. DP(NETIF_MSG_IFDOWN,
  726. "write %x to HC %d (addr 0x%x)\n",
  727. val, port, addr);
  728. /* flush all outstanding writes */
  729. mmiowb();
  730. REG_WR(bp, addr, val);
  731. if (REG_RD(bp, addr) != val)
  732. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  733. }
  734. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  735. {
  736. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  737. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  738. IGU_PF_CONF_INT_LINE_EN |
  739. IGU_PF_CONF_ATTN_BIT_EN);
  740. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  741. /* flush all outstanding writes */
  742. mmiowb();
  743. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  744. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  745. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  746. }
  747. static void bnx2x_int_disable(struct bnx2x *bp)
  748. {
  749. if (bp->common.int_block == INT_BLOCK_HC)
  750. bnx2x_hc_int_disable(bp);
  751. else
  752. bnx2x_igu_int_disable(bp);
  753. }
  754. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  755. {
  756. int i;
  757. u16 j;
  758. struct hc_sp_status_block_data sp_sb_data;
  759. int func = BP_FUNC(bp);
  760. #ifdef BNX2X_STOP_ON_ERROR
  761. u16 start = 0, end = 0;
  762. u8 cos;
  763. #endif
  764. if (disable_int)
  765. bnx2x_int_disable(bp);
  766. bp->stats_state = STATS_STATE_DISABLED;
  767. bp->eth_stats.unrecoverable_error++;
  768. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  769. BNX2X_ERR("begin crash dump -----------------\n");
  770. /* Indices */
  771. /* Common */
  772. 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",
  773. bp->def_idx, bp->def_att_idx, bp->attn_state,
  774. bp->spq_prod_idx, bp->stats_counter);
  775. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  776. bp->def_status_blk->atten_status_block.attn_bits,
  777. bp->def_status_blk->atten_status_block.attn_bits_ack,
  778. bp->def_status_blk->atten_status_block.status_block_id,
  779. bp->def_status_blk->atten_status_block.attn_bits_index);
  780. BNX2X_ERR(" def (");
  781. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  782. pr_cont("0x%x%s",
  783. bp->def_status_blk->sp_sb.index_values[i],
  784. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  785. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  786. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  787. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  788. i*sizeof(u32));
  789. 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",
  790. sp_sb_data.igu_sb_id,
  791. sp_sb_data.igu_seg_id,
  792. sp_sb_data.p_func.pf_id,
  793. sp_sb_data.p_func.vnic_id,
  794. sp_sb_data.p_func.vf_id,
  795. sp_sb_data.p_func.vf_valid,
  796. sp_sb_data.state);
  797. for_each_eth_queue(bp, i) {
  798. struct bnx2x_fastpath *fp = &bp->fp[i];
  799. int loop;
  800. struct hc_status_block_data_e2 sb_data_e2;
  801. struct hc_status_block_data_e1x sb_data_e1x;
  802. struct hc_status_block_sm *hc_sm_p =
  803. CHIP_IS_E1x(bp) ?
  804. sb_data_e1x.common.state_machine :
  805. sb_data_e2.common.state_machine;
  806. struct hc_index_data *hc_index_p =
  807. CHIP_IS_E1x(bp) ?
  808. sb_data_e1x.index_data :
  809. sb_data_e2.index_data;
  810. u8 data_size, cos;
  811. u32 *sb_data_p;
  812. struct bnx2x_fp_txdata txdata;
  813. /* Rx */
  814. 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",
  815. i, fp->rx_bd_prod, fp->rx_bd_cons,
  816. fp->rx_comp_prod,
  817. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  818. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  819. fp->rx_sge_prod, fp->last_max_sge,
  820. le16_to_cpu(fp->fp_hc_idx));
  821. /* Tx */
  822. for_each_cos_in_tx_queue(fp, cos)
  823. {
  824. txdata = *fp->txdata_ptr[cos];
  825. 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",
  826. i, txdata.tx_pkt_prod,
  827. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  828. txdata.tx_bd_cons,
  829. le16_to_cpu(*txdata.tx_cons_sb));
  830. }
  831. loop = CHIP_IS_E1x(bp) ?
  832. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  833. /* host sb data */
  834. if (IS_FCOE_FP(fp))
  835. continue;
  836. BNX2X_ERR(" run indexes (");
  837. for (j = 0; j < HC_SB_MAX_SM; j++)
  838. pr_cont("0x%x%s",
  839. fp->sb_running_index[j],
  840. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  841. BNX2X_ERR(" indexes (");
  842. for (j = 0; j < loop; j++)
  843. pr_cont("0x%x%s",
  844. fp->sb_index_values[j],
  845. (j == loop - 1) ? ")" : " ");
  846. /* fw sb data */
  847. data_size = CHIP_IS_E1x(bp) ?
  848. sizeof(struct hc_status_block_data_e1x) :
  849. sizeof(struct hc_status_block_data_e2);
  850. data_size /= sizeof(u32);
  851. sb_data_p = CHIP_IS_E1x(bp) ?
  852. (u32 *)&sb_data_e1x :
  853. (u32 *)&sb_data_e2;
  854. /* copy sb data in here */
  855. for (j = 0; j < data_size; j++)
  856. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  857. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  858. j * sizeof(u32));
  859. if (!CHIP_IS_E1x(bp)) {
  860. 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",
  861. sb_data_e2.common.p_func.pf_id,
  862. sb_data_e2.common.p_func.vf_id,
  863. sb_data_e2.common.p_func.vf_valid,
  864. sb_data_e2.common.p_func.vnic_id,
  865. sb_data_e2.common.same_igu_sb_1b,
  866. sb_data_e2.common.state);
  867. } else {
  868. 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",
  869. sb_data_e1x.common.p_func.pf_id,
  870. sb_data_e1x.common.p_func.vf_id,
  871. sb_data_e1x.common.p_func.vf_valid,
  872. sb_data_e1x.common.p_func.vnic_id,
  873. sb_data_e1x.common.same_igu_sb_1b,
  874. sb_data_e1x.common.state);
  875. }
  876. /* SB_SMs data */
  877. for (j = 0; j < HC_SB_MAX_SM; j++) {
  878. 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",
  879. j, hc_sm_p[j].__flags,
  880. hc_sm_p[j].igu_sb_id,
  881. hc_sm_p[j].igu_seg_id,
  882. hc_sm_p[j].time_to_expire,
  883. hc_sm_p[j].timer_value);
  884. }
  885. /* Indices data */
  886. for (j = 0; j < loop; j++) {
  887. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  888. hc_index_p[j].flags,
  889. hc_index_p[j].timeout);
  890. }
  891. }
  892. #ifdef BNX2X_STOP_ON_ERROR
  893. /* event queue */
  894. for (i = 0; i < NUM_EQ_DESC; i++) {
  895. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  896. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  897. i, bp->eq_ring[i].message.opcode,
  898. bp->eq_ring[i].message.error);
  899. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  900. }
  901. /* Rings */
  902. /* Rx */
  903. for_each_valid_rx_queue(bp, i) {
  904. struct bnx2x_fastpath *fp = &bp->fp[i];
  905. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  906. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  907. for (j = start; j != end; j = RX_BD(j + 1)) {
  908. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  909. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  910. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  911. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  912. }
  913. start = RX_SGE(fp->rx_sge_prod);
  914. end = RX_SGE(fp->last_max_sge);
  915. for (j = start; j != end; j = RX_SGE(j + 1)) {
  916. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  917. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  918. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  919. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  920. }
  921. start = RCQ_BD(fp->rx_comp_cons - 10);
  922. end = RCQ_BD(fp->rx_comp_cons + 503);
  923. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  924. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  925. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  926. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  927. }
  928. }
  929. /* Tx */
  930. for_each_valid_tx_queue(bp, i) {
  931. struct bnx2x_fastpath *fp = &bp->fp[i];
  932. for_each_cos_in_tx_queue(fp, cos) {
  933. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  934. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  935. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  936. for (j = start; j != end; j = TX_BD(j + 1)) {
  937. struct sw_tx_bd *sw_bd =
  938. &txdata->tx_buf_ring[j];
  939. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  940. i, cos, j, sw_bd->skb,
  941. sw_bd->first_bd);
  942. }
  943. start = TX_BD(txdata->tx_bd_cons - 10);
  944. end = TX_BD(txdata->tx_bd_cons + 254);
  945. for (j = start; j != end; j = TX_BD(j + 1)) {
  946. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  947. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  948. i, cos, j, tx_bd[0], tx_bd[1],
  949. tx_bd[2], tx_bd[3]);
  950. }
  951. }
  952. }
  953. #endif
  954. bnx2x_fw_dump(bp);
  955. bnx2x_mc_assert(bp);
  956. BNX2X_ERR("end crash dump -----------------\n");
  957. }
  958. /*
  959. * FLR Support for E2
  960. *
  961. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  962. * initialization.
  963. */
  964. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  965. #define FLR_WAIT_INTERVAL 50 /* usec */
  966. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  967. struct pbf_pN_buf_regs {
  968. int pN;
  969. u32 init_crd;
  970. u32 crd;
  971. u32 crd_freed;
  972. };
  973. struct pbf_pN_cmd_regs {
  974. int pN;
  975. u32 lines_occup;
  976. u32 lines_freed;
  977. };
  978. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  979. struct pbf_pN_buf_regs *regs,
  980. u32 poll_count)
  981. {
  982. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  983. u32 cur_cnt = poll_count;
  984. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  985. crd = crd_start = REG_RD(bp, regs->crd);
  986. init_crd = REG_RD(bp, regs->init_crd);
  987. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  988. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  989. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  990. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  991. (init_crd - crd_start))) {
  992. if (cur_cnt--) {
  993. udelay(FLR_WAIT_INTERVAL);
  994. crd = REG_RD(bp, regs->crd);
  995. crd_freed = REG_RD(bp, regs->crd_freed);
  996. } else {
  997. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  998. regs->pN);
  999. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1000. regs->pN, crd);
  1001. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1002. regs->pN, crd_freed);
  1003. break;
  1004. }
  1005. }
  1006. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1007. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1008. }
  1009. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1010. struct pbf_pN_cmd_regs *regs,
  1011. u32 poll_count)
  1012. {
  1013. u32 occup, to_free, freed, freed_start;
  1014. u32 cur_cnt = poll_count;
  1015. occup = to_free = REG_RD(bp, regs->lines_occup);
  1016. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1017. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1018. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1019. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1020. if (cur_cnt--) {
  1021. udelay(FLR_WAIT_INTERVAL);
  1022. occup = REG_RD(bp, regs->lines_occup);
  1023. freed = REG_RD(bp, regs->lines_freed);
  1024. } else {
  1025. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1026. regs->pN);
  1027. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1028. regs->pN, occup);
  1029. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1030. regs->pN, freed);
  1031. break;
  1032. }
  1033. }
  1034. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1035. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1036. }
  1037. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1038. u32 expected, u32 poll_count)
  1039. {
  1040. u32 cur_cnt = poll_count;
  1041. u32 val;
  1042. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1043. udelay(FLR_WAIT_INTERVAL);
  1044. return val;
  1045. }
  1046. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1047. char *msg, u32 poll_cnt)
  1048. {
  1049. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1050. if (val != 0) {
  1051. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1052. return 1;
  1053. }
  1054. return 0;
  1055. }
  1056. /* Common routines with VF FLR cleanup */
  1057. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1058. {
  1059. /* adjust polling timeout */
  1060. if (CHIP_REV_IS_EMUL(bp))
  1061. return FLR_POLL_CNT * 2000;
  1062. if (CHIP_REV_IS_FPGA(bp))
  1063. return FLR_POLL_CNT * 120;
  1064. return FLR_POLL_CNT;
  1065. }
  1066. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1067. {
  1068. struct pbf_pN_cmd_regs cmd_regs[] = {
  1069. {0, (CHIP_IS_E3B0(bp)) ?
  1070. PBF_REG_TQ_OCCUPANCY_Q0 :
  1071. PBF_REG_P0_TQ_OCCUPANCY,
  1072. (CHIP_IS_E3B0(bp)) ?
  1073. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1074. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1075. {1, (CHIP_IS_E3B0(bp)) ?
  1076. PBF_REG_TQ_OCCUPANCY_Q1 :
  1077. PBF_REG_P1_TQ_OCCUPANCY,
  1078. (CHIP_IS_E3B0(bp)) ?
  1079. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1080. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1081. {4, (CHIP_IS_E3B0(bp)) ?
  1082. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1083. PBF_REG_P4_TQ_OCCUPANCY,
  1084. (CHIP_IS_E3B0(bp)) ?
  1085. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1086. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1087. };
  1088. struct pbf_pN_buf_regs buf_regs[] = {
  1089. {0, (CHIP_IS_E3B0(bp)) ?
  1090. PBF_REG_INIT_CRD_Q0 :
  1091. PBF_REG_P0_INIT_CRD ,
  1092. (CHIP_IS_E3B0(bp)) ?
  1093. PBF_REG_CREDIT_Q0 :
  1094. PBF_REG_P0_CREDIT,
  1095. (CHIP_IS_E3B0(bp)) ?
  1096. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1097. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1098. {1, (CHIP_IS_E3B0(bp)) ?
  1099. PBF_REG_INIT_CRD_Q1 :
  1100. PBF_REG_P1_INIT_CRD,
  1101. (CHIP_IS_E3B0(bp)) ?
  1102. PBF_REG_CREDIT_Q1 :
  1103. PBF_REG_P1_CREDIT,
  1104. (CHIP_IS_E3B0(bp)) ?
  1105. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1106. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1107. {4, (CHIP_IS_E3B0(bp)) ?
  1108. PBF_REG_INIT_CRD_LB_Q :
  1109. PBF_REG_P4_INIT_CRD,
  1110. (CHIP_IS_E3B0(bp)) ?
  1111. PBF_REG_CREDIT_LB_Q :
  1112. PBF_REG_P4_CREDIT,
  1113. (CHIP_IS_E3B0(bp)) ?
  1114. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1115. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1116. };
  1117. int i;
  1118. /* Verify the command queues are flushed P0, P1, P4 */
  1119. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1120. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1121. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1122. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1123. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1124. }
  1125. #define OP_GEN_PARAM(param) \
  1126. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1127. #define OP_GEN_TYPE(type) \
  1128. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1129. #define OP_GEN_AGG_VECT(index) \
  1130. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1131. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1132. {
  1133. u32 op_gen_command = 0;
  1134. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1135. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1136. int ret = 0;
  1137. if (REG_RD(bp, comp_addr)) {
  1138. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1139. return 1;
  1140. }
  1141. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1142. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1143. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1144. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1145. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1146. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1147. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1148. BNX2X_ERR("FW final cleanup did not succeed\n");
  1149. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1150. (REG_RD(bp, comp_addr)));
  1151. bnx2x_panic();
  1152. return 1;
  1153. }
  1154. /* Zero completion for next FLR */
  1155. REG_WR(bp, comp_addr, 0);
  1156. return ret;
  1157. }
  1158. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1159. {
  1160. u16 status;
  1161. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1162. return status & PCI_EXP_DEVSTA_TRPND;
  1163. }
  1164. /* PF FLR specific routines
  1165. */
  1166. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1167. {
  1168. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1169. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1170. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1171. "CFC PF usage counter timed out",
  1172. poll_cnt))
  1173. return 1;
  1174. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1175. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1176. DORQ_REG_PF_USAGE_CNT,
  1177. "DQ PF usage counter timed out",
  1178. poll_cnt))
  1179. return 1;
  1180. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1181. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1182. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1183. "QM PF usage counter timed out",
  1184. poll_cnt))
  1185. return 1;
  1186. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1187. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1188. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1189. "Timers VNIC usage counter timed out",
  1190. poll_cnt))
  1191. return 1;
  1192. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1193. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1194. "Timers NUM_SCANS usage counter timed out",
  1195. poll_cnt))
  1196. return 1;
  1197. /* Wait DMAE PF usage counter to zero */
  1198. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1199. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1200. "DMAE dommand register timed out",
  1201. poll_cnt))
  1202. return 1;
  1203. return 0;
  1204. }
  1205. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1206. {
  1207. u32 val;
  1208. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1209. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1210. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1211. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1212. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1213. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1214. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1215. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1216. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1217. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1218. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1219. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1220. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1221. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1222. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1223. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1224. val);
  1225. }
  1226. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1227. {
  1228. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1229. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1230. /* Re-enable PF target read access */
  1231. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1232. /* Poll HW usage counters */
  1233. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1234. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1235. return -EBUSY;
  1236. /* Zero the igu 'trailing edge' and 'leading edge' */
  1237. /* Send the FW cleanup command */
  1238. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1239. return -EBUSY;
  1240. /* ATC cleanup */
  1241. /* Verify TX hw is flushed */
  1242. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1243. /* Wait 100ms (not adjusted according to platform) */
  1244. msleep(100);
  1245. /* Verify no pending pci transactions */
  1246. if (bnx2x_is_pcie_pending(bp->pdev))
  1247. BNX2X_ERR("PCIE Transactions still pending\n");
  1248. /* Debug */
  1249. bnx2x_hw_enable_status(bp);
  1250. /*
  1251. * Master enable - Due to WB DMAE writes performed before this
  1252. * register is re-initialized as part of the regular function init
  1253. */
  1254. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1255. return 0;
  1256. }
  1257. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1258. {
  1259. int port = BP_PORT(bp);
  1260. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1261. u32 val = REG_RD(bp, addr);
  1262. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1263. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1264. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1265. if (msix) {
  1266. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1267. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1268. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1269. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1270. if (single_msix)
  1271. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1272. } else if (msi) {
  1273. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1274. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1275. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1276. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1277. } else {
  1278. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1279. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1280. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1281. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1282. if (!CHIP_IS_E1(bp)) {
  1283. DP(NETIF_MSG_IFUP,
  1284. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1285. REG_WR(bp, addr, val);
  1286. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1287. }
  1288. }
  1289. if (CHIP_IS_E1(bp))
  1290. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1291. DP(NETIF_MSG_IFUP,
  1292. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1293. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1294. REG_WR(bp, addr, val);
  1295. /*
  1296. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1297. */
  1298. mmiowb();
  1299. barrier();
  1300. if (!CHIP_IS_E1(bp)) {
  1301. /* init leading/trailing edge */
  1302. if (IS_MF(bp)) {
  1303. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1304. if (bp->port.pmf)
  1305. /* enable nig and gpio3 attention */
  1306. val |= 0x1100;
  1307. } else
  1308. val = 0xffff;
  1309. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1310. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1311. }
  1312. /* Make sure that interrupts are indeed enabled from here on */
  1313. mmiowb();
  1314. }
  1315. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1316. {
  1317. u32 val;
  1318. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1319. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1320. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1321. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1322. if (msix) {
  1323. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1324. IGU_PF_CONF_SINGLE_ISR_EN);
  1325. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1326. IGU_PF_CONF_ATTN_BIT_EN);
  1327. if (single_msix)
  1328. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1329. } else if (msi) {
  1330. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1331. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1332. IGU_PF_CONF_ATTN_BIT_EN |
  1333. IGU_PF_CONF_SINGLE_ISR_EN);
  1334. } else {
  1335. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1336. val |= (IGU_PF_CONF_INT_LINE_EN |
  1337. IGU_PF_CONF_ATTN_BIT_EN |
  1338. IGU_PF_CONF_SINGLE_ISR_EN);
  1339. }
  1340. /* Clean previous status - need to configure igu prior to ack*/
  1341. if ((!msix) || single_msix) {
  1342. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1343. bnx2x_ack_int(bp);
  1344. }
  1345. val |= IGU_PF_CONF_FUNC_EN;
  1346. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1347. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1348. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1349. if (val & IGU_PF_CONF_INT_LINE_EN)
  1350. pci_intx(bp->pdev, true);
  1351. barrier();
  1352. /* init leading/trailing edge */
  1353. if (IS_MF(bp)) {
  1354. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1355. if (bp->port.pmf)
  1356. /* enable nig and gpio3 attention */
  1357. val |= 0x1100;
  1358. } else
  1359. val = 0xffff;
  1360. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1361. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1362. /* Make sure that interrupts are indeed enabled from here on */
  1363. mmiowb();
  1364. }
  1365. void bnx2x_int_enable(struct bnx2x *bp)
  1366. {
  1367. if (bp->common.int_block == INT_BLOCK_HC)
  1368. bnx2x_hc_int_enable(bp);
  1369. else
  1370. bnx2x_igu_int_enable(bp);
  1371. }
  1372. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1373. {
  1374. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1375. int i, offset;
  1376. if (disable_hw)
  1377. /* prevent the HW from sending interrupts */
  1378. bnx2x_int_disable(bp);
  1379. /* make sure all ISRs are done */
  1380. if (msix) {
  1381. synchronize_irq(bp->msix_table[0].vector);
  1382. offset = 1;
  1383. if (CNIC_SUPPORT(bp))
  1384. offset++;
  1385. for_each_eth_queue(bp, i)
  1386. synchronize_irq(bp->msix_table[offset++].vector);
  1387. } else
  1388. synchronize_irq(bp->pdev->irq);
  1389. /* make sure sp_task is not running */
  1390. cancel_delayed_work(&bp->sp_task);
  1391. cancel_delayed_work(&bp->period_task);
  1392. flush_workqueue(bnx2x_wq);
  1393. }
  1394. /* fast path */
  1395. /*
  1396. * General service functions
  1397. */
  1398. /* Return true if succeeded to acquire the lock */
  1399. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1400. {
  1401. u32 lock_status;
  1402. u32 resource_bit = (1 << resource);
  1403. int func = BP_FUNC(bp);
  1404. u32 hw_lock_control_reg;
  1405. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1406. "Trying to take a lock on resource %d\n", resource);
  1407. /* Validating that the resource is within range */
  1408. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1409. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1410. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1411. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1412. return false;
  1413. }
  1414. if (func <= 5)
  1415. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1416. else
  1417. hw_lock_control_reg =
  1418. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1419. /* Try to acquire the lock */
  1420. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1421. lock_status = REG_RD(bp, hw_lock_control_reg);
  1422. if (lock_status & resource_bit)
  1423. return true;
  1424. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1425. "Failed to get a lock on resource %d\n", resource);
  1426. return false;
  1427. }
  1428. /**
  1429. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1430. *
  1431. * @bp: driver handle
  1432. *
  1433. * Returns the recovery leader resource id according to the engine this function
  1434. * belongs to. Currently only only 2 engines is supported.
  1435. */
  1436. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1437. {
  1438. if (BP_PATH(bp))
  1439. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1440. else
  1441. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1442. }
  1443. /**
  1444. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1445. *
  1446. * @bp: driver handle
  1447. *
  1448. * Tries to acquire a leader lock for current engine.
  1449. */
  1450. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1451. {
  1452. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1453. }
  1454. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1455. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1456. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1457. {
  1458. /* Set the interrupt occurred bit for the sp-task to recognize it
  1459. * must ack the interrupt and transition according to the IGU
  1460. * state machine.
  1461. */
  1462. atomic_set(&bp->interrupt_occurred, 1);
  1463. /* The sp_task must execute only after this bit
  1464. * is set, otherwise we will get out of sync and miss all
  1465. * further interrupts. Hence, the barrier.
  1466. */
  1467. smp_wmb();
  1468. /* schedule sp_task to workqueue */
  1469. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1470. }
  1471. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1472. {
  1473. struct bnx2x *bp = fp->bp;
  1474. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1475. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1476. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1477. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1478. DP(BNX2X_MSG_SP,
  1479. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1480. fp->index, cid, command, bp->state,
  1481. rr_cqe->ramrod_cqe.ramrod_type);
  1482. /* If cid is within VF range, replace the slowpath object with the
  1483. * one corresponding to this VF
  1484. */
  1485. if (cid >= BNX2X_FIRST_VF_CID &&
  1486. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1487. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1488. switch (command) {
  1489. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1490. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1491. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1492. break;
  1493. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1494. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1495. drv_cmd = BNX2X_Q_CMD_SETUP;
  1496. break;
  1497. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1498. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1499. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1500. break;
  1501. case (RAMROD_CMD_ID_ETH_HALT):
  1502. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1503. drv_cmd = BNX2X_Q_CMD_HALT;
  1504. break;
  1505. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1506. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1507. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1508. break;
  1509. case (RAMROD_CMD_ID_ETH_EMPTY):
  1510. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1511. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1512. break;
  1513. default:
  1514. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1515. command, fp->index);
  1516. return;
  1517. }
  1518. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1519. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1520. /* q_obj->complete_cmd() failure means that this was
  1521. * an unexpected completion.
  1522. *
  1523. * In this case we don't want to increase the bp->spq_left
  1524. * because apparently we haven't sent this command the first
  1525. * place.
  1526. */
  1527. #ifdef BNX2X_STOP_ON_ERROR
  1528. bnx2x_panic();
  1529. #else
  1530. return;
  1531. #endif
  1532. /* SRIOV: reschedule any 'in_progress' operations */
  1533. bnx2x_iov_sp_event(bp, cid, true);
  1534. smp_mb__before_atomic_inc();
  1535. atomic_inc(&bp->cq_spq_left);
  1536. /* push the change in bp->spq_left and towards the memory */
  1537. smp_mb__after_atomic_inc();
  1538. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1539. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1540. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1541. /* if Q update ramrod is completed for last Q in AFEX vif set
  1542. * flow, then ACK MCP at the end
  1543. *
  1544. * mark pending ACK to MCP bit.
  1545. * prevent case that both bits are cleared.
  1546. * At the end of load/unload driver checks that
  1547. * sp_state is cleared, and this order prevents
  1548. * races
  1549. */
  1550. smp_mb__before_clear_bit();
  1551. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1552. wmb();
  1553. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1554. smp_mb__after_clear_bit();
  1555. /* schedule the sp task as mcp ack is required */
  1556. bnx2x_schedule_sp_task(bp);
  1557. }
  1558. return;
  1559. }
  1560. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1561. {
  1562. struct bnx2x *bp = netdev_priv(dev_instance);
  1563. u16 status = bnx2x_ack_int(bp);
  1564. u16 mask;
  1565. int i;
  1566. u8 cos;
  1567. /* Return here if interrupt is shared and it's not for us */
  1568. if (unlikely(status == 0)) {
  1569. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1570. return IRQ_NONE;
  1571. }
  1572. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1573. #ifdef BNX2X_STOP_ON_ERROR
  1574. if (unlikely(bp->panic))
  1575. return IRQ_HANDLED;
  1576. #endif
  1577. for_each_eth_queue(bp, i) {
  1578. struct bnx2x_fastpath *fp = &bp->fp[i];
  1579. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1580. if (status & mask) {
  1581. /* Handle Rx or Tx according to SB id */
  1582. prefetch(fp->rx_cons_sb);
  1583. for_each_cos_in_tx_queue(fp, cos)
  1584. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1585. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1586. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1587. status &= ~mask;
  1588. }
  1589. }
  1590. if (CNIC_SUPPORT(bp)) {
  1591. mask = 0x2;
  1592. if (status & (mask | 0x1)) {
  1593. struct cnic_ops *c_ops = NULL;
  1594. rcu_read_lock();
  1595. c_ops = rcu_dereference(bp->cnic_ops);
  1596. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1597. CNIC_DRV_STATE_HANDLES_IRQ))
  1598. c_ops->cnic_handler(bp->cnic_data, NULL);
  1599. rcu_read_unlock();
  1600. status &= ~mask;
  1601. }
  1602. }
  1603. if (unlikely(status & 0x1)) {
  1604. /* schedule sp task to perform default status block work, ack
  1605. * attentions and enable interrupts.
  1606. */
  1607. bnx2x_schedule_sp_task(bp);
  1608. status &= ~0x1;
  1609. if (!status)
  1610. return IRQ_HANDLED;
  1611. }
  1612. if (unlikely(status))
  1613. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1614. status);
  1615. return IRQ_HANDLED;
  1616. }
  1617. /* Link */
  1618. /*
  1619. * General service functions
  1620. */
  1621. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1622. {
  1623. u32 lock_status;
  1624. u32 resource_bit = (1 << resource);
  1625. int func = BP_FUNC(bp);
  1626. u32 hw_lock_control_reg;
  1627. int cnt;
  1628. /* Validating that the resource is within range */
  1629. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1630. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1631. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1632. return -EINVAL;
  1633. }
  1634. if (func <= 5) {
  1635. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1636. } else {
  1637. hw_lock_control_reg =
  1638. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1639. }
  1640. /* Validating that the resource is not already taken */
  1641. lock_status = REG_RD(bp, hw_lock_control_reg);
  1642. if (lock_status & resource_bit) {
  1643. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1644. lock_status, resource_bit);
  1645. return -EEXIST;
  1646. }
  1647. /* Try for 5 second every 5ms */
  1648. for (cnt = 0; cnt < 1000; cnt++) {
  1649. /* Try to acquire the lock */
  1650. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1651. lock_status = REG_RD(bp, hw_lock_control_reg);
  1652. if (lock_status & resource_bit)
  1653. return 0;
  1654. msleep(5);
  1655. }
  1656. BNX2X_ERR("Timeout\n");
  1657. return -EAGAIN;
  1658. }
  1659. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1660. {
  1661. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1662. }
  1663. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1664. {
  1665. u32 lock_status;
  1666. u32 resource_bit = (1 << resource);
  1667. int func = BP_FUNC(bp);
  1668. u32 hw_lock_control_reg;
  1669. /* Validating that the resource is within range */
  1670. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1671. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1672. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1673. return -EINVAL;
  1674. }
  1675. if (func <= 5) {
  1676. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1677. } else {
  1678. hw_lock_control_reg =
  1679. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1680. }
  1681. /* Validating that the resource is currently taken */
  1682. lock_status = REG_RD(bp, hw_lock_control_reg);
  1683. if (!(lock_status & resource_bit)) {
  1684. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1685. lock_status, resource_bit);
  1686. return -EFAULT;
  1687. }
  1688. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1689. return 0;
  1690. }
  1691. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1692. {
  1693. /* The GPIO should be swapped if swap register is set and active */
  1694. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1695. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1696. int gpio_shift = gpio_num +
  1697. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1698. u32 gpio_mask = (1 << gpio_shift);
  1699. u32 gpio_reg;
  1700. int value;
  1701. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1702. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1703. return -EINVAL;
  1704. }
  1705. /* read GPIO value */
  1706. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1707. /* get the requested pin value */
  1708. if ((gpio_reg & gpio_mask) == gpio_mask)
  1709. value = 1;
  1710. else
  1711. value = 0;
  1712. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1713. return value;
  1714. }
  1715. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1716. {
  1717. /* The GPIO should be swapped if swap register is set and active */
  1718. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1719. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1720. int gpio_shift = gpio_num +
  1721. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1722. u32 gpio_mask = (1 << gpio_shift);
  1723. u32 gpio_reg;
  1724. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1725. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1726. return -EINVAL;
  1727. }
  1728. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1729. /* read GPIO and mask except the float bits */
  1730. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1731. switch (mode) {
  1732. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1733. DP(NETIF_MSG_LINK,
  1734. "Set GPIO %d (shift %d) -> output low\n",
  1735. gpio_num, gpio_shift);
  1736. /* clear FLOAT and set CLR */
  1737. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1738. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1739. break;
  1740. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1741. DP(NETIF_MSG_LINK,
  1742. "Set GPIO %d (shift %d) -> output high\n",
  1743. gpio_num, gpio_shift);
  1744. /* clear FLOAT and set SET */
  1745. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1746. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1747. break;
  1748. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1749. DP(NETIF_MSG_LINK,
  1750. "Set GPIO %d (shift %d) -> input\n",
  1751. gpio_num, gpio_shift);
  1752. /* set FLOAT */
  1753. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1754. break;
  1755. default:
  1756. break;
  1757. }
  1758. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1759. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1760. return 0;
  1761. }
  1762. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1763. {
  1764. u32 gpio_reg = 0;
  1765. int rc = 0;
  1766. /* Any port swapping should be handled by caller. */
  1767. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1768. /* read GPIO and mask except the float bits */
  1769. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1770. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1771. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1772. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1773. switch (mode) {
  1774. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1775. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1776. /* set CLR */
  1777. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1778. break;
  1779. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1780. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1781. /* set SET */
  1782. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1783. break;
  1784. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1785. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1786. /* set FLOAT */
  1787. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1788. break;
  1789. default:
  1790. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1791. rc = -EINVAL;
  1792. break;
  1793. }
  1794. if (rc == 0)
  1795. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1796. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1797. return rc;
  1798. }
  1799. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1800. {
  1801. /* The GPIO should be swapped if swap register is set and active */
  1802. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1803. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1804. int gpio_shift = gpio_num +
  1805. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1806. u32 gpio_mask = (1 << gpio_shift);
  1807. u32 gpio_reg;
  1808. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1809. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1810. return -EINVAL;
  1811. }
  1812. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1813. /* read GPIO int */
  1814. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1815. switch (mode) {
  1816. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1817. DP(NETIF_MSG_LINK,
  1818. "Clear GPIO INT %d (shift %d) -> output low\n",
  1819. gpio_num, gpio_shift);
  1820. /* clear SET and set CLR */
  1821. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1822. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1823. break;
  1824. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1825. DP(NETIF_MSG_LINK,
  1826. "Set GPIO INT %d (shift %d) -> output high\n",
  1827. gpio_num, gpio_shift);
  1828. /* clear CLR and set SET */
  1829. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1830. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1831. break;
  1832. default:
  1833. break;
  1834. }
  1835. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1836. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1837. return 0;
  1838. }
  1839. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1840. {
  1841. u32 spio_reg;
  1842. /* Only 2 SPIOs are configurable */
  1843. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1844. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1845. return -EINVAL;
  1846. }
  1847. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1848. /* read SPIO and mask except the float bits */
  1849. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1850. switch (mode) {
  1851. case MISC_SPIO_OUTPUT_LOW:
  1852. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1853. /* clear FLOAT and set CLR */
  1854. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1855. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1856. break;
  1857. case MISC_SPIO_OUTPUT_HIGH:
  1858. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1859. /* clear FLOAT and set SET */
  1860. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1861. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1862. break;
  1863. case MISC_SPIO_INPUT_HI_Z:
  1864. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1865. /* set FLOAT */
  1866. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1867. break;
  1868. default:
  1869. break;
  1870. }
  1871. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1872. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1873. return 0;
  1874. }
  1875. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1876. {
  1877. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1878. switch (bp->link_vars.ieee_fc &
  1879. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1880. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1881. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1882. ADVERTISED_Pause);
  1883. break;
  1884. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1885. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1886. ADVERTISED_Pause);
  1887. break;
  1888. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1889. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1890. break;
  1891. default:
  1892. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1893. ADVERTISED_Pause);
  1894. break;
  1895. }
  1896. }
  1897. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1898. {
  1899. /* Initialize link parameters structure variables
  1900. * It is recommended to turn off RX FC for jumbo frames
  1901. * for better performance
  1902. */
  1903. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1904. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1905. else
  1906. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1907. }
  1908. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1909. {
  1910. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1911. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1912. if (!BP_NOMCP(bp)) {
  1913. bnx2x_set_requested_fc(bp);
  1914. bnx2x_acquire_phy_lock(bp);
  1915. if (load_mode == LOAD_DIAG) {
  1916. struct link_params *lp = &bp->link_params;
  1917. lp->loopback_mode = LOOPBACK_XGXS;
  1918. /* do PHY loopback at 10G speed, if possible */
  1919. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1920. if (lp->speed_cap_mask[cfx_idx] &
  1921. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1922. lp->req_line_speed[cfx_idx] =
  1923. SPEED_10000;
  1924. else
  1925. lp->req_line_speed[cfx_idx] =
  1926. SPEED_1000;
  1927. }
  1928. }
  1929. if (load_mode == LOAD_LOOPBACK_EXT) {
  1930. struct link_params *lp = &bp->link_params;
  1931. lp->loopback_mode = LOOPBACK_EXT;
  1932. }
  1933. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1934. bnx2x_release_phy_lock(bp);
  1935. bnx2x_calc_fc_adv(bp);
  1936. if (bp->link_vars.link_up) {
  1937. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1938. bnx2x_link_report(bp);
  1939. }
  1940. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1941. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1942. return rc;
  1943. }
  1944. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1945. return -EINVAL;
  1946. }
  1947. void bnx2x_link_set(struct bnx2x *bp)
  1948. {
  1949. if (!BP_NOMCP(bp)) {
  1950. bnx2x_acquire_phy_lock(bp);
  1951. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1952. bnx2x_release_phy_lock(bp);
  1953. bnx2x_calc_fc_adv(bp);
  1954. } else
  1955. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1956. }
  1957. static void bnx2x__link_reset(struct bnx2x *bp)
  1958. {
  1959. if (!BP_NOMCP(bp)) {
  1960. bnx2x_acquire_phy_lock(bp);
  1961. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1962. bnx2x_release_phy_lock(bp);
  1963. } else
  1964. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1965. }
  1966. void bnx2x_force_link_reset(struct bnx2x *bp)
  1967. {
  1968. bnx2x_acquire_phy_lock(bp);
  1969. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1970. bnx2x_release_phy_lock(bp);
  1971. }
  1972. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1973. {
  1974. u8 rc = 0;
  1975. if (!BP_NOMCP(bp)) {
  1976. bnx2x_acquire_phy_lock(bp);
  1977. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1978. is_serdes);
  1979. bnx2x_release_phy_lock(bp);
  1980. } else
  1981. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1982. return rc;
  1983. }
  1984. /* Calculates the sum of vn_min_rates.
  1985. It's needed for further normalizing of the min_rates.
  1986. Returns:
  1987. sum of vn_min_rates.
  1988. or
  1989. 0 - if all the min_rates are 0.
  1990. In the later case fairness algorithm should be deactivated.
  1991. If not all min_rates are zero then those that are zeroes will be set to 1.
  1992. */
  1993. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1994. struct cmng_init_input *input)
  1995. {
  1996. int all_zero = 1;
  1997. int vn;
  1998. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1999. u32 vn_cfg = bp->mf_config[vn];
  2000. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2001. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2002. /* Skip hidden vns */
  2003. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2004. vn_min_rate = 0;
  2005. /* If min rate is zero - set it to 1 */
  2006. else if (!vn_min_rate)
  2007. vn_min_rate = DEF_MIN_RATE;
  2008. else
  2009. all_zero = 0;
  2010. input->vnic_min_rate[vn] = vn_min_rate;
  2011. }
  2012. /* if ETS or all min rates are zeros - disable fairness */
  2013. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2014. input->flags.cmng_enables &=
  2015. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2016. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2017. } else if (all_zero) {
  2018. input->flags.cmng_enables &=
  2019. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2020. DP(NETIF_MSG_IFUP,
  2021. "All MIN values are zeroes fairness will be disabled\n");
  2022. } else
  2023. input->flags.cmng_enables |=
  2024. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2025. }
  2026. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2027. struct cmng_init_input *input)
  2028. {
  2029. u16 vn_max_rate;
  2030. u32 vn_cfg = bp->mf_config[vn];
  2031. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2032. vn_max_rate = 0;
  2033. else {
  2034. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2035. if (IS_MF_SI(bp)) {
  2036. /* maxCfg in percents of linkspeed */
  2037. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2038. } else /* SD modes */
  2039. /* maxCfg is absolute in 100Mb units */
  2040. vn_max_rate = maxCfg * 100;
  2041. }
  2042. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2043. input->vnic_max_rate[vn] = vn_max_rate;
  2044. }
  2045. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2046. {
  2047. if (CHIP_REV_IS_SLOW(bp))
  2048. return CMNG_FNS_NONE;
  2049. if (IS_MF(bp))
  2050. return CMNG_FNS_MINMAX;
  2051. return CMNG_FNS_NONE;
  2052. }
  2053. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2054. {
  2055. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2056. if (BP_NOMCP(bp))
  2057. return; /* what should be the default value in this case */
  2058. /* For 2 port configuration the absolute function number formula
  2059. * is:
  2060. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2061. *
  2062. * and there are 4 functions per port
  2063. *
  2064. * For 4 port configuration it is
  2065. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2066. *
  2067. * and there are 2 functions per port
  2068. */
  2069. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2070. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2071. if (func >= E1H_FUNC_MAX)
  2072. break;
  2073. bp->mf_config[vn] =
  2074. MF_CFG_RD(bp, func_mf_config[func].config);
  2075. }
  2076. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2077. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2078. bp->flags |= MF_FUNC_DIS;
  2079. } else {
  2080. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2081. bp->flags &= ~MF_FUNC_DIS;
  2082. }
  2083. }
  2084. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2085. {
  2086. struct cmng_init_input input;
  2087. memset(&input, 0, sizeof(struct cmng_init_input));
  2088. input.port_rate = bp->link_vars.line_speed;
  2089. if (cmng_type == CMNG_FNS_MINMAX) {
  2090. int vn;
  2091. /* read mf conf from shmem */
  2092. if (read_cfg)
  2093. bnx2x_read_mf_cfg(bp);
  2094. /* vn_weight_sum and enable fairness if not 0 */
  2095. bnx2x_calc_vn_min(bp, &input);
  2096. /* calculate and set min-max rate for each vn */
  2097. if (bp->port.pmf)
  2098. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2099. bnx2x_calc_vn_max(bp, vn, &input);
  2100. /* always enable rate shaping and fairness */
  2101. input.flags.cmng_enables |=
  2102. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2103. bnx2x_init_cmng(&input, &bp->cmng);
  2104. return;
  2105. }
  2106. /* rate shaping and fairness are disabled */
  2107. DP(NETIF_MSG_IFUP,
  2108. "rate shaping and fairness are disabled\n");
  2109. }
  2110. static void storm_memset_cmng(struct bnx2x *bp,
  2111. struct cmng_init *cmng,
  2112. u8 port)
  2113. {
  2114. int vn;
  2115. size_t size = sizeof(struct cmng_struct_per_port);
  2116. u32 addr = BAR_XSTRORM_INTMEM +
  2117. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2118. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2119. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2120. int func = func_by_vn(bp, vn);
  2121. addr = BAR_XSTRORM_INTMEM +
  2122. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2123. size = sizeof(struct rate_shaping_vars_per_vn);
  2124. __storm_memset_struct(bp, addr, size,
  2125. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2126. addr = BAR_XSTRORM_INTMEM +
  2127. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2128. size = sizeof(struct fairness_vars_per_vn);
  2129. __storm_memset_struct(bp, addr, size,
  2130. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2131. }
  2132. }
  2133. /* This function is called upon link interrupt */
  2134. static void bnx2x_link_attn(struct bnx2x *bp)
  2135. {
  2136. /* Make sure that we are synced with the current statistics */
  2137. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2138. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2139. if (bp->link_vars.link_up) {
  2140. /* dropless flow control */
  2141. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2142. int port = BP_PORT(bp);
  2143. u32 pause_enabled = 0;
  2144. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2145. pause_enabled = 1;
  2146. REG_WR(bp, BAR_USTRORM_INTMEM +
  2147. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2148. pause_enabled);
  2149. }
  2150. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2151. struct host_port_stats *pstats;
  2152. pstats = bnx2x_sp(bp, port_stats);
  2153. /* reset old mac stats */
  2154. memset(&(pstats->mac_stx[0]), 0,
  2155. sizeof(struct mac_stx));
  2156. }
  2157. if (bp->state == BNX2X_STATE_OPEN)
  2158. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2159. }
  2160. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2161. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2162. if (cmng_fns != CMNG_FNS_NONE) {
  2163. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2164. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2165. } else
  2166. /* rate shaping and fairness are disabled */
  2167. DP(NETIF_MSG_IFUP,
  2168. "single function mode without fairness\n");
  2169. }
  2170. __bnx2x_link_report(bp);
  2171. if (IS_MF(bp))
  2172. bnx2x_link_sync_notify(bp);
  2173. }
  2174. void bnx2x__link_status_update(struct bnx2x *bp)
  2175. {
  2176. if (bp->state != BNX2X_STATE_OPEN)
  2177. return;
  2178. /* read updated dcb configuration */
  2179. if (IS_PF(bp)) {
  2180. bnx2x_dcbx_pmf_update(bp);
  2181. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2182. if (bp->link_vars.link_up)
  2183. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2184. else
  2185. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2186. /* indicate link status */
  2187. bnx2x_link_report(bp);
  2188. } else { /* VF */
  2189. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2190. SUPPORTED_10baseT_Full |
  2191. SUPPORTED_100baseT_Half |
  2192. SUPPORTED_100baseT_Full |
  2193. SUPPORTED_1000baseT_Full |
  2194. SUPPORTED_2500baseX_Full |
  2195. SUPPORTED_10000baseT_Full |
  2196. SUPPORTED_TP |
  2197. SUPPORTED_FIBRE |
  2198. SUPPORTED_Autoneg |
  2199. SUPPORTED_Pause |
  2200. SUPPORTED_Asym_Pause);
  2201. bp->port.advertising[0] = bp->port.supported[0];
  2202. bp->link_params.bp = bp;
  2203. bp->link_params.port = BP_PORT(bp);
  2204. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2205. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2206. bp->link_params.req_line_speed[0] = SPEED_10000;
  2207. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2208. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2209. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2210. bp->link_vars.line_speed = SPEED_10000;
  2211. bp->link_vars.link_status =
  2212. (LINK_STATUS_LINK_UP |
  2213. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2214. bp->link_vars.link_up = 1;
  2215. bp->link_vars.duplex = DUPLEX_FULL;
  2216. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2217. __bnx2x_link_report(bp);
  2218. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2219. }
  2220. }
  2221. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2222. u16 vlan_val, u8 allowed_prio)
  2223. {
  2224. struct bnx2x_func_state_params func_params = {NULL};
  2225. struct bnx2x_func_afex_update_params *f_update_params =
  2226. &func_params.params.afex_update;
  2227. func_params.f_obj = &bp->func_obj;
  2228. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2229. /* no need to wait for RAMROD completion, so don't
  2230. * set RAMROD_COMP_WAIT flag
  2231. */
  2232. f_update_params->vif_id = vifid;
  2233. f_update_params->afex_default_vlan = vlan_val;
  2234. f_update_params->allowed_priorities = allowed_prio;
  2235. /* if ramrod can not be sent, response to MCP immediately */
  2236. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2237. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2238. return 0;
  2239. }
  2240. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2241. u16 vif_index, u8 func_bit_map)
  2242. {
  2243. struct bnx2x_func_state_params func_params = {NULL};
  2244. struct bnx2x_func_afex_viflists_params *update_params =
  2245. &func_params.params.afex_viflists;
  2246. int rc;
  2247. u32 drv_msg_code;
  2248. /* validate only LIST_SET and LIST_GET are received from switch */
  2249. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2250. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2251. cmd_type);
  2252. func_params.f_obj = &bp->func_obj;
  2253. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2254. /* set parameters according to cmd_type */
  2255. update_params->afex_vif_list_command = cmd_type;
  2256. update_params->vif_list_index = vif_index;
  2257. update_params->func_bit_map =
  2258. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2259. update_params->func_to_clear = 0;
  2260. drv_msg_code =
  2261. (cmd_type == VIF_LIST_RULE_GET) ?
  2262. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2263. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2264. /* if ramrod can not be sent, respond to MCP immediately for
  2265. * SET and GET requests (other are not triggered from MCP)
  2266. */
  2267. rc = bnx2x_func_state_change(bp, &func_params);
  2268. if (rc < 0)
  2269. bnx2x_fw_command(bp, drv_msg_code, 0);
  2270. return 0;
  2271. }
  2272. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2273. {
  2274. struct afex_stats afex_stats;
  2275. u32 func = BP_ABS_FUNC(bp);
  2276. u32 mf_config;
  2277. u16 vlan_val;
  2278. u32 vlan_prio;
  2279. u16 vif_id;
  2280. u8 allowed_prio;
  2281. u8 vlan_mode;
  2282. u32 addr_to_write, vifid, addrs, stats_type, i;
  2283. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2284. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2285. DP(BNX2X_MSG_MCP,
  2286. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2287. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2288. }
  2289. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2290. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2291. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2292. DP(BNX2X_MSG_MCP,
  2293. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2294. vifid, addrs);
  2295. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2296. addrs);
  2297. }
  2298. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2299. addr_to_write = SHMEM2_RD(bp,
  2300. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2301. stats_type = SHMEM2_RD(bp,
  2302. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2303. DP(BNX2X_MSG_MCP,
  2304. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2305. addr_to_write);
  2306. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2307. /* write response to scratchpad, for MCP */
  2308. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2309. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2310. *(((u32 *)(&afex_stats))+i));
  2311. /* send ack message to MCP */
  2312. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2313. }
  2314. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2315. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2316. bp->mf_config[BP_VN(bp)] = mf_config;
  2317. DP(BNX2X_MSG_MCP,
  2318. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2319. mf_config);
  2320. /* if VIF_SET is "enabled" */
  2321. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2322. /* set rate limit directly to internal RAM */
  2323. struct cmng_init_input cmng_input;
  2324. struct rate_shaping_vars_per_vn m_rs_vn;
  2325. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2326. u32 addr = BAR_XSTRORM_INTMEM +
  2327. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2328. bp->mf_config[BP_VN(bp)] = mf_config;
  2329. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2330. m_rs_vn.vn_counter.rate =
  2331. cmng_input.vnic_max_rate[BP_VN(bp)];
  2332. m_rs_vn.vn_counter.quota =
  2333. (m_rs_vn.vn_counter.rate *
  2334. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2335. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2336. /* read relevant values from mf_cfg struct in shmem */
  2337. vif_id =
  2338. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2339. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2340. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2341. vlan_val =
  2342. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2343. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2344. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2345. vlan_prio = (mf_config &
  2346. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2347. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2348. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2349. vlan_mode =
  2350. (MF_CFG_RD(bp,
  2351. func_mf_config[func].afex_config) &
  2352. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2353. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2354. allowed_prio =
  2355. (MF_CFG_RD(bp,
  2356. func_mf_config[func].afex_config) &
  2357. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2358. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2359. /* send ramrod to FW, return in case of failure */
  2360. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2361. allowed_prio))
  2362. return;
  2363. bp->afex_def_vlan_tag = vlan_val;
  2364. bp->afex_vlan_mode = vlan_mode;
  2365. } else {
  2366. /* notify link down because BP->flags is disabled */
  2367. bnx2x_link_report(bp);
  2368. /* send INVALID VIF ramrod to FW */
  2369. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2370. /* Reset the default afex VLAN */
  2371. bp->afex_def_vlan_tag = -1;
  2372. }
  2373. }
  2374. }
  2375. static void bnx2x_pmf_update(struct bnx2x *bp)
  2376. {
  2377. int port = BP_PORT(bp);
  2378. u32 val;
  2379. bp->port.pmf = 1;
  2380. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2381. /*
  2382. * We need the mb() to ensure the ordering between the writing to
  2383. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2384. */
  2385. smp_mb();
  2386. /* queue a periodic task */
  2387. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2388. bnx2x_dcbx_pmf_update(bp);
  2389. /* enable nig attention */
  2390. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2391. if (bp->common.int_block == INT_BLOCK_HC) {
  2392. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2393. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2394. } else if (!CHIP_IS_E1x(bp)) {
  2395. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2396. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2397. }
  2398. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2399. }
  2400. /* end of Link */
  2401. /* slow path */
  2402. /*
  2403. * General service functions
  2404. */
  2405. /* send the MCP a request, block until there is a reply */
  2406. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2407. {
  2408. int mb_idx = BP_FW_MB_IDX(bp);
  2409. u32 seq;
  2410. u32 rc = 0;
  2411. u32 cnt = 1;
  2412. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2413. mutex_lock(&bp->fw_mb_mutex);
  2414. seq = ++bp->fw_seq;
  2415. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2416. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2417. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2418. (command | seq), param);
  2419. do {
  2420. /* let the FW do it's magic ... */
  2421. msleep(delay);
  2422. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2423. /* Give the FW up to 5 second (500*10ms) */
  2424. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2425. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2426. cnt*delay, rc, seq);
  2427. /* is this a reply to our command? */
  2428. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2429. rc &= FW_MSG_CODE_MASK;
  2430. else {
  2431. /* FW BUG! */
  2432. BNX2X_ERR("FW failed to respond!\n");
  2433. bnx2x_fw_dump(bp);
  2434. rc = 0;
  2435. }
  2436. mutex_unlock(&bp->fw_mb_mutex);
  2437. return rc;
  2438. }
  2439. static void storm_memset_func_cfg(struct bnx2x *bp,
  2440. struct tstorm_eth_function_common_config *tcfg,
  2441. u16 abs_fid)
  2442. {
  2443. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2444. u32 addr = BAR_TSTRORM_INTMEM +
  2445. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2446. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2447. }
  2448. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2449. {
  2450. if (CHIP_IS_E1x(bp)) {
  2451. struct tstorm_eth_function_common_config tcfg = {0};
  2452. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2453. }
  2454. /* Enable the function in the FW */
  2455. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2456. storm_memset_func_en(bp, p->func_id, 1);
  2457. /* spq */
  2458. if (p->func_flgs & FUNC_FLG_SPQ) {
  2459. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2460. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2461. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2462. }
  2463. }
  2464. /**
  2465. * bnx2x_get_common_flags - Return common flags
  2466. *
  2467. * @bp device handle
  2468. * @fp queue handle
  2469. * @zero_stats TRUE if statistics zeroing is needed
  2470. *
  2471. * Return the flags that are common for the Tx-only and not normal connections.
  2472. */
  2473. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2474. struct bnx2x_fastpath *fp,
  2475. bool zero_stats)
  2476. {
  2477. unsigned long flags = 0;
  2478. /* PF driver will always initialize the Queue to an ACTIVE state */
  2479. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2480. /* tx only connections collect statistics (on the same index as the
  2481. * parent connection). The statistics are zeroed when the parent
  2482. * connection is initialized.
  2483. */
  2484. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2485. if (zero_stats)
  2486. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2487. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2488. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2489. #ifdef BNX2X_STOP_ON_ERROR
  2490. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2491. #endif
  2492. return flags;
  2493. }
  2494. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2495. struct bnx2x_fastpath *fp,
  2496. bool leading)
  2497. {
  2498. unsigned long flags = 0;
  2499. /* calculate other queue flags */
  2500. if (IS_MF_SD(bp))
  2501. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2502. if (IS_FCOE_FP(fp)) {
  2503. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2504. /* For FCoE - force usage of default priority (for afex) */
  2505. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2506. }
  2507. if (!fp->disable_tpa) {
  2508. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2509. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2510. if (fp->mode == TPA_MODE_GRO)
  2511. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2512. }
  2513. if (leading) {
  2514. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2515. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2516. }
  2517. /* Always set HW VLAN stripping */
  2518. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2519. /* configure silent vlan removal */
  2520. if (IS_MF_AFEX(bp))
  2521. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2522. return flags | bnx2x_get_common_flags(bp, fp, true);
  2523. }
  2524. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2525. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2526. u8 cos)
  2527. {
  2528. gen_init->stat_id = bnx2x_stats_id(fp);
  2529. gen_init->spcl_id = fp->cl_id;
  2530. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2531. if (IS_FCOE_FP(fp))
  2532. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2533. else
  2534. gen_init->mtu = bp->dev->mtu;
  2535. gen_init->cos = cos;
  2536. }
  2537. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2538. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2539. struct bnx2x_rxq_setup_params *rxq_init)
  2540. {
  2541. u8 max_sge = 0;
  2542. u16 sge_sz = 0;
  2543. u16 tpa_agg_size = 0;
  2544. if (!fp->disable_tpa) {
  2545. pause->sge_th_lo = SGE_TH_LO(bp);
  2546. pause->sge_th_hi = SGE_TH_HI(bp);
  2547. /* validate SGE ring has enough to cross high threshold */
  2548. WARN_ON(bp->dropless_fc &&
  2549. pause->sge_th_hi + FW_PREFETCH_CNT >
  2550. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2551. tpa_agg_size = TPA_AGG_SIZE;
  2552. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2553. SGE_PAGE_SHIFT;
  2554. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2555. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2556. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2557. }
  2558. /* pause - not for e1 */
  2559. if (!CHIP_IS_E1(bp)) {
  2560. pause->bd_th_lo = BD_TH_LO(bp);
  2561. pause->bd_th_hi = BD_TH_HI(bp);
  2562. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2563. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2564. /*
  2565. * validate that rings have enough entries to cross
  2566. * high thresholds
  2567. */
  2568. WARN_ON(bp->dropless_fc &&
  2569. pause->bd_th_hi + FW_PREFETCH_CNT >
  2570. bp->rx_ring_size);
  2571. WARN_ON(bp->dropless_fc &&
  2572. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2573. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2574. pause->pri_map = 1;
  2575. }
  2576. /* rxq setup */
  2577. rxq_init->dscr_map = fp->rx_desc_mapping;
  2578. rxq_init->sge_map = fp->rx_sge_mapping;
  2579. rxq_init->rcq_map = fp->rx_comp_mapping;
  2580. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2581. /* This should be a maximum number of data bytes that may be
  2582. * placed on the BD (not including paddings).
  2583. */
  2584. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2585. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2586. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2587. rxq_init->tpa_agg_sz = tpa_agg_size;
  2588. rxq_init->sge_buf_sz = sge_sz;
  2589. rxq_init->max_sges_pkt = max_sge;
  2590. rxq_init->rss_engine_id = BP_FUNC(bp);
  2591. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2592. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2593. *
  2594. * For PF Clients it should be the maximum available number.
  2595. * VF driver(s) may want to define it to a smaller value.
  2596. */
  2597. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2598. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2599. rxq_init->fw_sb_id = fp->fw_sb_id;
  2600. if (IS_FCOE_FP(fp))
  2601. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2602. else
  2603. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2604. /* configure silent vlan removal
  2605. * if multi function mode is afex, then mask default vlan
  2606. */
  2607. if (IS_MF_AFEX(bp)) {
  2608. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2609. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2610. }
  2611. }
  2612. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2613. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2614. u8 cos)
  2615. {
  2616. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2617. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2618. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2619. txq_init->fw_sb_id = fp->fw_sb_id;
  2620. /*
  2621. * set the tss leading client id for TX classification ==
  2622. * leading RSS client id
  2623. */
  2624. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2625. if (IS_FCOE_FP(fp)) {
  2626. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2627. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2628. }
  2629. }
  2630. static void bnx2x_pf_init(struct bnx2x *bp)
  2631. {
  2632. struct bnx2x_func_init_params func_init = {0};
  2633. struct event_ring_data eq_data = { {0} };
  2634. u16 flags;
  2635. if (!CHIP_IS_E1x(bp)) {
  2636. /* reset IGU PF statistics: MSIX + ATTN */
  2637. /* PF */
  2638. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2639. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2640. (CHIP_MODE_IS_4_PORT(bp) ?
  2641. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2642. /* ATTN */
  2643. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2644. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2645. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2646. (CHIP_MODE_IS_4_PORT(bp) ?
  2647. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2648. }
  2649. /* function setup flags */
  2650. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2651. /* This flag is relevant for E1x only.
  2652. * E2 doesn't have a TPA configuration in a function level.
  2653. */
  2654. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2655. func_init.func_flgs = flags;
  2656. func_init.pf_id = BP_FUNC(bp);
  2657. func_init.func_id = BP_FUNC(bp);
  2658. func_init.spq_map = bp->spq_mapping;
  2659. func_init.spq_prod = bp->spq_prod_idx;
  2660. bnx2x_func_init(bp, &func_init);
  2661. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2662. /*
  2663. * Congestion management values depend on the link rate
  2664. * There is no active link so initial link rate is set to 10 Gbps.
  2665. * When the link comes up The congestion management values are
  2666. * re-calculated according to the actual link rate.
  2667. */
  2668. bp->link_vars.line_speed = SPEED_10000;
  2669. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2670. /* Only the PMF sets the HW */
  2671. if (bp->port.pmf)
  2672. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2673. /* init Event Queue - PCI bus guarantees correct endianity*/
  2674. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2675. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2676. eq_data.producer = bp->eq_prod;
  2677. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2678. eq_data.sb_id = DEF_SB_ID;
  2679. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2680. }
  2681. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2682. {
  2683. int port = BP_PORT(bp);
  2684. bnx2x_tx_disable(bp);
  2685. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2686. }
  2687. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2688. {
  2689. int port = BP_PORT(bp);
  2690. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2691. /* Tx queue should be only re-enabled */
  2692. netif_tx_wake_all_queues(bp->dev);
  2693. /*
  2694. * Should not call netif_carrier_on since it will be called if the link
  2695. * is up when checking for link state
  2696. */
  2697. }
  2698. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2699. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2700. {
  2701. struct eth_stats_info *ether_stat =
  2702. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2703. struct bnx2x_vlan_mac_obj *mac_obj =
  2704. &bp->sp_objs->mac_obj;
  2705. int i;
  2706. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2707. ETH_STAT_INFO_VERSION_LEN);
  2708. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2709. * mac_local field in ether_stat struct. The base address is offset by 2
  2710. * bytes to account for the field being 8 bytes but a mac address is
  2711. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2712. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2713. * allocated by the ether_stat struct, so the macs will land in their
  2714. * proper positions.
  2715. */
  2716. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2717. memset(ether_stat->mac_local + i, 0,
  2718. sizeof(ether_stat->mac_local[0]));
  2719. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2720. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2721. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2722. ETH_ALEN);
  2723. ether_stat->mtu_size = bp->dev->mtu;
  2724. if (bp->dev->features & NETIF_F_RXCSUM)
  2725. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2726. if (bp->dev->features & NETIF_F_TSO)
  2727. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2728. ether_stat->feature_flags |= bp->common.boot_mode;
  2729. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2730. ether_stat->txq_size = bp->tx_ring_size;
  2731. ether_stat->rxq_size = bp->rx_ring_size;
  2732. }
  2733. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2734. {
  2735. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2736. struct fcoe_stats_info *fcoe_stat =
  2737. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2738. if (!CNIC_LOADED(bp))
  2739. return;
  2740. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2741. fcoe_stat->qos_priority =
  2742. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2743. /* insert FCoE stats from ramrod response */
  2744. if (!NO_FCOE(bp)) {
  2745. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2746. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2747. tstorm_queue_statistics;
  2748. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2749. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2750. xstorm_queue_statistics;
  2751. struct fcoe_statistics_params *fw_fcoe_stat =
  2752. &bp->fw_stats_data->fcoe;
  2753. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2754. fcoe_stat->rx_bytes_lo,
  2755. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2756. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2757. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2758. fcoe_stat->rx_bytes_lo,
  2759. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2760. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2761. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2762. fcoe_stat->rx_bytes_lo,
  2763. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2764. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2765. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2766. fcoe_stat->rx_bytes_lo,
  2767. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2768. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2769. fcoe_stat->rx_frames_lo,
  2770. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2771. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2772. fcoe_stat->rx_frames_lo,
  2773. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2774. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2775. fcoe_stat->rx_frames_lo,
  2776. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2777. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2778. fcoe_stat->rx_frames_lo,
  2779. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2780. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2781. fcoe_stat->tx_bytes_lo,
  2782. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2783. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2784. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2785. fcoe_stat->tx_bytes_lo,
  2786. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2787. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2788. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2789. fcoe_stat->tx_bytes_lo,
  2790. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2791. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2792. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2793. fcoe_stat->tx_bytes_lo,
  2794. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2795. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2796. fcoe_stat->tx_frames_lo,
  2797. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2798. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2799. fcoe_stat->tx_frames_lo,
  2800. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2801. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2802. fcoe_stat->tx_frames_lo,
  2803. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2804. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2805. fcoe_stat->tx_frames_lo,
  2806. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2807. }
  2808. /* ask L5 driver to add data to the struct */
  2809. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2810. }
  2811. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2812. {
  2813. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2814. struct iscsi_stats_info *iscsi_stat =
  2815. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2816. if (!CNIC_LOADED(bp))
  2817. return;
  2818. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2819. ETH_ALEN);
  2820. iscsi_stat->qos_priority =
  2821. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2822. /* ask L5 driver to add data to the struct */
  2823. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2824. }
  2825. /* called due to MCP event (on pmf):
  2826. * reread new bandwidth configuration
  2827. * configure FW
  2828. * notify others function about the change
  2829. */
  2830. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2831. {
  2832. if (bp->link_vars.link_up) {
  2833. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2834. bnx2x_link_sync_notify(bp);
  2835. }
  2836. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2837. }
  2838. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2839. {
  2840. bnx2x_config_mf_bw(bp);
  2841. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2842. }
  2843. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2844. {
  2845. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2846. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2847. }
  2848. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2849. {
  2850. enum drv_info_opcode op_code;
  2851. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2852. /* if drv_info version supported by MFW doesn't match - send NACK */
  2853. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2854. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2855. return;
  2856. }
  2857. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2858. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2859. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2860. sizeof(union drv_info_to_mcp));
  2861. switch (op_code) {
  2862. case ETH_STATS_OPCODE:
  2863. bnx2x_drv_info_ether_stat(bp);
  2864. break;
  2865. case FCOE_STATS_OPCODE:
  2866. bnx2x_drv_info_fcoe_stat(bp);
  2867. break;
  2868. case ISCSI_STATS_OPCODE:
  2869. bnx2x_drv_info_iscsi_stat(bp);
  2870. break;
  2871. default:
  2872. /* if op code isn't supported - send NACK */
  2873. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2874. return;
  2875. }
  2876. /* if we got drv_info attn from MFW then these fields are defined in
  2877. * shmem2 for sure
  2878. */
  2879. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2880. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2881. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2882. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2883. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2884. }
  2885. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2886. {
  2887. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2888. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2889. /*
  2890. * This is the only place besides the function initialization
  2891. * where the bp->flags can change so it is done without any
  2892. * locks
  2893. */
  2894. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2895. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2896. bp->flags |= MF_FUNC_DIS;
  2897. bnx2x_e1h_disable(bp);
  2898. } else {
  2899. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2900. bp->flags &= ~MF_FUNC_DIS;
  2901. bnx2x_e1h_enable(bp);
  2902. }
  2903. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2904. }
  2905. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2906. bnx2x_config_mf_bw(bp);
  2907. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2908. }
  2909. /* Report results to MCP */
  2910. if (dcc_event)
  2911. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2912. else
  2913. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2914. }
  2915. /* must be called under the spq lock */
  2916. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2917. {
  2918. struct eth_spe *next_spe = bp->spq_prod_bd;
  2919. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2920. bp->spq_prod_bd = bp->spq;
  2921. bp->spq_prod_idx = 0;
  2922. DP(BNX2X_MSG_SP, "end of spq\n");
  2923. } else {
  2924. bp->spq_prod_bd++;
  2925. bp->spq_prod_idx++;
  2926. }
  2927. return next_spe;
  2928. }
  2929. /* must be called under the spq lock */
  2930. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2931. {
  2932. int func = BP_FUNC(bp);
  2933. /*
  2934. * Make sure that BD data is updated before writing the producer:
  2935. * BD data is written to the memory, the producer is read from the
  2936. * memory, thus we need a full memory barrier to ensure the ordering.
  2937. */
  2938. mb();
  2939. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2940. bp->spq_prod_idx);
  2941. mmiowb();
  2942. }
  2943. /**
  2944. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2945. *
  2946. * @cmd: command to check
  2947. * @cmd_type: command type
  2948. */
  2949. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2950. {
  2951. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2952. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2953. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2954. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2955. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2956. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2957. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2958. return true;
  2959. else
  2960. return false;
  2961. }
  2962. /**
  2963. * bnx2x_sp_post - place a single command on an SP ring
  2964. *
  2965. * @bp: driver handle
  2966. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2967. * @cid: SW CID the command is related to
  2968. * @data_hi: command private data address (high 32 bits)
  2969. * @data_lo: command private data address (low 32 bits)
  2970. * @cmd_type: command type (e.g. NONE, ETH)
  2971. *
  2972. * SP data is handled as if it's always an address pair, thus data fields are
  2973. * not swapped to little endian in upper functions. Instead this function swaps
  2974. * data as if it's two u32 fields.
  2975. */
  2976. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2977. u32 data_hi, u32 data_lo, int cmd_type)
  2978. {
  2979. struct eth_spe *spe;
  2980. u16 type;
  2981. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2982. #ifdef BNX2X_STOP_ON_ERROR
  2983. if (unlikely(bp->panic)) {
  2984. BNX2X_ERR("Can't post SP when there is panic\n");
  2985. return -EIO;
  2986. }
  2987. #endif
  2988. spin_lock_bh(&bp->spq_lock);
  2989. if (common) {
  2990. if (!atomic_read(&bp->eq_spq_left)) {
  2991. BNX2X_ERR("BUG! EQ ring full!\n");
  2992. spin_unlock_bh(&bp->spq_lock);
  2993. bnx2x_panic();
  2994. return -EBUSY;
  2995. }
  2996. } else if (!atomic_read(&bp->cq_spq_left)) {
  2997. BNX2X_ERR("BUG! SPQ ring full!\n");
  2998. spin_unlock_bh(&bp->spq_lock);
  2999. bnx2x_panic();
  3000. return -EBUSY;
  3001. }
  3002. spe = bnx2x_sp_get_next(bp);
  3003. /* CID needs port number to be encoded int it */
  3004. spe->hdr.conn_and_cmd_data =
  3005. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3006. HW_CID(bp, cid));
  3007. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  3008. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3009. SPE_HDR_FUNCTION_ID);
  3010. spe->hdr.type = cpu_to_le16(type);
  3011. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3012. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3013. /*
  3014. * It's ok if the actual decrement is issued towards the memory
  3015. * somewhere between the spin_lock and spin_unlock. Thus no
  3016. * more explicit memory barrier is needed.
  3017. */
  3018. if (common)
  3019. atomic_dec(&bp->eq_spq_left);
  3020. else
  3021. atomic_dec(&bp->cq_spq_left);
  3022. DP(BNX2X_MSG_SP,
  3023. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3024. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3025. (u32)(U64_LO(bp->spq_mapping) +
  3026. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3027. HW_CID(bp, cid), data_hi, data_lo, type,
  3028. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3029. bnx2x_sp_prod_update(bp);
  3030. spin_unlock_bh(&bp->spq_lock);
  3031. return 0;
  3032. }
  3033. /* acquire split MCP access lock register */
  3034. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3035. {
  3036. u32 j, val;
  3037. int rc = 0;
  3038. might_sleep();
  3039. for (j = 0; j < 1000; j++) {
  3040. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3041. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3042. if (val & MCPR_ACCESS_LOCK_LOCK)
  3043. break;
  3044. msleep(5);
  3045. }
  3046. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3047. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3048. rc = -EBUSY;
  3049. }
  3050. return rc;
  3051. }
  3052. /* release split MCP access lock register */
  3053. static void bnx2x_release_alr(struct bnx2x *bp)
  3054. {
  3055. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3056. }
  3057. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3058. #define BNX2X_DEF_SB_IDX 0x0002
  3059. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3060. {
  3061. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3062. u16 rc = 0;
  3063. barrier(); /* status block is written to by the chip */
  3064. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3065. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3066. rc |= BNX2X_DEF_SB_ATT_IDX;
  3067. }
  3068. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3069. bp->def_idx = def_sb->sp_sb.running_index;
  3070. rc |= BNX2X_DEF_SB_IDX;
  3071. }
  3072. /* Do not reorder: indices reading should complete before handling */
  3073. barrier();
  3074. return rc;
  3075. }
  3076. /*
  3077. * slow path service functions
  3078. */
  3079. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3080. {
  3081. int port = BP_PORT(bp);
  3082. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3083. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3084. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3085. NIG_REG_MASK_INTERRUPT_PORT0;
  3086. u32 aeu_mask;
  3087. u32 nig_mask = 0;
  3088. u32 reg_addr;
  3089. if (bp->attn_state & asserted)
  3090. BNX2X_ERR("IGU ERROR\n");
  3091. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3092. aeu_mask = REG_RD(bp, aeu_addr);
  3093. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3094. aeu_mask, asserted);
  3095. aeu_mask &= ~(asserted & 0x3ff);
  3096. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3097. REG_WR(bp, aeu_addr, aeu_mask);
  3098. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3099. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3100. bp->attn_state |= asserted;
  3101. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3102. if (asserted & ATTN_HARD_WIRED_MASK) {
  3103. if (asserted & ATTN_NIG_FOR_FUNC) {
  3104. bnx2x_acquire_phy_lock(bp);
  3105. /* save nig interrupt mask */
  3106. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3107. /* If nig_mask is not set, no need to call the update
  3108. * function.
  3109. */
  3110. if (nig_mask) {
  3111. REG_WR(bp, nig_int_mask_addr, 0);
  3112. bnx2x_link_attn(bp);
  3113. }
  3114. /* handle unicore attn? */
  3115. }
  3116. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3117. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3118. if (asserted & GPIO_2_FUNC)
  3119. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3120. if (asserted & GPIO_3_FUNC)
  3121. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3122. if (asserted & GPIO_4_FUNC)
  3123. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3124. if (port == 0) {
  3125. if (asserted & ATTN_GENERAL_ATTN_1) {
  3126. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3127. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3128. }
  3129. if (asserted & ATTN_GENERAL_ATTN_2) {
  3130. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3131. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3132. }
  3133. if (asserted & ATTN_GENERAL_ATTN_3) {
  3134. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3135. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3136. }
  3137. } else {
  3138. if (asserted & ATTN_GENERAL_ATTN_4) {
  3139. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3140. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3141. }
  3142. if (asserted & ATTN_GENERAL_ATTN_5) {
  3143. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3144. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3145. }
  3146. if (asserted & ATTN_GENERAL_ATTN_6) {
  3147. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3148. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3149. }
  3150. }
  3151. } /* if hardwired */
  3152. if (bp->common.int_block == INT_BLOCK_HC)
  3153. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3154. COMMAND_REG_ATTN_BITS_SET);
  3155. else
  3156. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3157. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3158. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3159. REG_WR(bp, reg_addr, asserted);
  3160. /* now set back the mask */
  3161. if (asserted & ATTN_NIG_FOR_FUNC) {
  3162. /* Verify that IGU ack through BAR was written before restoring
  3163. * NIG mask. This loop should exit after 2-3 iterations max.
  3164. */
  3165. if (bp->common.int_block != INT_BLOCK_HC) {
  3166. u32 cnt = 0, igu_acked;
  3167. do {
  3168. igu_acked = REG_RD(bp,
  3169. IGU_REG_ATTENTION_ACK_BITS);
  3170. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3171. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3172. if (!igu_acked)
  3173. DP(NETIF_MSG_HW,
  3174. "Failed to verify IGU ack on time\n");
  3175. barrier();
  3176. }
  3177. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3178. bnx2x_release_phy_lock(bp);
  3179. }
  3180. }
  3181. static void bnx2x_fan_failure(struct bnx2x *bp)
  3182. {
  3183. int port = BP_PORT(bp);
  3184. u32 ext_phy_config;
  3185. /* mark the failure */
  3186. ext_phy_config =
  3187. SHMEM_RD(bp,
  3188. dev_info.port_hw_config[port].external_phy_config);
  3189. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3190. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3191. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3192. ext_phy_config);
  3193. /* log the failure */
  3194. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3195. "Please contact OEM Support for assistance\n");
  3196. /* Schedule device reset (unload)
  3197. * This is due to some boards consuming sufficient power when driver is
  3198. * up to overheat if fan fails.
  3199. */
  3200. smp_mb__before_clear_bit();
  3201. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3202. smp_mb__after_clear_bit();
  3203. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3204. }
  3205. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3206. {
  3207. int port = BP_PORT(bp);
  3208. int reg_offset;
  3209. u32 val;
  3210. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3211. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3212. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3213. val = REG_RD(bp, reg_offset);
  3214. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3215. REG_WR(bp, reg_offset, val);
  3216. BNX2X_ERR("SPIO5 hw attention\n");
  3217. /* Fan failure attention */
  3218. bnx2x_hw_reset_phy(&bp->link_params);
  3219. bnx2x_fan_failure(bp);
  3220. }
  3221. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3222. bnx2x_acquire_phy_lock(bp);
  3223. bnx2x_handle_module_detect_int(&bp->link_params);
  3224. bnx2x_release_phy_lock(bp);
  3225. }
  3226. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3227. val = REG_RD(bp, reg_offset);
  3228. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3229. REG_WR(bp, reg_offset, val);
  3230. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3231. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3232. bnx2x_panic();
  3233. }
  3234. }
  3235. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3236. {
  3237. u32 val;
  3238. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3239. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3240. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3241. /* DORQ discard attention */
  3242. if (val & 0x2)
  3243. BNX2X_ERR("FATAL error from DORQ\n");
  3244. }
  3245. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3246. int port = BP_PORT(bp);
  3247. int reg_offset;
  3248. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3249. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3250. val = REG_RD(bp, reg_offset);
  3251. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3252. REG_WR(bp, reg_offset, val);
  3253. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3254. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3255. bnx2x_panic();
  3256. }
  3257. }
  3258. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3259. {
  3260. u32 val;
  3261. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3262. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3263. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3264. /* CFC error attention */
  3265. if (val & 0x2)
  3266. BNX2X_ERR("FATAL error from CFC\n");
  3267. }
  3268. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3269. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3270. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3271. /* RQ_USDMDP_FIFO_OVERFLOW */
  3272. if (val & 0x18000)
  3273. BNX2X_ERR("FATAL error from PXP\n");
  3274. if (!CHIP_IS_E1x(bp)) {
  3275. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3276. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3277. }
  3278. }
  3279. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3280. int port = BP_PORT(bp);
  3281. int reg_offset;
  3282. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3283. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3284. val = REG_RD(bp, reg_offset);
  3285. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3286. REG_WR(bp, reg_offset, val);
  3287. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3288. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3289. bnx2x_panic();
  3290. }
  3291. }
  3292. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3293. {
  3294. u32 val;
  3295. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3296. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3297. int func = BP_FUNC(bp);
  3298. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3299. bnx2x_read_mf_cfg(bp);
  3300. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3301. func_mf_config[BP_ABS_FUNC(bp)].config);
  3302. val = SHMEM_RD(bp,
  3303. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3304. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3305. bnx2x_dcc_event(bp,
  3306. (val & DRV_STATUS_DCC_EVENT_MASK));
  3307. if (val & DRV_STATUS_SET_MF_BW)
  3308. bnx2x_set_mf_bw(bp);
  3309. if (val & DRV_STATUS_DRV_INFO_REQ)
  3310. bnx2x_handle_drv_info_req(bp);
  3311. if (val & DRV_STATUS_VF_DISABLED)
  3312. bnx2x_vf_handle_flr_event(bp);
  3313. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3314. bnx2x_pmf_update(bp);
  3315. if (bp->port.pmf &&
  3316. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3317. bp->dcbx_enabled > 0)
  3318. /* start dcbx state machine */
  3319. bnx2x_dcbx_set_params(bp,
  3320. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3321. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3322. bnx2x_handle_afex_cmd(bp,
  3323. val & DRV_STATUS_AFEX_EVENT_MASK);
  3324. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3325. bnx2x_handle_eee_event(bp);
  3326. if (bp->link_vars.periodic_flags &
  3327. PERIODIC_FLAGS_LINK_EVENT) {
  3328. /* sync with link */
  3329. bnx2x_acquire_phy_lock(bp);
  3330. bp->link_vars.periodic_flags &=
  3331. ~PERIODIC_FLAGS_LINK_EVENT;
  3332. bnx2x_release_phy_lock(bp);
  3333. if (IS_MF(bp))
  3334. bnx2x_link_sync_notify(bp);
  3335. bnx2x_link_report(bp);
  3336. }
  3337. /* Always call it here: bnx2x_link_report() will
  3338. * prevent the link indication duplication.
  3339. */
  3340. bnx2x__link_status_update(bp);
  3341. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3342. BNX2X_ERR("MC assert!\n");
  3343. bnx2x_mc_assert(bp);
  3344. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3345. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3346. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3347. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3348. bnx2x_panic();
  3349. } else if (attn & BNX2X_MCP_ASSERT) {
  3350. BNX2X_ERR("MCP assert!\n");
  3351. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3352. bnx2x_fw_dump(bp);
  3353. } else
  3354. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3355. }
  3356. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3357. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3358. if (attn & BNX2X_GRC_TIMEOUT) {
  3359. val = CHIP_IS_E1(bp) ? 0 :
  3360. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3361. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3362. }
  3363. if (attn & BNX2X_GRC_RSV) {
  3364. val = CHIP_IS_E1(bp) ? 0 :
  3365. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3366. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3367. }
  3368. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3369. }
  3370. }
  3371. /*
  3372. * Bits map:
  3373. * 0-7 - Engine0 load counter.
  3374. * 8-15 - Engine1 load counter.
  3375. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3376. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3377. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3378. * on the engine
  3379. * 19 - Engine1 ONE_IS_LOADED.
  3380. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3381. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3382. * just the one belonging to its engine).
  3383. *
  3384. */
  3385. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3386. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3387. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3388. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3389. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3390. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3391. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3392. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3393. /*
  3394. * Set the GLOBAL_RESET bit.
  3395. *
  3396. * Should be run under rtnl lock
  3397. */
  3398. void bnx2x_set_reset_global(struct bnx2x *bp)
  3399. {
  3400. u32 val;
  3401. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3402. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3403. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3404. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3405. }
  3406. /*
  3407. * Clear the GLOBAL_RESET bit.
  3408. *
  3409. * Should be run under rtnl lock
  3410. */
  3411. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3412. {
  3413. u32 val;
  3414. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3415. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3416. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3417. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3418. }
  3419. /*
  3420. * Checks the GLOBAL_RESET bit.
  3421. *
  3422. * should be run under rtnl lock
  3423. */
  3424. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3425. {
  3426. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3427. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3428. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3429. }
  3430. /*
  3431. * Clear RESET_IN_PROGRESS bit for the current engine.
  3432. *
  3433. * Should be run under rtnl lock
  3434. */
  3435. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3436. {
  3437. u32 val;
  3438. u32 bit = BP_PATH(bp) ?
  3439. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3440. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3441. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3442. /* Clear the bit */
  3443. val &= ~bit;
  3444. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3445. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3446. }
  3447. /*
  3448. * Set RESET_IN_PROGRESS for the current engine.
  3449. *
  3450. * should be run under rtnl lock
  3451. */
  3452. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3453. {
  3454. u32 val;
  3455. u32 bit = BP_PATH(bp) ?
  3456. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3457. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3458. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3459. /* Set the bit */
  3460. val |= bit;
  3461. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3462. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3463. }
  3464. /*
  3465. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3466. * should be run under rtnl lock
  3467. */
  3468. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3469. {
  3470. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3471. u32 bit = engine ?
  3472. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3473. /* return false if bit is set */
  3474. return (val & bit) ? false : true;
  3475. }
  3476. /*
  3477. * set pf load for the current pf.
  3478. *
  3479. * should be run under rtnl lock
  3480. */
  3481. void bnx2x_set_pf_load(struct bnx2x *bp)
  3482. {
  3483. u32 val1, val;
  3484. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3485. BNX2X_PATH0_LOAD_CNT_MASK;
  3486. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3487. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3488. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3489. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3490. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3491. /* get the current counter value */
  3492. val1 = (val & mask) >> shift;
  3493. /* set bit of that PF */
  3494. val1 |= (1 << bp->pf_num);
  3495. /* clear the old value */
  3496. val &= ~mask;
  3497. /* set the new one */
  3498. val |= ((val1 << shift) & mask);
  3499. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3500. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3501. }
  3502. /**
  3503. * bnx2x_clear_pf_load - clear pf load mark
  3504. *
  3505. * @bp: driver handle
  3506. *
  3507. * Should be run under rtnl lock.
  3508. * Decrements the load counter for the current engine. Returns
  3509. * whether other functions are still loaded
  3510. */
  3511. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3512. {
  3513. u32 val1, val;
  3514. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3515. BNX2X_PATH0_LOAD_CNT_MASK;
  3516. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3517. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3518. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3519. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3520. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3521. /* get the current counter value */
  3522. val1 = (val & mask) >> shift;
  3523. /* clear bit of that PF */
  3524. val1 &= ~(1 << bp->pf_num);
  3525. /* clear the old value */
  3526. val &= ~mask;
  3527. /* set the new one */
  3528. val |= ((val1 << shift) & mask);
  3529. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3530. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3531. return val1 != 0;
  3532. }
  3533. /*
  3534. * Read the load status for the current engine.
  3535. *
  3536. * should be run under rtnl lock
  3537. */
  3538. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3539. {
  3540. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3541. BNX2X_PATH0_LOAD_CNT_MASK);
  3542. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3543. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3544. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3545. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3546. val = (val & mask) >> shift;
  3547. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3548. engine, val);
  3549. return val != 0;
  3550. }
  3551. static void _print_next_block(int idx, const char *blk)
  3552. {
  3553. pr_cont("%s%s", idx ? ", " : "", blk);
  3554. }
  3555. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3556. bool print)
  3557. {
  3558. int i = 0;
  3559. u32 cur_bit = 0;
  3560. for (i = 0; sig; i++) {
  3561. cur_bit = ((u32)0x1 << i);
  3562. if (sig & cur_bit) {
  3563. switch (cur_bit) {
  3564. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3565. if (print)
  3566. _print_next_block(par_num++, "BRB");
  3567. break;
  3568. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3569. if (print)
  3570. _print_next_block(par_num++, "PARSER");
  3571. break;
  3572. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3573. if (print)
  3574. _print_next_block(par_num++, "TSDM");
  3575. break;
  3576. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3577. if (print)
  3578. _print_next_block(par_num++,
  3579. "SEARCHER");
  3580. break;
  3581. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3582. if (print)
  3583. _print_next_block(par_num++, "TCM");
  3584. break;
  3585. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3586. if (print)
  3587. _print_next_block(par_num++, "TSEMI");
  3588. break;
  3589. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3590. if (print)
  3591. _print_next_block(par_num++, "XPB");
  3592. break;
  3593. }
  3594. /* Clear the bit */
  3595. sig &= ~cur_bit;
  3596. }
  3597. }
  3598. return par_num;
  3599. }
  3600. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3601. bool *global, bool print)
  3602. {
  3603. int i = 0;
  3604. u32 cur_bit = 0;
  3605. for (i = 0; sig; i++) {
  3606. cur_bit = ((u32)0x1 << i);
  3607. if (sig & cur_bit) {
  3608. switch (cur_bit) {
  3609. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3610. if (print)
  3611. _print_next_block(par_num++, "PBF");
  3612. break;
  3613. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3614. if (print)
  3615. _print_next_block(par_num++, "QM");
  3616. break;
  3617. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3618. if (print)
  3619. _print_next_block(par_num++, "TM");
  3620. break;
  3621. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3622. if (print)
  3623. _print_next_block(par_num++, "XSDM");
  3624. break;
  3625. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3626. if (print)
  3627. _print_next_block(par_num++, "XCM");
  3628. break;
  3629. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3630. if (print)
  3631. _print_next_block(par_num++, "XSEMI");
  3632. break;
  3633. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3634. if (print)
  3635. _print_next_block(par_num++,
  3636. "DOORBELLQ");
  3637. break;
  3638. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3639. if (print)
  3640. _print_next_block(par_num++, "NIG");
  3641. break;
  3642. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3643. if (print)
  3644. _print_next_block(par_num++,
  3645. "VAUX PCI CORE");
  3646. *global = true;
  3647. break;
  3648. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3649. if (print)
  3650. _print_next_block(par_num++, "DEBUG");
  3651. break;
  3652. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3653. if (print)
  3654. _print_next_block(par_num++, "USDM");
  3655. break;
  3656. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3657. if (print)
  3658. _print_next_block(par_num++, "UCM");
  3659. break;
  3660. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3661. if (print)
  3662. _print_next_block(par_num++, "USEMI");
  3663. break;
  3664. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3665. if (print)
  3666. _print_next_block(par_num++, "UPB");
  3667. break;
  3668. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3669. if (print)
  3670. _print_next_block(par_num++, "CSDM");
  3671. break;
  3672. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3673. if (print)
  3674. _print_next_block(par_num++, "CCM");
  3675. break;
  3676. }
  3677. /* Clear the bit */
  3678. sig &= ~cur_bit;
  3679. }
  3680. }
  3681. return par_num;
  3682. }
  3683. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3684. bool print)
  3685. {
  3686. int i = 0;
  3687. u32 cur_bit = 0;
  3688. for (i = 0; sig; i++) {
  3689. cur_bit = ((u32)0x1 << i);
  3690. if (sig & cur_bit) {
  3691. switch (cur_bit) {
  3692. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3693. if (print)
  3694. _print_next_block(par_num++, "CSEMI");
  3695. break;
  3696. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3697. if (print)
  3698. _print_next_block(par_num++, "PXP");
  3699. break;
  3700. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3701. if (print)
  3702. _print_next_block(par_num++,
  3703. "PXPPCICLOCKCLIENT");
  3704. break;
  3705. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3706. if (print)
  3707. _print_next_block(par_num++, "CFC");
  3708. break;
  3709. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3710. if (print)
  3711. _print_next_block(par_num++, "CDU");
  3712. break;
  3713. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3714. if (print)
  3715. _print_next_block(par_num++, "DMAE");
  3716. break;
  3717. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3718. if (print)
  3719. _print_next_block(par_num++, "IGU");
  3720. break;
  3721. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3722. if (print)
  3723. _print_next_block(par_num++, "MISC");
  3724. break;
  3725. }
  3726. /* Clear the bit */
  3727. sig &= ~cur_bit;
  3728. }
  3729. }
  3730. return par_num;
  3731. }
  3732. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3733. bool *global, bool print)
  3734. {
  3735. int i = 0;
  3736. u32 cur_bit = 0;
  3737. for (i = 0; sig; i++) {
  3738. cur_bit = ((u32)0x1 << i);
  3739. if (sig & cur_bit) {
  3740. switch (cur_bit) {
  3741. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3742. if (print)
  3743. _print_next_block(par_num++, "MCP ROM");
  3744. *global = true;
  3745. break;
  3746. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3747. if (print)
  3748. _print_next_block(par_num++,
  3749. "MCP UMP RX");
  3750. *global = true;
  3751. break;
  3752. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3753. if (print)
  3754. _print_next_block(par_num++,
  3755. "MCP UMP TX");
  3756. *global = true;
  3757. break;
  3758. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3759. if (print)
  3760. _print_next_block(par_num++,
  3761. "MCP SCPAD");
  3762. *global = true;
  3763. break;
  3764. }
  3765. /* Clear the bit */
  3766. sig &= ~cur_bit;
  3767. }
  3768. }
  3769. return par_num;
  3770. }
  3771. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3772. bool print)
  3773. {
  3774. int i = 0;
  3775. u32 cur_bit = 0;
  3776. for (i = 0; sig; i++) {
  3777. cur_bit = ((u32)0x1 << i);
  3778. if (sig & cur_bit) {
  3779. switch (cur_bit) {
  3780. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3781. if (print)
  3782. _print_next_block(par_num++, "PGLUE_B");
  3783. break;
  3784. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3785. if (print)
  3786. _print_next_block(par_num++, "ATC");
  3787. break;
  3788. }
  3789. /* Clear the bit */
  3790. sig &= ~cur_bit;
  3791. }
  3792. }
  3793. return par_num;
  3794. }
  3795. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3796. u32 *sig)
  3797. {
  3798. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3799. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3800. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3801. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3802. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3803. int par_num = 0;
  3804. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3805. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3806. sig[0] & HW_PRTY_ASSERT_SET_0,
  3807. sig[1] & HW_PRTY_ASSERT_SET_1,
  3808. sig[2] & HW_PRTY_ASSERT_SET_2,
  3809. sig[3] & HW_PRTY_ASSERT_SET_3,
  3810. sig[4] & HW_PRTY_ASSERT_SET_4);
  3811. if (print)
  3812. netdev_err(bp->dev,
  3813. "Parity errors detected in blocks: ");
  3814. par_num = bnx2x_check_blocks_with_parity0(
  3815. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3816. par_num = bnx2x_check_blocks_with_parity1(
  3817. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3818. par_num = bnx2x_check_blocks_with_parity2(
  3819. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3820. par_num = bnx2x_check_blocks_with_parity3(
  3821. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3822. par_num = bnx2x_check_blocks_with_parity4(
  3823. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3824. if (print)
  3825. pr_cont("\n");
  3826. return true;
  3827. } else
  3828. return false;
  3829. }
  3830. /**
  3831. * bnx2x_chk_parity_attn - checks for parity attentions.
  3832. *
  3833. * @bp: driver handle
  3834. * @global: true if there was a global attention
  3835. * @print: show parity attention in syslog
  3836. */
  3837. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3838. {
  3839. struct attn_route attn = { {0} };
  3840. int port = BP_PORT(bp);
  3841. attn.sig[0] = REG_RD(bp,
  3842. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3843. port*4);
  3844. attn.sig[1] = REG_RD(bp,
  3845. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3846. port*4);
  3847. attn.sig[2] = REG_RD(bp,
  3848. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3849. port*4);
  3850. attn.sig[3] = REG_RD(bp,
  3851. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3852. port*4);
  3853. if (!CHIP_IS_E1x(bp))
  3854. attn.sig[4] = REG_RD(bp,
  3855. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3856. port*4);
  3857. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3858. }
  3859. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3860. {
  3861. u32 val;
  3862. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3863. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3864. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3865. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3866. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3867. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3868. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3869. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3870. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3871. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3872. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3873. if (val &
  3874. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3875. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3876. if (val &
  3877. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3878. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3879. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3880. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3881. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3882. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3883. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3884. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3885. }
  3886. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3887. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3888. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3889. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3890. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3891. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3892. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3893. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3894. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3895. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3896. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3897. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3898. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3899. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3900. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3901. }
  3902. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3903. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3904. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3905. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3906. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3907. }
  3908. }
  3909. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3910. {
  3911. struct attn_route attn, *group_mask;
  3912. int port = BP_PORT(bp);
  3913. int index;
  3914. u32 reg_addr;
  3915. u32 val;
  3916. u32 aeu_mask;
  3917. bool global = false;
  3918. /* need to take HW lock because MCP or other port might also
  3919. try to handle this event */
  3920. bnx2x_acquire_alr(bp);
  3921. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3922. #ifndef BNX2X_STOP_ON_ERROR
  3923. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3924. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3925. /* Disable HW interrupts */
  3926. bnx2x_int_disable(bp);
  3927. /* In case of parity errors don't handle attentions so that
  3928. * other function would "see" parity errors.
  3929. */
  3930. #else
  3931. bnx2x_panic();
  3932. #endif
  3933. bnx2x_release_alr(bp);
  3934. return;
  3935. }
  3936. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3937. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3938. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3939. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3940. if (!CHIP_IS_E1x(bp))
  3941. attn.sig[4] =
  3942. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3943. else
  3944. attn.sig[4] = 0;
  3945. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3946. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3947. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3948. if (deasserted & (1 << index)) {
  3949. group_mask = &bp->attn_group[index];
  3950. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3951. index,
  3952. group_mask->sig[0], group_mask->sig[1],
  3953. group_mask->sig[2], group_mask->sig[3],
  3954. group_mask->sig[4]);
  3955. bnx2x_attn_int_deasserted4(bp,
  3956. attn.sig[4] & group_mask->sig[4]);
  3957. bnx2x_attn_int_deasserted3(bp,
  3958. attn.sig[3] & group_mask->sig[3]);
  3959. bnx2x_attn_int_deasserted1(bp,
  3960. attn.sig[1] & group_mask->sig[1]);
  3961. bnx2x_attn_int_deasserted2(bp,
  3962. attn.sig[2] & group_mask->sig[2]);
  3963. bnx2x_attn_int_deasserted0(bp,
  3964. attn.sig[0] & group_mask->sig[0]);
  3965. }
  3966. }
  3967. bnx2x_release_alr(bp);
  3968. if (bp->common.int_block == INT_BLOCK_HC)
  3969. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3970. COMMAND_REG_ATTN_BITS_CLR);
  3971. else
  3972. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3973. val = ~deasserted;
  3974. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3975. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3976. REG_WR(bp, reg_addr, val);
  3977. if (~bp->attn_state & deasserted)
  3978. BNX2X_ERR("IGU ERROR\n");
  3979. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3980. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3981. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3982. aeu_mask = REG_RD(bp, reg_addr);
  3983. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3984. aeu_mask, deasserted);
  3985. aeu_mask |= (deasserted & 0x3ff);
  3986. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3987. REG_WR(bp, reg_addr, aeu_mask);
  3988. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3989. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3990. bp->attn_state &= ~deasserted;
  3991. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3992. }
  3993. static void bnx2x_attn_int(struct bnx2x *bp)
  3994. {
  3995. /* read local copy of bits */
  3996. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3997. attn_bits);
  3998. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3999. attn_bits_ack);
  4000. u32 attn_state = bp->attn_state;
  4001. /* look for changed bits */
  4002. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4003. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4004. DP(NETIF_MSG_HW,
  4005. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4006. attn_bits, attn_ack, asserted, deasserted);
  4007. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4008. BNX2X_ERR("BAD attention state\n");
  4009. /* handle bits that were raised */
  4010. if (asserted)
  4011. bnx2x_attn_int_asserted(bp, asserted);
  4012. if (deasserted)
  4013. bnx2x_attn_int_deasserted(bp, deasserted);
  4014. }
  4015. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4016. u16 index, u8 op, u8 update)
  4017. {
  4018. u32 igu_addr = bp->igu_base_addr;
  4019. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4020. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4021. igu_addr);
  4022. }
  4023. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4024. {
  4025. /* No memory barriers */
  4026. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4027. mmiowb(); /* keep prod updates ordered */
  4028. }
  4029. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4030. union event_ring_elem *elem)
  4031. {
  4032. u8 err = elem->message.error;
  4033. if (!bp->cnic_eth_dev.starting_cid ||
  4034. (cid < bp->cnic_eth_dev.starting_cid &&
  4035. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4036. return 1;
  4037. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4038. if (unlikely(err)) {
  4039. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4040. cid);
  4041. bnx2x_panic_dump(bp, false);
  4042. }
  4043. bnx2x_cnic_cfc_comp(bp, cid, err);
  4044. return 0;
  4045. }
  4046. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4047. {
  4048. struct bnx2x_mcast_ramrod_params rparam;
  4049. int rc;
  4050. memset(&rparam, 0, sizeof(rparam));
  4051. rparam.mcast_obj = &bp->mcast_obj;
  4052. netif_addr_lock_bh(bp->dev);
  4053. /* Clear pending state for the last command */
  4054. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4055. /* If there are pending mcast commands - send them */
  4056. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4057. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4058. if (rc < 0)
  4059. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4060. rc);
  4061. }
  4062. netif_addr_unlock_bh(bp->dev);
  4063. }
  4064. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4065. union event_ring_elem *elem)
  4066. {
  4067. unsigned long ramrod_flags = 0;
  4068. int rc = 0;
  4069. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4070. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4071. /* Always push next commands out, don't wait here */
  4072. __set_bit(RAMROD_CONT, &ramrod_flags);
  4073. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4074. >> BNX2X_SWCID_SHIFT) {
  4075. case BNX2X_FILTER_MAC_PENDING:
  4076. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4077. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4078. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4079. else
  4080. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4081. break;
  4082. case BNX2X_FILTER_MCAST_PENDING:
  4083. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4084. /* This is only relevant for 57710 where multicast MACs are
  4085. * configured as unicast MACs using the same ramrod.
  4086. */
  4087. bnx2x_handle_mcast_eqe(bp);
  4088. return;
  4089. default:
  4090. BNX2X_ERR("Unsupported classification command: %d\n",
  4091. elem->message.data.eth_event.echo);
  4092. return;
  4093. }
  4094. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4095. if (rc < 0)
  4096. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4097. else if (rc > 0)
  4098. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4099. }
  4100. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4101. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4102. {
  4103. netif_addr_lock_bh(bp->dev);
  4104. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4105. /* Send rx_mode command again if was requested */
  4106. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4107. bnx2x_set_storm_rx_mode(bp);
  4108. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4109. &bp->sp_state))
  4110. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4111. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4112. &bp->sp_state))
  4113. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4114. netif_addr_unlock_bh(bp->dev);
  4115. }
  4116. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4117. union event_ring_elem *elem)
  4118. {
  4119. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4120. DP(BNX2X_MSG_SP,
  4121. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4122. elem->message.data.vif_list_event.func_bit_map);
  4123. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4124. elem->message.data.vif_list_event.func_bit_map);
  4125. } else if (elem->message.data.vif_list_event.echo ==
  4126. VIF_LIST_RULE_SET) {
  4127. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4128. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4129. }
  4130. }
  4131. /* called with rtnl_lock */
  4132. static void bnx2x_after_function_update(struct bnx2x *bp)
  4133. {
  4134. int q, rc;
  4135. struct bnx2x_fastpath *fp;
  4136. struct bnx2x_queue_state_params queue_params = {NULL};
  4137. struct bnx2x_queue_update_params *q_update_params =
  4138. &queue_params.params.update;
  4139. /* Send Q update command with afex vlan removal values for all Qs */
  4140. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4141. /* set silent vlan removal values according to vlan mode */
  4142. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4143. &q_update_params->update_flags);
  4144. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4145. &q_update_params->update_flags);
  4146. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4147. /* in access mode mark mask and value are 0 to strip all vlans */
  4148. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4149. q_update_params->silent_removal_value = 0;
  4150. q_update_params->silent_removal_mask = 0;
  4151. } else {
  4152. q_update_params->silent_removal_value =
  4153. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4154. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4155. }
  4156. for_each_eth_queue(bp, q) {
  4157. /* Set the appropriate Queue object */
  4158. fp = &bp->fp[q];
  4159. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4160. /* send the ramrod */
  4161. rc = bnx2x_queue_state_change(bp, &queue_params);
  4162. if (rc < 0)
  4163. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4164. q);
  4165. }
  4166. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4167. fp = &bp->fp[FCOE_IDX(bp)];
  4168. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4169. /* clear pending completion bit */
  4170. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4171. /* mark latest Q bit */
  4172. smp_mb__before_clear_bit();
  4173. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4174. smp_mb__after_clear_bit();
  4175. /* send Q update ramrod for FCoE Q */
  4176. rc = bnx2x_queue_state_change(bp, &queue_params);
  4177. if (rc < 0)
  4178. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4179. q);
  4180. } else {
  4181. /* If no FCoE ring - ACK MCP now */
  4182. bnx2x_link_report(bp);
  4183. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4184. }
  4185. }
  4186. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4187. struct bnx2x *bp, u32 cid)
  4188. {
  4189. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4190. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4191. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4192. else
  4193. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4194. }
  4195. static void bnx2x_eq_int(struct bnx2x *bp)
  4196. {
  4197. u16 hw_cons, sw_cons, sw_prod;
  4198. union event_ring_elem *elem;
  4199. u8 echo;
  4200. u32 cid;
  4201. u8 opcode;
  4202. int rc, spqe_cnt = 0;
  4203. struct bnx2x_queue_sp_obj *q_obj;
  4204. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4205. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4206. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4207. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4208. * when we get the next-page we need to adjust so the loop
  4209. * condition below will be met. The next element is the size of a
  4210. * regular element and hence incrementing by 1
  4211. */
  4212. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4213. hw_cons++;
  4214. /* This function may never run in parallel with itself for a
  4215. * specific bp, thus there is no need in "paired" read memory
  4216. * barrier here.
  4217. */
  4218. sw_cons = bp->eq_cons;
  4219. sw_prod = bp->eq_prod;
  4220. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4221. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4222. for (; sw_cons != hw_cons;
  4223. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4224. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4225. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4226. if (!rc) {
  4227. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4228. rc);
  4229. goto next_spqe;
  4230. }
  4231. /* elem CID originates from FW; actually LE */
  4232. cid = SW_CID((__force __le32)
  4233. elem->message.data.cfc_del_event.cid);
  4234. opcode = elem->message.opcode;
  4235. /* handle eq element */
  4236. switch (opcode) {
  4237. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4238. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4239. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4240. continue;
  4241. case EVENT_RING_OPCODE_STAT_QUERY:
  4242. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4243. "got statistics comp event %d\n",
  4244. bp->stats_comp++);
  4245. /* nothing to do with stats comp */
  4246. goto next_spqe;
  4247. case EVENT_RING_OPCODE_CFC_DEL:
  4248. /* handle according to cid range */
  4249. /*
  4250. * we may want to verify here that the bp state is
  4251. * HALTING
  4252. */
  4253. DP(BNX2X_MSG_SP,
  4254. "got delete ramrod for MULTI[%d]\n", cid);
  4255. if (CNIC_LOADED(bp) &&
  4256. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4257. goto next_spqe;
  4258. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4259. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4260. break;
  4261. goto next_spqe;
  4262. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4263. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4264. if (f_obj->complete_cmd(bp, f_obj,
  4265. BNX2X_F_CMD_TX_STOP))
  4266. break;
  4267. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4268. goto next_spqe;
  4269. case EVENT_RING_OPCODE_START_TRAFFIC:
  4270. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4271. if (f_obj->complete_cmd(bp, f_obj,
  4272. BNX2X_F_CMD_TX_START))
  4273. break;
  4274. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4275. goto next_spqe;
  4276. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4277. echo = elem->message.data.function_update_event.echo;
  4278. if (echo == SWITCH_UPDATE) {
  4279. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4280. "got FUNC_SWITCH_UPDATE ramrod\n");
  4281. if (f_obj->complete_cmd(
  4282. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4283. break;
  4284. } else {
  4285. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4286. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4287. f_obj->complete_cmd(bp, f_obj,
  4288. BNX2X_F_CMD_AFEX_UPDATE);
  4289. /* We will perform the Queues update from
  4290. * sp_rtnl task as all Queue SP operations
  4291. * should run under rtnl_lock.
  4292. */
  4293. smp_mb__before_clear_bit();
  4294. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4295. &bp->sp_rtnl_state);
  4296. smp_mb__after_clear_bit();
  4297. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4298. }
  4299. goto next_spqe;
  4300. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4301. f_obj->complete_cmd(bp, f_obj,
  4302. BNX2X_F_CMD_AFEX_VIFLISTS);
  4303. bnx2x_after_afex_vif_lists(bp, elem);
  4304. goto next_spqe;
  4305. case EVENT_RING_OPCODE_FUNCTION_START:
  4306. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4307. "got FUNC_START ramrod\n");
  4308. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4309. break;
  4310. goto next_spqe;
  4311. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4312. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4313. "got FUNC_STOP ramrod\n");
  4314. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4315. break;
  4316. goto next_spqe;
  4317. }
  4318. switch (opcode | bp->state) {
  4319. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4320. BNX2X_STATE_OPEN):
  4321. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4322. BNX2X_STATE_OPENING_WAIT4_PORT):
  4323. cid = elem->message.data.eth_event.echo &
  4324. BNX2X_SWCID_MASK;
  4325. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4326. cid);
  4327. rss_raw->clear_pending(rss_raw);
  4328. break;
  4329. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4330. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4331. case (EVENT_RING_OPCODE_SET_MAC |
  4332. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4333. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4334. BNX2X_STATE_OPEN):
  4335. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4336. BNX2X_STATE_DIAG):
  4337. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4338. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4339. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4340. bnx2x_handle_classification_eqe(bp, elem);
  4341. break;
  4342. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4343. BNX2X_STATE_OPEN):
  4344. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4345. BNX2X_STATE_DIAG):
  4346. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4347. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4348. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4349. bnx2x_handle_mcast_eqe(bp);
  4350. break;
  4351. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4352. BNX2X_STATE_OPEN):
  4353. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4354. BNX2X_STATE_DIAG):
  4355. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4356. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4357. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4358. bnx2x_handle_rx_mode_eqe(bp);
  4359. break;
  4360. default:
  4361. /* unknown event log error and continue */
  4362. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4363. elem->message.opcode, bp->state);
  4364. }
  4365. next_spqe:
  4366. spqe_cnt++;
  4367. } /* for */
  4368. smp_mb__before_atomic_inc();
  4369. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4370. bp->eq_cons = sw_cons;
  4371. bp->eq_prod = sw_prod;
  4372. /* Make sure that above mem writes were issued towards the memory */
  4373. smp_wmb();
  4374. /* update producer */
  4375. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4376. }
  4377. static void bnx2x_sp_task(struct work_struct *work)
  4378. {
  4379. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4380. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4381. /* make sure the atomic interrupt_occurred has been written */
  4382. smp_rmb();
  4383. if (atomic_read(&bp->interrupt_occurred)) {
  4384. /* what work needs to be performed? */
  4385. u16 status = bnx2x_update_dsb_idx(bp);
  4386. DP(BNX2X_MSG_SP, "status %x\n", status);
  4387. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4388. atomic_set(&bp->interrupt_occurred, 0);
  4389. /* HW attentions */
  4390. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4391. bnx2x_attn_int(bp);
  4392. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4393. }
  4394. /* SP events: STAT_QUERY and others */
  4395. if (status & BNX2X_DEF_SB_IDX) {
  4396. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4397. if (FCOE_INIT(bp) &&
  4398. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4399. /* Prevent local bottom-halves from running as
  4400. * we are going to change the local NAPI list.
  4401. */
  4402. local_bh_disable();
  4403. napi_schedule(&bnx2x_fcoe(bp, napi));
  4404. local_bh_enable();
  4405. }
  4406. /* Handle EQ completions */
  4407. bnx2x_eq_int(bp);
  4408. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4409. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4410. status &= ~BNX2X_DEF_SB_IDX;
  4411. }
  4412. /* if status is non zero then perhaps something went wrong */
  4413. if (unlikely(status))
  4414. DP(BNX2X_MSG_SP,
  4415. "got an unknown interrupt! (status 0x%x)\n", status);
  4416. /* ack status block only if something was actually handled */
  4417. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4418. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4419. }
  4420. /* must be called after the EQ processing (since eq leads to sriov
  4421. * ramrod completion flows).
  4422. * This flow may have been scheduled by the arrival of a ramrod
  4423. * completion, or by the sriov code rescheduling itself.
  4424. */
  4425. bnx2x_iov_sp_task(bp);
  4426. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4427. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4428. &bp->sp_state)) {
  4429. bnx2x_link_report(bp);
  4430. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4431. }
  4432. }
  4433. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4434. {
  4435. struct net_device *dev = dev_instance;
  4436. struct bnx2x *bp = netdev_priv(dev);
  4437. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4438. IGU_INT_DISABLE, 0);
  4439. #ifdef BNX2X_STOP_ON_ERROR
  4440. if (unlikely(bp->panic))
  4441. return IRQ_HANDLED;
  4442. #endif
  4443. if (CNIC_LOADED(bp)) {
  4444. struct cnic_ops *c_ops;
  4445. rcu_read_lock();
  4446. c_ops = rcu_dereference(bp->cnic_ops);
  4447. if (c_ops)
  4448. c_ops->cnic_handler(bp->cnic_data, NULL);
  4449. rcu_read_unlock();
  4450. }
  4451. /* schedule sp task to perform default status block work, ack
  4452. * attentions and enable interrupts.
  4453. */
  4454. bnx2x_schedule_sp_task(bp);
  4455. return IRQ_HANDLED;
  4456. }
  4457. /* end of slow path */
  4458. void bnx2x_drv_pulse(struct bnx2x *bp)
  4459. {
  4460. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4461. bp->fw_drv_pulse_wr_seq);
  4462. }
  4463. static void bnx2x_timer(unsigned long data)
  4464. {
  4465. struct bnx2x *bp = (struct bnx2x *) data;
  4466. if (!netif_running(bp->dev))
  4467. return;
  4468. if (IS_PF(bp) &&
  4469. !BP_NOMCP(bp)) {
  4470. int mb_idx = BP_FW_MB_IDX(bp);
  4471. u32 drv_pulse;
  4472. u32 mcp_pulse;
  4473. ++bp->fw_drv_pulse_wr_seq;
  4474. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4475. /* TBD - add SYSTEM_TIME */
  4476. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4477. bnx2x_drv_pulse(bp);
  4478. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4479. MCP_PULSE_SEQ_MASK);
  4480. /* The delta between driver pulse and mcp response
  4481. * should be 1 (before mcp response) or 0 (after mcp response)
  4482. */
  4483. if ((drv_pulse != mcp_pulse) &&
  4484. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4485. /* someone lost a heartbeat... */
  4486. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4487. drv_pulse, mcp_pulse);
  4488. }
  4489. }
  4490. if (bp->state == BNX2X_STATE_OPEN)
  4491. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4492. /* sample pf vf bulletin board for new posts from pf */
  4493. if (IS_VF(bp))
  4494. bnx2x_sample_bulletin(bp);
  4495. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4496. }
  4497. /* end of Statistics */
  4498. /* nic init */
  4499. /*
  4500. * nic init service functions
  4501. */
  4502. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4503. {
  4504. u32 i;
  4505. if (!(len%4) && !(addr%4))
  4506. for (i = 0; i < len; i += 4)
  4507. REG_WR(bp, addr + i, fill);
  4508. else
  4509. for (i = 0; i < len; i++)
  4510. REG_WR8(bp, addr + i, fill);
  4511. }
  4512. /* helper: writes FP SP data to FW - data_size in dwords */
  4513. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4514. int fw_sb_id,
  4515. u32 *sb_data_p,
  4516. u32 data_size)
  4517. {
  4518. int index;
  4519. for (index = 0; index < data_size; index++)
  4520. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4521. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4522. sizeof(u32)*index,
  4523. *(sb_data_p + index));
  4524. }
  4525. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4526. {
  4527. u32 *sb_data_p;
  4528. u32 data_size = 0;
  4529. struct hc_status_block_data_e2 sb_data_e2;
  4530. struct hc_status_block_data_e1x sb_data_e1x;
  4531. /* disable the function first */
  4532. if (!CHIP_IS_E1x(bp)) {
  4533. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4534. sb_data_e2.common.state = SB_DISABLED;
  4535. sb_data_e2.common.p_func.vf_valid = false;
  4536. sb_data_p = (u32 *)&sb_data_e2;
  4537. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4538. } else {
  4539. memset(&sb_data_e1x, 0,
  4540. sizeof(struct hc_status_block_data_e1x));
  4541. sb_data_e1x.common.state = SB_DISABLED;
  4542. sb_data_e1x.common.p_func.vf_valid = false;
  4543. sb_data_p = (u32 *)&sb_data_e1x;
  4544. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4545. }
  4546. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4547. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4548. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4549. CSTORM_STATUS_BLOCK_SIZE);
  4550. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4551. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4552. CSTORM_SYNC_BLOCK_SIZE);
  4553. }
  4554. /* helper: writes SP SB data to FW */
  4555. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4556. struct hc_sp_status_block_data *sp_sb_data)
  4557. {
  4558. int func = BP_FUNC(bp);
  4559. int i;
  4560. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4561. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4562. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4563. i*sizeof(u32),
  4564. *((u32 *)sp_sb_data + i));
  4565. }
  4566. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4567. {
  4568. int func = BP_FUNC(bp);
  4569. struct hc_sp_status_block_data sp_sb_data;
  4570. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4571. sp_sb_data.state = SB_DISABLED;
  4572. sp_sb_data.p_func.vf_valid = false;
  4573. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4574. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4575. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4576. CSTORM_SP_STATUS_BLOCK_SIZE);
  4577. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4578. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4579. CSTORM_SP_SYNC_BLOCK_SIZE);
  4580. }
  4581. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4582. int igu_sb_id, int igu_seg_id)
  4583. {
  4584. hc_sm->igu_sb_id = igu_sb_id;
  4585. hc_sm->igu_seg_id = igu_seg_id;
  4586. hc_sm->timer_value = 0xFF;
  4587. hc_sm->time_to_expire = 0xFFFFFFFF;
  4588. }
  4589. /* allocates state machine ids. */
  4590. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4591. {
  4592. /* zero out state machine indices */
  4593. /* rx indices */
  4594. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4595. /* tx indices */
  4596. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4597. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4598. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4599. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4600. /* map indices */
  4601. /* rx indices */
  4602. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4603. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4604. /* tx indices */
  4605. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4606. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4607. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4608. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4609. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4610. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4611. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4612. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4613. }
  4614. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4615. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4616. {
  4617. int igu_seg_id;
  4618. struct hc_status_block_data_e2 sb_data_e2;
  4619. struct hc_status_block_data_e1x sb_data_e1x;
  4620. struct hc_status_block_sm *hc_sm_p;
  4621. int data_size;
  4622. u32 *sb_data_p;
  4623. if (CHIP_INT_MODE_IS_BC(bp))
  4624. igu_seg_id = HC_SEG_ACCESS_NORM;
  4625. else
  4626. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4627. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4628. if (!CHIP_IS_E1x(bp)) {
  4629. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4630. sb_data_e2.common.state = SB_ENABLED;
  4631. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4632. sb_data_e2.common.p_func.vf_id = vfid;
  4633. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4634. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4635. sb_data_e2.common.same_igu_sb_1b = true;
  4636. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4637. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4638. hc_sm_p = sb_data_e2.common.state_machine;
  4639. sb_data_p = (u32 *)&sb_data_e2;
  4640. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4641. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4642. } else {
  4643. memset(&sb_data_e1x, 0,
  4644. sizeof(struct hc_status_block_data_e1x));
  4645. sb_data_e1x.common.state = SB_ENABLED;
  4646. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4647. sb_data_e1x.common.p_func.vf_id = 0xff;
  4648. sb_data_e1x.common.p_func.vf_valid = false;
  4649. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4650. sb_data_e1x.common.same_igu_sb_1b = true;
  4651. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4652. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4653. hc_sm_p = sb_data_e1x.common.state_machine;
  4654. sb_data_p = (u32 *)&sb_data_e1x;
  4655. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4656. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4657. }
  4658. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4659. igu_sb_id, igu_seg_id);
  4660. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4661. igu_sb_id, igu_seg_id);
  4662. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4663. /* write indices to HW - PCI guarantees endianity of regpairs */
  4664. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4665. }
  4666. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4667. u16 tx_usec, u16 rx_usec)
  4668. {
  4669. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4670. false, rx_usec);
  4671. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4672. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4673. tx_usec);
  4674. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4675. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4676. tx_usec);
  4677. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4678. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4679. tx_usec);
  4680. }
  4681. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4682. {
  4683. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4684. dma_addr_t mapping = bp->def_status_blk_mapping;
  4685. int igu_sp_sb_index;
  4686. int igu_seg_id;
  4687. int port = BP_PORT(bp);
  4688. int func = BP_FUNC(bp);
  4689. int reg_offset, reg_offset_en5;
  4690. u64 section;
  4691. int index;
  4692. struct hc_sp_status_block_data sp_sb_data;
  4693. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4694. if (CHIP_INT_MODE_IS_BC(bp)) {
  4695. igu_sp_sb_index = DEF_SB_IGU_ID;
  4696. igu_seg_id = HC_SEG_ACCESS_DEF;
  4697. } else {
  4698. igu_sp_sb_index = bp->igu_dsb_id;
  4699. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4700. }
  4701. /* ATTN */
  4702. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4703. atten_status_block);
  4704. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4705. bp->attn_state = 0;
  4706. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4707. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4708. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4709. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4710. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4711. int sindex;
  4712. /* take care of sig[0]..sig[4] */
  4713. for (sindex = 0; sindex < 4; sindex++)
  4714. bp->attn_group[index].sig[sindex] =
  4715. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4716. if (!CHIP_IS_E1x(bp))
  4717. /*
  4718. * enable5 is separate from the rest of the registers,
  4719. * and therefore the address skip is 4
  4720. * and not 16 between the different groups
  4721. */
  4722. bp->attn_group[index].sig[4] = REG_RD(bp,
  4723. reg_offset_en5 + 0x4*index);
  4724. else
  4725. bp->attn_group[index].sig[4] = 0;
  4726. }
  4727. if (bp->common.int_block == INT_BLOCK_HC) {
  4728. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4729. HC_REG_ATTN_MSG0_ADDR_L);
  4730. REG_WR(bp, reg_offset, U64_LO(section));
  4731. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4732. } else if (!CHIP_IS_E1x(bp)) {
  4733. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4734. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4735. }
  4736. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4737. sp_sb);
  4738. bnx2x_zero_sp_sb(bp);
  4739. /* PCI guarantees endianity of regpairs */
  4740. sp_sb_data.state = SB_ENABLED;
  4741. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4742. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4743. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4744. sp_sb_data.igu_seg_id = igu_seg_id;
  4745. sp_sb_data.p_func.pf_id = func;
  4746. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4747. sp_sb_data.p_func.vf_id = 0xff;
  4748. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4749. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4750. }
  4751. void bnx2x_update_coalesce(struct bnx2x *bp)
  4752. {
  4753. int i;
  4754. for_each_eth_queue(bp, i)
  4755. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4756. bp->tx_ticks, bp->rx_ticks);
  4757. }
  4758. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4759. {
  4760. spin_lock_init(&bp->spq_lock);
  4761. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4762. bp->spq_prod_idx = 0;
  4763. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4764. bp->spq_prod_bd = bp->spq;
  4765. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4766. }
  4767. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4768. {
  4769. int i;
  4770. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4771. union event_ring_elem *elem =
  4772. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4773. elem->next_page.addr.hi =
  4774. cpu_to_le32(U64_HI(bp->eq_mapping +
  4775. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4776. elem->next_page.addr.lo =
  4777. cpu_to_le32(U64_LO(bp->eq_mapping +
  4778. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4779. }
  4780. bp->eq_cons = 0;
  4781. bp->eq_prod = NUM_EQ_DESC;
  4782. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4783. /* we want a warning message before it gets wrought... */
  4784. atomic_set(&bp->eq_spq_left,
  4785. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4786. }
  4787. /* called with netif_addr_lock_bh() */
  4788. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4789. unsigned long rx_mode_flags,
  4790. unsigned long rx_accept_flags,
  4791. unsigned long tx_accept_flags,
  4792. unsigned long ramrod_flags)
  4793. {
  4794. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4795. int rc;
  4796. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4797. /* Prepare ramrod parameters */
  4798. ramrod_param.cid = 0;
  4799. ramrod_param.cl_id = cl_id;
  4800. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4801. ramrod_param.func_id = BP_FUNC(bp);
  4802. ramrod_param.pstate = &bp->sp_state;
  4803. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4804. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4805. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4806. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4807. ramrod_param.ramrod_flags = ramrod_flags;
  4808. ramrod_param.rx_mode_flags = rx_mode_flags;
  4809. ramrod_param.rx_accept_flags = rx_accept_flags;
  4810. ramrod_param.tx_accept_flags = tx_accept_flags;
  4811. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4812. if (rc < 0) {
  4813. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4814. return rc;
  4815. }
  4816. return 0;
  4817. }
  4818. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4819. unsigned long *rx_accept_flags,
  4820. unsigned long *tx_accept_flags)
  4821. {
  4822. /* Clear the flags first */
  4823. *rx_accept_flags = 0;
  4824. *tx_accept_flags = 0;
  4825. switch (rx_mode) {
  4826. case BNX2X_RX_MODE_NONE:
  4827. /*
  4828. * 'drop all' supersedes any accept flags that may have been
  4829. * passed to the function.
  4830. */
  4831. break;
  4832. case BNX2X_RX_MODE_NORMAL:
  4833. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4834. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4835. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4836. /* internal switching mode */
  4837. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4838. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4839. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4840. break;
  4841. case BNX2X_RX_MODE_ALLMULTI:
  4842. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4843. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4844. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4845. /* internal switching mode */
  4846. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4847. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4848. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4849. break;
  4850. case BNX2X_RX_MODE_PROMISC:
  4851. /* According to definition of SI mode, iface in promisc mode
  4852. * should receive matched and unmatched (in resolution of port)
  4853. * unicast packets.
  4854. */
  4855. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  4856. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4857. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4858. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4859. /* internal switching mode */
  4860. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4861. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4862. if (IS_MF_SI(bp))
  4863. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  4864. else
  4865. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4866. break;
  4867. default:
  4868. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  4869. return -EINVAL;
  4870. }
  4871. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  4872. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4873. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  4874. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  4875. }
  4876. return 0;
  4877. }
  4878. /* called with netif_addr_lock_bh() */
  4879. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4880. {
  4881. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4882. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4883. int rc;
  4884. if (!NO_FCOE(bp))
  4885. /* Configure rx_mode of FCoE Queue */
  4886. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4887. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  4888. &tx_accept_flags);
  4889. if (rc)
  4890. return rc;
  4891. __set_bit(RAMROD_RX, &ramrod_flags);
  4892. __set_bit(RAMROD_TX, &ramrod_flags);
  4893. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  4894. rx_accept_flags, tx_accept_flags,
  4895. ramrod_flags);
  4896. }
  4897. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4898. {
  4899. int i;
  4900. if (IS_MF_SI(bp))
  4901. /*
  4902. * In switch independent mode, the TSTORM needs to accept
  4903. * packets that failed classification, since approximate match
  4904. * mac addresses aren't written to NIG LLH
  4905. */
  4906. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4907. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4908. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4909. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4910. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4911. /* Zero this manually as its initialization is
  4912. currently missing in the initTool */
  4913. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4914. REG_WR(bp, BAR_USTRORM_INTMEM +
  4915. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4916. if (!CHIP_IS_E1x(bp)) {
  4917. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4918. CHIP_INT_MODE_IS_BC(bp) ?
  4919. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4920. }
  4921. }
  4922. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4923. {
  4924. switch (load_code) {
  4925. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4926. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4927. bnx2x_init_internal_common(bp);
  4928. /* no break */
  4929. case FW_MSG_CODE_DRV_LOAD_PORT:
  4930. /* nothing to do */
  4931. /* no break */
  4932. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4933. /* internal memory per function is
  4934. initialized inside bnx2x_pf_init */
  4935. break;
  4936. default:
  4937. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4938. break;
  4939. }
  4940. }
  4941. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4942. {
  4943. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4944. }
  4945. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4946. {
  4947. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4948. }
  4949. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4950. {
  4951. if (CHIP_IS_E1x(fp->bp))
  4952. return BP_L_ID(fp->bp) + fp->index;
  4953. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4954. return bnx2x_fp_igu_sb_id(fp);
  4955. }
  4956. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4957. {
  4958. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4959. u8 cos;
  4960. unsigned long q_type = 0;
  4961. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4962. fp->rx_queue = fp_idx;
  4963. fp->cid = fp_idx;
  4964. fp->cl_id = bnx2x_fp_cl_id(fp);
  4965. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4966. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4967. /* qZone id equals to FW (per path) client id */
  4968. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4969. /* init shortcut */
  4970. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4971. /* Setup SB indices */
  4972. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4973. /* Configure Queue State object */
  4974. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4975. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4976. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4977. /* init tx data */
  4978. for_each_cos_in_tx_queue(fp, cos) {
  4979. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4980. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4981. FP_COS_TO_TXQ(fp, cos, bp),
  4982. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4983. cids[cos] = fp->txdata_ptr[cos]->cid;
  4984. }
  4985. /* nothing more for vf to do here */
  4986. if (IS_VF(bp))
  4987. return;
  4988. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4989. fp->fw_sb_id, fp->igu_sb_id);
  4990. bnx2x_update_fpsb_idx(fp);
  4991. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4992. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4993. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4994. /**
  4995. * Configure classification DBs: Always enable Tx switching
  4996. */
  4997. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4998. DP(NETIF_MSG_IFUP,
  4999. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5000. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5001. fp->igu_sb_id);
  5002. }
  5003. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5004. {
  5005. int i;
  5006. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5007. struct eth_tx_next_bd *tx_next_bd =
  5008. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5009. tx_next_bd->addr_hi =
  5010. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5011. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5012. tx_next_bd->addr_lo =
  5013. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5014. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5015. }
  5016. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5017. txdata->tx_db.data.zero_fill1 = 0;
  5018. txdata->tx_db.data.prod = 0;
  5019. txdata->tx_pkt_prod = 0;
  5020. txdata->tx_pkt_cons = 0;
  5021. txdata->tx_bd_prod = 0;
  5022. txdata->tx_bd_cons = 0;
  5023. txdata->tx_pkt = 0;
  5024. }
  5025. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5026. {
  5027. int i;
  5028. for_each_tx_queue_cnic(bp, i)
  5029. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5030. }
  5031. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5032. {
  5033. int i;
  5034. u8 cos;
  5035. for_each_eth_queue(bp, i)
  5036. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5037. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5038. }
  5039. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5040. {
  5041. if (!NO_FCOE(bp))
  5042. bnx2x_init_fcoe_fp(bp);
  5043. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5044. BNX2X_VF_ID_INVALID, false,
  5045. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5046. /* ensure status block indices were read */
  5047. rmb();
  5048. bnx2x_init_rx_rings_cnic(bp);
  5049. bnx2x_init_tx_rings_cnic(bp);
  5050. /* flush all */
  5051. mb();
  5052. mmiowb();
  5053. }
  5054. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5055. {
  5056. int i;
  5057. /* Setup NIC internals and enable interrupts */
  5058. for_each_eth_queue(bp, i)
  5059. bnx2x_init_eth_fp(bp, i);
  5060. /* ensure status block indices were read */
  5061. rmb();
  5062. bnx2x_init_rx_rings(bp);
  5063. bnx2x_init_tx_rings(bp);
  5064. if (IS_PF(bp)) {
  5065. /* Initialize MOD_ABS interrupts */
  5066. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5067. bp->common.shmem_base,
  5068. bp->common.shmem2_base, BP_PORT(bp));
  5069. /* initialize the default status block and sp ring */
  5070. bnx2x_init_def_sb(bp);
  5071. bnx2x_update_dsb_idx(bp);
  5072. bnx2x_init_sp_ring(bp);
  5073. } else {
  5074. bnx2x_memset_stats(bp);
  5075. }
  5076. }
  5077. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5078. {
  5079. bnx2x_init_eq_ring(bp);
  5080. bnx2x_init_internal(bp, load_code);
  5081. bnx2x_pf_init(bp);
  5082. bnx2x_stats_init(bp);
  5083. /* flush all before enabling interrupts */
  5084. mb();
  5085. mmiowb();
  5086. bnx2x_int_enable(bp);
  5087. /* Check for SPIO5 */
  5088. bnx2x_attn_int_deasserted0(bp,
  5089. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5090. AEU_INPUTS_ATTN_BITS_SPIO5);
  5091. }
  5092. /* gzip service functions */
  5093. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5094. {
  5095. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5096. &bp->gunzip_mapping, GFP_KERNEL);
  5097. if (bp->gunzip_buf == NULL)
  5098. goto gunzip_nomem1;
  5099. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5100. if (bp->strm == NULL)
  5101. goto gunzip_nomem2;
  5102. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5103. if (bp->strm->workspace == NULL)
  5104. goto gunzip_nomem3;
  5105. return 0;
  5106. gunzip_nomem3:
  5107. kfree(bp->strm);
  5108. bp->strm = NULL;
  5109. gunzip_nomem2:
  5110. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5111. bp->gunzip_mapping);
  5112. bp->gunzip_buf = NULL;
  5113. gunzip_nomem1:
  5114. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5115. return -ENOMEM;
  5116. }
  5117. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5118. {
  5119. if (bp->strm) {
  5120. vfree(bp->strm->workspace);
  5121. kfree(bp->strm);
  5122. bp->strm = NULL;
  5123. }
  5124. if (bp->gunzip_buf) {
  5125. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5126. bp->gunzip_mapping);
  5127. bp->gunzip_buf = NULL;
  5128. }
  5129. }
  5130. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5131. {
  5132. int n, rc;
  5133. /* check gzip header */
  5134. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5135. BNX2X_ERR("Bad gzip header\n");
  5136. return -EINVAL;
  5137. }
  5138. n = 10;
  5139. #define FNAME 0x8
  5140. if (zbuf[3] & FNAME)
  5141. while ((zbuf[n++] != 0) && (n < len));
  5142. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5143. bp->strm->avail_in = len - n;
  5144. bp->strm->next_out = bp->gunzip_buf;
  5145. bp->strm->avail_out = FW_BUF_SIZE;
  5146. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5147. if (rc != Z_OK)
  5148. return rc;
  5149. rc = zlib_inflate(bp->strm, Z_FINISH);
  5150. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5151. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5152. bp->strm->msg);
  5153. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5154. if (bp->gunzip_outlen & 0x3)
  5155. netdev_err(bp->dev,
  5156. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5157. bp->gunzip_outlen);
  5158. bp->gunzip_outlen >>= 2;
  5159. zlib_inflateEnd(bp->strm);
  5160. if (rc == Z_STREAM_END)
  5161. return 0;
  5162. return rc;
  5163. }
  5164. /* nic load/unload */
  5165. /*
  5166. * General service functions
  5167. */
  5168. /* send a NIG loopback debug packet */
  5169. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5170. {
  5171. u32 wb_write[3];
  5172. /* Ethernet source and destination addresses */
  5173. wb_write[0] = 0x55555555;
  5174. wb_write[1] = 0x55555555;
  5175. wb_write[2] = 0x20; /* SOP */
  5176. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5177. /* NON-IP protocol */
  5178. wb_write[0] = 0x09000000;
  5179. wb_write[1] = 0x55555555;
  5180. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5181. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5182. }
  5183. /* some of the internal memories
  5184. * are not directly readable from the driver
  5185. * to test them we send debug packets
  5186. */
  5187. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5188. {
  5189. int factor;
  5190. int count, i;
  5191. u32 val = 0;
  5192. if (CHIP_REV_IS_FPGA(bp))
  5193. factor = 120;
  5194. else if (CHIP_REV_IS_EMUL(bp))
  5195. factor = 200;
  5196. else
  5197. factor = 1;
  5198. /* Disable inputs of parser neighbor blocks */
  5199. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5200. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5201. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5202. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5203. /* Write 0 to parser credits for CFC search request */
  5204. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5205. /* send Ethernet packet */
  5206. bnx2x_lb_pckt(bp);
  5207. /* TODO do i reset NIG statistic? */
  5208. /* Wait until NIG register shows 1 packet of size 0x10 */
  5209. count = 1000 * factor;
  5210. while (count) {
  5211. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5212. val = *bnx2x_sp(bp, wb_data[0]);
  5213. if (val == 0x10)
  5214. break;
  5215. msleep(10);
  5216. count--;
  5217. }
  5218. if (val != 0x10) {
  5219. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5220. return -1;
  5221. }
  5222. /* Wait until PRS register shows 1 packet */
  5223. count = 1000 * factor;
  5224. while (count) {
  5225. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5226. if (val == 1)
  5227. break;
  5228. msleep(10);
  5229. count--;
  5230. }
  5231. if (val != 0x1) {
  5232. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5233. return -2;
  5234. }
  5235. /* Reset and init BRB, PRS */
  5236. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5237. msleep(50);
  5238. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5239. msleep(50);
  5240. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5241. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5242. DP(NETIF_MSG_HW, "part2\n");
  5243. /* Disable inputs of parser neighbor blocks */
  5244. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5245. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5246. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5247. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5248. /* Write 0 to parser credits for CFC search request */
  5249. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5250. /* send 10 Ethernet packets */
  5251. for (i = 0; i < 10; i++)
  5252. bnx2x_lb_pckt(bp);
  5253. /* Wait until NIG register shows 10 + 1
  5254. packets of size 11*0x10 = 0xb0 */
  5255. count = 1000 * factor;
  5256. while (count) {
  5257. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5258. val = *bnx2x_sp(bp, wb_data[0]);
  5259. if (val == 0xb0)
  5260. break;
  5261. msleep(10);
  5262. count--;
  5263. }
  5264. if (val != 0xb0) {
  5265. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5266. return -3;
  5267. }
  5268. /* Wait until PRS register shows 2 packets */
  5269. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5270. if (val != 2)
  5271. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5272. /* Write 1 to parser credits for CFC search request */
  5273. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5274. /* Wait until PRS register shows 3 packets */
  5275. msleep(10 * factor);
  5276. /* Wait until NIG register shows 1 packet of size 0x10 */
  5277. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5278. if (val != 3)
  5279. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5280. /* clear NIG EOP FIFO */
  5281. for (i = 0; i < 11; i++)
  5282. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5283. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5284. if (val != 1) {
  5285. BNX2X_ERR("clear of NIG failed\n");
  5286. return -4;
  5287. }
  5288. /* Reset and init BRB, PRS, NIG */
  5289. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5290. msleep(50);
  5291. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5292. msleep(50);
  5293. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5294. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5295. if (!CNIC_SUPPORT(bp))
  5296. /* set NIC mode */
  5297. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5298. /* Enable inputs of parser neighbor blocks */
  5299. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5300. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5301. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5302. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5303. DP(NETIF_MSG_HW, "done\n");
  5304. return 0; /* OK */
  5305. }
  5306. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5307. {
  5308. u32 val;
  5309. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5310. if (!CHIP_IS_E1x(bp))
  5311. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5312. else
  5313. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5314. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5315. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5316. /*
  5317. * mask read length error interrupts in brb for parser
  5318. * (parsing unit and 'checksum and crc' unit)
  5319. * these errors are legal (PU reads fixed length and CAC can cause
  5320. * read length error on truncated packets)
  5321. */
  5322. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5323. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5324. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5325. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5326. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5327. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5328. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5329. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5330. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5331. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5332. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5333. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5334. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5335. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5336. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5337. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5338. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5339. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5340. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5341. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5342. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5343. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5344. if (!CHIP_IS_E1x(bp))
  5345. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5346. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5347. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5348. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5349. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5350. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5351. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5352. if (!CHIP_IS_E1x(bp))
  5353. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5354. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5355. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5356. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5357. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5358. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5359. }
  5360. static void bnx2x_reset_common(struct bnx2x *bp)
  5361. {
  5362. u32 val = 0x1400;
  5363. /* reset_common */
  5364. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5365. 0xd3ffff7f);
  5366. if (CHIP_IS_E3(bp)) {
  5367. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5368. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5369. }
  5370. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5371. }
  5372. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5373. {
  5374. bp->dmae_ready = 0;
  5375. spin_lock_init(&bp->dmae_lock);
  5376. }
  5377. static void bnx2x_init_pxp(struct bnx2x *bp)
  5378. {
  5379. u16 devctl;
  5380. int r_order, w_order;
  5381. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5382. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5383. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5384. if (bp->mrrs == -1)
  5385. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5386. else {
  5387. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5388. r_order = bp->mrrs;
  5389. }
  5390. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5391. }
  5392. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5393. {
  5394. int is_required;
  5395. u32 val;
  5396. int port;
  5397. if (BP_NOMCP(bp))
  5398. return;
  5399. is_required = 0;
  5400. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5401. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5402. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5403. is_required = 1;
  5404. /*
  5405. * The fan failure mechanism is usually related to the PHY type since
  5406. * the power consumption of the board is affected by the PHY. Currently,
  5407. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5408. */
  5409. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5410. for (port = PORT_0; port < PORT_MAX; port++) {
  5411. is_required |=
  5412. bnx2x_fan_failure_det_req(
  5413. bp,
  5414. bp->common.shmem_base,
  5415. bp->common.shmem2_base,
  5416. port);
  5417. }
  5418. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5419. if (is_required == 0)
  5420. return;
  5421. /* Fan failure is indicated by SPIO 5 */
  5422. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5423. /* set to active low mode */
  5424. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5425. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5426. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5427. /* enable interrupt to signal the IGU */
  5428. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5429. val |= MISC_SPIO_SPIO5;
  5430. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5431. }
  5432. void bnx2x_pf_disable(struct bnx2x *bp)
  5433. {
  5434. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5435. val &= ~IGU_PF_CONF_FUNC_EN;
  5436. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5437. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5438. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5439. }
  5440. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5441. {
  5442. u32 shmem_base[2], shmem2_base[2];
  5443. /* Avoid common init in case MFW supports LFA */
  5444. if (SHMEM2_RD(bp, size) >
  5445. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5446. return;
  5447. shmem_base[0] = bp->common.shmem_base;
  5448. shmem2_base[0] = bp->common.shmem2_base;
  5449. if (!CHIP_IS_E1x(bp)) {
  5450. shmem_base[1] =
  5451. SHMEM2_RD(bp, other_shmem_base_addr);
  5452. shmem2_base[1] =
  5453. SHMEM2_RD(bp, other_shmem2_base_addr);
  5454. }
  5455. bnx2x_acquire_phy_lock(bp);
  5456. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5457. bp->common.chip_id);
  5458. bnx2x_release_phy_lock(bp);
  5459. }
  5460. /**
  5461. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5462. *
  5463. * @bp: driver handle
  5464. */
  5465. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5466. {
  5467. u32 val;
  5468. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5469. /*
  5470. * take the RESET lock to protect undi_unload flow from accessing
  5471. * registers while we're resetting the chip
  5472. */
  5473. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5474. bnx2x_reset_common(bp);
  5475. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5476. val = 0xfffc;
  5477. if (CHIP_IS_E3(bp)) {
  5478. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5479. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5480. }
  5481. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5482. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5483. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5484. if (!CHIP_IS_E1x(bp)) {
  5485. u8 abs_func_id;
  5486. /**
  5487. * 4-port mode or 2-port mode we need to turn of master-enable
  5488. * for everyone, after that, turn it back on for self.
  5489. * so, we disregard multi-function or not, and always disable
  5490. * for all functions on the given path, this means 0,2,4,6 for
  5491. * path 0 and 1,3,5,7 for path 1
  5492. */
  5493. for (abs_func_id = BP_PATH(bp);
  5494. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5495. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5496. REG_WR(bp,
  5497. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5498. 1);
  5499. continue;
  5500. }
  5501. bnx2x_pretend_func(bp, abs_func_id);
  5502. /* clear pf enable */
  5503. bnx2x_pf_disable(bp);
  5504. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5505. }
  5506. }
  5507. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5508. if (CHIP_IS_E1(bp)) {
  5509. /* enable HW interrupt from PXP on USDM overflow
  5510. bit 16 on INT_MASK_0 */
  5511. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5512. }
  5513. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5514. bnx2x_init_pxp(bp);
  5515. #ifdef __BIG_ENDIAN
  5516. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5517. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5518. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5519. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5520. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5521. /* make sure this value is 0 */
  5522. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5523. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5524. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5525. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5526. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5527. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5528. #endif
  5529. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5530. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5531. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5532. /* let the HW do it's magic ... */
  5533. msleep(100);
  5534. /* finish PXP init */
  5535. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5536. if (val != 1) {
  5537. BNX2X_ERR("PXP2 CFG failed\n");
  5538. return -EBUSY;
  5539. }
  5540. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5541. if (val != 1) {
  5542. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5543. return -EBUSY;
  5544. }
  5545. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5546. * have entries with value "0" and valid bit on.
  5547. * This needs to be done by the first PF that is loaded in a path
  5548. * (i.e. common phase)
  5549. */
  5550. if (!CHIP_IS_E1x(bp)) {
  5551. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5552. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5553. * This occurs when a different function (func2,3) is being marked
  5554. * as "scan-off". Real-life scenario for example: if a driver is being
  5555. * load-unloaded while func6,7 are down. This will cause the timer to access
  5556. * the ilt, translate to a logical address and send a request to read/write.
  5557. * Since the ilt for the function that is down is not valid, this will cause
  5558. * a translation error which is unrecoverable.
  5559. * The Workaround is intended to make sure that when this happens nothing fatal
  5560. * will occur. The workaround:
  5561. * 1. First PF driver which loads on a path will:
  5562. * a. After taking the chip out of reset, by using pretend,
  5563. * it will write "0" to the following registers of
  5564. * the other vnics.
  5565. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5566. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5567. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5568. * And for itself it will write '1' to
  5569. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5570. * dmae-operations (writing to pram for example.)
  5571. * note: can be done for only function 6,7 but cleaner this
  5572. * way.
  5573. * b. Write zero+valid to the entire ILT.
  5574. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5575. * VNIC3 (of that port). The range allocated will be the
  5576. * entire ILT. This is needed to prevent ILT range error.
  5577. * 2. Any PF driver load flow:
  5578. * a. ILT update with the physical addresses of the allocated
  5579. * logical pages.
  5580. * b. Wait 20msec. - note that this timeout is needed to make
  5581. * sure there are no requests in one of the PXP internal
  5582. * queues with "old" ILT addresses.
  5583. * c. PF enable in the PGLC.
  5584. * d. Clear the was_error of the PF in the PGLC. (could have
  5585. * occurred while driver was down)
  5586. * e. PF enable in the CFC (WEAK + STRONG)
  5587. * f. Timers scan enable
  5588. * 3. PF driver unload flow:
  5589. * a. Clear the Timers scan_en.
  5590. * b. Polling for scan_on=0 for that PF.
  5591. * c. Clear the PF enable bit in the PXP.
  5592. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5593. * e. Write zero+valid to all ILT entries (The valid bit must
  5594. * stay set)
  5595. * f. If this is VNIC 3 of a port then also init
  5596. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5597. * to the last entry in the ILT.
  5598. *
  5599. * Notes:
  5600. * Currently the PF error in the PGLC is non recoverable.
  5601. * In the future the there will be a recovery routine for this error.
  5602. * Currently attention is masked.
  5603. * Having an MCP lock on the load/unload process does not guarantee that
  5604. * there is no Timer disable during Func6/7 enable. This is because the
  5605. * Timers scan is currently being cleared by the MCP on FLR.
  5606. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5607. * there is error before clearing it. But the flow above is simpler and
  5608. * more general.
  5609. * All ILT entries are written by zero+valid and not just PF6/7
  5610. * ILT entries since in the future the ILT entries allocation for
  5611. * PF-s might be dynamic.
  5612. */
  5613. struct ilt_client_info ilt_cli;
  5614. struct bnx2x_ilt ilt;
  5615. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5616. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5617. /* initialize dummy TM client */
  5618. ilt_cli.start = 0;
  5619. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5620. ilt_cli.client_num = ILT_CLIENT_TM;
  5621. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5622. * Step 2: set the timers first/last ilt entry to point
  5623. * to the entire range to prevent ILT range error for 3rd/4th
  5624. * vnic (this code assumes existence of the vnic)
  5625. *
  5626. * both steps performed by call to bnx2x_ilt_client_init_op()
  5627. * with dummy TM client
  5628. *
  5629. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5630. * and his brother are split registers
  5631. */
  5632. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5633. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5634. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5635. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5636. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5637. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5638. }
  5639. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5640. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5641. if (!CHIP_IS_E1x(bp)) {
  5642. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5643. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5644. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5645. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5646. /* let the HW do it's magic ... */
  5647. do {
  5648. msleep(200);
  5649. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5650. } while (factor-- && (val != 1));
  5651. if (val != 1) {
  5652. BNX2X_ERR("ATC_INIT failed\n");
  5653. return -EBUSY;
  5654. }
  5655. }
  5656. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5657. bnx2x_iov_init_dmae(bp);
  5658. /* clean the DMAE memory */
  5659. bp->dmae_ready = 1;
  5660. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5661. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5662. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5663. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5664. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5665. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5666. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5667. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5668. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5669. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5670. /* QM queues pointers table */
  5671. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5672. /* soft reset pulse */
  5673. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5674. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5675. if (CNIC_SUPPORT(bp))
  5676. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5677. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5678. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5679. if (!CHIP_REV_IS_SLOW(bp))
  5680. /* enable hw interrupt from doorbell Q */
  5681. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5682. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5683. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5684. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5685. if (!CHIP_IS_E1(bp))
  5686. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5687. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5688. if (IS_MF_AFEX(bp)) {
  5689. /* configure that VNTag and VLAN headers must be
  5690. * received in afex mode
  5691. */
  5692. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5693. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5694. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5695. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5696. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5697. } else {
  5698. /* Bit-map indicating which L2 hdrs may appear
  5699. * after the basic Ethernet header
  5700. */
  5701. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5702. bp->path_has_ovlan ? 7 : 6);
  5703. }
  5704. }
  5705. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5706. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5707. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5708. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5709. if (!CHIP_IS_E1x(bp)) {
  5710. /* reset VFC memories */
  5711. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5712. VFC_MEMORIES_RST_REG_CAM_RST |
  5713. VFC_MEMORIES_RST_REG_RAM_RST);
  5714. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5715. VFC_MEMORIES_RST_REG_CAM_RST |
  5716. VFC_MEMORIES_RST_REG_RAM_RST);
  5717. msleep(20);
  5718. }
  5719. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5720. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5721. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5722. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5723. /* sync semi rtc */
  5724. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5725. 0x80000000);
  5726. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5727. 0x80000000);
  5728. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5729. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5730. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5731. if (!CHIP_IS_E1x(bp)) {
  5732. if (IS_MF_AFEX(bp)) {
  5733. /* configure that VNTag and VLAN headers must be
  5734. * sent in afex mode
  5735. */
  5736. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5737. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5738. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5739. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5740. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5741. } else {
  5742. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5743. bp->path_has_ovlan ? 7 : 6);
  5744. }
  5745. }
  5746. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5747. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5748. if (CNIC_SUPPORT(bp)) {
  5749. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5750. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5751. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5752. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5753. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5754. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5755. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5756. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5757. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5758. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5759. }
  5760. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5761. if (sizeof(union cdu_context) != 1024)
  5762. /* we currently assume that a context is 1024 bytes */
  5763. dev_alert(&bp->pdev->dev,
  5764. "please adjust the size of cdu_context(%ld)\n",
  5765. (long)sizeof(union cdu_context));
  5766. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5767. val = (4 << 24) + (0 << 12) + 1024;
  5768. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5769. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5770. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5771. /* enable context validation interrupt from CFC */
  5772. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5773. /* set the thresholds to prevent CFC/CDU race */
  5774. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5775. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5776. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5777. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5778. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5779. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5780. /* Reset PCIE errors for debug */
  5781. REG_WR(bp, 0x2814, 0xffffffff);
  5782. REG_WR(bp, 0x3820, 0xffffffff);
  5783. if (!CHIP_IS_E1x(bp)) {
  5784. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5785. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5786. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5787. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5788. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5789. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5790. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5791. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5792. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5793. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5794. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5795. }
  5796. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5797. if (!CHIP_IS_E1(bp)) {
  5798. /* in E3 this done in per-port section */
  5799. if (!CHIP_IS_E3(bp))
  5800. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5801. }
  5802. if (CHIP_IS_E1H(bp))
  5803. /* not applicable for E2 (and above ...) */
  5804. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5805. if (CHIP_REV_IS_SLOW(bp))
  5806. msleep(200);
  5807. /* finish CFC init */
  5808. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5809. if (val != 1) {
  5810. BNX2X_ERR("CFC LL_INIT failed\n");
  5811. return -EBUSY;
  5812. }
  5813. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5814. if (val != 1) {
  5815. BNX2X_ERR("CFC AC_INIT failed\n");
  5816. return -EBUSY;
  5817. }
  5818. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5819. if (val != 1) {
  5820. BNX2X_ERR("CFC CAM_INIT failed\n");
  5821. return -EBUSY;
  5822. }
  5823. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5824. if (CHIP_IS_E1(bp)) {
  5825. /* read NIG statistic
  5826. to see if this is our first up since powerup */
  5827. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5828. val = *bnx2x_sp(bp, wb_data[0]);
  5829. /* do internal memory self test */
  5830. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5831. BNX2X_ERR("internal mem self test failed\n");
  5832. return -EBUSY;
  5833. }
  5834. }
  5835. bnx2x_setup_fan_failure_detection(bp);
  5836. /* clear PXP2 attentions */
  5837. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5838. bnx2x_enable_blocks_attention(bp);
  5839. bnx2x_enable_blocks_parity(bp);
  5840. if (!BP_NOMCP(bp)) {
  5841. if (CHIP_IS_E1x(bp))
  5842. bnx2x__common_init_phy(bp);
  5843. } else
  5844. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5845. return 0;
  5846. }
  5847. /**
  5848. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5849. *
  5850. * @bp: driver handle
  5851. */
  5852. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5853. {
  5854. int rc = bnx2x_init_hw_common(bp);
  5855. if (rc)
  5856. return rc;
  5857. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5858. if (!BP_NOMCP(bp))
  5859. bnx2x__common_init_phy(bp);
  5860. return 0;
  5861. }
  5862. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5863. {
  5864. int port = BP_PORT(bp);
  5865. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5866. u32 low, high;
  5867. u32 val;
  5868. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5869. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5870. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5871. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5872. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5873. /* Timers bug workaround: disables the pf_master bit in pglue at
  5874. * common phase, we need to enable it here before any dmae access are
  5875. * attempted. Therefore we manually added the enable-master to the
  5876. * port phase (it also happens in the function phase)
  5877. */
  5878. if (!CHIP_IS_E1x(bp))
  5879. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5880. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5881. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5882. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5883. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5884. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5885. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5886. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5887. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5888. /* QM cid (connection) count */
  5889. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5890. if (CNIC_SUPPORT(bp)) {
  5891. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5892. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5893. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5894. }
  5895. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5896. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5897. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5898. if (IS_MF(bp))
  5899. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5900. else if (bp->dev->mtu > 4096) {
  5901. if (bp->flags & ONE_PORT_FLAG)
  5902. low = 160;
  5903. else {
  5904. val = bp->dev->mtu;
  5905. /* (24*1024 + val*4)/256 */
  5906. low = 96 + (val/64) +
  5907. ((val % 64) ? 1 : 0);
  5908. }
  5909. } else
  5910. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5911. high = low + 56; /* 14*1024/256 */
  5912. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5913. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5914. }
  5915. if (CHIP_MODE_IS_4_PORT(bp))
  5916. REG_WR(bp, (BP_PORT(bp) ?
  5917. BRB1_REG_MAC_GUARANTIED_1 :
  5918. BRB1_REG_MAC_GUARANTIED_0), 40);
  5919. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5920. if (CHIP_IS_E3B0(bp)) {
  5921. if (IS_MF_AFEX(bp)) {
  5922. /* configure headers for AFEX mode */
  5923. REG_WR(bp, BP_PORT(bp) ?
  5924. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5925. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5926. REG_WR(bp, BP_PORT(bp) ?
  5927. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5928. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5929. REG_WR(bp, BP_PORT(bp) ?
  5930. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5931. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5932. } else {
  5933. /* Ovlan exists only if we are in multi-function +
  5934. * switch-dependent mode, in switch-independent there
  5935. * is no ovlan headers
  5936. */
  5937. REG_WR(bp, BP_PORT(bp) ?
  5938. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5939. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5940. (bp->path_has_ovlan ? 7 : 6));
  5941. }
  5942. }
  5943. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5944. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5945. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5946. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5947. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5948. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5949. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5950. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5951. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5952. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5953. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5954. if (CHIP_IS_E1x(bp)) {
  5955. /* configure PBF to work without PAUSE mtu 9000 */
  5956. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5957. /* update threshold */
  5958. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5959. /* update init credit */
  5960. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5961. /* probe changes */
  5962. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5963. udelay(50);
  5964. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5965. }
  5966. if (CNIC_SUPPORT(bp))
  5967. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5968. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5969. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5970. if (CHIP_IS_E1(bp)) {
  5971. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5972. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5973. }
  5974. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5975. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5976. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5977. /* init aeu_mask_attn_func_0/1:
  5978. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  5979. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  5980. * bits 4-7 are used for "per vn group attention" */
  5981. val = IS_MF(bp) ? 0xF7 : 0x7;
  5982. /* Enable DCBX attention for all but E1 */
  5983. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5984. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5985. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5986. if (!CHIP_IS_E1x(bp)) {
  5987. /* Bit-map indicating which L2 hdrs may appear after the
  5988. * basic Ethernet header
  5989. */
  5990. if (IS_MF_AFEX(bp))
  5991. REG_WR(bp, BP_PORT(bp) ?
  5992. NIG_REG_P1_HDRS_AFTER_BASIC :
  5993. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5994. else
  5995. REG_WR(bp, BP_PORT(bp) ?
  5996. NIG_REG_P1_HDRS_AFTER_BASIC :
  5997. NIG_REG_P0_HDRS_AFTER_BASIC,
  5998. IS_MF_SD(bp) ? 7 : 6);
  5999. if (CHIP_IS_E3(bp))
  6000. REG_WR(bp, BP_PORT(bp) ?
  6001. NIG_REG_LLH1_MF_MODE :
  6002. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6003. }
  6004. if (!CHIP_IS_E3(bp))
  6005. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6006. if (!CHIP_IS_E1(bp)) {
  6007. /* 0x2 disable mf_ov, 0x1 enable */
  6008. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6009. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6010. if (!CHIP_IS_E1x(bp)) {
  6011. val = 0;
  6012. switch (bp->mf_mode) {
  6013. case MULTI_FUNCTION_SD:
  6014. val = 1;
  6015. break;
  6016. case MULTI_FUNCTION_SI:
  6017. case MULTI_FUNCTION_AFEX:
  6018. val = 2;
  6019. break;
  6020. }
  6021. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6022. NIG_REG_LLH0_CLS_TYPE), val);
  6023. }
  6024. {
  6025. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6026. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6027. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6028. }
  6029. }
  6030. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6031. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6032. if (val & MISC_SPIO_SPIO5) {
  6033. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6034. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6035. val = REG_RD(bp, reg_addr);
  6036. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6037. REG_WR(bp, reg_addr, val);
  6038. }
  6039. return 0;
  6040. }
  6041. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6042. {
  6043. int reg;
  6044. u32 wb_write[2];
  6045. if (CHIP_IS_E1(bp))
  6046. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6047. else
  6048. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6049. wb_write[0] = ONCHIP_ADDR1(addr);
  6050. wb_write[1] = ONCHIP_ADDR2(addr);
  6051. REG_WR_DMAE(bp, reg, wb_write, 2);
  6052. }
  6053. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6054. {
  6055. u32 data, ctl, cnt = 100;
  6056. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6057. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6058. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6059. u32 sb_bit = 1 << (idu_sb_id%32);
  6060. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6061. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6062. /* Not supported in BC mode */
  6063. if (CHIP_INT_MODE_IS_BC(bp))
  6064. return;
  6065. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6066. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6067. IGU_REGULAR_CLEANUP_SET |
  6068. IGU_REGULAR_BCLEANUP;
  6069. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6070. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6071. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6072. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6073. data, igu_addr_data);
  6074. REG_WR(bp, igu_addr_data, data);
  6075. mmiowb();
  6076. barrier();
  6077. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6078. ctl, igu_addr_ctl);
  6079. REG_WR(bp, igu_addr_ctl, ctl);
  6080. mmiowb();
  6081. barrier();
  6082. /* wait for clean up to finish */
  6083. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6084. msleep(20);
  6085. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6086. DP(NETIF_MSG_HW,
  6087. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6088. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6089. }
  6090. }
  6091. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6092. {
  6093. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6094. }
  6095. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6096. {
  6097. u32 i, base = FUNC_ILT_BASE(func);
  6098. for (i = base; i < base + ILT_PER_FUNC; i++)
  6099. bnx2x_ilt_wr(bp, i, 0);
  6100. }
  6101. static void bnx2x_init_searcher(struct bnx2x *bp)
  6102. {
  6103. int port = BP_PORT(bp);
  6104. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6105. /* T1 hash bits value determines the T1 number of entries */
  6106. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6107. }
  6108. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6109. {
  6110. int rc;
  6111. struct bnx2x_func_state_params func_params = {NULL};
  6112. struct bnx2x_func_switch_update_params *switch_update_params =
  6113. &func_params.params.switch_update;
  6114. /* Prepare parameters for function state transitions */
  6115. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6116. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6117. func_params.f_obj = &bp->func_obj;
  6118. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6119. /* Function parameters */
  6120. switch_update_params->suspend = suspend;
  6121. rc = bnx2x_func_state_change(bp, &func_params);
  6122. return rc;
  6123. }
  6124. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6125. {
  6126. int rc, i, port = BP_PORT(bp);
  6127. int vlan_en = 0, mac_en[NUM_MACS];
  6128. /* Close input from network */
  6129. if (bp->mf_mode == SINGLE_FUNCTION) {
  6130. bnx2x_set_rx_filter(&bp->link_params, 0);
  6131. } else {
  6132. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6133. NIG_REG_LLH0_FUNC_EN);
  6134. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6135. NIG_REG_LLH0_FUNC_EN, 0);
  6136. for (i = 0; i < NUM_MACS; i++) {
  6137. mac_en[i] = REG_RD(bp, port ?
  6138. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6139. 4 * i) :
  6140. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6141. 4 * i));
  6142. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6143. 4 * i) :
  6144. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6145. }
  6146. }
  6147. /* Close BMC to host */
  6148. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6149. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6150. /* Suspend Tx switching to the PF. Completion of this ramrod
  6151. * further guarantees that all the packets of that PF / child
  6152. * VFs in BRB were processed by the Parser, so it is safe to
  6153. * change the NIC_MODE register.
  6154. */
  6155. rc = bnx2x_func_switch_update(bp, 1);
  6156. if (rc) {
  6157. BNX2X_ERR("Can't suspend tx-switching!\n");
  6158. return rc;
  6159. }
  6160. /* Change NIC_MODE register */
  6161. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6162. /* Open input from network */
  6163. if (bp->mf_mode == SINGLE_FUNCTION) {
  6164. bnx2x_set_rx_filter(&bp->link_params, 1);
  6165. } else {
  6166. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6167. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6168. for (i = 0; i < NUM_MACS; i++) {
  6169. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6170. 4 * i) :
  6171. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6172. mac_en[i]);
  6173. }
  6174. }
  6175. /* Enable BMC to host */
  6176. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6177. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6178. /* Resume Tx switching to the PF */
  6179. rc = bnx2x_func_switch_update(bp, 0);
  6180. if (rc) {
  6181. BNX2X_ERR("Can't resume tx-switching!\n");
  6182. return rc;
  6183. }
  6184. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6185. return 0;
  6186. }
  6187. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6188. {
  6189. int rc;
  6190. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6191. if (CONFIGURE_NIC_MODE(bp)) {
  6192. /* Configure searcher as part of function hw init */
  6193. bnx2x_init_searcher(bp);
  6194. /* Reset NIC mode */
  6195. rc = bnx2x_reset_nic_mode(bp);
  6196. if (rc)
  6197. BNX2X_ERR("Can't change NIC mode!\n");
  6198. return rc;
  6199. }
  6200. return 0;
  6201. }
  6202. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6203. {
  6204. int port = BP_PORT(bp);
  6205. int func = BP_FUNC(bp);
  6206. int init_phase = PHASE_PF0 + func;
  6207. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6208. u16 cdu_ilt_start;
  6209. u32 addr, val;
  6210. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6211. int i, main_mem_width, rc;
  6212. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6213. /* FLR cleanup - hmmm */
  6214. if (!CHIP_IS_E1x(bp)) {
  6215. rc = bnx2x_pf_flr_clnup(bp);
  6216. if (rc) {
  6217. bnx2x_fw_dump(bp);
  6218. return rc;
  6219. }
  6220. }
  6221. /* set MSI reconfigure capability */
  6222. if (bp->common.int_block == INT_BLOCK_HC) {
  6223. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6224. val = REG_RD(bp, addr);
  6225. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6226. REG_WR(bp, addr, val);
  6227. }
  6228. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6229. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6230. ilt = BP_ILT(bp);
  6231. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6232. if (IS_SRIOV(bp))
  6233. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6234. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6235. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6236. * those of the VFs, so start line should be reset
  6237. */
  6238. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6239. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6240. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6241. ilt->lines[cdu_ilt_start + i].page_mapping =
  6242. bp->context[i].cxt_mapping;
  6243. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6244. }
  6245. bnx2x_ilt_init_op(bp, INITOP_SET);
  6246. if (!CONFIGURE_NIC_MODE(bp)) {
  6247. bnx2x_init_searcher(bp);
  6248. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6249. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6250. } else {
  6251. /* Set NIC mode */
  6252. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6253. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6254. }
  6255. if (!CHIP_IS_E1x(bp)) {
  6256. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6257. /* Turn on a single ISR mode in IGU if driver is going to use
  6258. * INT#x or MSI
  6259. */
  6260. if (!(bp->flags & USING_MSIX_FLAG))
  6261. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6262. /*
  6263. * Timers workaround bug: function init part.
  6264. * Need to wait 20msec after initializing ILT,
  6265. * needed to make sure there are no requests in
  6266. * one of the PXP internal queues with "old" ILT addresses
  6267. */
  6268. msleep(20);
  6269. /*
  6270. * Master enable - Due to WB DMAE writes performed before this
  6271. * register is re-initialized as part of the regular function
  6272. * init
  6273. */
  6274. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6275. /* Enable the function in IGU */
  6276. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6277. }
  6278. bp->dmae_ready = 1;
  6279. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6280. if (!CHIP_IS_E1x(bp))
  6281. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6282. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6283. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6284. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6285. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6286. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6287. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6288. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6289. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6290. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6291. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6292. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6293. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6294. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6295. if (!CHIP_IS_E1x(bp))
  6296. REG_WR(bp, QM_REG_PF_EN, 1);
  6297. if (!CHIP_IS_E1x(bp)) {
  6298. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6299. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6300. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6301. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6302. }
  6303. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6304. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6305. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6306. bnx2x_iov_init_dq(bp);
  6307. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6308. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6309. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6310. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6311. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6312. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6313. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6314. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6315. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6316. if (!CHIP_IS_E1x(bp))
  6317. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6318. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6319. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6320. if (!CHIP_IS_E1x(bp))
  6321. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6322. if (IS_MF(bp)) {
  6323. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6324. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6325. }
  6326. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6327. /* HC init per function */
  6328. if (bp->common.int_block == INT_BLOCK_HC) {
  6329. if (CHIP_IS_E1H(bp)) {
  6330. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6331. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6332. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6333. }
  6334. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6335. } else {
  6336. int num_segs, sb_idx, prod_offset;
  6337. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6338. if (!CHIP_IS_E1x(bp)) {
  6339. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6340. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6341. }
  6342. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6343. if (!CHIP_IS_E1x(bp)) {
  6344. int dsb_idx = 0;
  6345. /**
  6346. * Producer memory:
  6347. * E2 mode: address 0-135 match to the mapping memory;
  6348. * 136 - PF0 default prod; 137 - PF1 default prod;
  6349. * 138 - PF2 default prod; 139 - PF3 default prod;
  6350. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6351. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6352. * 144-147 reserved.
  6353. *
  6354. * E1.5 mode - In backward compatible mode;
  6355. * for non default SB; each even line in the memory
  6356. * holds the U producer and each odd line hold
  6357. * the C producer. The first 128 producers are for
  6358. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6359. * producers are for the DSB for each PF.
  6360. * Each PF has five segments: (the order inside each
  6361. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6362. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6363. * 144-147 attn prods;
  6364. */
  6365. /* non-default-status-blocks */
  6366. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6367. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6368. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6369. prod_offset = (bp->igu_base_sb + sb_idx) *
  6370. num_segs;
  6371. for (i = 0; i < num_segs; i++) {
  6372. addr = IGU_REG_PROD_CONS_MEMORY +
  6373. (prod_offset + i) * 4;
  6374. REG_WR(bp, addr, 0);
  6375. }
  6376. /* send consumer update with value 0 */
  6377. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6378. USTORM_ID, 0, IGU_INT_NOP, 1);
  6379. bnx2x_igu_clear_sb(bp,
  6380. bp->igu_base_sb + sb_idx);
  6381. }
  6382. /* default-status-blocks */
  6383. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6384. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6385. if (CHIP_MODE_IS_4_PORT(bp))
  6386. dsb_idx = BP_FUNC(bp);
  6387. else
  6388. dsb_idx = BP_VN(bp);
  6389. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6390. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6391. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6392. /*
  6393. * igu prods come in chunks of E1HVN_MAX (4) -
  6394. * does not matters what is the current chip mode
  6395. */
  6396. for (i = 0; i < (num_segs * E1HVN_MAX);
  6397. i += E1HVN_MAX) {
  6398. addr = IGU_REG_PROD_CONS_MEMORY +
  6399. (prod_offset + i)*4;
  6400. REG_WR(bp, addr, 0);
  6401. }
  6402. /* send consumer update with 0 */
  6403. if (CHIP_INT_MODE_IS_BC(bp)) {
  6404. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6405. USTORM_ID, 0, IGU_INT_NOP, 1);
  6406. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6407. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6408. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6409. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6410. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6411. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6412. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6413. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6414. } else {
  6415. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6416. USTORM_ID, 0, IGU_INT_NOP, 1);
  6417. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6418. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6419. }
  6420. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6421. /* !!! These should become driver const once
  6422. rf-tool supports split-68 const */
  6423. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6424. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6425. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6426. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6427. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6428. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6429. }
  6430. }
  6431. /* Reset PCIE errors for debug */
  6432. REG_WR(bp, 0x2114, 0xffffffff);
  6433. REG_WR(bp, 0x2120, 0xffffffff);
  6434. if (CHIP_IS_E1x(bp)) {
  6435. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6436. main_mem_base = HC_REG_MAIN_MEMORY +
  6437. BP_PORT(bp) * (main_mem_size * 4);
  6438. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6439. main_mem_width = 8;
  6440. val = REG_RD(bp, main_mem_prty_clr);
  6441. if (val)
  6442. DP(NETIF_MSG_HW,
  6443. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6444. val);
  6445. /* Clear "false" parity errors in MSI-X table */
  6446. for (i = main_mem_base;
  6447. i < main_mem_base + main_mem_size * 4;
  6448. i += main_mem_width) {
  6449. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6450. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6451. i, main_mem_width / 4);
  6452. }
  6453. /* Clear HC parity attention */
  6454. REG_RD(bp, main_mem_prty_clr);
  6455. }
  6456. #ifdef BNX2X_STOP_ON_ERROR
  6457. /* Enable STORMs SP logging */
  6458. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6459. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6460. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6461. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6462. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6463. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6464. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6465. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6466. #endif
  6467. bnx2x_phy_probe(&bp->link_params);
  6468. return 0;
  6469. }
  6470. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6471. {
  6472. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6473. if (!CHIP_IS_E1x(bp))
  6474. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6475. sizeof(struct host_hc_status_block_e2));
  6476. else
  6477. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6478. sizeof(struct host_hc_status_block_e1x));
  6479. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6480. }
  6481. void bnx2x_free_mem(struct bnx2x *bp)
  6482. {
  6483. int i;
  6484. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6485. sizeof(struct host_sp_status_block));
  6486. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6487. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6488. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6489. sizeof(struct bnx2x_slowpath));
  6490. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6491. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6492. bp->context[i].size);
  6493. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6494. BNX2X_FREE(bp->ilt->lines);
  6495. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6496. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6497. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6498. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6499. bnx2x_iov_free_mem(bp);
  6500. }
  6501. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6502. {
  6503. if (!CHIP_IS_E1x(bp))
  6504. /* size = the status block + ramrod buffers */
  6505. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6506. sizeof(struct host_hc_status_block_e2));
  6507. else
  6508. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6509. &bp->cnic_sb_mapping,
  6510. sizeof(struct
  6511. host_hc_status_block_e1x));
  6512. if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6513. /* allocate searcher T2 table, as it wasn't allocated before */
  6514. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6515. /* write address to which L5 should insert its values */
  6516. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6517. &bp->slowpath->drv_info_to_mcp;
  6518. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6519. goto alloc_mem_err;
  6520. return 0;
  6521. alloc_mem_err:
  6522. bnx2x_free_mem_cnic(bp);
  6523. BNX2X_ERR("Can't allocate memory\n");
  6524. return -ENOMEM;
  6525. }
  6526. int bnx2x_alloc_mem(struct bnx2x *bp)
  6527. {
  6528. int i, allocated, context_size;
  6529. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6530. /* allocate searcher T2 table */
  6531. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6532. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6533. sizeof(struct host_sp_status_block));
  6534. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6535. sizeof(struct bnx2x_slowpath));
  6536. /* Allocate memory for CDU context:
  6537. * This memory is allocated separately and not in the generic ILT
  6538. * functions because CDU differs in few aspects:
  6539. * 1. There are multiple entities allocating memory for context -
  6540. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6541. * its own ILT lines.
  6542. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6543. * for the other ILT clients), to be efficient we want to support
  6544. * allocation of sub-page-size in the last entry.
  6545. * 3. Context pointers are used by the driver to pass to FW / update
  6546. * the context (for the other ILT clients the pointers are used just to
  6547. * free the memory during unload).
  6548. */
  6549. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6550. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6551. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6552. (context_size - allocated));
  6553. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6554. &bp->context[i].cxt_mapping,
  6555. bp->context[i].size);
  6556. allocated += bp->context[i].size;
  6557. }
  6558. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6559. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6560. goto alloc_mem_err;
  6561. if (bnx2x_iov_alloc_mem(bp))
  6562. goto alloc_mem_err;
  6563. /* Slow path ring */
  6564. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6565. /* EQ */
  6566. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6567. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6568. return 0;
  6569. alloc_mem_err:
  6570. bnx2x_free_mem(bp);
  6571. BNX2X_ERR("Can't allocate memory\n");
  6572. return -ENOMEM;
  6573. }
  6574. /*
  6575. * Init service functions
  6576. */
  6577. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6578. struct bnx2x_vlan_mac_obj *obj, bool set,
  6579. int mac_type, unsigned long *ramrod_flags)
  6580. {
  6581. int rc;
  6582. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6583. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6584. /* Fill general parameters */
  6585. ramrod_param.vlan_mac_obj = obj;
  6586. ramrod_param.ramrod_flags = *ramrod_flags;
  6587. /* Fill a user request section if needed */
  6588. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6589. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6590. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6591. /* Set the command: ADD or DEL */
  6592. if (set)
  6593. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6594. else
  6595. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6596. }
  6597. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6598. if (rc == -EEXIST) {
  6599. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6600. /* do not treat adding same MAC as error */
  6601. rc = 0;
  6602. } else if (rc < 0)
  6603. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6604. return rc;
  6605. }
  6606. int bnx2x_del_all_macs(struct bnx2x *bp,
  6607. struct bnx2x_vlan_mac_obj *mac_obj,
  6608. int mac_type, bool wait_for_comp)
  6609. {
  6610. int rc;
  6611. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6612. /* Wait for completion of requested */
  6613. if (wait_for_comp)
  6614. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6615. /* Set the mac type of addresses we want to clear */
  6616. __set_bit(mac_type, &vlan_mac_flags);
  6617. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6618. if (rc < 0)
  6619. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6620. return rc;
  6621. }
  6622. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6623. {
  6624. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6625. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6626. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6627. "Ignoring Zero MAC for STORAGE SD mode\n");
  6628. return 0;
  6629. }
  6630. if (IS_PF(bp)) {
  6631. unsigned long ramrod_flags = 0;
  6632. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6633. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6634. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6635. &bp->sp_objs->mac_obj, set,
  6636. BNX2X_ETH_MAC, &ramrod_flags);
  6637. } else { /* vf */
  6638. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6639. bp->fp->index, true);
  6640. }
  6641. }
  6642. int bnx2x_setup_leading(struct bnx2x *bp)
  6643. {
  6644. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6645. }
  6646. /**
  6647. * bnx2x_set_int_mode - configure interrupt mode
  6648. *
  6649. * @bp: driver handle
  6650. *
  6651. * In case of MSI-X it will also try to enable MSI-X.
  6652. */
  6653. int bnx2x_set_int_mode(struct bnx2x *bp)
  6654. {
  6655. int rc = 0;
  6656. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6657. return -EINVAL;
  6658. switch (int_mode) {
  6659. case BNX2X_INT_MODE_MSIX:
  6660. /* attempt to enable msix */
  6661. rc = bnx2x_enable_msix(bp);
  6662. /* msix attained */
  6663. if (!rc)
  6664. return 0;
  6665. /* vfs use only msix */
  6666. if (rc && IS_VF(bp))
  6667. return rc;
  6668. /* failed to enable multiple MSI-X */
  6669. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6670. bp->num_queues,
  6671. 1 + bp->num_cnic_queues);
  6672. /* falling through... */
  6673. case BNX2X_INT_MODE_MSI:
  6674. bnx2x_enable_msi(bp);
  6675. /* falling through... */
  6676. case BNX2X_INT_MODE_INTX:
  6677. bp->num_ethernet_queues = 1;
  6678. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6679. BNX2X_DEV_INFO("set number of queues to 1\n");
  6680. break;
  6681. default:
  6682. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6683. return -EINVAL;
  6684. }
  6685. return 0;
  6686. }
  6687. /* must be called prior to any HW initializations */
  6688. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6689. {
  6690. if (IS_SRIOV(bp))
  6691. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6692. return L2_ILT_LINES(bp);
  6693. }
  6694. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6695. {
  6696. struct ilt_client_info *ilt_client;
  6697. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6698. u16 line = 0;
  6699. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6700. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6701. /* CDU */
  6702. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6703. ilt_client->client_num = ILT_CLIENT_CDU;
  6704. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6705. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6706. ilt_client->start = line;
  6707. line += bnx2x_cid_ilt_lines(bp);
  6708. if (CNIC_SUPPORT(bp))
  6709. line += CNIC_ILT_LINES;
  6710. ilt_client->end = line - 1;
  6711. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6712. ilt_client->start,
  6713. ilt_client->end,
  6714. ilt_client->page_size,
  6715. ilt_client->flags,
  6716. ilog2(ilt_client->page_size >> 12));
  6717. /* QM */
  6718. if (QM_INIT(bp->qm_cid_count)) {
  6719. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6720. ilt_client->client_num = ILT_CLIENT_QM;
  6721. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6722. ilt_client->flags = 0;
  6723. ilt_client->start = line;
  6724. /* 4 bytes for each cid */
  6725. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6726. QM_ILT_PAGE_SZ);
  6727. ilt_client->end = line - 1;
  6728. DP(NETIF_MSG_IFUP,
  6729. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6730. ilt_client->start,
  6731. ilt_client->end,
  6732. ilt_client->page_size,
  6733. ilt_client->flags,
  6734. ilog2(ilt_client->page_size >> 12));
  6735. }
  6736. if (CNIC_SUPPORT(bp)) {
  6737. /* SRC */
  6738. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6739. ilt_client->client_num = ILT_CLIENT_SRC;
  6740. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6741. ilt_client->flags = 0;
  6742. ilt_client->start = line;
  6743. line += SRC_ILT_LINES;
  6744. ilt_client->end = line - 1;
  6745. DP(NETIF_MSG_IFUP,
  6746. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6747. ilt_client->start,
  6748. ilt_client->end,
  6749. ilt_client->page_size,
  6750. ilt_client->flags,
  6751. ilog2(ilt_client->page_size >> 12));
  6752. /* TM */
  6753. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6754. ilt_client->client_num = ILT_CLIENT_TM;
  6755. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6756. ilt_client->flags = 0;
  6757. ilt_client->start = line;
  6758. line += TM_ILT_LINES;
  6759. ilt_client->end = line - 1;
  6760. DP(NETIF_MSG_IFUP,
  6761. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6762. ilt_client->start,
  6763. ilt_client->end,
  6764. ilt_client->page_size,
  6765. ilt_client->flags,
  6766. ilog2(ilt_client->page_size >> 12));
  6767. }
  6768. BUG_ON(line > ILT_MAX_LINES);
  6769. }
  6770. /**
  6771. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6772. *
  6773. * @bp: driver handle
  6774. * @fp: pointer to fastpath
  6775. * @init_params: pointer to parameters structure
  6776. *
  6777. * parameters configured:
  6778. * - HC configuration
  6779. * - Queue's CDU context
  6780. */
  6781. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6782. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6783. {
  6784. u8 cos;
  6785. int cxt_index, cxt_offset;
  6786. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6787. if (!IS_FCOE_FP(fp)) {
  6788. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6789. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6790. /* If HC is supported, enable host coalescing in the transition
  6791. * to INIT state.
  6792. */
  6793. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6794. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6795. /* HC rate */
  6796. init_params->rx.hc_rate = bp->rx_ticks ?
  6797. (1000000 / bp->rx_ticks) : 0;
  6798. init_params->tx.hc_rate = bp->tx_ticks ?
  6799. (1000000 / bp->tx_ticks) : 0;
  6800. /* FW SB ID */
  6801. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6802. fp->fw_sb_id;
  6803. /*
  6804. * CQ index among the SB indices: FCoE clients uses the default
  6805. * SB, therefore it's different.
  6806. */
  6807. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6808. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6809. }
  6810. /* set maximum number of COSs supported by this queue */
  6811. init_params->max_cos = fp->max_cos;
  6812. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6813. fp->index, init_params->max_cos);
  6814. /* set the context pointers queue object */
  6815. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6816. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6817. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6818. ILT_PAGE_CIDS);
  6819. init_params->cxts[cos] =
  6820. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6821. }
  6822. }
  6823. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6824. struct bnx2x_queue_state_params *q_params,
  6825. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6826. int tx_index, bool leading)
  6827. {
  6828. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6829. /* Set the command */
  6830. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6831. /* Set tx-only QUEUE flags: don't zero statistics */
  6832. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6833. /* choose the index of the cid to send the slow path on */
  6834. tx_only_params->cid_index = tx_index;
  6835. /* Set general TX_ONLY_SETUP parameters */
  6836. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6837. /* Set Tx TX_ONLY_SETUP parameters */
  6838. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6839. DP(NETIF_MSG_IFUP,
  6840. "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",
  6841. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6842. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6843. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6844. /* send the ramrod */
  6845. return bnx2x_queue_state_change(bp, q_params);
  6846. }
  6847. /**
  6848. * bnx2x_setup_queue - setup queue
  6849. *
  6850. * @bp: driver handle
  6851. * @fp: pointer to fastpath
  6852. * @leading: is leading
  6853. *
  6854. * This function performs 2 steps in a Queue state machine
  6855. * actually: 1) RESET->INIT 2) INIT->SETUP
  6856. */
  6857. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6858. bool leading)
  6859. {
  6860. struct bnx2x_queue_state_params q_params = {NULL};
  6861. struct bnx2x_queue_setup_params *setup_params =
  6862. &q_params.params.setup;
  6863. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6864. &q_params.params.tx_only;
  6865. int rc;
  6866. u8 tx_index;
  6867. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6868. /* reset IGU state skip FCoE L2 queue */
  6869. if (!IS_FCOE_FP(fp))
  6870. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6871. IGU_INT_ENABLE, 0);
  6872. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6873. /* We want to wait for completion in this context */
  6874. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6875. /* Prepare the INIT parameters */
  6876. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6877. /* Set the command */
  6878. q_params.cmd = BNX2X_Q_CMD_INIT;
  6879. /* Change the state to INIT */
  6880. rc = bnx2x_queue_state_change(bp, &q_params);
  6881. if (rc) {
  6882. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6883. return rc;
  6884. }
  6885. DP(NETIF_MSG_IFUP, "init complete\n");
  6886. /* Now move the Queue to the SETUP state... */
  6887. memset(setup_params, 0, sizeof(*setup_params));
  6888. /* Set QUEUE flags */
  6889. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6890. /* Set general SETUP parameters */
  6891. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6892. FIRST_TX_COS_INDEX);
  6893. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6894. &setup_params->rxq_params);
  6895. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6896. FIRST_TX_COS_INDEX);
  6897. /* Set the command */
  6898. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6899. if (IS_FCOE_FP(fp))
  6900. bp->fcoe_init = true;
  6901. /* Change the state to SETUP */
  6902. rc = bnx2x_queue_state_change(bp, &q_params);
  6903. if (rc) {
  6904. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6905. return rc;
  6906. }
  6907. /* loop through the relevant tx-only indices */
  6908. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6909. tx_index < fp->max_cos;
  6910. tx_index++) {
  6911. /* prepare and send tx-only ramrod*/
  6912. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6913. tx_only_params, tx_index, leading);
  6914. if (rc) {
  6915. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6916. fp->index, tx_index);
  6917. return rc;
  6918. }
  6919. }
  6920. return rc;
  6921. }
  6922. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6923. {
  6924. struct bnx2x_fastpath *fp = &bp->fp[index];
  6925. struct bnx2x_fp_txdata *txdata;
  6926. struct bnx2x_queue_state_params q_params = {NULL};
  6927. int rc, tx_index;
  6928. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6929. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6930. /* We want to wait for completion in this context */
  6931. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6932. /* close tx-only connections */
  6933. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6934. tx_index < fp->max_cos;
  6935. tx_index++){
  6936. /* ascertain this is a normal queue*/
  6937. txdata = fp->txdata_ptr[tx_index];
  6938. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6939. txdata->txq_index);
  6940. /* send halt terminate on tx-only connection */
  6941. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6942. memset(&q_params.params.terminate, 0,
  6943. sizeof(q_params.params.terminate));
  6944. q_params.params.terminate.cid_index = tx_index;
  6945. rc = bnx2x_queue_state_change(bp, &q_params);
  6946. if (rc)
  6947. return rc;
  6948. /* send halt terminate on tx-only connection */
  6949. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6950. memset(&q_params.params.cfc_del, 0,
  6951. sizeof(q_params.params.cfc_del));
  6952. q_params.params.cfc_del.cid_index = tx_index;
  6953. rc = bnx2x_queue_state_change(bp, &q_params);
  6954. if (rc)
  6955. return rc;
  6956. }
  6957. /* Stop the primary connection: */
  6958. /* ...halt the connection */
  6959. q_params.cmd = BNX2X_Q_CMD_HALT;
  6960. rc = bnx2x_queue_state_change(bp, &q_params);
  6961. if (rc)
  6962. return rc;
  6963. /* ...terminate the connection */
  6964. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6965. memset(&q_params.params.terminate, 0,
  6966. sizeof(q_params.params.terminate));
  6967. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6968. rc = bnx2x_queue_state_change(bp, &q_params);
  6969. if (rc)
  6970. return rc;
  6971. /* ...delete cfc entry */
  6972. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6973. memset(&q_params.params.cfc_del, 0,
  6974. sizeof(q_params.params.cfc_del));
  6975. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6976. return bnx2x_queue_state_change(bp, &q_params);
  6977. }
  6978. static void bnx2x_reset_func(struct bnx2x *bp)
  6979. {
  6980. int port = BP_PORT(bp);
  6981. int func = BP_FUNC(bp);
  6982. int i;
  6983. /* Disable the function in the FW */
  6984. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6985. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6986. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6987. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6988. /* FP SBs */
  6989. for_each_eth_queue(bp, i) {
  6990. struct bnx2x_fastpath *fp = &bp->fp[i];
  6991. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6992. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6993. SB_DISABLED);
  6994. }
  6995. if (CNIC_LOADED(bp))
  6996. /* CNIC SB */
  6997. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6998. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6999. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7000. /* SP SB */
  7001. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7002. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7003. SB_DISABLED);
  7004. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7005. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7006. 0);
  7007. /* Configure IGU */
  7008. if (bp->common.int_block == INT_BLOCK_HC) {
  7009. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7010. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7011. } else {
  7012. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7013. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7014. }
  7015. if (CNIC_LOADED(bp)) {
  7016. /* Disable Timer scan */
  7017. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7018. /*
  7019. * Wait for at least 10ms and up to 2 second for the timers
  7020. * scan to complete
  7021. */
  7022. for (i = 0; i < 200; i++) {
  7023. msleep(10);
  7024. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7025. break;
  7026. }
  7027. }
  7028. /* Clear ILT */
  7029. bnx2x_clear_func_ilt(bp, func);
  7030. /* Timers workaround bug for E2: if this is vnic-3,
  7031. * we need to set the entire ilt range for this timers.
  7032. */
  7033. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7034. struct ilt_client_info ilt_cli;
  7035. /* use dummy TM client */
  7036. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7037. ilt_cli.start = 0;
  7038. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7039. ilt_cli.client_num = ILT_CLIENT_TM;
  7040. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7041. }
  7042. /* this assumes that reset_port() called before reset_func()*/
  7043. if (!CHIP_IS_E1x(bp))
  7044. bnx2x_pf_disable(bp);
  7045. bp->dmae_ready = 0;
  7046. }
  7047. static void bnx2x_reset_port(struct bnx2x *bp)
  7048. {
  7049. int port = BP_PORT(bp);
  7050. u32 val;
  7051. /* Reset physical Link */
  7052. bnx2x__link_reset(bp);
  7053. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7054. /* Do not rcv packets to BRB */
  7055. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7056. /* Do not direct rcv packets that are not for MCP to the BRB */
  7057. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7058. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7059. /* Configure AEU */
  7060. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7061. msleep(100);
  7062. /* Check for BRB port occupancy */
  7063. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7064. if (val)
  7065. DP(NETIF_MSG_IFDOWN,
  7066. "BRB1 is not empty %d blocks are occupied\n", val);
  7067. /* TODO: Close Doorbell port? */
  7068. }
  7069. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7070. {
  7071. struct bnx2x_func_state_params func_params = {NULL};
  7072. /* Prepare parameters for function state transitions */
  7073. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7074. func_params.f_obj = &bp->func_obj;
  7075. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7076. func_params.params.hw_init.load_phase = load_code;
  7077. return bnx2x_func_state_change(bp, &func_params);
  7078. }
  7079. static int bnx2x_func_stop(struct bnx2x *bp)
  7080. {
  7081. struct bnx2x_func_state_params func_params = {NULL};
  7082. int rc;
  7083. /* Prepare parameters for function state transitions */
  7084. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7085. func_params.f_obj = &bp->func_obj;
  7086. func_params.cmd = BNX2X_F_CMD_STOP;
  7087. /*
  7088. * Try to stop the function the 'good way'. If fails (in case
  7089. * of a parity error during bnx2x_chip_cleanup()) and we are
  7090. * not in a debug mode, perform a state transaction in order to
  7091. * enable further HW_RESET transaction.
  7092. */
  7093. rc = bnx2x_func_state_change(bp, &func_params);
  7094. if (rc) {
  7095. #ifdef BNX2X_STOP_ON_ERROR
  7096. return rc;
  7097. #else
  7098. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7099. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7100. return bnx2x_func_state_change(bp, &func_params);
  7101. #endif
  7102. }
  7103. return 0;
  7104. }
  7105. /**
  7106. * bnx2x_send_unload_req - request unload mode from the MCP.
  7107. *
  7108. * @bp: driver handle
  7109. * @unload_mode: requested function's unload mode
  7110. *
  7111. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7112. */
  7113. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7114. {
  7115. u32 reset_code = 0;
  7116. int port = BP_PORT(bp);
  7117. /* Select the UNLOAD request mode */
  7118. if (unload_mode == UNLOAD_NORMAL)
  7119. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7120. else if (bp->flags & NO_WOL_FLAG)
  7121. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7122. else if (bp->wol) {
  7123. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7124. u8 *mac_addr = bp->dev->dev_addr;
  7125. u32 val;
  7126. u16 pmc;
  7127. /* The mac address is written to entries 1-4 to
  7128. * preserve entry 0 which is used by the PMF
  7129. */
  7130. u8 entry = (BP_VN(bp) + 1)*8;
  7131. val = (mac_addr[0] << 8) | mac_addr[1];
  7132. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7133. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7134. (mac_addr[4] << 8) | mac_addr[5];
  7135. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7136. /* Enable the PME and clear the status */
  7137. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7138. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7139. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7140. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7141. } else
  7142. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7143. /* Send the request to the MCP */
  7144. if (!BP_NOMCP(bp))
  7145. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7146. else {
  7147. int path = BP_PATH(bp);
  7148. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7149. path, load_count[path][0], load_count[path][1],
  7150. load_count[path][2]);
  7151. load_count[path][0]--;
  7152. load_count[path][1 + port]--;
  7153. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7154. path, load_count[path][0], load_count[path][1],
  7155. load_count[path][2]);
  7156. if (load_count[path][0] == 0)
  7157. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7158. else if (load_count[path][1 + port] == 0)
  7159. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7160. else
  7161. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7162. }
  7163. return reset_code;
  7164. }
  7165. /**
  7166. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7167. *
  7168. * @bp: driver handle
  7169. * @keep_link: true iff link should be kept up
  7170. */
  7171. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7172. {
  7173. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7174. /* Report UNLOAD_DONE to MCP */
  7175. if (!BP_NOMCP(bp))
  7176. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7177. }
  7178. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7179. {
  7180. int tout = 50;
  7181. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7182. if (!bp->port.pmf)
  7183. return 0;
  7184. /*
  7185. * (assumption: No Attention from MCP at this stage)
  7186. * PMF probably in the middle of TX disable/enable transaction
  7187. * 1. Sync IRS for default SB
  7188. * 2. Sync SP queue - this guarantees us that attention handling started
  7189. * 3. Wait, that TX disable/enable transaction completes
  7190. *
  7191. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7192. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7193. * received completion for the transaction the state is TX_STOPPED.
  7194. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7195. * transaction.
  7196. */
  7197. /* make sure default SB ISR is done */
  7198. if (msix)
  7199. synchronize_irq(bp->msix_table[0].vector);
  7200. else
  7201. synchronize_irq(bp->pdev->irq);
  7202. flush_workqueue(bnx2x_wq);
  7203. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7204. BNX2X_F_STATE_STARTED && tout--)
  7205. msleep(20);
  7206. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7207. BNX2X_F_STATE_STARTED) {
  7208. #ifdef BNX2X_STOP_ON_ERROR
  7209. BNX2X_ERR("Wrong function state\n");
  7210. return -EBUSY;
  7211. #else
  7212. /*
  7213. * Failed to complete the transaction in a "good way"
  7214. * Force both transactions with CLR bit
  7215. */
  7216. struct bnx2x_func_state_params func_params = {NULL};
  7217. DP(NETIF_MSG_IFDOWN,
  7218. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7219. func_params.f_obj = &bp->func_obj;
  7220. __set_bit(RAMROD_DRV_CLR_ONLY,
  7221. &func_params.ramrod_flags);
  7222. /* STARTED-->TX_ST0PPED */
  7223. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7224. bnx2x_func_state_change(bp, &func_params);
  7225. /* TX_ST0PPED-->STARTED */
  7226. func_params.cmd = BNX2X_F_CMD_TX_START;
  7227. return bnx2x_func_state_change(bp, &func_params);
  7228. #endif
  7229. }
  7230. return 0;
  7231. }
  7232. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7233. {
  7234. int port = BP_PORT(bp);
  7235. int i, rc = 0;
  7236. u8 cos;
  7237. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7238. u32 reset_code;
  7239. /* Wait until tx fastpath tasks complete */
  7240. for_each_tx_queue(bp, i) {
  7241. struct bnx2x_fastpath *fp = &bp->fp[i];
  7242. for_each_cos_in_tx_queue(fp, cos)
  7243. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7244. #ifdef BNX2X_STOP_ON_ERROR
  7245. if (rc)
  7246. return;
  7247. #endif
  7248. }
  7249. /* Give HW time to discard old tx messages */
  7250. usleep_range(1000, 2000);
  7251. /* Clean all ETH MACs */
  7252. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7253. false);
  7254. if (rc < 0)
  7255. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7256. /* Clean up UC list */
  7257. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7258. true);
  7259. if (rc < 0)
  7260. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7261. rc);
  7262. /* Disable LLH */
  7263. if (!CHIP_IS_E1(bp))
  7264. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7265. /* Set "drop all" (stop Rx).
  7266. * We need to take a netif_addr_lock() here in order to prevent
  7267. * a race between the completion code and this code.
  7268. */
  7269. netif_addr_lock_bh(bp->dev);
  7270. /* Schedule the rx_mode command */
  7271. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7272. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7273. else
  7274. bnx2x_set_storm_rx_mode(bp);
  7275. /* Cleanup multicast configuration */
  7276. rparam.mcast_obj = &bp->mcast_obj;
  7277. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7278. if (rc < 0)
  7279. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7280. netif_addr_unlock_bh(bp->dev);
  7281. bnx2x_iov_chip_cleanup(bp);
  7282. /*
  7283. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7284. * this function should perform FUNC, PORT or COMMON HW
  7285. * reset.
  7286. */
  7287. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7288. /*
  7289. * (assumption: No Attention from MCP at this stage)
  7290. * PMF probably in the middle of TX disable/enable transaction
  7291. */
  7292. rc = bnx2x_func_wait_started(bp);
  7293. if (rc) {
  7294. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7295. #ifdef BNX2X_STOP_ON_ERROR
  7296. return;
  7297. #endif
  7298. }
  7299. /* Close multi and leading connections
  7300. * Completions for ramrods are collected in a synchronous way
  7301. */
  7302. for_each_eth_queue(bp, i)
  7303. if (bnx2x_stop_queue(bp, i))
  7304. #ifdef BNX2X_STOP_ON_ERROR
  7305. return;
  7306. #else
  7307. goto unload_error;
  7308. #endif
  7309. if (CNIC_LOADED(bp)) {
  7310. for_each_cnic_queue(bp, i)
  7311. if (bnx2x_stop_queue(bp, i))
  7312. #ifdef BNX2X_STOP_ON_ERROR
  7313. return;
  7314. #else
  7315. goto unload_error;
  7316. #endif
  7317. }
  7318. /* If SP settings didn't get completed so far - something
  7319. * very wrong has happen.
  7320. */
  7321. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7322. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7323. #ifndef BNX2X_STOP_ON_ERROR
  7324. unload_error:
  7325. #endif
  7326. rc = bnx2x_func_stop(bp);
  7327. if (rc) {
  7328. BNX2X_ERR("Function stop failed!\n");
  7329. #ifdef BNX2X_STOP_ON_ERROR
  7330. return;
  7331. #endif
  7332. }
  7333. /* Disable HW interrupts, NAPI */
  7334. bnx2x_netif_stop(bp, 1);
  7335. /* Delete all NAPI objects */
  7336. bnx2x_del_all_napi(bp);
  7337. if (CNIC_LOADED(bp))
  7338. bnx2x_del_all_napi_cnic(bp);
  7339. /* Release IRQs */
  7340. bnx2x_free_irq(bp);
  7341. /* Reset the chip */
  7342. rc = bnx2x_reset_hw(bp, reset_code);
  7343. if (rc)
  7344. BNX2X_ERR("HW_RESET failed\n");
  7345. /* Report UNLOAD_DONE to MCP */
  7346. bnx2x_send_unload_done(bp, keep_link);
  7347. }
  7348. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7349. {
  7350. u32 val;
  7351. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7352. if (CHIP_IS_E1(bp)) {
  7353. int port = BP_PORT(bp);
  7354. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7355. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7356. val = REG_RD(bp, addr);
  7357. val &= ~(0x300);
  7358. REG_WR(bp, addr, val);
  7359. } else {
  7360. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7361. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7362. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7363. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7364. }
  7365. }
  7366. /* Close gates #2, #3 and #4: */
  7367. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7368. {
  7369. u32 val;
  7370. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7371. if (!CHIP_IS_E1(bp)) {
  7372. /* #4 */
  7373. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7374. /* #2 */
  7375. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7376. }
  7377. /* #3 */
  7378. if (CHIP_IS_E1x(bp)) {
  7379. /* Prevent interrupts from HC on both ports */
  7380. val = REG_RD(bp, HC_REG_CONFIG_1);
  7381. REG_WR(bp, HC_REG_CONFIG_1,
  7382. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7383. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7384. val = REG_RD(bp, HC_REG_CONFIG_0);
  7385. REG_WR(bp, HC_REG_CONFIG_0,
  7386. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7387. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7388. } else {
  7389. /* Prevent incoming interrupts in IGU */
  7390. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7391. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7392. (!close) ?
  7393. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7394. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7395. }
  7396. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7397. close ? "closing" : "opening");
  7398. mmiowb();
  7399. }
  7400. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7401. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7402. {
  7403. /* Do some magic... */
  7404. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7405. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7406. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7407. }
  7408. /**
  7409. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7410. *
  7411. * @bp: driver handle
  7412. * @magic_val: old value of the `magic' bit.
  7413. */
  7414. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7415. {
  7416. /* Restore the `magic' bit value... */
  7417. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7418. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7419. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7420. }
  7421. /**
  7422. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7423. *
  7424. * @bp: driver handle
  7425. * @magic_val: old value of 'magic' bit.
  7426. *
  7427. * Takes care of CLP configurations.
  7428. */
  7429. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7430. {
  7431. u32 shmem;
  7432. u32 validity_offset;
  7433. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7434. /* Set `magic' bit in order to save MF config */
  7435. if (!CHIP_IS_E1(bp))
  7436. bnx2x_clp_reset_prep(bp, magic_val);
  7437. /* Get shmem offset */
  7438. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7439. validity_offset =
  7440. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7441. /* Clear validity map flags */
  7442. if (shmem > 0)
  7443. REG_WR(bp, shmem + validity_offset, 0);
  7444. }
  7445. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7446. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7447. /**
  7448. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7449. *
  7450. * @bp: driver handle
  7451. */
  7452. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7453. {
  7454. /* special handling for emulation and FPGA,
  7455. wait 10 times longer */
  7456. if (CHIP_REV_IS_SLOW(bp))
  7457. msleep(MCP_ONE_TIMEOUT*10);
  7458. else
  7459. msleep(MCP_ONE_TIMEOUT);
  7460. }
  7461. /*
  7462. * initializes bp->common.shmem_base and waits for validity signature to appear
  7463. */
  7464. static int bnx2x_init_shmem(struct bnx2x *bp)
  7465. {
  7466. int cnt = 0;
  7467. u32 val = 0;
  7468. do {
  7469. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7470. if (bp->common.shmem_base) {
  7471. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7472. if (val & SHR_MEM_VALIDITY_MB)
  7473. return 0;
  7474. }
  7475. bnx2x_mcp_wait_one(bp);
  7476. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7477. BNX2X_ERR("BAD MCP validity signature\n");
  7478. return -ENODEV;
  7479. }
  7480. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7481. {
  7482. int rc = bnx2x_init_shmem(bp);
  7483. /* Restore the `magic' bit value */
  7484. if (!CHIP_IS_E1(bp))
  7485. bnx2x_clp_reset_done(bp, magic_val);
  7486. return rc;
  7487. }
  7488. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7489. {
  7490. if (!CHIP_IS_E1(bp)) {
  7491. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7492. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7493. mmiowb();
  7494. }
  7495. }
  7496. /*
  7497. * Reset the whole chip except for:
  7498. * - PCIE core
  7499. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7500. * one reset bit)
  7501. * - IGU
  7502. * - MISC (including AEU)
  7503. * - GRC
  7504. * - RBCN, RBCP
  7505. */
  7506. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7507. {
  7508. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7509. u32 global_bits2, stay_reset2;
  7510. /*
  7511. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7512. * (per chip) blocks.
  7513. */
  7514. global_bits2 =
  7515. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7516. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7517. /* Don't reset the following blocks.
  7518. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7519. * reset, as in 4 port device they might still be owned
  7520. * by the MCP (there is only one leader per path).
  7521. */
  7522. not_reset_mask1 =
  7523. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7524. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7525. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7526. not_reset_mask2 =
  7527. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7528. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7529. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7530. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7531. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7532. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7533. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7534. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7535. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7536. MISC_REGISTERS_RESET_REG_2_PGLC |
  7537. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7538. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7539. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7540. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7541. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7542. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7543. /*
  7544. * Keep the following blocks in reset:
  7545. * - all xxMACs are handled by the bnx2x_link code.
  7546. */
  7547. stay_reset2 =
  7548. MISC_REGISTERS_RESET_REG_2_XMAC |
  7549. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7550. /* Full reset masks according to the chip */
  7551. reset_mask1 = 0xffffffff;
  7552. if (CHIP_IS_E1(bp))
  7553. reset_mask2 = 0xffff;
  7554. else if (CHIP_IS_E1H(bp))
  7555. reset_mask2 = 0x1ffff;
  7556. else if (CHIP_IS_E2(bp))
  7557. reset_mask2 = 0xfffff;
  7558. else /* CHIP_IS_E3 */
  7559. reset_mask2 = 0x3ffffff;
  7560. /* Don't reset global blocks unless we need to */
  7561. if (!global)
  7562. reset_mask2 &= ~global_bits2;
  7563. /*
  7564. * In case of attention in the QM, we need to reset PXP
  7565. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7566. * because otherwise QM reset would release 'close the gates' shortly
  7567. * before resetting the PXP, then the PSWRQ would send a write
  7568. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7569. * read the payload data from PSWWR, but PSWWR would not
  7570. * respond. The write queue in PGLUE would stuck, dmae commands
  7571. * would not return. Therefore it's important to reset the second
  7572. * reset register (containing the
  7573. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7574. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7575. * bit).
  7576. */
  7577. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7578. reset_mask2 & (~not_reset_mask2));
  7579. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7580. reset_mask1 & (~not_reset_mask1));
  7581. barrier();
  7582. mmiowb();
  7583. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7584. reset_mask2 & (~stay_reset2));
  7585. barrier();
  7586. mmiowb();
  7587. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7588. mmiowb();
  7589. }
  7590. /**
  7591. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7592. * It should get cleared in no more than 1s.
  7593. *
  7594. * @bp: driver handle
  7595. *
  7596. * It should get cleared in no more than 1s. Returns 0 if
  7597. * pending writes bit gets cleared.
  7598. */
  7599. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7600. {
  7601. u32 cnt = 1000;
  7602. u32 pend_bits = 0;
  7603. do {
  7604. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7605. if (pend_bits == 0)
  7606. break;
  7607. usleep_range(1000, 2000);
  7608. } while (cnt-- > 0);
  7609. if (cnt <= 0) {
  7610. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7611. pend_bits);
  7612. return -EBUSY;
  7613. }
  7614. return 0;
  7615. }
  7616. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7617. {
  7618. int cnt = 1000;
  7619. u32 val = 0;
  7620. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7621. u32 tags_63_32 = 0;
  7622. /* Empty the Tetris buffer, wait for 1s */
  7623. do {
  7624. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7625. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7626. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7627. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7628. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7629. if (CHIP_IS_E3(bp))
  7630. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7631. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7632. ((port_is_idle_0 & 0x1) == 0x1) &&
  7633. ((port_is_idle_1 & 0x1) == 0x1) &&
  7634. (pgl_exp_rom2 == 0xffffffff) &&
  7635. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7636. break;
  7637. usleep_range(1000, 2000);
  7638. } while (cnt-- > 0);
  7639. if (cnt <= 0) {
  7640. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7641. 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",
  7642. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7643. pgl_exp_rom2);
  7644. return -EAGAIN;
  7645. }
  7646. barrier();
  7647. /* Close gates #2, #3 and #4 */
  7648. bnx2x_set_234_gates(bp, true);
  7649. /* Poll for IGU VQs for 57712 and newer chips */
  7650. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7651. return -EAGAIN;
  7652. /* TBD: Indicate that "process kill" is in progress to MCP */
  7653. /* Clear "unprepared" bit */
  7654. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7655. barrier();
  7656. /* Make sure all is written to the chip before the reset */
  7657. mmiowb();
  7658. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7659. * PSWHST, GRC and PSWRD Tetris buffer.
  7660. */
  7661. usleep_range(1000, 2000);
  7662. /* Prepare to chip reset: */
  7663. /* MCP */
  7664. if (global)
  7665. bnx2x_reset_mcp_prep(bp, &val);
  7666. /* PXP */
  7667. bnx2x_pxp_prep(bp);
  7668. barrier();
  7669. /* reset the chip */
  7670. bnx2x_process_kill_chip_reset(bp, global);
  7671. barrier();
  7672. /* Recover after reset: */
  7673. /* MCP */
  7674. if (global && bnx2x_reset_mcp_comp(bp, val))
  7675. return -EAGAIN;
  7676. /* TBD: Add resetting the NO_MCP mode DB here */
  7677. /* Open the gates #2, #3 and #4 */
  7678. bnx2x_set_234_gates(bp, false);
  7679. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7680. * reset state, re-enable attentions. */
  7681. return 0;
  7682. }
  7683. static int bnx2x_leader_reset(struct bnx2x *bp)
  7684. {
  7685. int rc = 0;
  7686. bool global = bnx2x_reset_is_global(bp);
  7687. u32 load_code;
  7688. /* if not going to reset MCP - load "fake" driver to reset HW while
  7689. * driver is owner of the HW
  7690. */
  7691. if (!global && !BP_NOMCP(bp)) {
  7692. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7693. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7694. if (!load_code) {
  7695. BNX2X_ERR("MCP response failure, aborting\n");
  7696. rc = -EAGAIN;
  7697. goto exit_leader_reset;
  7698. }
  7699. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7700. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7701. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7702. rc = -EAGAIN;
  7703. goto exit_leader_reset2;
  7704. }
  7705. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7706. if (!load_code) {
  7707. BNX2X_ERR("MCP response failure, aborting\n");
  7708. rc = -EAGAIN;
  7709. goto exit_leader_reset2;
  7710. }
  7711. }
  7712. /* Try to recover after the failure */
  7713. if (bnx2x_process_kill(bp, global)) {
  7714. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7715. BP_PATH(bp));
  7716. rc = -EAGAIN;
  7717. goto exit_leader_reset2;
  7718. }
  7719. /*
  7720. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7721. * state.
  7722. */
  7723. bnx2x_set_reset_done(bp);
  7724. if (global)
  7725. bnx2x_clear_reset_global(bp);
  7726. exit_leader_reset2:
  7727. /* unload "fake driver" if it was loaded */
  7728. if (!global && !BP_NOMCP(bp)) {
  7729. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7730. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7731. }
  7732. exit_leader_reset:
  7733. bp->is_leader = 0;
  7734. bnx2x_release_leader_lock(bp);
  7735. smp_mb();
  7736. return rc;
  7737. }
  7738. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7739. {
  7740. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7741. /* Disconnect this device */
  7742. netif_device_detach(bp->dev);
  7743. /*
  7744. * Block ifup for all function on this engine until "process kill"
  7745. * or power cycle.
  7746. */
  7747. bnx2x_set_reset_in_progress(bp);
  7748. /* Shut down the power */
  7749. bnx2x_set_power_state(bp, PCI_D3hot);
  7750. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7751. smp_mb();
  7752. }
  7753. /*
  7754. * Assumption: runs under rtnl lock. This together with the fact
  7755. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7756. * will never be called when netif_running(bp->dev) is false.
  7757. */
  7758. static void bnx2x_parity_recover(struct bnx2x *bp)
  7759. {
  7760. bool global = false;
  7761. u32 error_recovered, error_unrecovered;
  7762. bool is_parity;
  7763. DP(NETIF_MSG_HW, "Handling parity\n");
  7764. while (1) {
  7765. switch (bp->recovery_state) {
  7766. case BNX2X_RECOVERY_INIT:
  7767. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7768. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7769. WARN_ON(!is_parity);
  7770. /* Try to get a LEADER_LOCK HW lock */
  7771. if (bnx2x_trylock_leader_lock(bp)) {
  7772. bnx2x_set_reset_in_progress(bp);
  7773. /*
  7774. * Check if there is a global attention and if
  7775. * there was a global attention, set the global
  7776. * reset bit.
  7777. */
  7778. if (global)
  7779. bnx2x_set_reset_global(bp);
  7780. bp->is_leader = 1;
  7781. }
  7782. /* Stop the driver */
  7783. /* If interface has been removed - break */
  7784. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7785. return;
  7786. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7787. /* Ensure "is_leader", MCP command sequence and
  7788. * "recovery_state" update values are seen on other
  7789. * CPUs.
  7790. */
  7791. smp_mb();
  7792. break;
  7793. case BNX2X_RECOVERY_WAIT:
  7794. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7795. if (bp->is_leader) {
  7796. int other_engine = BP_PATH(bp) ? 0 : 1;
  7797. bool other_load_status =
  7798. bnx2x_get_load_status(bp, other_engine);
  7799. bool load_status =
  7800. bnx2x_get_load_status(bp, BP_PATH(bp));
  7801. global = bnx2x_reset_is_global(bp);
  7802. /*
  7803. * In case of a parity in a global block, let
  7804. * the first leader that performs a
  7805. * leader_reset() reset the global blocks in
  7806. * order to clear global attentions. Otherwise
  7807. * the gates will remain closed for that
  7808. * engine.
  7809. */
  7810. if (load_status ||
  7811. (global && other_load_status)) {
  7812. /* Wait until all other functions get
  7813. * down.
  7814. */
  7815. schedule_delayed_work(&bp->sp_rtnl_task,
  7816. HZ/10);
  7817. return;
  7818. } else {
  7819. /* If all other functions got down -
  7820. * try to bring the chip back to
  7821. * normal. In any case it's an exit
  7822. * point for a leader.
  7823. */
  7824. if (bnx2x_leader_reset(bp)) {
  7825. bnx2x_recovery_failed(bp);
  7826. return;
  7827. }
  7828. /* If we are here, means that the
  7829. * leader has succeeded and doesn't
  7830. * want to be a leader any more. Try
  7831. * to continue as a none-leader.
  7832. */
  7833. break;
  7834. }
  7835. } else { /* non-leader */
  7836. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7837. /* Try to get a LEADER_LOCK HW lock as
  7838. * long as a former leader may have
  7839. * been unloaded by the user or
  7840. * released a leadership by another
  7841. * reason.
  7842. */
  7843. if (bnx2x_trylock_leader_lock(bp)) {
  7844. /* I'm a leader now! Restart a
  7845. * switch case.
  7846. */
  7847. bp->is_leader = 1;
  7848. break;
  7849. }
  7850. schedule_delayed_work(&bp->sp_rtnl_task,
  7851. HZ/10);
  7852. return;
  7853. } else {
  7854. /*
  7855. * If there was a global attention, wait
  7856. * for it to be cleared.
  7857. */
  7858. if (bnx2x_reset_is_global(bp)) {
  7859. schedule_delayed_work(
  7860. &bp->sp_rtnl_task,
  7861. HZ/10);
  7862. return;
  7863. }
  7864. error_recovered =
  7865. bp->eth_stats.recoverable_error;
  7866. error_unrecovered =
  7867. bp->eth_stats.unrecoverable_error;
  7868. bp->recovery_state =
  7869. BNX2X_RECOVERY_NIC_LOADING;
  7870. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7871. error_unrecovered++;
  7872. netdev_err(bp->dev,
  7873. "Recovery failed. Power cycle needed\n");
  7874. /* Disconnect this device */
  7875. netif_device_detach(bp->dev);
  7876. /* Shut down the power */
  7877. bnx2x_set_power_state(
  7878. bp, PCI_D3hot);
  7879. smp_mb();
  7880. } else {
  7881. bp->recovery_state =
  7882. BNX2X_RECOVERY_DONE;
  7883. error_recovered++;
  7884. smp_mb();
  7885. }
  7886. bp->eth_stats.recoverable_error =
  7887. error_recovered;
  7888. bp->eth_stats.unrecoverable_error =
  7889. error_unrecovered;
  7890. return;
  7891. }
  7892. }
  7893. default:
  7894. return;
  7895. }
  7896. }
  7897. }
  7898. static int bnx2x_close(struct net_device *dev);
  7899. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7900. * scheduled on a general queue in order to prevent a dead lock.
  7901. */
  7902. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7903. {
  7904. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7905. rtnl_lock();
  7906. if (!netif_running(bp->dev)) {
  7907. rtnl_unlock();
  7908. return;
  7909. }
  7910. /* if stop on error is defined no recovery flows should be executed */
  7911. #ifdef BNX2X_STOP_ON_ERROR
  7912. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7913. "you will need to reboot when done\n");
  7914. goto sp_rtnl_not_reset;
  7915. #endif
  7916. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7917. /*
  7918. * Clear all pending SP commands as we are going to reset the
  7919. * function anyway.
  7920. */
  7921. bp->sp_rtnl_state = 0;
  7922. smp_mb();
  7923. bnx2x_parity_recover(bp);
  7924. rtnl_unlock();
  7925. return;
  7926. }
  7927. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7928. /*
  7929. * Clear all pending SP commands as we are going to reset the
  7930. * function anyway.
  7931. */
  7932. bp->sp_rtnl_state = 0;
  7933. smp_mb();
  7934. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7935. bnx2x_nic_load(bp, LOAD_NORMAL);
  7936. rtnl_unlock();
  7937. return;
  7938. }
  7939. #ifdef BNX2X_STOP_ON_ERROR
  7940. sp_rtnl_not_reset:
  7941. #endif
  7942. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7943. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7944. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7945. bnx2x_after_function_update(bp);
  7946. /*
  7947. * in case of fan failure we need to reset id if the "stop on error"
  7948. * debug flag is set, since we trying to prevent permanent overheating
  7949. * damage
  7950. */
  7951. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7952. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7953. netif_device_detach(bp->dev);
  7954. bnx2x_close(bp->dev);
  7955. rtnl_unlock();
  7956. return;
  7957. }
  7958. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7959. DP(BNX2X_MSG_SP,
  7960. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7961. bnx2x_vfpf_set_mcast(bp->dev);
  7962. }
  7963. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7964. &bp->sp_rtnl_state)) {
  7965. DP(BNX2X_MSG_SP,
  7966. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7967. bnx2x_vfpf_storm_rx_mode(bp);
  7968. }
  7969. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  7970. &bp->sp_rtnl_state))
  7971. bnx2x_pf_set_vfs_vlan(bp);
  7972. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  7973. * can be called from other contexts as well)
  7974. */
  7975. rtnl_unlock();
  7976. /* enable SR-IOV if applicable */
  7977. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  7978. &bp->sp_rtnl_state)) {
  7979. bnx2x_disable_sriov(bp);
  7980. bnx2x_enable_sriov(bp);
  7981. }
  7982. }
  7983. static void bnx2x_period_task(struct work_struct *work)
  7984. {
  7985. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7986. if (!netif_running(bp->dev))
  7987. goto period_task_exit;
  7988. if (CHIP_REV_IS_SLOW(bp)) {
  7989. BNX2X_ERR("period task called on emulation, ignoring\n");
  7990. goto period_task_exit;
  7991. }
  7992. bnx2x_acquire_phy_lock(bp);
  7993. /*
  7994. * The barrier is needed to ensure the ordering between the writing to
  7995. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7996. * the reading here.
  7997. */
  7998. smp_mb();
  7999. if (bp->port.pmf) {
  8000. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8001. /* Re-queue task in 1 sec */
  8002. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8003. }
  8004. bnx2x_release_phy_lock(bp);
  8005. period_task_exit:
  8006. return;
  8007. }
  8008. /*
  8009. * Init service functions
  8010. */
  8011. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8012. {
  8013. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8014. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8015. return base + (BP_ABS_FUNC(bp)) * stride;
  8016. }
  8017. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8018. struct bnx2x_mac_vals *vals)
  8019. {
  8020. u32 val, base_addr, offset, mask, reset_reg;
  8021. bool mac_stopped = false;
  8022. u8 port = BP_PORT(bp);
  8023. /* reset addresses as they also mark which values were changed */
  8024. vals->bmac_addr = 0;
  8025. vals->umac_addr = 0;
  8026. vals->xmac_addr = 0;
  8027. vals->emac_addr = 0;
  8028. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8029. if (!CHIP_IS_E3(bp)) {
  8030. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8031. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8032. if ((mask & reset_reg) && val) {
  8033. u32 wb_data[2];
  8034. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8035. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8036. : NIG_REG_INGRESS_BMAC0_MEM;
  8037. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8038. : BIGMAC_REGISTER_BMAC_CONTROL;
  8039. /*
  8040. * use rd/wr since we cannot use dmae. This is safe
  8041. * since MCP won't access the bus due to the request
  8042. * to unload, and no function on the path can be
  8043. * loaded at this time.
  8044. */
  8045. wb_data[0] = REG_RD(bp, base_addr + offset);
  8046. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8047. vals->bmac_addr = base_addr + offset;
  8048. vals->bmac_val[0] = wb_data[0];
  8049. vals->bmac_val[1] = wb_data[1];
  8050. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8051. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8052. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8053. }
  8054. BNX2X_DEV_INFO("Disable emac Rx\n");
  8055. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8056. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8057. REG_WR(bp, vals->emac_addr, 0);
  8058. mac_stopped = true;
  8059. } else {
  8060. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8061. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8062. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8063. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8064. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8065. val & ~(1 << 1));
  8066. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8067. val | (1 << 1));
  8068. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8069. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8070. REG_WR(bp, vals->xmac_addr, 0);
  8071. mac_stopped = true;
  8072. }
  8073. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8074. if (mask & reset_reg) {
  8075. BNX2X_DEV_INFO("Disable umac Rx\n");
  8076. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8077. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8078. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8079. REG_WR(bp, vals->umac_addr, 0);
  8080. mac_stopped = true;
  8081. }
  8082. }
  8083. if (mac_stopped)
  8084. msleep(20);
  8085. }
  8086. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8087. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8088. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8089. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8090. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8091. {
  8092. u16 rcq, bd;
  8093. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8094. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8095. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8096. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8097. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8098. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8099. port, bd, rcq);
  8100. }
  8101. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8102. {
  8103. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8104. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8105. if (!rc) {
  8106. BNX2X_ERR("MCP response failure, aborting\n");
  8107. return -EBUSY;
  8108. }
  8109. return 0;
  8110. }
  8111. static struct bnx2x_prev_path_list *
  8112. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8113. {
  8114. struct bnx2x_prev_path_list *tmp_list;
  8115. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8116. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8117. bp->pdev->bus->number == tmp_list->bus &&
  8118. BP_PATH(bp) == tmp_list->path)
  8119. return tmp_list;
  8120. return NULL;
  8121. }
  8122. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8123. {
  8124. struct bnx2x_prev_path_list *tmp_list;
  8125. int rc;
  8126. rc = down_interruptible(&bnx2x_prev_sem);
  8127. if (rc) {
  8128. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8129. return rc;
  8130. }
  8131. tmp_list = bnx2x_prev_path_get_entry(bp);
  8132. if (tmp_list) {
  8133. tmp_list->aer = 1;
  8134. rc = 0;
  8135. } else {
  8136. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8137. BP_PATH(bp));
  8138. }
  8139. up(&bnx2x_prev_sem);
  8140. return rc;
  8141. }
  8142. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8143. {
  8144. struct bnx2x_prev_path_list *tmp_list;
  8145. int rc = false;
  8146. if (down_trylock(&bnx2x_prev_sem))
  8147. return false;
  8148. tmp_list = bnx2x_prev_path_get_entry(bp);
  8149. if (tmp_list) {
  8150. if (tmp_list->aer) {
  8151. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8152. BP_PATH(bp));
  8153. } else {
  8154. rc = true;
  8155. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8156. BP_PATH(bp));
  8157. }
  8158. }
  8159. up(&bnx2x_prev_sem);
  8160. return rc;
  8161. }
  8162. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8163. {
  8164. struct bnx2x_prev_path_list *entry;
  8165. bool val;
  8166. down(&bnx2x_prev_sem);
  8167. entry = bnx2x_prev_path_get_entry(bp);
  8168. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8169. up(&bnx2x_prev_sem);
  8170. return val;
  8171. }
  8172. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8173. {
  8174. struct bnx2x_prev_path_list *tmp_list;
  8175. int rc;
  8176. rc = down_interruptible(&bnx2x_prev_sem);
  8177. if (rc) {
  8178. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8179. return rc;
  8180. }
  8181. /* Check whether the entry for this path already exists */
  8182. tmp_list = bnx2x_prev_path_get_entry(bp);
  8183. if (tmp_list) {
  8184. if (!tmp_list->aer) {
  8185. BNX2X_ERR("Re-Marking the path.\n");
  8186. } else {
  8187. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8188. BP_PATH(bp));
  8189. tmp_list->aer = 0;
  8190. }
  8191. up(&bnx2x_prev_sem);
  8192. return 0;
  8193. }
  8194. up(&bnx2x_prev_sem);
  8195. /* Create an entry for this path and add it */
  8196. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8197. if (!tmp_list) {
  8198. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8199. return -ENOMEM;
  8200. }
  8201. tmp_list->bus = bp->pdev->bus->number;
  8202. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8203. tmp_list->path = BP_PATH(bp);
  8204. tmp_list->aer = 0;
  8205. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8206. rc = down_interruptible(&bnx2x_prev_sem);
  8207. if (rc) {
  8208. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8209. kfree(tmp_list);
  8210. } else {
  8211. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8212. BP_PATH(bp));
  8213. list_add(&tmp_list->list, &bnx2x_prev_list);
  8214. up(&bnx2x_prev_sem);
  8215. }
  8216. return rc;
  8217. }
  8218. static int bnx2x_do_flr(struct bnx2x *bp)
  8219. {
  8220. int i;
  8221. u16 status;
  8222. struct pci_dev *dev = bp->pdev;
  8223. if (CHIP_IS_E1x(bp)) {
  8224. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8225. return -EINVAL;
  8226. }
  8227. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8228. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8229. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8230. bp->common.bc_ver);
  8231. return -EINVAL;
  8232. }
  8233. /* Wait for Transaction Pending bit clean */
  8234. for (i = 0; i < 4; i++) {
  8235. if (i)
  8236. msleep((1 << (i - 1)) * 100);
  8237. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8238. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8239. goto clear;
  8240. }
  8241. dev_err(&dev->dev,
  8242. "transaction is not cleared; proceeding with reset anyway\n");
  8243. clear:
  8244. BNX2X_DEV_INFO("Initiating FLR\n");
  8245. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8246. return 0;
  8247. }
  8248. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8249. {
  8250. int rc;
  8251. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8252. /* Test if previous unload process was already finished for this path */
  8253. if (bnx2x_prev_is_path_marked(bp))
  8254. return bnx2x_prev_mcp_done(bp);
  8255. BNX2X_DEV_INFO("Path is unmarked\n");
  8256. /* If function has FLR capabilities, and existing FW version matches
  8257. * the one required, then FLR will be sufficient to clean any residue
  8258. * left by previous driver
  8259. */
  8260. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8261. if (!rc) {
  8262. /* fw version is good */
  8263. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8264. rc = bnx2x_do_flr(bp);
  8265. }
  8266. if (!rc) {
  8267. /* FLR was performed */
  8268. BNX2X_DEV_INFO("FLR successful\n");
  8269. return 0;
  8270. }
  8271. BNX2X_DEV_INFO("Could not FLR\n");
  8272. /* Close the MCP request, return failure*/
  8273. rc = bnx2x_prev_mcp_done(bp);
  8274. if (!rc)
  8275. rc = BNX2X_PREV_WAIT_NEEDED;
  8276. return rc;
  8277. }
  8278. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8279. {
  8280. u32 reset_reg, tmp_reg = 0, rc;
  8281. bool prev_undi = false;
  8282. struct bnx2x_mac_vals mac_vals;
  8283. /* It is possible a previous function received 'common' answer,
  8284. * but hasn't loaded yet, therefore creating a scenario of
  8285. * multiple functions receiving 'common' on the same path.
  8286. */
  8287. BNX2X_DEV_INFO("Common unload Flow\n");
  8288. memset(&mac_vals, 0, sizeof(mac_vals));
  8289. if (bnx2x_prev_is_path_marked(bp))
  8290. return bnx2x_prev_mcp_done(bp);
  8291. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8292. /* Reset should be performed after BRB is emptied */
  8293. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8294. u32 timer_count = 1000;
  8295. /* Close the MAC Rx to prevent BRB from filling up */
  8296. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8297. /* close LLH filters towards the BRB */
  8298. bnx2x_set_rx_filter(&bp->link_params, 0);
  8299. /* Check if the UNDI driver was previously loaded
  8300. * UNDI driver initializes CID offset for normal bell to 0x7
  8301. */
  8302. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8303. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8304. if (tmp_reg == 0x7) {
  8305. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8306. prev_undi = true;
  8307. /* clear the UNDI indication */
  8308. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8309. /* clear possible idle check errors */
  8310. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8311. }
  8312. }
  8313. if (!CHIP_IS_E1x(bp))
  8314. /* block FW from writing to host */
  8315. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8316. /* wait until BRB is empty */
  8317. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8318. while (timer_count) {
  8319. u32 prev_brb = tmp_reg;
  8320. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8321. if (!tmp_reg)
  8322. break;
  8323. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8324. /* reset timer as long as BRB actually gets emptied */
  8325. if (prev_brb > tmp_reg)
  8326. timer_count = 1000;
  8327. else
  8328. timer_count--;
  8329. /* If UNDI resides in memory, manually increment it */
  8330. if (prev_undi)
  8331. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8332. udelay(10);
  8333. }
  8334. if (!timer_count)
  8335. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8336. }
  8337. /* No packets are in the pipeline, path is ready for reset */
  8338. bnx2x_reset_common(bp);
  8339. if (mac_vals.xmac_addr)
  8340. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8341. if (mac_vals.umac_addr)
  8342. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8343. if (mac_vals.emac_addr)
  8344. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8345. if (mac_vals.bmac_addr) {
  8346. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8347. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8348. }
  8349. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8350. if (rc) {
  8351. bnx2x_prev_mcp_done(bp);
  8352. return rc;
  8353. }
  8354. return bnx2x_prev_mcp_done(bp);
  8355. }
  8356. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8357. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8358. * the addresses of the transaction, resulting in was-error bit set in the pci
  8359. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8360. * to clear the interrupt which detected this from the pglueb and the was done
  8361. * bit
  8362. */
  8363. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8364. {
  8365. if (!CHIP_IS_E1x(bp)) {
  8366. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8367. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8368. DP(BNX2X_MSG_SP,
  8369. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8370. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8371. 1 << BP_FUNC(bp));
  8372. }
  8373. }
  8374. }
  8375. static int bnx2x_prev_unload(struct bnx2x *bp)
  8376. {
  8377. int time_counter = 10;
  8378. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8379. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8380. /* clear hw from errors which may have resulted from an interrupted
  8381. * dmae transaction.
  8382. */
  8383. bnx2x_prev_interrupted_dmae(bp);
  8384. /* Release previously held locks */
  8385. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8386. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8387. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8388. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8389. if (hw_lock_val) {
  8390. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8391. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8392. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8393. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8394. }
  8395. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8396. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8397. } else
  8398. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8399. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8400. BNX2X_DEV_INFO("Release previously held alr\n");
  8401. bnx2x_release_alr(bp);
  8402. }
  8403. do {
  8404. int aer = 0;
  8405. /* Lock MCP using an unload request */
  8406. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8407. if (!fw) {
  8408. BNX2X_ERR("MCP response failure, aborting\n");
  8409. rc = -EBUSY;
  8410. break;
  8411. }
  8412. rc = down_interruptible(&bnx2x_prev_sem);
  8413. if (rc) {
  8414. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8415. rc);
  8416. } else {
  8417. /* If Path is marked by EEH, ignore unload status */
  8418. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8419. bnx2x_prev_path_get_entry(bp)->aer);
  8420. up(&bnx2x_prev_sem);
  8421. }
  8422. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8423. rc = bnx2x_prev_unload_common(bp);
  8424. break;
  8425. }
  8426. /* non-common reply from MCP might require looping */
  8427. rc = bnx2x_prev_unload_uncommon(bp);
  8428. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8429. break;
  8430. msleep(20);
  8431. } while (--time_counter);
  8432. if (!time_counter || rc) {
  8433. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8434. rc = -EBUSY;
  8435. }
  8436. /* Mark function if its port was used to boot from SAN */
  8437. if (bnx2x_port_after_undi(bp))
  8438. bp->link_params.feature_config_flags |=
  8439. FEATURE_CONFIG_BOOT_FROM_SAN;
  8440. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8441. return rc;
  8442. }
  8443. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8444. {
  8445. u32 val, val2, val3, val4, id, boot_mode;
  8446. u16 pmc;
  8447. /* Get the chip revision id and number. */
  8448. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8449. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8450. id = ((val & 0xffff) << 16);
  8451. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8452. id |= ((val & 0xf) << 12);
  8453. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8454. * the configuration space (so we need to reg_rd)
  8455. */
  8456. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8457. id |= (((val >> 24) & 0xf) << 4);
  8458. val = REG_RD(bp, MISC_REG_BOND_ID);
  8459. id |= (val & 0xf);
  8460. bp->common.chip_id = id;
  8461. /* force 57811 according to MISC register */
  8462. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8463. if (CHIP_IS_57810(bp))
  8464. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8465. (bp->common.chip_id & 0x0000FFFF);
  8466. else if (CHIP_IS_57810_MF(bp))
  8467. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8468. (bp->common.chip_id & 0x0000FFFF);
  8469. bp->common.chip_id |= 0x1;
  8470. }
  8471. /* Set doorbell size */
  8472. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8473. if (!CHIP_IS_E1x(bp)) {
  8474. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8475. if ((val & 1) == 0)
  8476. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8477. else
  8478. val = (val >> 1) & 1;
  8479. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8480. "2_PORT_MODE");
  8481. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8482. CHIP_2_PORT_MODE;
  8483. if (CHIP_MODE_IS_4_PORT(bp))
  8484. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8485. else
  8486. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8487. } else {
  8488. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8489. bp->pfid = bp->pf_num; /* 0..7 */
  8490. }
  8491. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8492. bp->link_params.chip_id = bp->common.chip_id;
  8493. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8494. val = (REG_RD(bp, 0x2874) & 0x55);
  8495. if ((bp->common.chip_id & 0x1) ||
  8496. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8497. bp->flags |= ONE_PORT_FLAG;
  8498. BNX2X_DEV_INFO("single port device\n");
  8499. }
  8500. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8501. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8502. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8503. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8504. bp->common.flash_size, bp->common.flash_size);
  8505. bnx2x_init_shmem(bp);
  8506. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8507. MISC_REG_GENERIC_CR_1 :
  8508. MISC_REG_GENERIC_CR_0));
  8509. bp->link_params.shmem_base = bp->common.shmem_base;
  8510. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8511. if (SHMEM2_RD(bp, size) >
  8512. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8513. bp->link_params.lfa_base =
  8514. REG_RD(bp, bp->common.shmem2_base +
  8515. (u32)offsetof(struct shmem2_region,
  8516. lfa_host_addr[BP_PORT(bp)]));
  8517. else
  8518. bp->link_params.lfa_base = 0;
  8519. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8520. bp->common.shmem_base, bp->common.shmem2_base);
  8521. if (!bp->common.shmem_base) {
  8522. BNX2X_DEV_INFO("MCP not active\n");
  8523. bp->flags |= NO_MCP_FLAG;
  8524. return;
  8525. }
  8526. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8527. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8528. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8529. SHARED_HW_CFG_LED_MODE_MASK) >>
  8530. SHARED_HW_CFG_LED_MODE_SHIFT);
  8531. bp->link_params.feature_config_flags = 0;
  8532. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8533. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8534. bp->link_params.feature_config_flags |=
  8535. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8536. else
  8537. bp->link_params.feature_config_flags &=
  8538. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8539. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8540. bp->common.bc_ver = val;
  8541. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8542. if (val < BNX2X_BC_VER) {
  8543. /* for now only warn
  8544. * later we might need to enforce this */
  8545. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8546. BNX2X_BC_VER, val);
  8547. }
  8548. bp->link_params.feature_config_flags |=
  8549. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8550. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8551. bp->link_params.feature_config_flags |=
  8552. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8553. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8554. bp->link_params.feature_config_flags |=
  8555. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8556. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8557. bp->link_params.feature_config_flags |=
  8558. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8559. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8560. bp->link_params.feature_config_flags |=
  8561. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8562. FEATURE_CONFIG_MT_SUPPORT : 0;
  8563. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8564. BC_SUPPORTS_PFC_STATS : 0;
  8565. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8566. BC_SUPPORTS_FCOE_FEATURES : 0;
  8567. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8568. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8569. boot_mode = SHMEM_RD(bp,
  8570. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8571. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8572. switch (boot_mode) {
  8573. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8574. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8575. break;
  8576. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8577. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8578. break;
  8579. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8580. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8581. break;
  8582. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8583. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8584. break;
  8585. }
  8586. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8587. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8588. BNX2X_DEV_INFO("%sWoL capable\n",
  8589. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8590. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8591. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8592. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8593. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8594. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8595. val, val2, val3, val4);
  8596. }
  8597. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8598. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8599. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8600. {
  8601. int pfid = BP_FUNC(bp);
  8602. int igu_sb_id;
  8603. u32 val;
  8604. u8 fid, igu_sb_cnt = 0;
  8605. bp->igu_base_sb = 0xff;
  8606. if (CHIP_INT_MODE_IS_BC(bp)) {
  8607. int vn = BP_VN(bp);
  8608. igu_sb_cnt = bp->igu_sb_cnt;
  8609. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8610. FP_SB_MAX_E1x;
  8611. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8612. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8613. return 0;
  8614. }
  8615. /* IGU in normal mode - read CAM */
  8616. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8617. igu_sb_id++) {
  8618. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8619. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8620. continue;
  8621. fid = IGU_FID(val);
  8622. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8623. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8624. continue;
  8625. if (IGU_VEC(val) == 0)
  8626. /* default status block */
  8627. bp->igu_dsb_id = igu_sb_id;
  8628. else {
  8629. if (bp->igu_base_sb == 0xff)
  8630. bp->igu_base_sb = igu_sb_id;
  8631. igu_sb_cnt++;
  8632. }
  8633. }
  8634. }
  8635. #ifdef CONFIG_PCI_MSI
  8636. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8637. * optional that number of CAM entries will not be equal to the value
  8638. * advertised in PCI.
  8639. * Driver should use the minimal value of both as the actual status
  8640. * block count
  8641. */
  8642. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8643. #endif
  8644. if (igu_sb_cnt == 0) {
  8645. BNX2X_ERR("CAM configuration error\n");
  8646. return -EINVAL;
  8647. }
  8648. return 0;
  8649. }
  8650. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8651. {
  8652. int cfg_size = 0, idx, port = BP_PORT(bp);
  8653. /* Aggregation of supported attributes of all external phys */
  8654. bp->port.supported[0] = 0;
  8655. bp->port.supported[1] = 0;
  8656. switch (bp->link_params.num_phys) {
  8657. case 1:
  8658. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8659. cfg_size = 1;
  8660. break;
  8661. case 2:
  8662. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8663. cfg_size = 1;
  8664. break;
  8665. case 3:
  8666. if (bp->link_params.multi_phy_config &
  8667. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8668. bp->port.supported[1] =
  8669. bp->link_params.phy[EXT_PHY1].supported;
  8670. bp->port.supported[0] =
  8671. bp->link_params.phy[EXT_PHY2].supported;
  8672. } else {
  8673. bp->port.supported[0] =
  8674. bp->link_params.phy[EXT_PHY1].supported;
  8675. bp->port.supported[1] =
  8676. bp->link_params.phy[EXT_PHY2].supported;
  8677. }
  8678. cfg_size = 2;
  8679. break;
  8680. }
  8681. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8682. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8683. SHMEM_RD(bp,
  8684. dev_info.port_hw_config[port].external_phy_config),
  8685. SHMEM_RD(bp,
  8686. dev_info.port_hw_config[port].external_phy_config2));
  8687. return;
  8688. }
  8689. if (CHIP_IS_E3(bp))
  8690. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8691. else {
  8692. switch (switch_cfg) {
  8693. case SWITCH_CFG_1G:
  8694. bp->port.phy_addr = REG_RD(
  8695. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8696. break;
  8697. case SWITCH_CFG_10G:
  8698. bp->port.phy_addr = REG_RD(
  8699. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8700. break;
  8701. default:
  8702. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8703. bp->port.link_config[0]);
  8704. return;
  8705. }
  8706. }
  8707. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8708. /* mask what we support according to speed_cap_mask per configuration */
  8709. for (idx = 0; idx < cfg_size; idx++) {
  8710. if (!(bp->link_params.speed_cap_mask[idx] &
  8711. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8712. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8713. if (!(bp->link_params.speed_cap_mask[idx] &
  8714. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8715. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8716. if (!(bp->link_params.speed_cap_mask[idx] &
  8717. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8718. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8719. if (!(bp->link_params.speed_cap_mask[idx] &
  8720. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8721. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8722. if (!(bp->link_params.speed_cap_mask[idx] &
  8723. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8724. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8725. SUPPORTED_1000baseT_Full);
  8726. if (!(bp->link_params.speed_cap_mask[idx] &
  8727. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8728. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8729. if (!(bp->link_params.speed_cap_mask[idx] &
  8730. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8731. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8732. }
  8733. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8734. bp->port.supported[1]);
  8735. }
  8736. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8737. {
  8738. u32 link_config, idx, cfg_size = 0;
  8739. bp->port.advertising[0] = 0;
  8740. bp->port.advertising[1] = 0;
  8741. switch (bp->link_params.num_phys) {
  8742. case 1:
  8743. case 2:
  8744. cfg_size = 1;
  8745. break;
  8746. case 3:
  8747. cfg_size = 2;
  8748. break;
  8749. }
  8750. for (idx = 0; idx < cfg_size; idx++) {
  8751. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8752. link_config = bp->port.link_config[idx];
  8753. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8754. case PORT_FEATURE_LINK_SPEED_AUTO:
  8755. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8756. bp->link_params.req_line_speed[idx] =
  8757. SPEED_AUTO_NEG;
  8758. bp->port.advertising[idx] |=
  8759. bp->port.supported[idx];
  8760. if (bp->link_params.phy[EXT_PHY1].type ==
  8761. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8762. bp->port.advertising[idx] |=
  8763. (SUPPORTED_100baseT_Half |
  8764. SUPPORTED_100baseT_Full);
  8765. } else {
  8766. /* force 10G, no AN */
  8767. bp->link_params.req_line_speed[idx] =
  8768. SPEED_10000;
  8769. bp->port.advertising[idx] |=
  8770. (ADVERTISED_10000baseT_Full |
  8771. ADVERTISED_FIBRE);
  8772. continue;
  8773. }
  8774. break;
  8775. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8776. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8777. bp->link_params.req_line_speed[idx] =
  8778. SPEED_10;
  8779. bp->port.advertising[idx] |=
  8780. (ADVERTISED_10baseT_Full |
  8781. ADVERTISED_TP);
  8782. } else {
  8783. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8784. link_config,
  8785. bp->link_params.speed_cap_mask[idx]);
  8786. return;
  8787. }
  8788. break;
  8789. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8790. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8791. bp->link_params.req_line_speed[idx] =
  8792. SPEED_10;
  8793. bp->link_params.req_duplex[idx] =
  8794. DUPLEX_HALF;
  8795. bp->port.advertising[idx] |=
  8796. (ADVERTISED_10baseT_Half |
  8797. ADVERTISED_TP);
  8798. } else {
  8799. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8800. link_config,
  8801. bp->link_params.speed_cap_mask[idx]);
  8802. return;
  8803. }
  8804. break;
  8805. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8806. if (bp->port.supported[idx] &
  8807. SUPPORTED_100baseT_Full) {
  8808. bp->link_params.req_line_speed[idx] =
  8809. SPEED_100;
  8810. bp->port.advertising[idx] |=
  8811. (ADVERTISED_100baseT_Full |
  8812. ADVERTISED_TP);
  8813. } else {
  8814. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8815. link_config,
  8816. bp->link_params.speed_cap_mask[idx]);
  8817. return;
  8818. }
  8819. break;
  8820. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8821. if (bp->port.supported[idx] &
  8822. SUPPORTED_100baseT_Half) {
  8823. bp->link_params.req_line_speed[idx] =
  8824. SPEED_100;
  8825. bp->link_params.req_duplex[idx] =
  8826. DUPLEX_HALF;
  8827. bp->port.advertising[idx] |=
  8828. (ADVERTISED_100baseT_Half |
  8829. ADVERTISED_TP);
  8830. } else {
  8831. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8832. link_config,
  8833. bp->link_params.speed_cap_mask[idx]);
  8834. return;
  8835. }
  8836. break;
  8837. case PORT_FEATURE_LINK_SPEED_1G:
  8838. if (bp->port.supported[idx] &
  8839. SUPPORTED_1000baseT_Full) {
  8840. bp->link_params.req_line_speed[idx] =
  8841. SPEED_1000;
  8842. bp->port.advertising[idx] |=
  8843. (ADVERTISED_1000baseT_Full |
  8844. ADVERTISED_TP);
  8845. } else {
  8846. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8847. link_config,
  8848. bp->link_params.speed_cap_mask[idx]);
  8849. return;
  8850. }
  8851. break;
  8852. case PORT_FEATURE_LINK_SPEED_2_5G:
  8853. if (bp->port.supported[idx] &
  8854. SUPPORTED_2500baseX_Full) {
  8855. bp->link_params.req_line_speed[idx] =
  8856. SPEED_2500;
  8857. bp->port.advertising[idx] |=
  8858. (ADVERTISED_2500baseX_Full |
  8859. ADVERTISED_TP);
  8860. } else {
  8861. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8862. link_config,
  8863. bp->link_params.speed_cap_mask[idx]);
  8864. return;
  8865. }
  8866. break;
  8867. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8868. if (bp->port.supported[idx] &
  8869. SUPPORTED_10000baseT_Full) {
  8870. bp->link_params.req_line_speed[idx] =
  8871. SPEED_10000;
  8872. bp->port.advertising[idx] |=
  8873. (ADVERTISED_10000baseT_Full |
  8874. ADVERTISED_FIBRE);
  8875. } else {
  8876. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8877. link_config,
  8878. bp->link_params.speed_cap_mask[idx]);
  8879. return;
  8880. }
  8881. break;
  8882. case PORT_FEATURE_LINK_SPEED_20G:
  8883. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8884. break;
  8885. default:
  8886. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8887. link_config);
  8888. bp->link_params.req_line_speed[idx] =
  8889. SPEED_AUTO_NEG;
  8890. bp->port.advertising[idx] =
  8891. bp->port.supported[idx];
  8892. break;
  8893. }
  8894. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8895. PORT_FEATURE_FLOW_CONTROL_MASK);
  8896. if (bp->link_params.req_flow_ctrl[idx] ==
  8897. BNX2X_FLOW_CTRL_AUTO) {
  8898. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8899. bp->link_params.req_flow_ctrl[idx] =
  8900. BNX2X_FLOW_CTRL_NONE;
  8901. else
  8902. bnx2x_set_requested_fc(bp);
  8903. }
  8904. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8905. bp->link_params.req_line_speed[idx],
  8906. bp->link_params.req_duplex[idx],
  8907. bp->link_params.req_flow_ctrl[idx],
  8908. bp->port.advertising[idx]);
  8909. }
  8910. }
  8911. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8912. {
  8913. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  8914. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  8915. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  8916. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  8917. }
  8918. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8919. {
  8920. int port = BP_PORT(bp);
  8921. u32 config;
  8922. u32 ext_phy_type, ext_phy_config, eee_mode;
  8923. bp->link_params.bp = bp;
  8924. bp->link_params.port = port;
  8925. bp->link_params.lane_config =
  8926. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8927. bp->link_params.speed_cap_mask[0] =
  8928. SHMEM_RD(bp,
  8929. dev_info.port_hw_config[port].speed_capability_mask) &
  8930. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  8931. bp->link_params.speed_cap_mask[1] =
  8932. SHMEM_RD(bp,
  8933. dev_info.port_hw_config[port].speed_capability_mask2) &
  8934. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  8935. bp->port.link_config[0] =
  8936. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8937. bp->port.link_config[1] =
  8938. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8939. bp->link_params.multi_phy_config =
  8940. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8941. /* If the device is capable of WoL, set the default state according
  8942. * to the HW
  8943. */
  8944. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8945. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8946. (config & PORT_FEATURE_WOL_ENABLED));
  8947. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8948. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  8949. bp->flags |= NO_ISCSI_FLAG;
  8950. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8951. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  8952. bp->flags |= NO_FCOE_FLAG;
  8953. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8954. bp->link_params.lane_config,
  8955. bp->link_params.speed_cap_mask[0],
  8956. bp->port.link_config[0]);
  8957. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8958. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8959. bnx2x_phy_probe(&bp->link_params);
  8960. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8961. bnx2x_link_settings_requested(bp);
  8962. /*
  8963. * If connected directly, work with the internal PHY, otherwise, work
  8964. * with the external PHY
  8965. */
  8966. ext_phy_config =
  8967. SHMEM_RD(bp,
  8968. dev_info.port_hw_config[port].external_phy_config);
  8969. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8970. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8971. bp->mdio.prtad = bp->port.phy_addr;
  8972. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8973. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8974. bp->mdio.prtad =
  8975. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8976. /* Configure link feature according to nvram value */
  8977. eee_mode = (((SHMEM_RD(bp, dev_info.
  8978. port_feature_config[port].eee_power_mode)) &
  8979. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8980. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8981. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8982. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8983. EEE_MODE_ENABLE_LPI |
  8984. EEE_MODE_OUTPUT_TIME;
  8985. } else {
  8986. bp->link_params.eee_mode = 0;
  8987. }
  8988. }
  8989. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8990. {
  8991. u32 no_flags = NO_ISCSI_FLAG;
  8992. int port = BP_PORT(bp);
  8993. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8994. drv_lic_key[port].max_iscsi_conn);
  8995. if (!CNIC_SUPPORT(bp)) {
  8996. bp->flags |= no_flags;
  8997. return;
  8998. }
  8999. /* Get the number of maximum allowed iSCSI connections */
  9000. bp->cnic_eth_dev.max_iscsi_conn =
  9001. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9002. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9003. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9004. bp->cnic_eth_dev.max_iscsi_conn);
  9005. /*
  9006. * If maximum allowed number of connections is zero -
  9007. * disable the feature.
  9008. */
  9009. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9010. bp->flags |= no_flags;
  9011. }
  9012. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9013. {
  9014. /* Port info */
  9015. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9016. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9017. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9018. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9019. /* Node info */
  9020. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9021. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9022. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9023. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9024. }
  9025. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9026. {
  9027. u8 count = 0;
  9028. if (IS_MF(bp)) {
  9029. u8 fid;
  9030. /* iterate over absolute function ids for this path: */
  9031. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9032. if (IS_MF_SD(bp)) {
  9033. u32 cfg = MF_CFG_RD(bp,
  9034. func_mf_config[fid].config);
  9035. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9036. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9037. FUNC_MF_CFG_PROTOCOL_FCOE))
  9038. count++;
  9039. } else {
  9040. u32 cfg = MF_CFG_RD(bp,
  9041. func_ext_config[fid].
  9042. func_cfg);
  9043. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9044. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9045. count++;
  9046. }
  9047. }
  9048. } else { /* SF */
  9049. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9050. for (port = 0; port < port_cnt; port++) {
  9051. u32 lic = SHMEM_RD(bp,
  9052. drv_lic_key[port].max_fcoe_conn) ^
  9053. FW_ENCODE_32BIT_PATTERN;
  9054. if (lic)
  9055. count++;
  9056. }
  9057. }
  9058. return count;
  9059. }
  9060. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9061. {
  9062. int port = BP_PORT(bp);
  9063. int func = BP_ABS_FUNC(bp);
  9064. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9065. drv_lic_key[port].max_fcoe_conn);
  9066. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9067. if (!CNIC_SUPPORT(bp)) {
  9068. bp->flags |= NO_FCOE_FLAG;
  9069. return;
  9070. }
  9071. /* Get the number of maximum allowed FCoE connections */
  9072. bp->cnic_eth_dev.max_fcoe_conn =
  9073. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9074. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9075. /* Calculate the number of maximum allowed FCoE tasks */
  9076. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9077. /* check if FCoE resources must be shared between different functions */
  9078. if (num_fcoe_func)
  9079. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9080. /* Read the WWN: */
  9081. if (!IS_MF(bp)) {
  9082. /* Port info */
  9083. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9084. SHMEM_RD(bp,
  9085. dev_info.port_hw_config[port].
  9086. fcoe_wwn_port_name_upper);
  9087. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9088. SHMEM_RD(bp,
  9089. dev_info.port_hw_config[port].
  9090. fcoe_wwn_port_name_lower);
  9091. /* Node info */
  9092. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9093. SHMEM_RD(bp,
  9094. dev_info.port_hw_config[port].
  9095. fcoe_wwn_node_name_upper);
  9096. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9097. SHMEM_RD(bp,
  9098. dev_info.port_hw_config[port].
  9099. fcoe_wwn_node_name_lower);
  9100. } else if (!IS_MF_SD(bp)) {
  9101. /*
  9102. * Read the WWN info only if the FCoE feature is enabled for
  9103. * this function.
  9104. */
  9105. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9106. bnx2x_get_ext_wwn_info(bp, func);
  9107. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9108. bnx2x_get_ext_wwn_info(bp, func);
  9109. }
  9110. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9111. /*
  9112. * If maximum allowed number of connections is zero -
  9113. * disable the feature.
  9114. */
  9115. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9116. bp->flags |= NO_FCOE_FLAG;
  9117. }
  9118. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9119. {
  9120. /*
  9121. * iSCSI may be dynamically disabled but reading
  9122. * info here we will decrease memory usage by driver
  9123. * if the feature is disabled for good
  9124. */
  9125. bnx2x_get_iscsi_info(bp);
  9126. bnx2x_get_fcoe_info(bp);
  9127. }
  9128. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9129. {
  9130. u32 val, val2;
  9131. int func = BP_ABS_FUNC(bp);
  9132. int port = BP_PORT(bp);
  9133. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9134. u8 *fip_mac = bp->fip_mac;
  9135. if (IS_MF(bp)) {
  9136. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9137. * FCoE MAC then the appropriate feature should be disabled.
  9138. * In non SD mode features configuration comes from struct
  9139. * func_ext_config.
  9140. */
  9141. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9142. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9143. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9144. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9145. iscsi_mac_addr_upper);
  9146. val = MF_CFG_RD(bp, func_ext_config[func].
  9147. iscsi_mac_addr_lower);
  9148. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9149. BNX2X_DEV_INFO
  9150. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9151. } else {
  9152. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9153. }
  9154. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9155. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9156. fcoe_mac_addr_upper);
  9157. val = MF_CFG_RD(bp, func_ext_config[func].
  9158. fcoe_mac_addr_lower);
  9159. bnx2x_set_mac_buf(fip_mac, val, val2);
  9160. BNX2X_DEV_INFO
  9161. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9162. } else {
  9163. bp->flags |= NO_FCOE_FLAG;
  9164. }
  9165. bp->mf_ext_config = cfg;
  9166. } else { /* SD MODE */
  9167. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9168. /* use primary mac as iscsi mac */
  9169. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9170. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9171. BNX2X_DEV_INFO
  9172. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9173. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9174. /* use primary mac as fip mac */
  9175. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9176. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9177. BNX2X_DEV_INFO
  9178. ("Read FIP MAC: %pM\n", fip_mac);
  9179. }
  9180. }
  9181. /* If this is a storage-only interface, use SAN mac as
  9182. * primary MAC. Notice that for SD this is already the case,
  9183. * as the SAN mac was copied from the primary MAC.
  9184. */
  9185. if (IS_MF_FCOE_AFEX(bp))
  9186. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9187. } else {
  9188. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9189. iscsi_mac_upper);
  9190. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9191. iscsi_mac_lower);
  9192. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9193. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9194. fcoe_fip_mac_upper);
  9195. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9196. fcoe_fip_mac_lower);
  9197. bnx2x_set_mac_buf(fip_mac, val, val2);
  9198. }
  9199. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9200. if (!is_valid_ether_addr(iscsi_mac)) {
  9201. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9202. memset(iscsi_mac, 0, ETH_ALEN);
  9203. }
  9204. /* Disable FCoE if MAC configuration is invalid. */
  9205. if (!is_valid_ether_addr(fip_mac)) {
  9206. bp->flags |= NO_FCOE_FLAG;
  9207. memset(bp->fip_mac, 0, ETH_ALEN);
  9208. }
  9209. }
  9210. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9211. {
  9212. u32 val, val2;
  9213. int func = BP_ABS_FUNC(bp);
  9214. int port = BP_PORT(bp);
  9215. /* Zero primary MAC configuration */
  9216. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9217. if (BP_NOMCP(bp)) {
  9218. BNX2X_ERROR("warning: random MAC workaround active\n");
  9219. eth_hw_addr_random(bp->dev);
  9220. } else if (IS_MF(bp)) {
  9221. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9222. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9223. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9224. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9225. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9226. if (CNIC_SUPPORT(bp))
  9227. bnx2x_get_cnic_mac_hwinfo(bp);
  9228. } else {
  9229. /* in SF read MACs from port configuration */
  9230. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9231. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9232. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9233. if (CNIC_SUPPORT(bp))
  9234. bnx2x_get_cnic_mac_hwinfo(bp);
  9235. }
  9236. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9237. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9238. dev_err(&bp->pdev->dev,
  9239. "bad Ethernet MAC address configuration: %pM\n"
  9240. "change it manually before bringing up the appropriate network interface\n",
  9241. bp->dev->dev_addr);
  9242. }
  9243. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9244. {
  9245. int tmp;
  9246. u32 cfg;
  9247. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9248. /* Take function: tmp = func */
  9249. tmp = BP_ABS_FUNC(bp);
  9250. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9251. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9252. } else {
  9253. /* Take port: tmp = port */
  9254. tmp = BP_PORT(bp);
  9255. cfg = SHMEM_RD(bp,
  9256. dev_info.port_hw_config[tmp].generic_features);
  9257. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9258. }
  9259. return cfg;
  9260. }
  9261. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9262. {
  9263. int /*abs*/func = BP_ABS_FUNC(bp);
  9264. int vn;
  9265. u32 val = 0;
  9266. int rc = 0;
  9267. bnx2x_get_common_hwinfo(bp);
  9268. /*
  9269. * initialize IGU parameters
  9270. */
  9271. if (CHIP_IS_E1x(bp)) {
  9272. bp->common.int_block = INT_BLOCK_HC;
  9273. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9274. bp->igu_base_sb = 0;
  9275. } else {
  9276. bp->common.int_block = INT_BLOCK_IGU;
  9277. /* do not allow device reset during IGU info processing */
  9278. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9279. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9280. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9281. int tout = 5000;
  9282. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9283. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9284. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9285. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9286. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9287. tout--;
  9288. usleep_range(1000, 2000);
  9289. }
  9290. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9291. dev_err(&bp->pdev->dev,
  9292. "FORCING Normal Mode failed!!!\n");
  9293. bnx2x_release_hw_lock(bp,
  9294. HW_LOCK_RESOURCE_RESET);
  9295. return -EPERM;
  9296. }
  9297. }
  9298. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9299. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9300. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9301. } else
  9302. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9303. rc = bnx2x_get_igu_cam_info(bp);
  9304. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9305. if (rc)
  9306. return rc;
  9307. }
  9308. /*
  9309. * set base FW non-default (fast path) status block id, this value is
  9310. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9311. * determine the id used by the FW.
  9312. */
  9313. if (CHIP_IS_E1x(bp))
  9314. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9315. else /*
  9316. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9317. * the same queue are indicated on the same IGU SB). So we prefer
  9318. * FW and IGU SBs to be the same value.
  9319. */
  9320. bp->base_fw_ndsb = bp->igu_base_sb;
  9321. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9322. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9323. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9324. /*
  9325. * Initialize MF configuration
  9326. */
  9327. bp->mf_ov = 0;
  9328. bp->mf_mode = 0;
  9329. vn = BP_VN(bp);
  9330. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9331. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9332. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9333. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9334. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9335. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9336. else
  9337. bp->common.mf_cfg_base = bp->common.shmem_base +
  9338. offsetof(struct shmem_region, func_mb) +
  9339. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9340. /*
  9341. * get mf configuration:
  9342. * 1. Existence of MF configuration
  9343. * 2. MAC address must be legal (check only upper bytes)
  9344. * for Switch-Independent mode;
  9345. * OVLAN must be legal for Switch-Dependent mode
  9346. * 3. SF_MODE configures specific MF mode
  9347. */
  9348. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9349. /* get mf configuration */
  9350. val = SHMEM_RD(bp,
  9351. dev_info.shared_feature_config.config);
  9352. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9353. switch (val) {
  9354. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9355. val = MF_CFG_RD(bp, func_mf_config[func].
  9356. mac_upper);
  9357. /* check for legal mac (upper bytes)*/
  9358. if (val != 0xffff) {
  9359. bp->mf_mode = MULTI_FUNCTION_SI;
  9360. bp->mf_config[vn] = MF_CFG_RD(bp,
  9361. func_mf_config[func].config);
  9362. } else
  9363. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9364. break;
  9365. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9366. if ((!CHIP_IS_E1x(bp)) &&
  9367. (MF_CFG_RD(bp, func_mf_config[func].
  9368. mac_upper) != 0xffff) &&
  9369. (SHMEM2_HAS(bp,
  9370. afex_driver_support))) {
  9371. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9372. bp->mf_config[vn] = MF_CFG_RD(bp,
  9373. func_mf_config[func].config);
  9374. } else {
  9375. BNX2X_DEV_INFO("can not configure afex mode\n");
  9376. }
  9377. break;
  9378. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9379. /* get OV configuration */
  9380. val = MF_CFG_RD(bp,
  9381. func_mf_config[FUNC_0].e1hov_tag);
  9382. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9383. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9384. bp->mf_mode = MULTI_FUNCTION_SD;
  9385. bp->mf_config[vn] = MF_CFG_RD(bp,
  9386. func_mf_config[func].config);
  9387. } else
  9388. BNX2X_DEV_INFO("illegal OV for SD\n");
  9389. break;
  9390. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9391. bp->mf_config[vn] = 0;
  9392. break;
  9393. default:
  9394. /* Unknown configuration: reset mf_config */
  9395. bp->mf_config[vn] = 0;
  9396. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9397. }
  9398. }
  9399. BNX2X_DEV_INFO("%s function mode\n",
  9400. IS_MF(bp) ? "multi" : "single");
  9401. switch (bp->mf_mode) {
  9402. case MULTI_FUNCTION_SD:
  9403. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9404. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9405. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9406. bp->mf_ov = val;
  9407. bp->path_has_ovlan = true;
  9408. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9409. func, bp->mf_ov, bp->mf_ov);
  9410. } else {
  9411. dev_err(&bp->pdev->dev,
  9412. "No valid MF OV for func %d, aborting\n",
  9413. func);
  9414. return -EPERM;
  9415. }
  9416. break;
  9417. case MULTI_FUNCTION_AFEX:
  9418. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9419. break;
  9420. case MULTI_FUNCTION_SI:
  9421. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9422. func);
  9423. break;
  9424. default:
  9425. if (vn) {
  9426. dev_err(&bp->pdev->dev,
  9427. "VN %d is in a single function mode, aborting\n",
  9428. vn);
  9429. return -EPERM;
  9430. }
  9431. break;
  9432. }
  9433. /* check if other port on the path needs ovlan:
  9434. * Since MF configuration is shared between ports
  9435. * Possible mixed modes are only
  9436. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9437. */
  9438. if (CHIP_MODE_IS_4_PORT(bp) &&
  9439. !bp->path_has_ovlan &&
  9440. !IS_MF(bp) &&
  9441. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9442. u8 other_port = !BP_PORT(bp);
  9443. u8 other_func = BP_PATH(bp) + 2*other_port;
  9444. val = MF_CFG_RD(bp,
  9445. func_mf_config[other_func].e1hov_tag);
  9446. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9447. bp->path_has_ovlan = true;
  9448. }
  9449. }
  9450. /* adjust igu_sb_cnt to MF for E1x */
  9451. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9452. bp->igu_sb_cnt /= E1HVN_MAX;
  9453. /* port info */
  9454. bnx2x_get_port_hwinfo(bp);
  9455. /* Get MAC addresses */
  9456. bnx2x_get_mac_hwinfo(bp);
  9457. bnx2x_get_cnic_info(bp);
  9458. return rc;
  9459. }
  9460. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9461. {
  9462. int cnt, i, block_end, rodi;
  9463. char vpd_start[BNX2X_VPD_LEN+1];
  9464. char str_id_reg[VENDOR_ID_LEN+1];
  9465. char str_id_cap[VENDOR_ID_LEN+1];
  9466. char *vpd_data;
  9467. char *vpd_extended_data = NULL;
  9468. u8 len;
  9469. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9470. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9471. if (cnt < BNX2X_VPD_LEN)
  9472. goto out_not_found;
  9473. /* VPD RO tag should be first tag after identifier string, hence
  9474. * we should be able to find it in first BNX2X_VPD_LEN chars
  9475. */
  9476. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9477. PCI_VPD_LRDT_RO_DATA);
  9478. if (i < 0)
  9479. goto out_not_found;
  9480. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9481. pci_vpd_lrdt_size(&vpd_start[i]);
  9482. i += PCI_VPD_LRDT_TAG_SIZE;
  9483. if (block_end > BNX2X_VPD_LEN) {
  9484. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9485. if (vpd_extended_data == NULL)
  9486. goto out_not_found;
  9487. /* read rest of vpd image into vpd_extended_data */
  9488. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9489. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9490. block_end - BNX2X_VPD_LEN,
  9491. vpd_extended_data + BNX2X_VPD_LEN);
  9492. if (cnt < (block_end - BNX2X_VPD_LEN))
  9493. goto out_not_found;
  9494. vpd_data = vpd_extended_data;
  9495. } else
  9496. vpd_data = vpd_start;
  9497. /* now vpd_data holds full vpd content in both cases */
  9498. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9499. PCI_VPD_RO_KEYWORD_MFR_ID);
  9500. if (rodi < 0)
  9501. goto out_not_found;
  9502. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9503. if (len != VENDOR_ID_LEN)
  9504. goto out_not_found;
  9505. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9506. /* vendor specific info */
  9507. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9508. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9509. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9510. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9511. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9512. PCI_VPD_RO_KEYWORD_VENDOR0);
  9513. if (rodi >= 0) {
  9514. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9515. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9516. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9517. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9518. bp->fw_ver[len] = ' ';
  9519. }
  9520. }
  9521. kfree(vpd_extended_data);
  9522. return;
  9523. }
  9524. out_not_found:
  9525. kfree(vpd_extended_data);
  9526. return;
  9527. }
  9528. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9529. {
  9530. u32 flags = 0;
  9531. if (CHIP_REV_IS_FPGA(bp))
  9532. SET_FLAGS(flags, MODE_FPGA);
  9533. else if (CHIP_REV_IS_EMUL(bp))
  9534. SET_FLAGS(flags, MODE_EMUL);
  9535. else
  9536. SET_FLAGS(flags, MODE_ASIC);
  9537. if (CHIP_MODE_IS_4_PORT(bp))
  9538. SET_FLAGS(flags, MODE_PORT4);
  9539. else
  9540. SET_FLAGS(flags, MODE_PORT2);
  9541. if (CHIP_IS_E2(bp))
  9542. SET_FLAGS(flags, MODE_E2);
  9543. else if (CHIP_IS_E3(bp)) {
  9544. SET_FLAGS(flags, MODE_E3);
  9545. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9546. SET_FLAGS(flags, MODE_E3_A0);
  9547. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9548. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9549. }
  9550. if (IS_MF(bp)) {
  9551. SET_FLAGS(flags, MODE_MF);
  9552. switch (bp->mf_mode) {
  9553. case MULTI_FUNCTION_SD:
  9554. SET_FLAGS(flags, MODE_MF_SD);
  9555. break;
  9556. case MULTI_FUNCTION_SI:
  9557. SET_FLAGS(flags, MODE_MF_SI);
  9558. break;
  9559. case MULTI_FUNCTION_AFEX:
  9560. SET_FLAGS(flags, MODE_MF_AFEX);
  9561. break;
  9562. }
  9563. } else
  9564. SET_FLAGS(flags, MODE_SF);
  9565. #if defined(__LITTLE_ENDIAN)
  9566. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9567. #else /*(__BIG_ENDIAN)*/
  9568. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9569. #endif
  9570. INIT_MODE_FLAGS(bp) = flags;
  9571. }
  9572. static int bnx2x_init_bp(struct bnx2x *bp)
  9573. {
  9574. int func;
  9575. int rc;
  9576. mutex_init(&bp->port.phy_mutex);
  9577. mutex_init(&bp->fw_mb_mutex);
  9578. spin_lock_init(&bp->stats_lock);
  9579. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9580. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9581. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9582. if (IS_PF(bp)) {
  9583. rc = bnx2x_get_hwinfo(bp);
  9584. if (rc)
  9585. return rc;
  9586. } else {
  9587. eth_zero_addr(bp->dev->dev_addr);
  9588. }
  9589. bnx2x_set_modes_bitmap(bp);
  9590. rc = bnx2x_alloc_mem_bp(bp);
  9591. if (rc)
  9592. return rc;
  9593. bnx2x_read_fwinfo(bp);
  9594. func = BP_FUNC(bp);
  9595. /* need to reset chip if undi was active */
  9596. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9597. /* init fw_seq */
  9598. bp->fw_seq =
  9599. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9600. DRV_MSG_SEQ_NUMBER_MASK;
  9601. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9602. bnx2x_prev_unload(bp);
  9603. }
  9604. if (CHIP_REV_IS_FPGA(bp))
  9605. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9606. if (BP_NOMCP(bp) && (func == 0))
  9607. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9608. bp->disable_tpa = disable_tpa;
  9609. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9610. /* Set TPA flags */
  9611. if (bp->disable_tpa) {
  9612. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9613. bp->dev->features &= ~NETIF_F_LRO;
  9614. } else {
  9615. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9616. bp->dev->features |= NETIF_F_LRO;
  9617. }
  9618. if (CHIP_IS_E1(bp))
  9619. bp->dropless_fc = 0;
  9620. else
  9621. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9622. bp->mrrs = mrrs;
  9623. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9624. if (IS_VF(bp))
  9625. bp->rx_ring_size = MAX_RX_AVAIL;
  9626. /* make sure that the numbers are in the right granularity */
  9627. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9628. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9629. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9630. init_timer(&bp->timer);
  9631. bp->timer.expires = jiffies + bp->current_interval;
  9632. bp->timer.data = (unsigned long) bp;
  9633. bp->timer.function = bnx2x_timer;
  9634. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9635. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9636. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9637. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9638. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9639. bnx2x_dcbx_init_params(bp);
  9640. } else {
  9641. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9642. }
  9643. if (CHIP_IS_E1x(bp))
  9644. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9645. else
  9646. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9647. /* multiple tx priority */
  9648. if (IS_VF(bp))
  9649. bp->max_cos = 1;
  9650. else if (CHIP_IS_E1x(bp))
  9651. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9652. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9653. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9654. else if (CHIP_IS_E3B0(bp))
  9655. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9656. else
  9657. BNX2X_ERR("unknown chip %x revision %x\n",
  9658. CHIP_NUM(bp), CHIP_REV(bp));
  9659. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9660. /* We need at least one default status block for slow-path events,
  9661. * second status block for the L2 queue, and a third status block for
  9662. * CNIC if supported.
  9663. */
  9664. if (CNIC_SUPPORT(bp))
  9665. bp->min_msix_vec_cnt = 3;
  9666. else
  9667. bp->min_msix_vec_cnt = 2;
  9668. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9669. return rc;
  9670. }
  9671. /****************************************************************************
  9672. * General service functions
  9673. ****************************************************************************/
  9674. /*
  9675. * net_device service functions
  9676. */
  9677. /* called with rtnl_lock */
  9678. static int bnx2x_open(struct net_device *dev)
  9679. {
  9680. struct bnx2x *bp = netdev_priv(dev);
  9681. bool global = false;
  9682. int other_engine = BP_PATH(bp) ? 0 : 1;
  9683. bool other_load_status, load_status;
  9684. int rc;
  9685. bp->stats_init = true;
  9686. netif_carrier_off(dev);
  9687. bnx2x_set_power_state(bp, PCI_D0);
  9688. /* If parity had happen during the unload, then attentions
  9689. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9690. * want the first function loaded on the current engine to
  9691. * complete the recovery.
  9692. * Parity recovery is only relevant for PF driver.
  9693. */
  9694. if (IS_PF(bp)) {
  9695. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9696. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9697. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9698. bnx2x_chk_parity_attn(bp, &global, true)) {
  9699. do {
  9700. /* If there are attentions and they are in a
  9701. * global blocks, set the GLOBAL_RESET bit
  9702. * regardless whether it will be this function
  9703. * that will complete the recovery or not.
  9704. */
  9705. if (global)
  9706. bnx2x_set_reset_global(bp);
  9707. /* Only the first function on the current
  9708. * engine should try to recover in open. In case
  9709. * of attentions in global blocks only the first
  9710. * in the chip should try to recover.
  9711. */
  9712. if ((!load_status &&
  9713. (!global || !other_load_status)) &&
  9714. bnx2x_trylock_leader_lock(bp) &&
  9715. !bnx2x_leader_reset(bp)) {
  9716. netdev_info(bp->dev,
  9717. "Recovered in open\n");
  9718. break;
  9719. }
  9720. /* recovery has failed... */
  9721. bnx2x_set_power_state(bp, PCI_D3hot);
  9722. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9723. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9724. "If you still see this message after a few retries then power cycle is required.\n");
  9725. return -EAGAIN;
  9726. } while (0);
  9727. }
  9728. }
  9729. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9730. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9731. if (rc)
  9732. return rc;
  9733. return bnx2x_open_epilog(bp);
  9734. }
  9735. /* called with rtnl_lock */
  9736. static int bnx2x_close(struct net_device *dev)
  9737. {
  9738. struct bnx2x *bp = netdev_priv(dev);
  9739. /* Unload the driver, release IRQs */
  9740. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9741. return 0;
  9742. }
  9743. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9744. struct bnx2x_mcast_ramrod_params *p)
  9745. {
  9746. int mc_count = netdev_mc_count(bp->dev);
  9747. struct bnx2x_mcast_list_elem *mc_mac =
  9748. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9749. struct netdev_hw_addr *ha;
  9750. if (!mc_mac)
  9751. return -ENOMEM;
  9752. INIT_LIST_HEAD(&p->mcast_list);
  9753. netdev_for_each_mc_addr(ha, bp->dev) {
  9754. mc_mac->mac = bnx2x_mc_addr(ha);
  9755. list_add_tail(&mc_mac->link, &p->mcast_list);
  9756. mc_mac++;
  9757. }
  9758. p->mcast_list_len = mc_count;
  9759. return 0;
  9760. }
  9761. static void bnx2x_free_mcast_macs_list(
  9762. struct bnx2x_mcast_ramrod_params *p)
  9763. {
  9764. struct bnx2x_mcast_list_elem *mc_mac =
  9765. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9766. link);
  9767. WARN_ON(!mc_mac);
  9768. kfree(mc_mac);
  9769. }
  9770. /**
  9771. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9772. *
  9773. * @bp: driver handle
  9774. *
  9775. * We will use zero (0) as a MAC type for these MACs.
  9776. */
  9777. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9778. {
  9779. int rc;
  9780. struct net_device *dev = bp->dev;
  9781. struct netdev_hw_addr *ha;
  9782. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9783. unsigned long ramrod_flags = 0;
  9784. /* First schedule a cleanup up of old configuration */
  9785. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9786. if (rc < 0) {
  9787. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9788. return rc;
  9789. }
  9790. netdev_for_each_uc_addr(ha, dev) {
  9791. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9792. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9793. if (rc == -EEXIST) {
  9794. DP(BNX2X_MSG_SP,
  9795. "Failed to schedule ADD operations: %d\n", rc);
  9796. /* do not treat adding same MAC as error */
  9797. rc = 0;
  9798. } else if (rc < 0) {
  9799. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9800. rc);
  9801. return rc;
  9802. }
  9803. }
  9804. /* Execute the pending commands */
  9805. __set_bit(RAMROD_CONT, &ramrod_flags);
  9806. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9807. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9808. }
  9809. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9810. {
  9811. struct net_device *dev = bp->dev;
  9812. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9813. int rc = 0;
  9814. rparam.mcast_obj = &bp->mcast_obj;
  9815. /* first, clear all configured multicast MACs */
  9816. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9817. if (rc < 0) {
  9818. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9819. return rc;
  9820. }
  9821. /* then, configure a new MACs list */
  9822. if (netdev_mc_count(dev)) {
  9823. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9824. if (rc) {
  9825. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9826. rc);
  9827. return rc;
  9828. }
  9829. /* Now add the new MACs */
  9830. rc = bnx2x_config_mcast(bp, &rparam,
  9831. BNX2X_MCAST_CMD_ADD);
  9832. if (rc < 0)
  9833. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9834. rc);
  9835. bnx2x_free_mcast_macs_list(&rparam);
  9836. }
  9837. return rc;
  9838. }
  9839. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9840. void bnx2x_set_rx_mode(struct net_device *dev)
  9841. {
  9842. struct bnx2x *bp = netdev_priv(dev);
  9843. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9844. if (bp->state != BNX2X_STATE_OPEN) {
  9845. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9846. return;
  9847. }
  9848. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9849. if (dev->flags & IFF_PROMISC)
  9850. rx_mode = BNX2X_RX_MODE_PROMISC;
  9851. else if ((dev->flags & IFF_ALLMULTI) ||
  9852. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9853. CHIP_IS_E1(bp)))
  9854. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9855. else {
  9856. if (IS_PF(bp)) {
  9857. /* some multicasts */
  9858. if (bnx2x_set_mc_list(bp) < 0)
  9859. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9860. if (bnx2x_set_uc_list(bp) < 0)
  9861. rx_mode = BNX2X_RX_MODE_PROMISC;
  9862. } else {
  9863. /* configuring mcast to a vf involves sleeping (when we
  9864. * wait for the pf's response). Since this function is
  9865. * called from non sleepable context we must schedule
  9866. * a work item for this purpose
  9867. */
  9868. smp_mb__before_clear_bit();
  9869. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9870. &bp->sp_rtnl_state);
  9871. smp_mb__after_clear_bit();
  9872. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9873. }
  9874. }
  9875. bp->rx_mode = rx_mode;
  9876. /* handle ISCSI SD mode */
  9877. if (IS_MF_ISCSI_SD(bp))
  9878. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9879. /* Schedule the rx_mode command */
  9880. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9881. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9882. return;
  9883. }
  9884. if (IS_PF(bp)) {
  9885. bnx2x_set_storm_rx_mode(bp);
  9886. } else {
  9887. /* configuring rx mode to storms in a vf involves sleeping (when
  9888. * we wait for the pf's response). Since this function is
  9889. * called from non sleepable context we must schedule
  9890. * a work item for this purpose
  9891. */
  9892. smp_mb__before_clear_bit();
  9893. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9894. &bp->sp_rtnl_state);
  9895. smp_mb__after_clear_bit();
  9896. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9897. }
  9898. }
  9899. /* called with rtnl_lock */
  9900. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9901. int devad, u16 addr)
  9902. {
  9903. struct bnx2x *bp = netdev_priv(netdev);
  9904. u16 value;
  9905. int rc;
  9906. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9907. prtad, devad, addr);
  9908. /* The HW expects different devad if CL22 is used */
  9909. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9910. bnx2x_acquire_phy_lock(bp);
  9911. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9912. bnx2x_release_phy_lock(bp);
  9913. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9914. if (!rc)
  9915. rc = value;
  9916. return rc;
  9917. }
  9918. /* called with rtnl_lock */
  9919. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9920. u16 addr, u16 value)
  9921. {
  9922. struct bnx2x *bp = netdev_priv(netdev);
  9923. int rc;
  9924. DP(NETIF_MSG_LINK,
  9925. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9926. prtad, devad, addr, value);
  9927. /* The HW expects different devad if CL22 is used */
  9928. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9929. bnx2x_acquire_phy_lock(bp);
  9930. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9931. bnx2x_release_phy_lock(bp);
  9932. return rc;
  9933. }
  9934. /* called with rtnl_lock */
  9935. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9936. {
  9937. struct bnx2x *bp = netdev_priv(dev);
  9938. struct mii_ioctl_data *mdio = if_mii(ifr);
  9939. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9940. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9941. if (!netif_running(dev))
  9942. return -EAGAIN;
  9943. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9944. }
  9945. #ifdef CONFIG_NET_POLL_CONTROLLER
  9946. static void poll_bnx2x(struct net_device *dev)
  9947. {
  9948. struct bnx2x *bp = netdev_priv(dev);
  9949. int i;
  9950. for_each_eth_queue(bp, i) {
  9951. struct bnx2x_fastpath *fp = &bp->fp[i];
  9952. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9953. }
  9954. }
  9955. #endif
  9956. static int bnx2x_validate_addr(struct net_device *dev)
  9957. {
  9958. struct bnx2x *bp = netdev_priv(dev);
  9959. /* query the bulletin board for mac address configured by the PF */
  9960. if (IS_VF(bp))
  9961. bnx2x_sample_bulletin(bp);
  9962. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9963. BNX2X_ERR("Non-valid Ethernet address\n");
  9964. return -EADDRNOTAVAIL;
  9965. }
  9966. return 0;
  9967. }
  9968. static const struct net_device_ops bnx2x_netdev_ops = {
  9969. .ndo_open = bnx2x_open,
  9970. .ndo_stop = bnx2x_close,
  9971. .ndo_start_xmit = bnx2x_start_xmit,
  9972. .ndo_select_queue = bnx2x_select_queue,
  9973. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9974. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9975. .ndo_validate_addr = bnx2x_validate_addr,
  9976. .ndo_do_ioctl = bnx2x_ioctl,
  9977. .ndo_change_mtu = bnx2x_change_mtu,
  9978. .ndo_fix_features = bnx2x_fix_features,
  9979. .ndo_set_features = bnx2x_set_features,
  9980. .ndo_tx_timeout = bnx2x_tx_timeout,
  9981. #ifdef CONFIG_NET_POLL_CONTROLLER
  9982. .ndo_poll_controller = poll_bnx2x,
  9983. #endif
  9984. .ndo_setup_tc = bnx2x_setup_tc,
  9985. #ifdef CONFIG_BNX2X_SRIOV
  9986. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  9987. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  9988. .ndo_get_vf_config = bnx2x_get_vf_config,
  9989. #endif
  9990. #ifdef NETDEV_FCOE_WWNN
  9991. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9992. #endif
  9993. };
  9994. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9995. {
  9996. struct device *dev = &bp->pdev->dev;
  9997. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9998. bp->flags |= USING_DAC_FLAG;
  9999. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  10000. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  10001. return -EIO;
  10002. }
  10003. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  10004. dev_err(dev, "System does not support DMA, aborting\n");
  10005. return -EIO;
  10006. }
  10007. return 0;
  10008. }
  10009. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10010. struct net_device *dev, unsigned long board_type)
  10011. {
  10012. int rc;
  10013. u32 pci_cfg_dword;
  10014. bool chip_is_e1x = (board_type == BCM57710 ||
  10015. board_type == BCM57711 ||
  10016. board_type == BCM57711E);
  10017. SET_NETDEV_DEV(dev, &pdev->dev);
  10018. bp->dev = dev;
  10019. bp->pdev = pdev;
  10020. rc = pci_enable_device(pdev);
  10021. if (rc) {
  10022. dev_err(&bp->pdev->dev,
  10023. "Cannot enable PCI device, aborting\n");
  10024. goto err_out;
  10025. }
  10026. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10027. dev_err(&bp->pdev->dev,
  10028. "Cannot find PCI device base address, aborting\n");
  10029. rc = -ENODEV;
  10030. goto err_out_disable;
  10031. }
  10032. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10033. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10034. rc = -ENODEV;
  10035. goto err_out_disable;
  10036. }
  10037. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10038. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10039. PCICFG_REVESION_ID_ERROR_VAL) {
  10040. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10041. rc = -ENODEV;
  10042. goto err_out_disable;
  10043. }
  10044. if (atomic_read(&pdev->enable_cnt) == 1) {
  10045. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10046. if (rc) {
  10047. dev_err(&bp->pdev->dev,
  10048. "Cannot obtain PCI resources, aborting\n");
  10049. goto err_out_disable;
  10050. }
  10051. pci_set_master(pdev);
  10052. pci_save_state(pdev);
  10053. }
  10054. if (IS_PF(bp)) {
  10055. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  10056. if (bp->pm_cap == 0) {
  10057. dev_err(&bp->pdev->dev,
  10058. "Cannot find power management capability, aborting\n");
  10059. rc = -EIO;
  10060. goto err_out_release;
  10061. }
  10062. }
  10063. if (!pci_is_pcie(pdev)) {
  10064. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10065. rc = -EIO;
  10066. goto err_out_release;
  10067. }
  10068. rc = bnx2x_set_coherency_mask(bp);
  10069. if (rc)
  10070. goto err_out_release;
  10071. dev->mem_start = pci_resource_start(pdev, 0);
  10072. dev->base_addr = dev->mem_start;
  10073. dev->mem_end = pci_resource_end(pdev, 0);
  10074. dev->irq = pdev->irq;
  10075. bp->regview = pci_ioremap_bar(pdev, 0);
  10076. if (!bp->regview) {
  10077. dev_err(&bp->pdev->dev,
  10078. "Cannot map register space, aborting\n");
  10079. rc = -ENOMEM;
  10080. goto err_out_release;
  10081. }
  10082. /* In E1/E1H use pci device function given by kernel.
  10083. * In E2/E3 read physical function from ME register since these chips
  10084. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10085. * (depending on hypervisor).
  10086. */
  10087. if (chip_is_e1x) {
  10088. bp->pf_num = PCI_FUNC(pdev->devfn);
  10089. } else {
  10090. /* chip is E2/3*/
  10091. pci_read_config_dword(bp->pdev,
  10092. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10093. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10094. ME_REG_ABS_PF_NUM_SHIFT);
  10095. }
  10096. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10097. bnx2x_set_power_state(bp, PCI_D0);
  10098. /* clean indirect addresses */
  10099. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10100. PCICFG_VENDOR_ID_OFFSET);
  10101. /*
  10102. * Clean the following indirect addresses for all functions since it
  10103. * is not used by the driver.
  10104. */
  10105. if (IS_PF(bp)) {
  10106. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10107. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10108. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10109. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10110. if (chip_is_e1x) {
  10111. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10112. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10113. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10114. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10115. }
  10116. /* Enable internal target-read (in case we are probed after PF
  10117. * FLR). Must be done prior to any BAR read access. Only for
  10118. * 57712 and up
  10119. */
  10120. if (!chip_is_e1x)
  10121. REG_WR(bp,
  10122. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10123. }
  10124. dev->watchdog_timeo = TX_TIMEOUT;
  10125. dev->netdev_ops = &bnx2x_netdev_ops;
  10126. bnx2x_set_ethtool_ops(bp, dev);
  10127. dev->priv_flags |= IFF_UNICAST_FLT;
  10128. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10129. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10130. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10131. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10132. if (!CHIP_IS_E1x(bp)) {
  10133. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10134. dev->hw_enc_features =
  10135. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10136. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10137. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10138. }
  10139. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10140. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10141. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10142. if (bp->flags & USING_DAC_FLAG)
  10143. dev->features |= NETIF_F_HIGHDMA;
  10144. /* Add Loopback capability to the device */
  10145. dev->hw_features |= NETIF_F_LOOPBACK;
  10146. #ifdef BCM_DCBNL
  10147. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10148. #endif
  10149. /* get_port_hwinfo() will set prtad and mmds properly */
  10150. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10151. bp->mdio.mmds = 0;
  10152. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10153. bp->mdio.dev = dev;
  10154. bp->mdio.mdio_read = bnx2x_mdio_read;
  10155. bp->mdio.mdio_write = bnx2x_mdio_write;
  10156. return 0;
  10157. err_out_release:
  10158. if (atomic_read(&pdev->enable_cnt) == 1)
  10159. pci_release_regions(pdev);
  10160. err_out_disable:
  10161. pci_disable_device(pdev);
  10162. pci_set_drvdata(pdev, NULL);
  10163. err_out:
  10164. return rc;
  10165. }
  10166. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width,
  10167. enum bnx2x_pci_bus_speed *speed)
  10168. {
  10169. u32 link_speed, val = 0;
  10170. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10171. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10172. link_speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10173. switch (link_speed) {
  10174. case 3:
  10175. *speed = BNX2X_PCI_LINK_SPEED_8000;
  10176. break;
  10177. case 2:
  10178. *speed = BNX2X_PCI_LINK_SPEED_5000;
  10179. break;
  10180. default:
  10181. *speed = BNX2X_PCI_LINK_SPEED_2500;
  10182. }
  10183. }
  10184. static int bnx2x_check_firmware(struct bnx2x *bp)
  10185. {
  10186. const struct firmware *firmware = bp->firmware;
  10187. struct bnx2x_fw_file_hdr *fw_hdr;
  10188. struct bnx2x_fw_file_section *sections;
  10189. u32 offset, len, num_ops;
  10190. __be16 *ops_offsets;
  10191. int i;
  10192. const u8 *fw_ver;
  10193. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10194. BNX2X_ERR("Wrong FW size\n");
  10195. return -EINVAL;
  10196. }
  10197. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10198. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10199. /* Make sure none of the offsets and sizes make us read beyond
  10200. * the end of the firmware data */
  10201. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10202. offset = be32_to_cpu(sections[i].offset);
  10203. len = be32_to_cpu(sections[i].len);
  10204. if (offset + len > firmware->size) {
  10205. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10206. return -EINVAL;
  10207. }
  10208. }
  10209. /* Likewise for the init_ops offsets */
  10210. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10211. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10212. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10213. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10214. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10215. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10216. return -EINVAL;
  10217. }
  10218. }
  10219. /* Check FW version */
  10220. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10221. fw_ver = firmware->data + offset;
  10222. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10223. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10224. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10225. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10226. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10227. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10228. BCM_5710_FW_MAJOR_VERSION,
  10229. BCM_5710_FW_MINOR_VERSION,
  10230. BCM_5710_FW_REVISION_VERSION,
  10231. BCM_5710_FW_ENGINEERING_VERSION);
  10232. return -EINVAL;
  10233. }
  10234. return 0;
  10235. }
  10236. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10237. {
  10238. const __be32 *source = (const __be32 *)_source;
  10239. u32 *target = (u32 *)_target;
  10240. u32 i;
  10241. for (i = 0; i < n/4; i++)
  10242. target[i] = be32_to_cpu(source[i]);
  10243. }
  10244. /*
  10245. Ops array is stored in the following format:
  10246. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10247. */
  10248. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10249. {
  10250. const __be32 *source = (const __be32 *)_source;
  10251. struct raw_op *target = (struct raw_op *)_target;
  10252. u32 i, j, tmp;
  10253. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10254. tmp = be32_to_cpu(source[j]);
  10255. target[i].op = (tmp >> 24) & 0xff;
  10256. target[i].offset = tmp & 0xffffff;
  10257. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10258. }
  10259. }
  10260. /* IRO array is stored in the following format:
  10261. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10262. */
  10263. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10264. {
  10265. const __be32 *source = (const __be32 *)_source;
  10266. struct iro *target = (struct iro *)_target;
  10267. u32 i, j, tmp;
  10268. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10269. target[i].base = be32_to_cpu(source[j]);
  10270. j++;
  10271. tmp = be32_to_cpu(source[j]);
  10272. target[i].m1 = (tmp >> 16) & 0xffff;
  10273. target[i].m2 = tmp & 0xffff;
  10274. j++;
  10275. tmp = be32_to_cpu(source[j]);
  10276. target[i].m3 = (tmp >> 16) & 0xffff;
  10277. target[i].size = tmp & 0xffff;
  10278. j++;
  10279. }
  10280. }
  10281. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10282. {
  10283. const __be16 *source = (const __be16 *)_source;
  10284. u16 *target = (u16 *)_target;
  10285. u32 i;
  10286. for (i = 0; i < n/2; i++)
  10287. target[i] = be16_to_cpu(source[i]);
  10288. }
  10289. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10290. do { \
  10291. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10292. bp->arr = kmalloc(len, GFP_KERNEL); \
  10293. if (!bp->arr) \
  10294. goto lbl; \
  10295. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10296. (u8 *)bp->arr, len); \
  10297. } while (0)
  10298. static int bnx2x_init_firmware(struct bnx2x *bp)
  10299. {
  10300. const char *fw_file_name;
  10301. struct bnx2x_fw_file_hdr *fw_hdr;
  10302. int rc;
  10303. if (bp->firmware)
  10304. return 0;
  10305. if (CHIP_IS_E1(bp))
  10306. fw_file_name = FW_FILE_NAME_E1;
  10307. else if (CHIP_IS_E1H(bp))
  10308. fw_file_name = FW_FILE_NAME_E1H;
  10309. else if (!CHIP_IS_E1x(bp))
  10310. fw_file_name = FW_FILE_NAME_E2;
  10311. else {
  10312. BNX2X_ERR("Unsupported chip revision\n");
  10313. return -EINVAL;
  10314. }
  10315. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10316. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10317. if (rc) {
  10318. BNX2X_ERR("Can't load firmware file %s\n",
  10319. fw_file_name);
  10320. goto request_firmware_exit;
  10321. }
  10322. rc = bnx2x_check_firmware(bp);
  10323. if (rc) {
  10324. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10325. goto request_firmware_exit;
  10326. }
  10327. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10328. /* Initialize the pointers to the init arrays */
  10329. /* Blob */
  10330. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10331. /* Opcodes */
  10332. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10333. /* Offsets */
  10334. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10335. be16_to_cpu_n);
  10336. /* STORMs firmware */
  10337. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10338. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10339. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10340. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10341. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10342. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10343. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10344. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10345. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10346. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10347. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10348. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10349. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10350. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10351. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10352. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10353. /* IRO */
  10354. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10355. return 0;
  10356. iro_alloc_err:
  10357. kfree(bp->init_ops_offsets);
  10358. init_offsets_alloc_err:
  10359. kfree(bp->init_ops);
  10360. init_ops_alloc_err:
  10361. kfree(bp->init_data);
  10362. request_firmware_exit:
  10363. release_firmware(bp->firmware);
  10364. bp->firmware = NULL;
  10365. return rc;
  10366. }
  10367. static void bnx2x_release_firmware(struct bnx2x *bp)
  10368. {
  10369. kfree(bp->init_ops_offsets);
  10370. kfree(bp->init_ops);
  10371. kfree(bp->init_data);
  10372. release_firmware(bp->firmware);
  10373. bp->firmware = NULL;
  10374. }
  10375. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10376. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10377. .init_hw_cmn = bnx2x_init_hw_common,
  10378. .init_hw_port = bnx2x_init_hw_port,
  10379. .init_hw_func = bnx2x_init_hw_func,
  10380. .reset_hw_cmn = bnx2x_reset_common,
  10381. .reset_hw_port = bnx2x_reset_port,
  10382. .reset_hw_func = bnx2x_reset_func,
  10383. .gunzip_init = bnx2x_gunzip_init,
  10384. .gunzip_end = bnx2x_gunzip_end,
  10385. .init_fw = bnx2x_init_firmware,
  10386. .release_fw = bnx2x_release_firmware,
  10387. };
  10388. void bnx2x__init_func_obj(struct bnx2x *bp)
  10389. {
  10390. /* Prepare DMAE related driver resources */
  10391. bnx2x_setup_dmae(bp);
  10392. bnx2x_init_func_obj(bp, &bp->func_obj,
  10393. bnx2x_sp(bp, func_rdata),
  10394. bnx2x_sp_mapping(bp, func_rdata),
  10395. bnx2x_sp(bp, func_afex_rdata),
  10396. bnx2x_sp_mapping(bp, func_afex_rdata),
  10397. &bnx2x_func_sp_drv);
  10398. }
  10399. /* must be called after sriov-enable */
  10400. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10401. {
  10402. int cid_count = BNX2X_L2_MAX_CID(bp);
  10403. if (IS_SRIOV(bp))
  10404. cid_count += BNX2X_VF_CIDS;
  10405. if (CNIC_SUPPORT(bp))
  10406. cid_count += CNIC_CID_MAX;
  10407. return roundup(cid_count, QM_CID_ROUND);
  10408. }
  10409. /**
  10410. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10411. *
  10412. * @dev: pci device
  10413. *
  10414. */
  10415. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10416. int cnic_cnt, bool is_vf)
  10417. {
  10418. int pos, index;
  10419. u16 control = 0;
  10420. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10421. /*
  10422. * If MSI-X is not supported - return number of SBs needed to support
  10423. * one fast path queue: one FP queue + SB for CNIC
  10424. */
  10425. if (!pos) {
  10426. dev_info(&pdev->dev, "no msix capability found\n");
  10427. return 1 + cnic_cnt;
  10428. }
  10429. dev_info(&pdev->dev, "msix capability found\n");
  10430. /*
  10431. * The value in the PCI configuration space is the index of the last
  10432. * entry, namely one less than the actual size of the table, which is
  10433. * exactly what we want to return from this function: number of all SBs
  10434. * without the default SB.
  10435. * For VFs there is no default SB, then we return (index+1).
  10436. */
  10437. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10438. index = control & PCI_MSIX_FLAGS_QSIZE;
  10439. return is_vf ? index + 1 : index;
  10440. }
  10441. static int set_max_cos_est(int chip_id)
  10442. {
  10443. switch (chip_id) {
  10444. case BCM57710:
  10445. case BCM57711:
  10446. case BCM57711E:
  10447. return BNX2X_MULTI_TX_COS_E1X;
  10448. case BCM57712:
  10449. case BCM57712_MF:
  10450. case BCM57712_VF:
  10451. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10452. case BCM57800:
  10453. case BCM57800_MF:
  10454. case BCM57800_VF:
  10455. case BCM57810:
  10456. case BCM57810_MF:
  10457. case BCM57840_4_10:
  10458. case BCM57840_2_20:
  10459. case BCM57840_O:
  10460. case BCM57840_MFO:
  10461. case BCM57810_VF:
  10462. case BCM57840_MF:
  10463. case BCM57840_VF:
  10464. case BCM57811:
  10465. case BCM57811_MF:
  10466. case BCM57811_VF:
  10467. return BNX2X_MULTI_TX_COS_E3B0;
  10468. return 1;
  10469. default:
  10470. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10471. return -ENODEV;
  10472. }
  10473. }
  10474. static int set_is_vf(int chip_id)
  10475. {
  10476. switch (chip_id) {
  10477. case BCM57712_VF:
  10478. case BCM57800_VF:
  10479. case BCM57810_VF:
  10480. case BCM57840_VF:
  10481. case BCM57811_VF:
  10482. return true;
  10483. default:
  10484. return false;
  10485. }
  10486. }
  10487. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10488. static int bnx2x_init_one(struct pci_dev *pdev,
  10489. const struct pci_device_id *ent)
  10490. {
  10491. struct net_device *dev = NULL;
  10492. struct bnx2x *bp;
  10493. int pcie_width;
  10494. enum bnx2x_pci_bus_speed pcie_speed;
  10495. int rc, max_non_def_sbs;
  10496. int rx_count, tx_count, rss_count, doorbell_size;
  10497. int max_cos_est;
  10498. bool is_vf;
  10499. int cnic_cnt;
  10500. /* An estimated maximum supported CoS number according to the chip
  10501. * version.
  10502. * We will try to roughly estimate the maximum number of CoSes this chip
  10503. * may support in order to minimize the memory allocated for Tx
  10504. * netdev_queue's. This number will be accurately calculated during the
  10505. * initialization of bp->max_cos based on the chip versions AND chip
  10506. * revision in the bnx2x_init_bp().
  10507. */
  10508. max_cos_est = set_max_cos_est(ent->driver_data);
  10509. if (max_cos_est < 0)
  10510. return max_cos_est;
  10511. is_vf = set_is_vf(ent->driver_data);
  10512. cnic_cnt = is_vf ? 0 : 1;
  10513. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10514. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10515. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10516. if (rss_count < 1)
  10517. return -EINVAL;
  10518. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10519. rx_count = rss_count + cnic_cnt;
  10520. /* Maximum number of netdev Tx queues:
  10521. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10522. */
  10523. tx_count = rss_count * max_cos_est + cnic_cnt;
  10524. /* dev zeroed in init_etherdev */
  10525. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10526. if (!dev)
  10527. return -ENOMEM;
  10528. bp = netdev_priv(dev);
  10529. bp->flags = 0;
  10530. if (is_vf)
  10531. bp->flags |= IS_VF_FLAG;
  10532. bp->igu_sb_cnt = max_non_def_sbs;
  10533. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10534. bp->msg_enable = debug;
  10535. bp->cnic_support = cnic_cnt;
  10536. bp->cnic_probe = bnx2x_cnic_probe;
  10537. pci_set_drvdata(pdev, dev);
  10538. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10539. if (rc < 0) {
  10540. free_netdev(dev);
  10541. return rc;
  10542. }
  10543. BNX2X_DEV_INFO("This is a %s function\n",
  10544. IS_PF(bp) ? "physical" : "virtual");
  10545. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10546. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10547. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10548. tx_count, rx_count);
  10549. rc = bnx2x_init_bp(bp);
  10550. if (rc)
  10551. goto init_one_exit;
  10552. /* Map doorbells here as we need the real value of bp->max_cos which
  10553. * is initialized in bnx2x_init_bp() to determine the number of
  10554. * l2 connections.
  10555. */
  10556. if (IS_VF(bp)) {
  10557. bp->doorbells = bnx2x_vf_doorbells(bp);
  10558. rc = bnx2x_vf_pci_alloc(bp);
  10559. if (rc)
  10560. goto init_one_exit;
  10561. } else {
  10562. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10563. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10564. dev_err(&bp->pdev->dev,
  10565. "Cannot map doorbells, bar size too small, aborting\n");
  10566. rc = -ENOMEM;
  10567. goto init_one_exit;
  10568. }
  10569. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10570. doorbell_size);
  10571. }
  10572. if (!bp->doorbells) {
  10573. dev_err(&bp->pdev->dev,
  10574. "Cannot map doorbell space, aborting\n");
  10575. rc = -ENOMEM;
  10576. goto init_one_exit;
  10577. }
  10578. if (IS_VF(bp)) {
  10579. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10580. if (rc)
  10581. goto init_one_exit;
  10582. }
  10583. /* Enable SRIOV if capability found in configuration space */
  10584. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10585. if (rc)
  10586. goto init_one_exit;
  10587. /* calc qm_cid_count */
  10588. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10589. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10590. /* disable FCOE L2 queue for E1x*/
  10591. if (CHIP_IS_E1x(bp))
  10592. bp->flags |= NO_FCOE_FLAG;
  10593. /* Set bp->num_queues for MSI-X mode*/
  10594. bnx2x_set_num_queues(bp);
  10595. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10596. * needed.
  10597. */
  10598. rc = bnx2x_set_int_mode(bp);
  10599. if (rc) {
  10600. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10601. goto init_one_exit;
  10602. }
  10603. BNX2X_DEV_INFO("set interrupts successfully\n");
  10604. /* register the net device */
  10605. rc = register_netdev(dev);
  10606. if (rc) {
  10607. dev_err(&pdev->dev, "Cannot register net device\n");
  10608. goto init_one_exit;
  10609. }
  10610. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10611. if (!NO_FCOE(bp)) {
  10612. /* Add storage MAC address */
  10613. rtnl_lock();
  10614. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10615. rtnl_unlock();
  10616. }
  10617. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10618. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10619. pcie_width, pcie_speed);
  10620. BNX2X_DEV_INFO("%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10621. board_info[ent->driver_data].name,
  10622. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10623. pcie_width,
  10624. pcie_speed == BNX2X_PCI_LINK_SPEED_2500 ? "2.5GHz" :
  10625. pcie_speed == BNX2X_PCI_LINK_SPEED_5000 ? "5.0GHz" :
  10626. pcie_speed == BNX2X_PCI_LINK_SPEED_8000 ? "8.0GHz" :
  10627. "Unknown",
  10628. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10629. return 0;
  10630. init_one_exit:
  10631. if (bp->regview)
  10632. iounmap(bp->regview);
  10633. if (IS_PF(bp) && bp->doorbells)
  10634. iounmap(bp->doorbells);
  10635. free_netdev(dev);
  10636. if (atomic_read(&pdev->enable_cnt) == 1)
  10637. pci_release_regions(pdev);
  10638. pci_disable_device(pdev);
  10639. pci_set_drvdata(pdev, NULL);
  10640. return rc;
  10641. }
  10642. static void __bnx2x_remove(struct pci_dev *pdev,
  10643. struct net_device *dev,
  10644. struct bnx2x *bp,
  10645. bool remove_netdev)
  10646. {
  10647. /* Delete storage MAC address */
  10648. if (!NO_FCOE(bp)) {
  10649. rtnl_lock();
  10650. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10651. rtnl_unlock();
  10652. }
  10653. #ifdef BCM_DCBNL
  10654. /* Delete app tlvs from dcbnl */
  10655. bnx2x_dcbnl_update_applist(bp, true);
  10656. #endif
  10657. /* Close the interface - either directly or implicitly */
  10658. if (remove_netdev) {
  10659. unregister_netdev(dev);
  10660. } else {
  10661. rtnl_lock();
  10662. if (netif_running(dev))
  10663. bnx2x_close(dev);
  10664. rtnl_unlock();
  10665. }
  10666. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10667. if (IS_PF(bp))
  10668. bnx2x_set_power_state(bp, PCI_D0);
  10669. /* Disable MSI/MSI-X */
  10670. bnx2x_disable_msi(bp);
  10671. /* Power off */
  10672. if (IS_PF(bp))
  10673. bnx2x_set_power_state(bp, PCI_D3hot);
  10674. /* Make sure RESET task is not scheduled before continuing */
  10675. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10676. bnx2x_iov_remove_one(bp);
  10677. /* send message via vfpf channel to release the resources of this vf */
  10678. if (IS_VF(bp))
  10679. bnx2x_vfpf_release(bp);
  10680. /* Assumes no further PCIe PM changes will occur */
  10681. if (system_state == SYSTEM_POWER_OFF) {
  10682. pci_wake_from_d3(pdev, bp->wol);
  10683. pci_set_power_state(pdev, PCI_D3hot);
  10684. }
  10685. if (bp->regview)
  10686. iounmap(bp->regview);
  10687. /* for vf doorbells are part of the regview and were unmapped along with
  10688. * it. FW is only loaded by PF.
  10689. */
  10690. if (IS_PF(bp)) {
  10691. if (bp->doorbells)
  10692. iounmap(bp->doorbells);
  10693. bnx2x_release_firmware(bp);
  10694. }
  10695. bnx2x_free_mem_bp(bp);
  10696. if (remove_netdev)
  10697. free_netdev(dev);
  10698. if (atomic_read(&pdev->enable_cnt) == 1)
  10699. pci_release_regions(pdev);
  10700. pci_disable_device(pdev);
  10701. pci_set_drvdata(pdev, NULL);
  10702. }
  10703. static void bnx2x_remove_one(struct pci_dev *pdev)
  10704. {
  10705. struct net_device *dev = pci_get_drvdata(pdev);
  10706. struct bnx2x *bp;
  10707. if (!dev) {
  10708. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10709. return;
  10710. }
  10711. bp = netdev_priv(dev);
  10712. __bnx2x_remove(pdev, dev, bp, true);
  10713. }
  10714. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10715. {
  10716. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  10717. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10718. if (CNIC_LOADED(bp))
  10719. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10720. /* Stop Tx */
  10721. bnx2x_tx_disable(bp);
  10722. /* Delete all NAPI objects */
  10723. bnx2x_del_all_napi(bp);
  10724. if (CNIC_LOADED(bp))
  10725. bnx2x_del_all_napi_cnic(bp);
  10726. netdev_reset_tc(bp->dev);
  10727. del_timer_sync(&bp->timer);
  10728. cancel_delayed_work(&bp->sp_task);
  10729. cancel_delayed_work(&bp->period_task);
  10730. spin_lock_bh(&bp->stats_lock);
  10731. bp->stats_state = STATS_STATE_DISABLED;
  10732. spin_unlock_bh(&bp->stats_lock);
  10733. bnx2x_save_statistics(bp);
  10734. netif_carrier_off(bp->dev);
  10735. return 0;
  10736. }
  10737. /**
  10738. * bnx2x_io_error_detected - called when PCI error is detected
  10739. * @pdev: Pointer to PCI device
  10740. * @state: The current pci connection state
  10741. *
  10742. * This function is called after a PCI bus error affecting
  10743. * this device has been detected.
  10744. */
  10745. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10746. pci_channel_state_t state)
  10747. {
  10748. struct net_device *dev = pci_get_drvdata(pdev);
  10749. struct bnx2x *bp = netdev_priv(dev);
  10750. rtnl_lock();
  10751. BNX2X_ERR("IO error detected\n");
  10752. netif_device_detach(dev);
  10753. if (state == pci_channel_io_perm_failure) {
  10754. rtnl_unlock();
  10755. return PCI_ERS_RESULT_DISCONNECT;
  10756. }
  10757. if (netif_running(dev))
  10758. bnx2x_eeh_nic_unload(bp);
  10759. bnx2x_prev_path_mark_eeh(bp);
  10760. pci_disable_device(pdev);
  10761. rtnl_unlock();
  10762. /* Request a slot reset */
  10763. return PCI_ERS_RESULT_NEED_RESET;
  10764. }
  10765. /**
  10766. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10767. * @pdev: Pointer to PCI device
  10768. *
  10769. * Restart the card from scratch, as if from a cold-boot.
  10770. */
  10771. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10772. {
  10773. struct net_device *dev = pci_get_drvdata(pdev);
  10774. struct bnx2x *bp = netdev_priv(dev);
  10775. int i;
  10776. rtnl_lock();
  10777. BNX2X_ERR("IO slot reset initializing...\n");
  10778. if (pci_enable_device(pdev)) {
  10779. dev_err(&pdev->dev,
  10780. "Cannot re-enable PCI device after reset\n");
  10781. rtnl_unlock();
  10782. return PCI_ERS_RESULT_DISCONNECT;
  10783. }
  10784. pci_set_master(pdev);
  10785. pci_restore_state(pdev);
  10786. pci_save_state(pdev);
  10787. if (netif_running(dev))
  10788. bnx2x_set_power_state(bp, PCI_D0);
  10789. if (netif_running(dev)) {
  10790. BNX2X_ERR("IO slot reset --> driver unload\n");
  10791. /* MCP should have been reset; Need to wait for validity */
  10792. bnx2x_init_shmem(bp);
  10793. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  10794. u32 v;
  10795. v = SHMEM2_RD(bp,
  10796. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  10797. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  10798. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  10799. }
  10800. bnx2x_drain_tx_queues(bp);
  10801. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  10802. bnx2x_netif_stop(bp, 1);
  10803. bnx2x_free_irq(bp);
  10804. /* Report UNLOAD_DONE to MCP */
  10805. bnx2x_send_unload_done(bp, true);
  10806. bp->sp_state = 0;
  10807. bp->port.pmf = 0;
  10808. bnx2x_prev_unload(bp);
  10809. /* We should have reseted the engine, so It's fair to
  10810. * assume the FW will no longer write to the bnx2x driver.
  10811. */
  10812. bnx2x_squeeze_objects(bp);
  10813. bnx2x_free_skbs(bp);
  10814. for_each_rx_queue(bp, i)
  10815. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10816. bnx2x_free_fp_mem(bp);
  10817. bnx2x_free_mem(bp);
  10818. bp->state = BNX2X_STATE_CLOSED;
  10819. }
  10820. rtnl_unlock();
  10821. return PCI_ERS_RESULT_RECOVERED;
  10822. }
  10823. /**
  10824. * bnx2x_io_resume - called when traffic can start flowing again
  10825. * @pdev: Pointer to PCI device
  10826. *
  10827. * This callback is called when the error recovery driver tells us that
  10828. * its OK to resume normal operation.
  10829. */
  10830. static void bnx2x_io_resume(struct pci_dev *pdev)
  10831. {
  10832. struct net_device *dev = pci_get_drvdata(pdev);
  10833. struct bnx2x *bp = netdev_priv(dev);
  10834. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10835. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10836. return;
  10837. }
  10838. rtnl_lock();
  10839. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10840. DRV_MSG_SEQ_NUMBER_MASK;
  10841. if (netif_running(dev))
  10842. bnx2x_nic_load(bp, LOAD_NORMAL);
  10843. netif_device_attach(dev);
  10844. rtnl_unlock();
  10845. }
  10846. static const struct pci_error_handlers bnx2x_err_handler = {
  10847. .error_detected = bnx2x_io_error_detected,
  10848. .slot_reset = bnx2x_io_slot_reset,
  10849. .resume = bnx2x_io_resume,
  10850. };
  10851. static void bnx2x_shutdown(struct pci_dev *pdev)
  10852. {
  10853. struct net_device *dev = pci_get_drvdata(pdev);
  10854. struct bnx2x *bp;
  10855. if (!dev)
  10856. return;
  10857. bp = netdev_priv(dev);
  10858. if (!bp)
  10859. return;
  10860. rtnl_lock();
  10861. netif_device_detach(dev);
  10862. rtnl_unlock();
  10863. /* Don't remove the netdevice, as there are scenarios which will cause
  10864. * the kernel to hang, e.g., when trying to remove bnx2i while the
  10865. * rootfs is mounted from SAN.
  10866. */
  10867. __bnx2x_remove(pdev, dev, bp, false);
  10868. }
  10869. static struct pci_driver bnx2x_pci_driver = {
  10870. .name = DRV_MODULE_NAME,
  10871. .id_table = bnx2x_pci_tbl,
  10872. .probe = bnx2x_init_one,
  10873. .remove = bnx2x_remove_one,
  10874. .suspend = bnx2x_suspend,
  10875. .resume = bnx2x_resume,
  10876. .err_handler = &bnx2x_err_handler,
  10877. #ifdef CONFIG_BNX2X_SRIOV
  10878. .sriov_configure = bnx2x_sriov_configure,
  10879. #endif
  10880. .shutdown = bnx2x_shutdown,
  10881. };
  10882. static int __init bnx2x_init(void)
  10883. {
  10884. int ret;
  10885. pr_info("%s", version);
  10886. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10887. if (bnx2x_wq == NULL) {
  10888. pr_err("Cannot create workqueue\n");
  10889. return -ENOMEM;
  10890. }
  10891. ret = pci_register_driver(&bnx2x_pci_driver);
  10892. if (ret) {
  10893. pr_err("Cannot register driver\n");
  10894. destroy_workqueue(bnx2x_wq);
  10895. }
  10896. return ret;
  10897. }
  10898. static void __exit bnx2x_cleanup(void)
  10899. {
  10900. struct list_head *pos, *q;
  10901. pci_unregister_driver(&bnx2x_pci_driver);
  10902. destroy_workqueue(bnx2x_wq);
  10903. /* Free globally allocated resources */
  10904. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10905. struct bnx2x_prev_path_list *tmp =
  10906. list_entry(pos, struct bnx2x_prev_path_list, list);
  10907. list_del(pos);
  10908. kfree(tmp);
  10909. }
  10910. }
  10911. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10912. {
  10913. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10914. }
  10915. module_init(bnx2x_init);
  10916. module_exit(bnx2x_cleanup);
  10917. /**
  10918. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10919. *
  10920. * @bp: driver handle
  10921. * @set: set or clear the CAM entry
  10922. *
  10923. * This function will wait until the ramrod completion returns.
  10924. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10925. */
  10926. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10927. {
  10928. unsigned long ramrod_flags = 0;
  10929. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10930. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10931. &bp->iscsi_l2_mac_obj, true,
  10932. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10933. }
  10934. /* count denotes the number of new completions we have seen */
  10935. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10936. {
  10937. struct eth_spe *spe;
  10938. int cxt_index, cxt_offset;
  10939. #ifdef BNX2X_STOP_ON_ERROR
  10940. if (unlikely(bp->panic))
  10941. return;
  10942. #endif
  10943. spin_lock_bh(&bp->spq_lock);
  10944. BUG_ON(bp->cnic_spq_pending < count);
  10945. bp->cnic_spq_pending -= count;
  10946. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10947. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10948. & SPE_HDR_CONN_TYPE) >>
  10949. SPE_HDR_CONN_TYPE_SHIFT;
  10950. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10951. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10952. /* Set validation for iSCSI L2 client before sending SETUP
  10953. * ramrod
  10954. */
  10955. if (type == ETH_CONNECTION_TYPE) {
  10956. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10957. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10958. ILT_PAGE_CIDS;
  10959. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10960. (cxt_index * ILT_PAGE_CIDS);
  10961. bnx2x_set_ctx_validation(bp,
  10962. &bp->context[cxt_index].
  10963. vcxt[cxt_offset].eth,
  10964. BNX2X_ISCSI_ETH_CID(bp));
  10965. }
  10966. }
  10967. /*
  10968. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10969. * and in the air. We also check that number of outstanding
  10970. * COMMON ramrods is not more than the EQ and SPQ can
  10971. * accommodate.
  10972. */
  10973. if (type == ETH_CONNECTION_TYPE) {
  10974. if (!atomic_read(&bp->cq_spq_left))
  10975. break;
  10976. else
  10977. atomic_dec(&bp->cq_spq_left);
  10978. } else if (type == NONE_CONNECTION_TYPE) {
  10979. if (!atomic_read(&bp->eq_spq_left))
  10980. break;
  10981. else
  10982. atomic_dec(&bp->eq_spq_left);
  10983. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10984. (type == FCOE_CONNECTION_TYPE)) {
  10985. if (bp->cnic_spq_pending >=
  10986. bp->cnic_eth_dev.max_kwqe_pending)
  10987. break;
  10988. else
  10989. bp->cnic_spq_pending++;
  10990. } else {
  10991. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10992. bnx2x_panic();
  10993. break;
  10994. }
  10995. spe = bnx2x_sp_get_next(bp);
  10996. *spe = *bp->cnic_kwq_cons;
  10997. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10998. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10999. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11000. bp->cnic_kwq_cons = bp->cnic_kwq;
  11001. else
  11002. bp->cnic_kwq_cons++;
  11003. }
  11004. bnx2x_sp_prod_update(bp);
  11005. spin_unlock_bh(&bp->spq_lock);
  11006. }
  11007. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11008. struct kwqe_16 *kwqes[], u32 count)
  11009. {
  11010. struct bnx2x *bp = netdev_priv(dev);
  11011. int i;
  11012. #ifdef BNX2X_STOP_ON_ERROR
  11013. if (unlikely(bp->panic)) {
  11014. BNX2X_ERR("Can't post to SP queue while panic\n");
  11015. return -EIO;
  11016. }
  11017. #endif
  11018. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11019. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11020. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11021. return -EAGAIN;
  11022. }
  11023. spin_lock_bh(&bp->spq_lock);
  11024. for (i = 0; i < count; i++) {
  11025. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11026. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11027. break;
  11028. *bp->cnic_kwq_prod = *spe;
  11029. bp->cnic_kwq_pending++;
  11030. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11031. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11032. spe->data.update_data_addr.hi,
  11033. spe->data.update_data_addr.lo,
  11034. bp->cnic_kwq_pending);
  11035. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11036. bp->cnic_kwq_prod = bp->cnic_kwq;
  11037. else
  11038. bp->cnic_kwq_prod++;
  11039. }
  11040. spin_unlock_bh(&bp->spq_lock);
  11041. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11042. bnx2x_cnic_sp_post(bp, 0);
  11043. return i;
  11044. }
  11045. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11046. {
  11047. struct cnic_ops *c_ops;
  11048. int rc = 0;
  11049. mutex_lock(&bp->cnic_mutex);
  11050. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11051. lockdep_is_held(&bp->cnic_mutex));
  11052. if (c_ops)
  11053. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11054. mutex_unlock(&bp->cnic_mutex);
  11055. return rc;
  11056. }
  11057. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11058. {
  11059. struct cnic_ops *c_ops;
  11060. int rc = 0;
  11061. rcu_read_lock();
  11062. c_ops = rcu_dereference(bp->cnic_ops);
  11063. if (c_ops)
  11064. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11065. rcu_read_unlock();
  11066. return rc;
  11067. }
  11068. /*
  11069. * for commands that have no data
  11070. */
  11071. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11072. {
  11073. struct cnic_ctl_info ctl = {0};
  11074. ctl.cmd = cmd;
  11075. return bnx2x_cnic_ctl_send(bp, &ctl);
  11076. }
  11077. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11078. {
  11079. struct cnic_ctl_info ctl = {0};
  11080. /* first we tell CNIC and only then we count this as a completion */
  11081. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11082. ctl.data.comp.cid = cid;
  11083. ctl.data.comp.error = err;
  11084. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11085. bnx2x_cnic_sp_post(bp, 0);
  11086. }
  11087. /* Called with netif_addr_lock_bh() taken.
  11088. * Sets an rx_mode config for an iSCSI ETH client.
  11089. * Doesn't block.
  11090. * Completion should be checked outside.
  11091. */
  11092. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11093. {
  11094. unsigned long accept_flags = 0, ramrod_flags = 0;
  11095. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11096. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11097. if (start) {
  11098. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11099. * because it's the only way for UIO Queue to accept
  11100. * multicasts (in non-promiscuous mode only one Queue per
  11101. * function will receive multicast packets (leading in our
  11102. * case).
  11103. */
  11104. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11105. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11106. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11107. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11108. /* Clear STOP_PENDING bit if START is requested */
  11109. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11110. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11111. } else
  11112. /* Clear START_PENDING bit if STOP is requested */
  11113. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11114. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11115. set_bit(sched_state, &bp->sp_state);
  11116. else {
  11117. __set_bit(RAMROD_RX, &ramrod_flags);
  11118. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11119. ramrod_flags);
  11120. }
  11121. }
  11122. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11123. {
  11124. struct bnx2x *bp = netdev_priv(dev);
  11125. int rc = 0;
  11126. switch (ctl->cmd) {
  11127. case DRV_CTL_CTXTBL_WR_CMD: {
  11128. u32 index = ctl->data.io.offset;
  11129. dma_addr_t addr = ctl->data.io.dma_addr;
  11130. bnx2x_ilt_wr(bp, index, addr);
  11131. break;
  11132. }
  11133. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11134. int count = ctl->data.credit.credit_count;
  11135. bnx2x_cnic_sp_post(bp, count);
  11136. break;
  11137. }
  11138. /* rtnl_lock is held. */
  11139. case DRV_CTL_START_L2_CMD: {
  11140. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11141. unsigned long sp_bits = 0;
  11142. /* Configure the iSCSI classification object */
  11143. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11144. cp->iscsi_l2_client_id,
  11145. cp->iscsi_l2_cid, BP_FUNC(bp),
  11146. bnx2x_sp(bp, mac_rdata),
  11147. bnx2x_sp_mapping(bp, mac_rdata),
  11148. BNX2X_FILTER_MAC_PENDING,
  11149. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11150. &bp->macs_pool);
  11151. /* Set iSCSI MAC address */
  11152. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11153. if (rc)
  11154. break;
  11155. mmiowb();
  11156. barrier();
  11157. /* Start accepting on iSCSI L2 ring */
  11158. netif_addr_lock_bh(dev);
  11159. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11160. netif_addr_unlock_bh(dev);
  11161. /* bits to wait on */
  11162. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11163. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11164. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11165. BNX2X_ERR("rx_mode completion timed out!\n");
  11166. break;
  11167. }
  11168. /* rtnl_lock is held. */
  11169. case DRV_CTL_STOP_L2_CMD: {
  11170. unsigned long sp_bits = 0;
  11171. /* Stop accepting on iSCSI L2 ring */
  11172. netif_addr_lock_bh(dev);
  11173. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11174. netif_addr_unlock_bh(dev);
  11175. /* bits to wait on */
  11176. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11177. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11178. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11179. BNX2X_ERR("rx_mode completion timed out!\n");
  11180. mmiowb();
  11181. barrier();
  11182. /* Unset iSCSI L2 MAC */
  11183. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11184. BNX2X_ISCSI_ETH_MAC, true);
  11185. break;
  11186. }
  11187. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11188. int count = ctl->data.credit.credit_count;
  11189. smp_mb__before_atomic_inc();
  11190. atomic_add(count, &bp->cq_spq_left);
  11191. smp_mb__after_atomic_inc();
  11192. break;
  11193. }
  11194. case DRV_CTL_ULP_REGISTER_CMD: {
  11195. int ulp_type = ctl->data.register_data.ulp_type;
  11196. if (CHIP_IS_E3(bp)) {
  11197. int idx = BP_FW_MB_IDX(bp);
  11198. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11199. int path = BP_PATH(bp);
  11200. int port = BP_PORT(bp);
  11201. int i;
  11202. u32 scratch_offset;
  11203. u32 *host_addr;
  11204. /* first write capability to shmem2 */
  11205. if (ulp_type == CNIC_ULP_ISCSI)
  11206. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11207. else if (ulp_type == CNIC_ULP_FCOE)
  11208. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11209. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11210. if ((ulp_type != CNIC_ULP_FCOE) ||
  11211. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11212. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11213. break;
  11214. /* if reached here - should write fcoe capabilities */
  11215. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11216. if (!scratch_offset)
  11217. break;
  11218. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11219. fcoe_features[path][port]);
  11220. host_addr = (u32 *) &(ctl->data.register_data.
  11221. fcoe_features);
  11222. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11223. i += 4)
  11224. REG_WR(bp, scratch_offset + i,
  11225. *(host_addr + i/4));
  11226. }
  11227. break;
  11228. }
  11229. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11230. int ulp_type = ctl->data.ulp_type;
  11231. if (CHIP_IS_E3(bp)) {
  11232. int idx = BP_FW_MB_IDX(bp);
  11233. u32 cap;
  11234. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11235. if (ulp_type == CNIC_ULP_ISCSI)
  11236. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11237. else if (ulp_type == CNIC_ULP_FCOE)
  11238. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11239. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11240. }
  11241. break;
  11242. }
  11243. default:
  11244. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11245. rc = -EINVAL;
  11246. }
  11247. return rc;
  11248. }
  11249. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11250. {
  11251. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11252. if (bp->flags & USING_MSIX_FLAG) {
  11253. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11254. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11255. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11256. } else {
  11257. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11258. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11259. }
  11260. if (!CHIP_IS_E1x(bp))
  11261. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11262. else
  11263. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11264. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11265. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11266. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11267. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11268. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11269. cp->num_irq = 2;
  11270. }
  11271. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11272. {
  11273. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11274. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11275. bnx2x_cid_ilt_lines(bp);
  11276. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11277. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11278. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11279. if (NO_ISCSI_OOO(bp))
  11280. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11281. }
  11282. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11283. void *data)
  11284. {
  11285. struct bnx2x *bp = netdev_priv(dev);
  11286. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11287. int rc;
  11288. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11289. if (ops == NULL) {
  11290. BNX2X_ERR("NULL ops received\n");
  11291. return -EINVAL;
  11292. }
  11293. if (!CNIC_SUPPORT(bp)) {
  11294. BNX2X_ERR("Can't register CNIC when not supported\n");
  11295. return -EOPNOTSUPP;
  11296. }
  11297. if (!CNIC_LOADED(bp)) {
  11298. rc = bnx2x_load_cnic(bp);
  11299. if (rc) {
  11300. BNX2X_ERR("CNIC-related load failed\n");
  11301. return rc;
  11302. }
  11303. }
  11304. bp->cnic_enabled = true;
  11305. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11306. if (!bp->cnic_kwq)
  11307. return -ENOMEM;
  11308. bp->cnic_kwq_cons = bp->cnic_kwq;
  11309. bp->cnic_kwq_prod = bp->cnic_kwq;
  11310. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11311. bp->cnic_spq_pending = 0;
  11312. bp->cnic_kwq_pending = 0;
  11313. bp->cnic_data = data;
  11314. cp->num_irq = 0;
  11315. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11316. cp->iro_arr = bp->iro_arr;
  11317. bnx2x_setup_cnic_irq_info(bp);
  11318. rcu_assign_pointer(bp->cnic_ops, ops);
  11319. return 0;
  11320. }
  11321. static int bnx2x_unregister_cnic(struct net_device *dev)
  11322. {
  11323. struct bnx2x *bp = netdev_priv(dev);
  11324. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11325. mutex_lock(&bp->cnic_mutex);
  11326. cp->drv_state = 0;
  11327. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11328. mutex_unlock(&bp->cnic_mutex);
  11329. synchronize_rcu();
  11330. bp->cnic_enabled = false;
  11331. kfree(bp->cnic_kwq);
  11332. bp->cnic_kwq = NULL;
  11333. return 0;
  11334. }
  11335. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11336. {
  11337. struct bnx2x *bp = netdev_priv(dev);
  11338. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11339. /* If both iSCSI and FCoE are disabled - return NULL in
  11340. * order to indicate CNIC that it should not try to work
  11341. * with this device.
  11342. */
  11343. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11344. return NULL;
  11345. cp->drv_owner = THIS_MODULE;
  11346. cp->chip_id = CHIP_ID(bp);
  11347. cp->pdev = bp->pdev;
  11348. cp->io_base = bp->regview;
  11349. cp->io_base2 = bp->doorbells;
  11350. cp->max_kwqe_pending = 8;
  11351. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11352. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11353. bnx2x_cid_ilt_lines(bp);
  11354. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11355. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11356. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11357. cp->drv_ctl = bnx2x_drv_ctl;
  11358. cp->drv_register_cnic = bnx2x_register_cnic;
  11359. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11360. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11361. cp->iscsi_l2_client_id =
  11362. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11363. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11364. if (NO_ISCSI_OOO(bp))
  11365. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11366. if (NO_ISCSI(bp))
  11367. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11368. if (NO_FCOE(bp))
  11369. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11370. BNX2X_DEV_INFO(
  11371. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11372. cp->ctx_blk_size,
  11373. cp->ctx_tbl_offset,
  11374. cp->ctx_tbl_len,
  11375. cp->starting_cid);
  11376. return cp;
  11377. }
  11378. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11379. {
  11380. struct bnx2x *bp = fp->bp;
  11381. u32 offset = BAR_USTRORM_INTMEM;
  11382. if (IS_VF(bp))
  11383. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11384. else if (!CHIP_IS_E1x(bp))
  11385. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11386. else
  11387. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11388. return offset;
  11389. }
  11390. /* called only on E1H or E2.
  11391. * When pretending to be PF, the pretend value is the function number 0...7
  11392. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11393. * combination
  11394. */
  11395. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11396. {
  11397. u32 pretend_reg;
  11398. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11399. return -1;
  11400. /* get my own pretend register */
  11401. pretend_reg = bnx2x_get_pretend_reg(bp);
  11402. REG_WR(bp, pretend_reg, pretend_func_val);
  11403. REG_RD(bp, pretend_reg);
  11404. return 0;
  11405. }