bnx2x_main.c 363 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448
  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. #define INT_MODE_INTx 1
  96. #define INT_MODE_MSI 2
  97. int int_mode;
  98. module_param(int_mode, int, 0);
  99. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  100. "(1 INT#x; 2 MSI)");
  101. static int dropless_fc;
  102. module_param(dropless_fc, int, 0);
  103. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, 0);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, 0);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. struct workqueue_struct *bnx2x_wq;
  111. struct bnx2x_mac_vals {
  112. u32 xmac_addr;
  113. u32 xmac_val;
  114. u32 emac_addr;
  115. u32 emac_val;
  116. u32 umac_addr;
  117. u32 umac_val;
  118. u32 bmac_addr;
  119. u32 bmac_val[2];
  120. };
  121. enum bnx2x_board_type {
  122. BCM57710 = 0,
  123. BCM57711,
  124. BCM57711E,
  125. BCM57712,
  126. BCM57712_MF,
  127. BCM57712_VF,
  128. BCM57800,
  129. BCM57800_MF,
  130. BCM57800_VF,
  131. BCM57810,
  132. BCM57810_MF,
  133. BCM57810_VF,
  134. BCM57840_4_10,
  135. BCM57840_2_20,
  136. BCM57840_MF,
  137. BCM57840_VF,
  138. BCM57811,
  139. BCM57811_MF,
  140. BCM57840_O,
  141. BCM57840_MFO,
  142. BCM57811_VF
  143. };
  144. /* indexed by board_type, above */
  145. static struct {
  146. char *name;
  147. } board_info[] = {
  148. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  149. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  150. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  151. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  152. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  153. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  154. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  155. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  156. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  157. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  158. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  159. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  160. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  161. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  162. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  163. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  164. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  165. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  166. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  167. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  168. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  169. };
  170. #ifndef PCI_DEVICE_ID_NX2_57710
  171. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  172. #endif
  173. #ifndef PCI_DEVICE_ID_NX2_57711
  174. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  175. #endif
  176. #ifndef PCI_DEVICE_ID_NX2_57711E
  177. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  178. #endif
  179. #ifndef PCI_DEVICE_ID_NX2_57712
  180. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  181. #endif
  182. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  183. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  184. #endif
  185. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  186. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  187. #endif
  188. #ifndef PCI_DEVICE_ID_NX2_57800
  189. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  190. #endif
  191. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  192. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  193. #endif
  194. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  195. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  196. #endif
  197. #ifndef PCI_DEVICE_ID_NX2_57810
  198. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  199. #endif
  200. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  201. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  202. #endif
  203. #ifndef PCI_DEVICE_ID_NX2_57840_O
  204. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  205. #endif
  206. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  207. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  208. #endif
  209. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  210. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  211. #endif
  212. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  213. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  214. #endif
  215. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  216. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  217. #endif
  218. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  219. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  220. #endif
  221. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  222. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  223. #endif
  224. #ifndef PCI_DEVICE_ID_NX2_57811
  225. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  226. #endif
  227. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  228. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  229. #endif
  230. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  231. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  232. #endif
  233. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  255. { 0 }
  256. };
  257. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  258. /* Global resources for unloading a previously loaded device */
  259. #define BNX2X_PREV_WAIT_NEEDED 1
  260. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  261. static LIST_HEAD(bnx2x_prev_list);
  262. /****************************************************************************
  263. * General service functions
  264. ****************************************************************************/
  265. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  266. u32 addr, dma_addr_t mapping)
  267. {
  268. REG_WR(bp, addr, U64_LO(mapping));
  269. REG_WR(bp, addr + 4, U64_HI(mapping));
  270. }
  271. static void storm_memset_spq_addr(struct bnx2x *bp,
  272. dma_addr_t mapping, u16 abs_fid)
  273. {
  274. u32 addr = XSEM_REG_FAST_MEMORY +
  275. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  276. __storm_memset_dma_mapping(bp, addr, mapping);
  277. }
  278. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  279. u16 pf_id)
  280. {
  281. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  282. pf_id);
  283. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  284. pf_id);
  285. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  288. pf_id);
  289. }
  290. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  291. u8 enable)
  292. {
  293. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  294. enable);
  295. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  296. enable);
  297. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  300. enable);
  301. }
  302. static void storm_memset_eq_data(struct bnx2x *bp,
  303. struct event_ring_data *eq_data,
  304. u16 pfid)
  305. {
  306. size_t size = sizeof(struct event_ring_data);
  307. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  308. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  309. }
  310. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  311. u16 pfid)
  312. {
  313. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  314. REG_WR16(bp, addr, eq_prod);
  315. }
  316. /* used only at init
  317. * locking is done by mcp
  318. */
  319. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  320. {
  321. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  322. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  323. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  324. PCICFG_VENDOR_ID_OFFSET);
  325. }
  326. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  327. {
  328. u32 val;
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  330. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  331. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  332. PCICFG_VENDOR_ID_OFFSET);
  333. return val;
  334. }
  335. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  336. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  337. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  338. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  339. #define DMAE_DP_DST_NONE "dst_addr [none]"
  340. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  341. {
  342. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  343. switch (dmae->opcode & DMAE_COMMAND_DST) {
  344. case DMAE_CMD_DST_PCI:
  345. if (src_type == DMAE_CMD_SRC_PCI)
  346. DP(msglvl, "DMAE: opcode 0x%08x\n"
  347. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  348. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  349. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  350. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  351. dmae->comp_addr_hi, dmae->comp_addr_lo,
  352. dmae->comp_val);
  353. else
  354. DP(msglvl, "DMAE: opcode 0x%08x\n"
  355. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  356. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  357. dmae->opcode, dmae->src_addr_lo >> 2,
  358. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  359. dmae->comp_addr_hi, dmae->comp_addr_lo,
  360. dmae->comp_val);
  361. break;
  362. case DMAE_CMD_DST_GRC:
  363. if (src_type == DMAE_CMD_SRC_PCI)
  364. DP(msglvl, "DMAE: opcode 0x%08x\n"
  365. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  366. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  367. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  368. dmae->len, dmae->dst_addr_lo >> 2,
  369. dmae->comp_addr_hi, dmae->comp_addr_lo,
  370. dmae->comp_val);
  371. else
  372. DP(msglvl, "DMAE: opcode 0x%08x\n"
  373. "src [%08x], len [%d*4], dst [%08x]\n"
  374. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  375. dmae->opcode, dmae->src_addr_lo >> 2,
  376. dmae->len, dmae->dst_addr_lo >> 2,
  377. dmae->comp_addr_hi, dmae->comp_addr_lo,
  378. dmae->comp_val);
  379. break;
  380. default:
  381. if (src_type == DMAE_CMD_SRC_PCI)
  382. DP(msglvl, "DMAE: opcode 0x%08x\n"
  383. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  384. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  385. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  386. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  387. dmae->comp_val);
  388. else
  389. DP(msglvl, "DMAE: opcode 0x%08x\n"
  390. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  391. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  392. dmae->opcode, dmae->src_addr_lo >> 2,
  393. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  394. dmae->comp_val);
  395. break;
  396. }
  397. }
  398. /* copy command into DMAE command memory and set DMAE command go */
  399. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  400. {
  401. u32 cmd_offset;
  402. int i;
  403. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  404. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  405. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  406. }
  407. REG_WR(bp, dmae_reg_go_c[idx], 1);
  408. }
  409. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  410. {
  411. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  412. DMAE_CMD_C_ENABLE);
  413. }
  414. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  415. {
  416. return opcode & ~DMAE_CMD_SRC_RESET;
  417. }
  418. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  419. bool with_comp, u8 comp_type)
  420. {
  421. u32 opcode = 0;
  422. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  423. (dst_type << DMAE_COMMAND_DST_SHIFT));
  424. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  425. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  426. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  427. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  428. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  429. #ifdef __BIG_ENDIAN
  430. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  431. #else
  432. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  433. #endif
  434. if (with_comp)
  435. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  436. return opcode;
  437. }
  438. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  439. struct dmae_command *dmae,
  440. u8 src_type, u8 dst_type)
  441. {
  442. memset(dmae, 0, sizeof(struct dmae_command));
  443. /* set the opcode */
  444. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  445. true, DMAE_COMP_PCI);
  446. /* fill in the completion parameters */
  447. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  448. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  449. dmae->comp_val = DMAE_COMP_VAL;
  450. }
  451. /* issue a dmae command over the init-channel and wait for completion */
  452. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  453. {
  454. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  455. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  456. int rc = 0;
  457. /*
  458. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  459. * as long as this code is called both from syscall context and
  460. * from ndo_set_rx_mode() flow that may be called from BH.
  461. */
  462. spin_lock_bh(&bp->dmae_lock);
  463. /* reset completion */
  464. *wb_comp = 0;
  465. /* post the command on the channel used for initializations */
  466. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  467. /* wait for completion */
  468. udelay(5);
  469. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  470. if (!cnt ||
  471. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  472. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  473. BNX2X_ERR("DMAE timeout!\n");
  474. rc = DMAE_TIMEOUT;
  475. goto unlock;
  476. }
  477. cnt--;
  478. udelay(50);
  479. }
  480. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  481. BNX2X_ERR("DMAE PCI error!\n");
  482. rc = DMAE_PCI_ERROR;
  483. }
  484. unlock:
  485. spin_unlock_bh(&bp->dmae_lock);
  486. return rc;
  487. }
  488. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  489. u32 len32)
  490. {
  491. struct dmae_command dmae;
  492. if (!bp->dmae_ready) {
  493. u32 *data = bnx2x_sp(bp, wb_data[0]);
  494. if (CHIP_IS_E1(bp))
  495. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  496. else
  497. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  498. return;
  499. }
  500. /* set opcode and fixed command fields */
  501. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  502. /* fill in addresses and len */
  503. dmae.src_addr_lo = U64_LO(dma_addr);
  504. dmae.src_addr_hi = U64_HI(dma_addr);
  505. dmae.dst_addr_lo = dst_addr >> 2;
  506. dmae.dst_addr_hi = 0;
  507. dmae.len = len32;
  508. /* issue the command and wait for completion */
  509. bnx2x_issue_dmae_with_comp(bp, &dmae);
  510. }
  511. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  512. {
  513. struct dmae_command dmae;
  514. if (!bp->dmae_ready) {
  515. u32 *data = bnx2x_sp(bp, wb_data[0]);
  516. int i;
  517. if (CHIP_IS_E1(bp))
  518. for (i = 0; i < len32; i++)
  519. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  520. else
  521. for (i = 0; i < len32; i++)
  522. data[i] = REG_RD(bp, src_addr + i*4);
  523. return;
  524. }
  525. /* set opcode and fixed command fields */
  526. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  527. /* fill in addresses and len */
  528. dmae.src_addr_lo = src_addr >> 2;
  529. dmae.src_addr_hi = 0;
  530. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  531. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  532. dmae.len = len32;
  533. /* issue the command and wait for completion */
  534. bnx2x_issue_dmae_with_comp(bp, &dmae);
  535. }
  536. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  537. u32 addr, u32 len)
  538. {
  539. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  540. int offset = 0;
  541. while (len > dmae_wr_max) {
  542. bnx2x_write_dmae(bp, phys_addr + offset,
  543. addr + offset, dmae_wr_max);
  544. offset += dmae_wr_max * 4;
  545. len -= dmae_wr_max;
  546. }
  547. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  548. }
  549. static int bnx2x_mc_assert(struct bnx2x *bp)
  550. {
  551. char last_idx;
  552. int i, rc = 0;
  553. u32 row0, row1, row2, row3;
  554. /* XSTORM */
  555. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  556. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  557. if (last_idx)
  558. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  559. /* print the asserts */
  560. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  561. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  562. XSTORM_ASSERT_LIST_OFFSET(i));
  563. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  564. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  565. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  566. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  567. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  568. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  569. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  570. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  571. i, row3, row2, row1, row0);
  572. rc++;
  573. } else {
  574. break;
  575. }
  576. }
  577. /* TSTORM */
  578. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  579. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  580. if (last_idx)
  581. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  582. /* print the asserts */
  583. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  584. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  585. TSTORM_ASSERT_LIST_OFFSET(i));
  586. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  587. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  588. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  589. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  590. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  591. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  592. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  593. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  594. i, row3, row2, row1, row0);
  595. rc++;
  596. } else {
  597. break;
  598. }
  599. }
  600. /* CSTORM */
  601. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  602. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  603. if (last_idx)
  604. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  605. /* print the asserts */
  606. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  607. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  608. CSTORM_ASSERT_LIST_OFFSET(i));
  609. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  610. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  611. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  612. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  613. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  614. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  615. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  616. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  617. i, row3, row2, row1, row0);
  618. rc++;
  619. } else {
  620. break;
  621. }
  622. }
  623. /* USTORM */
  624. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  625. USTORM_ASSERT_LIST_INDEX_OFFSET);
  626. if (last_idx)
  627. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  628. /* print the asserts */
  629. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  630. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  631. USTORM_ASSERT_LIST_OFFSET(i));
  632. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  633. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  634. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  635. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  636. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  637. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  638. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  639. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  640. i, row3, row2, row1, row0);
  641. rc++;
  642. } else {
  643. break;
  644. }
  645. }
  646. return rc;
  647. }
  648. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  649. {
  650. u32 addr, val;
  651. u32 mark, offset;
  652. __be32 data[9];
  653. int word;
  654. u32 trace_shmem_base;
  655. if (BP_NOMCP(bp)) {
  656. BNX2X_ERR("NO MCP - can not dump\n");
  657. return;
  658. }
  659. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  660. (bp->common.bc_ver & 0xff0000) >> 16,
  661. (bp->common.bc_ver & 0xff00) >> 8,
  662. (bp->common.bc_ver & 0xff));
  663. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  664. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  665. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  666. if (BP_PATH(bp) == 0)
  667. trace_shmem_base = bp->common.shmem_base;
  668. else
  669. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  670. addr = trace_shmem_base - 0x800;
  671. /* validate TRCB signature */
  672. mark = REG_RD(bp, addr);
  673. if (mark != MFW_TRACE_SIGNATURE) {
  674. BNX2X_ERR("Trace buffer signature is missing.");
  675. return ;
  676. }
  677. /* read cyclic buffer pointer */
  678. addr += 4;
  679. mark = REG_RD(bp, addr);
  680. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  681. + ((mark + 0x3) & ~0x3) - 0x08000000;
  682. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  683. printk("%s", lvl);
  684. /* dump buffer after the mark */
  685. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  686. for (word = 0; word < 8; word++)
  687. data[word] = htonl(REG_RD(bp, offset + 4*word));
  688. data[8] = 0x0;
  689. pr_cont("%s", (char *)data);
  690. }
  691. /* dump buffer before the mark */
  692. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  693. for (word = 0; word < 8; word++)
  694. data[word] = htonl(REG_RD(bp, offset + 4*word));
  695. data[8] = 0x0;
  696. pr_cont("%s", (char *)data);
  697. }
  698. printk("%s" "end of fw dump\n", lvl);
  699. }
  700. static void bnx2x_fw_dump(struct bnx2x *bp)
  701. {
  702. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  703. }
  704. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  705. {
  706. int port = BP_PORT(bp);
  707. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  708. u32 val = REG_RD(bp, addr);
  709. /* in E1 we must use only PCI configuration space to disable
  710. * MSI/MSIX capablility
  711. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  712. */
  713. if (CHIP_IS_E1(bp)) {
  714. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  715. * Use mask register to prevent from HC sending interrupts
  716. * after we exit the function
  717. */
  718. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  719. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  720. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  721. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  722. } else
  723. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  724. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  725. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  726. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  727. DP(NETIF_MSG_IFDOWN,
  728. "write %x to HC %d (addr 0x%x)\n",
  729. val, port, addr);
  730. /* flush all outstanding writes */
  731. mmiowb();
  732. REG_WR(bp, addr, val);
  733. if (REG_RD(bp, addr) != val)
  734. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  735. }
  736. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  737. {
  738. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  739. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  740. IGU_PF_CONF_INT_LINE_EN |
  741. IGU_PF_CONF_ATTN_BIT_EN);
  742. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  743. /* flush all outstanding writes */
  744. mmiowb();
  745. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  746. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  747. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  748. }
  749. static void bnx2x_int_disable(struct bnx2x *bp)
  750. {
  751. if (bp->common.int_block == INT_BLOCK_HC)
  752. bnx2x_hc_int_disable(bp);
  753. else
  754. bnx2x_igu_int_disable(bp);
  755. }
  756. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  757. {
  758. int i;
  759. u16 j;
  760. struct hc_sp_status_block_data sp_sb_data;
  761. int func = BP_FUNC(bp);
  762. #ifdef BNX2X_STOP_ON_ERROR
  763. u16 start = 0, end = 0;
  764. u8 cos;
  765. #endif
  766. if (disable_int)
  767. bnx2x_int_disable(bp);
  768. bp->stats_state = STATS_STATE_DISABLED;
  769. bp->eth_stats.unrecoverable_error++;
  770. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  771. BNX2X_ERR("begin crash dump -----------------\n");
  772. /* Indices */
  773. /* Common */
  774. 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",
  775. bp->def_idx, bp->def_att_idx, bp->attn_state,
  776. bp->spq_prod_idx, bp->stats_counter);
  777. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  778. bp->def_status_blk->atten_status_block.attn_bits,
  779. bp->def_status_blk->atten_status_block.attn_bits_ack,
  780. bp->def_status_blk->atten_status_block.status_block_id,
  781. bp->def_status_blk->atten_status_block.attn_bits_index);
  782. BNX2X_ERR(" def (");
  783. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  784. pr_cont("0x%x%s",
  785. bp->def_status_blk->sp_sb.index_values[i],
  786. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  787. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  788. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  789. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  790. i*sizeof(u32));
  791. 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",
  792. sp_sb_data.igu_sb_id,
  793. sp_sb_data.igu_seg_id,
  794. sp_sb_data.p_func.pf_id,
  795. sp_sb_data.p_func.vnic_id,
  796. sp_sb_data.p_func.vf_id,
  797. sp_sb_data.p_func.vf_valid,
  798. sp_sb_data.state);
  799. for_each_eth_queue(bp, i) {
  800. struct bnx2x_fastpath *fp = &bp->fp[i];
  801. int loop;
  802. struct hc_status_block_data_e2 sb_data_e2;
  803. struct hc_status_block_data_e1x sb_data_e1x;
  804. struct hc_status_block_sm *hc_sm_p =
  805. CHIP_IS_E1x(bp) ?
  806. sb_data_e1x.common.state_machine :
  807. sb_data_e2.common.state_machine;
  808. struct hc_index_data *hc_index_p =
  809. CHIP_IS_E1x(bp) ?
  810. sb_data_e1x.index_data :
  811. sb_data_e2.index_data;
  812. u8 data_size, cos;
  813. u32 *sb_data_p;
  814. struct bnx2x_fp_txdata txdata;
  815. /* Rx */
  816. 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",
  817. i, fp->rx_bd_prod, fp->rx_bd_cons,
  818. fp->rx_comp_prod,
  819. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  820. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  821. fp->rx_sge_prod, fp->last_max_sge,
  822. le16_to_cpu(fp->fp_hc_idx));
  823. /* Tx */
  824. for_each_cos_in_tx_queue(fp, cos)
  825. {
  826. txdata = *fp->txdata_ptr[cos];
  827. 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",
  828. i, txdata.tx_pkt_prod,
  829. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  830. txdata.tx_bd_cons,
  831. le16_to_cpu(*txdata.tx_cons_sb));
  832. }
  833. loop = CHIP_IS_E1x(bp) ?
  834. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  835. /* host sb data */
  836. if (IS_FCOE_FP(fp))
  837. continue;
  838. BNX2X_ERR(" run indexes (");
  839. for (j = 0; j < HC_SB_MAX_SM; j++)
  840. pr_cont("0x%x%s",
  841. fp->sb_running_index[j],
  842. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  843. BNX2X_ERR(" indexes (");
  844. for (j = 0; j < loop; j++)
  845. pr_cont("0x%x%s",
  846. fp->sb_index_values[j],
  847. (j == loop - 1) ? ")" : " ");
  848. /* fw sb data */
  849. data_size = CHIP_IS_E1x(bp) ?
  850. sizeof(struct hc_status_block_data_e1x) :
  851. sizeof(struct hc_status_block_data_e2);
  852. data_size /= sizeof(u32);
  853. sb_data_p = CHIP_IS_E1x(bp) ?
  854. (u32 *)&sb_data_e1x :
  855. (u32 *)&sb_data_e2;
  856. /* copy sb data in here */
  857. for (j = 0; j < data_size; j++)
  858. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  859. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  860. j * sizeof(u32));
  861. if (!CHIP_IS_E1x(bp)) {
  862. 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",
  863. sb_data_e2.common.p_func.pf_id,
  864. sb_data_e2.common.p_func.vf_id,
  865. sb_data_e2.common.p_func.vf_valid,
  866. sb_data_e2.common.p_func.vnic_id,
  867. sb_data_e2.common.same_igu_sb_1b,
  868. sb_data_e2.common.state);
  869. } else {
  870. 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",
  871. sb_data_e1x.common.p_func.pf_id,
  872. sb_data_e1x.common.p_func.vf_id,
  873. sb_data_e1x.common.p_func.vf_valid,
  874. sb_data_e1x.common.p_func.vnic_id,
  875. sb_data_e1x.common.same_igu_sb_1b,
  876. sb_data_e1x.common.state);
  877. }
  878. /* SB_SMs data */
  879. for (j = 0; j < HC_SB_MAX_SM; j++) {
  880. 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",
  881. j, hc_sm_p[j].__flags,
  882. hc_sm_p[j].igu_sb_id,
  883. hc_sm_p[j].igu_seg_id,
  884. hc_sm_p[j].time_to_expire,
  885. hc_sm_p[j].timer_value);
  886. }
  887. /* Indecies data */
  888. for (j = 0; j < loop; j++) {
  889. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  890. hc_index_p[j].flags,
  891. hc_index_p[j].timeout);
  892. }
  893. }
  894. #ifdef BNX2X_STOP_ON_ERROR
  895. /* event queue */
  896. for (i = 0; i < NUM_EQ_DESC; i++) {
  897. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  898. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  899. i, bp->eq_ring[i].message.opcode,
  900. bp->eq_ring[i].message.error);
  901. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  902. }
  903. /* Rings */
  904. /* Rx */
  905. for_each_valid_rx_queue(bp, i) {
  906. struct bnx2x_fastpath *fp = &bp->fp[i];
  907. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  908. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  909. for (j = start; j != end; j = RX_BD(j + 1)) {
  910. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  911. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  912. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  913. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  914. }
  915. start = RX_SGE(fp->rx_sge_prod);
  916. end = RX_SGE(fp->last_max_sge);
  917. for (j = start; j != end; j = RX_SGE(j + 1)) {
  918. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  919. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  920. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  921. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  922. }
  923. start = RCQ_BD(fp->rx_comp_cons - 10);
  924. end = RCQ_BD(fp->rx_comp_cons + 503);
  925. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  926. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  927. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  928. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  929. }
  930. }
  931. /* Tx */
  932. for_each_valid_tx_queue(bp, i) {
  933. struct bnx2x_fastpath *fp = &bp->fp[i];
  934. for_each_cos_in_tx_queue(fp, cos) {
  935. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  936. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  937. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  938. for (j = start; j != end; j = TX_BD(j + 1)) {
  939. struct sw_tx_bd *sw_bd =
  940. &txdata->tx_buf_ring[j];
  941. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  942. i, cos, j, sw_bd->skb,
  943. sw_bd->first_bd);
  944. }
  945. start = TX_BD(txdata->tx_bd_cons - 10);
  946. end = TX_BD(txdata->tx_bd_cons + 254);
  947. for (j = start; j != end; j = TX_BD(j + 1)) {
  948. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  949. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  950. i, cos, j, tx_bd[0], tx_bd[1],
  951. tx_bd[2], tx_bd[3]);
  952. }
  953. }
  954. }
  955. #endif
  956. bnx2x_fw_dump(bp);
  957. bnx2x_mc_assert(bp);
  958. BNX2X_ERR("end crash dump -----------------\n");
  959. }
  960. /*
  961. * FLR Support for E2
  962. *
  963. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  964. * initialization.
  965. */
  966. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  967. #define FLR_WAIT_INTERVAL 50 /* usec */
  968. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  969. struct pbf_pN_buf_regs {
  970. int pN;
  971. u32 init_crd;
  972. u32 crd;
  973. u32 crd_freed;
  974. };
  975. struct pbf_pN_cmd_regs {
  976. int pN;
  977. u32 lines_occup;
  978. u32 lines_freed;
  979. };
  980. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  981. struct pbf_pN_buf_regs *regs,
  982. u32 poll_count)
  983. {
  984. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  985. u32 cur_cnt = poll_count;
  986. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  987. crd = crd_start = REG_RD(bp, regs->crd);
  988. init_crd = REG_RD(bp, regs->init_crd);
  989. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  990. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  991. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  992. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  993. (init_crd - crd_start))) {
  994. if (cur_cnt--) {
  995. udelay(FLR_WAIT_INTERVAL);
  996. crd = REG_RD(bp, regs->crd);
  997. crd_freed = REG_RD(bp, regs->crd_freed);
  998. } else {
  999. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1000. regs->pN);
  1001. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1002. regs->pN, crd);
  1003. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1004. regs->pN, crd_freed);
  1005. break;
  1006. }
  1007. }
  1008. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1009. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1010. }
  1011. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1012. struct pbf_pN_cmd_regs *regs,
  1013. u32 poll_count)
  1014. {
  1015. u32 occup, to_free, freed, freed_start;
  1016. u32 cur_cnt = poll_count;
  1017. occup = to_free = REG_RD(bp, regs->lines_occup);
  1018. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1019. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1020. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1021. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1022. if (cur_cnt--) {
  1023. udelay(FLR_WAIT_INTERVAL);
  1024. occup = REG_RD(bp, regs->lines_occup);
  1025. freed = REG_RD(bp, regs->lines_freed);
  1026. } else {
  1027. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1028. regs->pN);
  1029. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1030. regs->pN, occup);
  1031. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1032. regs->pN, freed);
  1033. break;
  1034. }
  1035. }
  1036. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1037. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1038. }
  1039. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1040. u32 expected, u32 poll_count)
  1041. {
  1042. u32 cur_cnt = poll_count;
  1043. u32 val;
  1044. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1045. udelay(FLR_WAIT_INTERVAL);
  1046. return val;
  1047. }
  1048. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1049. char *msg, u32 poll_cnt)
  1050. {
  1051. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1052. if (val != 0) {
  1053. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1054. return 1;
  1055. }
  1056. return 0;
  1057. }
  1058. /* Common routines with VF FLR cleanup */
  1059. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1060. {
  1061. /* adjust polling timeout */
  1062. if (CHIP_REV_IS_EMUL(bp))
  1063. return FLR_POLL_CNT * 2000;
  1064. if (CHIP_REV_IS_FPGA(bp))
  1065. return FLR_POLL_CNT * 120;
  1066. return FLR_POLL_CNT;
  1067. }
  1068. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1069. {
  1070. struct pbf_pN_cmd_regs cmd_regs[] = {
  1071. {0, (CHIP_IS_E3B0(bp)) ?
  1072. PBF_REG_TQ_OCCUPANCY_Q0 :
  1073. PBF_REG_P0_TQ_OCCUPANCY,
  1074. (CHIP_IS_E3B0(bp)) ?
  1075. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1076. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1077. {1, (CHIP_IS_E3B0(bp)) ?
  1078. PBF_REG_TQ_OCCUPANCY_Q1 :
  1079. PBF_REG_P1_TQ_OCCUPANCY,
  1080. (CHIP_IS_E3B0(bp)) ?
  1081. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1082. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1083. {4, (CHIP_IS_E3B0(bp)) ?
  1084. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1085. PBF_REG_P4_TQ_OCCUPANCY,
  1086. (CHIP_IS_E3B0(bp)) ?
  1087. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1088. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1089. };
  1090. struct pbf_pN_buf_regs buf_regs[] = {
  1091. {0, (CHIP_IS_E3B0(bp)) ?
  1092. PBF_REG_INIT_CRD_Q0 :
  1093. PBF_REG_P0_INIT_CRD ,
  1094. (CHIP_IS_E3B0(bp)) ?
  1095. PBF_REG_CREDIT_Q0 :
  1096. PBF_REG_P0_CREDIT,
  1097. (CHIP_IS_E3B0(bp)) ?
  1098. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1099. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1100. {1, (CHIP_IS_E3B0(bp)) ?
  1101. PBF_REG_INIT_CRD_Q1 :
  1102. PBF_REG_P1_INIT_CRD,
  1103. (CHIP_IS_E3B0(bp)) ?
  1104. PBF_REG_CREDIT_Q1 :
  1105. PBF_REG_P1_CREDIT,
  1106. (CHIP_IS_E3B0(bp)) ?
  1107. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1108. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1109. {4, (CHIP_IS_E3B0(bp)) ?
  1110. PBF_REG_INIT_CRD_LB_Q :
  1111. PBF_REG_P4_INIT_CRD,
  1112. (CHIP_IS_E3B0(bp)) ?
  1113. PBF_REG_CREDIT_LB_Q :
  1114. PBF_REG_P4_CREDIT,
  1115. (CHIP_IS_E3B0(bp)) ?
  1116. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1117. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1118. };
  1119. int i;
  1120. /* Verify the command queues are flushed P0, P1, P4 */
  1121. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1122. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1123. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1124. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1125. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1126. }
  1127. #define OP_GEN_PARAM(param) \
  1128. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1129. #define OP_GEN_TYPE(type) \
  1130. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1131. #define OP_GEN_AGG_VECT(index) \
  1132. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1133. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1134. {
  1135. u32 op_gen_command = 0;
  1136. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1137. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1138. int ret = 0;
  1139. if (REG_RD(bp, comp_addr)) {
  1140. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1141. return 1;
  1142. }
  1143. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1144. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1145. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1146. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1147. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1148. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1149. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1150. BNX2X_ERR("FW final cleanup did not succeed\n");
  1151. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1152. (REG_RD(bp, comp_addr)));
  1153. bnx2x_panic();
  1154. return 1;
  1155. }
  1156. /* Zero completion for nxt FLR */
  1157. REG_WR(bp, comp_addr, 0);
  1158. return ret;
  1159. }
  1160. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1161. {
  1162. u16 status;
  1163. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1164. return status & PCI_EXP_DEVSTA_TRPND;
  1165. }
  1166. /* PF FLR specific routines
  1167. */
  1168. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1169. {
  1170. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1171. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1172. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1173. "CFC PF usage counter timed out",
  1174. poll_cnt))
  1175. return 1;
  1176. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1177. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1178. DORQ_REG_PF_USAGE_CNT,
  1179. "DQ PF usage counter timed out",
  1180. poll_cnt))
  1181. return 1;
  1182. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1183. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1184. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1185. "QM PF usage counter timed out",
  1186. poll_cnt))
  1187. return 1;
  1188. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1189. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1190. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1191. "Timers VNIC usage counter timed out",
  1192. poll_cnt))
  1193. return 1;
  1194. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1195. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1196. "Timers NUM_SCANS usage counter timed out",
  1197. poll_cnt))
  1198. return 1;
  1199. /* Wait DMAE PF usage counter to zero */
  1200. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1201. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1202. "DMAE dommand register timed out",
  1203. poll_cnt))
  1204. return 1;
  1205. return 0;
  1206. }
  1207. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1208. {
  1209. u32 val;
  1210. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1211. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1212. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1213. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1214. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1215. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1216. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1217. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1218. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1219. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1220. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1221. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1222. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1223. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1224. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1225. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1226. val);
  1227. }
  1228. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1229. {
  1230. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1231. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1232. /* Re-enable PF target read access */
  1233. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1234. /* Poll HW usage counters */
  1235. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1236. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1237. return -EBUSY;
  1238. /* Zero the igu 'trailing edge' and 'leading edge' */
  1239. /* Send the FW cleanup command */
  1240. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1241. return -EBUSY;
  1242. /* ATC cleanup */
  1243. /* Verify TX hw is flushed */
  1244. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1245. /* Wait 100ms (not adjusted according to platform) */
  1246. msleep(100);
  1247. /* Verify no pending pci transactions */
  1248. if (bnx2x_is_pcie_pending(bp->pdev))
  1249. BNX2X_ERR("PCIE Transactions still pending\n");
  1250. /* Debug */
  1251. bnx2x_hw_enable_status(bp);
  1252. /*
  1253. * Master enable - Due to WB DMAE writes performed before this
  1254. * register is re-initialized as part of the regular function init
  1255. */
  1256. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1257. return 0;
  1258. }
  1259. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1260. {
  1261. int port = BP_PORT(bp);
  1262. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1263. u32 val = REG_RD(bp, addr);
  1264. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1265. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1266. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1267. if (msix) {
  1268. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1269. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1270. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1271. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1272. if (single_msix)
  1273. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1274. } else if (msi) {
  1275. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1276. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1277. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1278. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1279. } else {
  1280. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1281. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1282. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1283. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1284. if (!CHIP_IS_E1(bp)) {
  1285. DP(NETIF_MSG_IFUP,
  1286. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1287. REG_WR(bp, addr, val);
  1288. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1289. }
  1290. }
  1291. if (CHIP_IS_E1(bp))
  1292. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1293. DP(NETIF_MSG_IFUP,
  1294. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1295. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1296. REG_WR(bp, addr, val);
  1297. /*
  1298. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1299. */
  1300. mmiowb();
  1301. barrier();
  1302. if (!CHIP_IS_E1(bp)) {
  1303. /* init leading/trailing edge */
  1304. if (IS_MF(bp)) {
  1305. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1306. if (bp->port.pmf)
  1307. /* enable nig and gpio3 attention */
  1308. val |= 0x1100;
  1309. } else
  1310. val = 0xffff;
  1311. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1312. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1313. }
  1314. /* Make sure that interrupts are indeed enabled from here on */
  1315. mmiowb();
  1316. }
  1317. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1318. {
  1319. u32 val;
  1320. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1321. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1322. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1323. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1324. if (msix) {
  1325. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1326. IGU_PF_CONF_SINGLE_ISR_EN);
  1327. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1328. IGU_PF_CONF_ATTN_BIT_EN);
  1329. if (single_msix)
  1330. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1331. } else if (msi) {
  1332. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1333. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1334. IGU_PF_CONF_ATTN_BIT_EN |
  1335. IGU_PF_CONF_SINGLE_ISR_EN);
  1336. } else {
  1337. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1338. val |= (IGU_PF_CONF_INT_LINE_EN |
  1339. IGU_PF_CONF_ATTN_BIT_EN |
  1340. IGU_PF_CONF_SINGLE_ISR_EN);
  1341. }
  1342. /* Clean previous status - need to configure igu prior to ack*/
  1343. if ((!msix) || single_msix) {
  1344. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1345. bnx2x_ack_int(bp);
  1346. }
  1347. val |= IGU_PF_CONF_FUNC_EN;
  1348. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1349. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1350. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1351. if (val & IGU_PF_CONF_INT_LINE_EN)
  1352. pci_intx(bp->pdev, true);
  1353. barrier();
  1354. /* init leading/trailing edge */
  1355. if (IS_MF(bp)) {
  1356. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1357. if (bp->port.pmf)
  1358. /* enable nig and gpio3 attention */
  1359. val |= 0x1100;
  1360. } else
  1361. val = 0xffff;
  1362. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1363. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1364. /* Make sure that interrupts are indeed enabled from here on */
  1365. mmiowb();
  1366. }
  1367. void bnx2x_int_enable(struct bnx2x *bp)
  1368. {
  1369. if (bp->common.int_block == INT_BLOCK_HC)
  1370. bnx2x_hc_int_enable(bp);
  1371. else
  1372. bnx2x_igu_int_enable(bp);
  1373. }
  1374. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1375. {
  1376. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1377. int i, offset;
  1378. if (disable_hw)
  1379. /* prevent the HW from sending interrupts */
  1380. bnx2x_int_disable(bp);
  1381. /* make sure all ISRs are done */
  1382. if (msix) {
  1383. synchronize_irq(bp->msix_table[0].vector);
  1384. offset = 1;
  1385. if (CNIC_SUPPORT(bp))
  1386. offset++;
  1387. for_each_eth_queue(bp, i)
  1388. synchronize_irq(bp->msix_table[offset++].vector);
  1389. } else
  1390. synchronize_irq(bp->pdev->irq);
  1391. /* make sure sp_task is not running */
  1392. cancel_delayed_work(&bp->sp_task);
  1393. cancel_delayed_work(&bp->period_task);
  1394. flush_workqueue(bnx2x_wq);
  1395. }
  1396. /* fast path */
  1397. /*
  1398. * General service functions
  1399. */
  1400. /* Return true if succeeded to acquire the lock */
  1401. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1402. {
  1403. u32 lock_status;
  1404. u32 resource_bit = (1 << resource);
  1405. int func = BP_FUNC(bp);
  1406. u32 hw_lock_control_reg;
  1407. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1408. "Trying to take a lock on resource %d\n", resource);
  1409. /* Validating that the resource is within range */
  1410. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1411. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1412. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1413. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1414. return false;
  1415. }
  1416. if (func <= 5)
  1417. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1418. else
  1419. hw_lock_control_reg =
  1420. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1421. /* Try to acquire the lock */
  1422. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1423. lock_status = REG_RD(bp, hw_lock_control_reg);
  1424. if (lock_status & resource_bit)
  1425. return true;
  1426. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1427. "Failed to get a lock on resource %d\n", resource);
  1428. return false;
  1429. }
  1430. /**
  1431. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1432. *
  1433. * @bp: driver handle
  1434. *
  1435. * Returns the recovery leader resource id according to the engine this function
  1436. * belongs to. Currently only only 2 engines is supported.
  1437. */
  1438. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1439. {
  1440. if (BP_PATH(bp))
  1441. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1442. else
  1443. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1444. }
  1445. /**
  1446. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1447. *
  1448. * @bp: driver handle
  1449. *
  1450. * Tries to acquire a leader lock for current engine.
  1451. */
  1452. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1453. {
  1454. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1455. }
  1456. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1457. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1458. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1459. {
  1460. /* Set the interrupt occurred bit for the sp-task to recognize it
  1461. * must ack the interrupt and transition according to the IGU
  1462. * state machine.
  1463. */
  1464. atomic_set(&bp->interrupt_occurred, 1);
  1465. /* The sp_task must execute only after this bit
  1466. * is set, otherwise we will get out of sync and miss all
  1467. * further interrupts. Hence, the barrier.
  1468. */
  1469. smp_wmb();
  1470. /* schedule sp_task to workqueue */
  1471. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1472. }
  1473. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1474. {
  1475. struct bnx2x *bp = fp->bp;
  1476. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1477. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1478. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1479. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1480. DP(BNX2X_MSG_SP,
  1481. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1482. fp->index, cid, command, bp->state,
  1483. rr_cqe->ramrod_cqe.ramrod_type);
  1484. /* If cid is within VF range, replace the slowpath object with the
  1485. * one corresponding to this VF
  1486. */
  1487. if (cid >= BNX2X_FIRST_VF_CID &&
  1488. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1489. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1490. switch (command) {
  1491. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1492. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1493. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1494. break;
  1495. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1496. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1497. drv_cmd = BNX2X_Q_CMD_SETUP;
  1498. break;
  1499. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1500. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1501. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1502. break;
  1503. case (RAMROD_CMD_ID_ETH_HALT):
  1504. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1505. drv_cmd = BNX2X_Q_CMD_HALT;
  1506. break;
  1507. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1508. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1509. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1510. break;
  1511. case (RAMROD_CMD_ID_ETH_EMPTY):
  1512. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1513. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1514. break;
  1515. default:
  1516. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1517. command, fp->index);
  1518. return;
  1519. }
  1520. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1521. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1522. /* q_obj->complete_cmd() failure means that this was
  1523. * an unexpected completion.
  1524. *
  1525. * In this case we don't want to increase the bp->spq_left
  1526. * because apparently we haven't sent this command the first
  1527. * place.
  1528. */
  1529. #ifdef BNX2X_STOP_ON_ERROR
  1530. bnx2x_panic();
  1531. #else
  1532. return;
  1533. #endif
  1534. /* SRIOV: reschedule any 'in_progress' operations */
  1535. bnx2x_iov_sp_event(bp, cid, true);
  1536. smp_mb__before_atomic_inc();
  1537. atomic_inc(&bp->cq_spq_left);
  1538. /* push the change in bp->spq_left and towards the memory */
  1539. smp_mb__after_atomic_inc();
  1540. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1541. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1542. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1543. /* if Q update ramrod is completed for last Q in AFEX vif set
  1544. * flow, then ACK MCP at the end
  1545. *
  1546. * mark pending ACK to MCP bit.
  1547. * prevent case that both bits are cleared.
  1548. * At the end of load/unload driver checks that
  1549. * sp_state is cleared, and this order prevents
  1550. * races
  1551. */
  1552. smp_mb__before_clear_bit();
  1553. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1554. wmb();
  1555. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1556. smp_mb__after_clear_bit();
  1557. /* schedule the sp task as mcp ack is required */
  1558. bnx2x_schedule_sp_task(bp);
  1559. }
  1560. return;
  1561. }
  1562. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1563. {
  1564. struct bnx2x *bp = netdev_priv(dev_instance);
  1565. u16 status = bnx2x_ack_int(bp);
  1566. u16 mask;
  1567. int i;
  1568. u8 cos;
  1569. /* Return here if interrupt is shared and it's not for us */
  1570. if (unlikely(status == 0)) {
  1571. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1572. return IRQ_NONE;
  1573. }
  1574. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1575. #ifdef BNX2X_STOP_ON_ERROR
  1576. if (unlikely(bp->panic))
  1577. return IRQ_HANDLED;
  1578. #endif
  1579. for_each_eth_queue(bp, i) {
  1580. struct bnx2x_fastpath *fp = &bp->fp[i];
  1581. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1582. if (status & mask) {
  1583. /* Handle Rx or Tx according to SB id */
  1584. prefetch(fp->rx_cons_sb);
  1585. for_each_cos_in_tx_queue(fp, cos)
  1586. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1587. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1588. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1589. status &= ~mask;
  1590. }
  1591. }
  1592. if (CNIC_SUPPORT(bp)) {
  1593. mask = 0x2;
  1594. if (status & (mask | 0x1)) {
  1595. struct cnic_ops *c_ops = NULL;
  1596. rcu_read_lock();
  1597. c_ops = rcu_dereference(bp->cnic_ops);
  1598. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1599. CNIC_DRV_STATE_HANDLES_IRQ))
  1600. c_ops->cnic_handler(bp->cnic_data, NULL);
  1601. rcu_read_unlock();
  1602. status &= ~mask;
  1603. }
  1604. }
  1605. if (unlikely(status & 0x1)) {
  1606. /* schedule sp task to perform default status block work, ack
  1607. * attentions and enable interrupts.
  1608. */
  1609. bnx2x_schedule_sp_task(bp);
  1610. status &= ~0x1;
  1611. if (!status)
  1612. return IRQ_HANDLED;
  1613. }
  1614. if (unlikely(status))
  1615. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1616. status);
  1617. return IRQ_HANDLED;
  1618. }
  1619. /* Link */
  1620. /*
  1621. * General service functions
  1622. */
  1623. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1624. {
  1625. u32 lock_status;
  1626. u32 resource_bit = (1 << resource);
  1627. int func = BP_FUNC(bp);
  1628. u32 hw_lock_control_reg;
  1629. int cnt;
  1630. /* Validating that the resource is within range */
  1631. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1632. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1633. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1634. return -EINVAL;
  1635. }
  1636. if (func <= 5) {
  1637. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1638. } else {
  1639. hw_lock_control_reg =
  1640. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1641. }
  1642. /* Validating that the resource is not already taken */
  1643. lock_status = REG_RD(bp, hw_lock_control_reg);
  1644. if (lock_status & resource_bit) {
  1645. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1646. lock_status, resource_bit);
  1647. return -EEXIST;
  1648. }
  1649. /* Try for 5 second every 5ms */
  1650. for (cnt = 0; cnt < 1000; cnt++) {
  1651. /* Try to acquire the lock */
  1652. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1653. lock_status = REG_RD(bp, hw_lock_control_reg);
  1654. if (lock_status & resource_bit)
  1655. return 0;
  1656. msleep(5);
  1657. }
  1658. BNX2X_ERR("Timeout\n");
  1659. return -EAGAIN;
  1660. }
  1661. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1662. {
  1663. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1664. }
  1665. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1666. {
  1667. u32 lock_status;
  1668. u32 resource_bit = (1 << resource);
  1669. int func = BP_FUNC(bp);
  1670. u32 hw_lock_control_reg;
  1671. /* Validating that the resource is within range */
  1672. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1673. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1674. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1675. return -EINVAL;
  1676. }
  1677. if (func <= 5) {
  1678. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1679. } else {
  1680. hw_lock_control_reg =
  1681. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1682. }
  1683. /* Validating that the resource is currently taken */
  1684. lock_status = REG_RD(bp, hw_lock_control_reg);
  1685. if (!(lock_status & resource_bit)) {
  1686. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1687. lock_status, resource_bit);
  1688. return -EFAULT;
  1689. }
  1690. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1691. return 0;
  1692. }
  1693. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1694. {
  1695. /* The GPIO should be swapped if swap register is set and active */
  1696. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1697. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1698. int gpio_shift = gpio_num +
  1699. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1700. u32 gpio_mask = (1 << gpio_shift);
  1701. u32 gpio_reg;
  1702. int value;
  1703. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1704. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1705. return -EINVAL;
  1706. }
  1707. /* read GPIO value */
  1708. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1709. /* get the requested pin value */
  1710. if ((gpio_reg & gpio_mask) == gpio_mask)
  1711. value = 1;
  1712. else
  1713. value = 0;
  1714. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1715. return value;
  1716. }
  1717. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1718. {
  1719. /* The GPIO should be swapped if swap register is set and active */
  1720. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1721. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1722. int gpio_shift = gpio_num +
  1723. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1724. u32 gpio_mask = (1 << gpio_shift);
  1725. u32 gpio_reg;
  1726. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1727. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1728. return -EINVAL;
  1729. }
  1730. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1731. /* read GPIO and mask except the float bits */
  1732. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1733. switch (mode) {
  1734. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1735. DP(NETIF_MSG_LINK,
  1736. "Set GPIO %d (shift %d) -> output low\n",
  1737. gpio_num, gpio_shift);
  1738. /* clear FLOAT and set CLR */
  1739. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1740. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1741. break;
  1742. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1743. DP(NETIF_MSG_LINK,
  1744. "Set GPIO %d (shift %d) -> output high\n",
  1745. gpio_num, gpio_shift);
  1746. /* clear FLOAT and set SET */
  1747. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1748. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1749. break;
  1750. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1751. DP(NETIF_MSG_LINK,
  1752. "Set GPIO %d (shift %d) -> input\n",
  1753. gpio_num, gpio_shift);
  1754. /* set FLOAT */
  1755. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1756. break;
  1757. default:
  1758. break;
  1759. }
  1760. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1761. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1762. return 0;
  1763. }
  1764. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1765. {
  1766. u32 gpio_reg = 0;
  1767. int rc = 0;
  1768. /* Any port swapping should be handled by caller. */
  1769. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1770. /* read GPIO and mask except the float bits */
  1771. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1772. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1773. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1774. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1775. switch (mode) {
  1776. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1777. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1778. /* set CLR */
  1779. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1780. break;
  1781. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1782. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1783. /* set SET */
  1784. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1785. break;
  1786. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1787. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1788. /* set FLOAT */
  1789. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1790. break;
  1791. default:
  1792. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1793. rc = -EINVAL;
  1794. break;
  1795. }
  1796. if (rc == 0)
  1797. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1798. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1799. return rc;
  1800. }
  1801. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1802. {
  1803. /* The GPIO should be swapped if swap register is set and active */
  1804. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1805. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1806. int gpio_shift = gpio_num +
  1807. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1808. u32 gpio_mask = (1 << gpio_shift);
  1809. u32 gpio_reg;
  1810. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1811. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1812. return -EINVAL;
  1813. }
  1814. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1815. /* read GPIO int */
  1816. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1817. switch (mode) {
  1818. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1819. DP(NETIF_MSG_LINK,
  1820. "Clear GPIO INT %d (shift %d) -> output low\n",
  1821. gpio_num, gpio_shift);
  1822. /* clear SET and set CLR */
  1823. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1824. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1825. break;
  1826. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1827. DP(NETIF_MSG_LINK,
  1828. "Set GPIO INT %d (shift %d) -> output high\n",
  1829. gpio_num, gpio_shift);
  1830. /* clear CLR and set SET */
  1831. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1832. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1833. break;
  1834. default:
  1835. break;
  1836. }
  1837. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1838. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1839. return 0;
  1840. }
  1841. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1842. {
  1843. u32 spio_reg;
  1844. /* Only 2 SPIOs are configurable */
  1845. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1846. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1847. return -EINVAL;
  1848. }
  1849. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1850. /* read SPIO and mask except the float bits */
  1851. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1852. switch (mode) {
  1853. case MISC_SPIO_OUTPUT_LOW:
  1854. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1855. /* clear FLOAT and set CLR */
  1856. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1857. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1858. break;
  1859. case MISC_SPIO_OUTPUT_HIGH:
  1860. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1861. /* clear FLOAT and set SET */
  1862. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1863. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1864. break;
  1865. case MISC_SPIO_INPUT_HI_Z:
  1866. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1867. /* set FLOAT */
  1868. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1869. break;
  1870. default:
  1871. break;
  1872. }
  1873. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1874. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1875. return 0;
  1876. }
  1877. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1878. {
  1879. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1880. switch (bp->link_vars.ieee_fc &
  1881. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1882. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1883. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1884. ADVERTISED_Pause);
  1885. break;
  1886. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1887. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1888. ADVERTISED_Pause);
  1889. break;
  1890. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1891. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1892. break;
  1893. default:
  1894. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1895. ADVERTISED_Pause);
  1896. break;
  1897. }
  1898. }
  1899. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1900. {
  1901. /* Initialize link parameters structure variables
  1902. * It is recommended to turn off RX FC for jumbo frames
  1903. * for better performance
  1904. */
  1905. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1906. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1907. else
  1908. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1909. }
  1910. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1911. {
  1912. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1913. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1914. if (!BP_NOMCP(bp)) {
  1915. bnx2x_set_requested_fc(bp);
  1916. bnx2x_acquire_phy_lock(bp);
  1917. if (load_mode == LOAD_DIAG) {
  1918. struct link_params *lp = &bp->link_params;
  1919. lp->loopback_mode = LOOPBACK_XGXS;
  1920. /* do PHY loopback at 10G speed, if possible */
  1921. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1922. if (lp->speed_cap_mask[cfx_idx] &
  1923. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1924. lp->req_line_speed[cfx_idx] =
  1925. SPEED_10000;
  1926. else
  1927. lp->req_line_speed[cfx_idx] =
  1928. SPEED_1000;
  1929. }
  1930. }
  1931. if (load_mode == LOAD_LOOPBACK_EXT) {
  1932. struct link_params *lp = &bp->link_params;
  1933. lp->loopback_mode = LOOPBACK_EXT;
  1934. }
  1935. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1936. bnx2x_release_phy_lock(bp);
  1937. bnx2x_calc_fc_adv(bp);
  1938. if (bp->link_vars.link_up) {
  1939. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1940. bnx2x_link_report(bp);
  1941. }
  1942. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1943. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1944. return rc;
  1945. }
  1946. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1947. return -EINVAL;
  1948. }
  1949. void bnx2x_link_set(struct bnx2x *bp)
  1950. {
  1951. if (!BP_NOMCP(bp)) {
  1952. bnx2x_acquire_phy_lock(bp);
  1953. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1954. bnx2x_release_phy_lock(bp);
  1955. bnx2x_calc_fc_adv(bp);
  1956. } else
  1957. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1958. }
  1959. static void bnx2x__link_reset(struct bnx2x *bp)
  1960. {
  1961. if (!BP_NOMCP(bp)) {
  1962. bnx2x_acquire_phy_lock(bp);
  1963. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1964. bnx2x_release_phy_lock(bp);
  1965. } else
  1966. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1967. }
  1968. void bnx2x_force_link_reset(struct bnx2x *bp)
  1969. {
  1970. bnx2x_acquire_phy_lock(bp);
  1971. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1972. bnx2x_release_phy_lock(bp);
  1973. }
  1974. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1975. {
  1976. u8 rc = 0;
  1977. if (!BP_NOMCP(bp)) {
  1978. bnx2x_acquire_phy_lock(bp);
  1979. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1980. is_serdes);
  1981. bnx2x_release_phy_lock(bp);
  1982. } else
  1983. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1984. return rc;
  1985. }
  1986. /* Calculates the sum of vn_min_rates.
  1987. It's needed for further normalizing of the min_rates.
  1988. Returns:
  1989. sum of vn_min_rates.
  1990. or
  1991. 0 - if all the min_rates are 0.
  1992. In the later case fainess algorithm should be deactivated.
  1993. If not all min_rates are zero then those that are zeroes will be set to 1.
  1994. */
  1995. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1996. struct cmng_init_input *input)
  1997. {
  1998. int all_zero = 1;
  1999. int vn;
  2000. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2001. u32 vn_cfg = bp->mf_config[vn];
  2002. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2003. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2004. /* Skip hidden vns */
  2005. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2006. vn_min_rate = 0;
  2007. /* If min rate is zero - set it to 1 */
  2008. else if (!vn_min_rate)
  2009. vn_min_rate = DEF_MIN_RATE;
  2010. else
  2011. all_zero = 0;
  2012. input->vnic_min_rate[vn] = vn_min_rate;
  2013. }
  2014. /* if ETS or all min rates are zeros - disable fairness */
  2015. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2016. input->flags.cmng_enables &=
  2017. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2018. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2019. } else if (all_zero) {
  2020. input->flags.cmng_enables &=
  2021. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2022. DP(NETIF_MSG_IFUP,
  2023. "All MIN values are zeroes fairness will be disabled\n");
  2024. } else
  2025. input->flags.cmng_enables |=
  2026. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2027. }
  2028. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2029. struct cmng_init_input *input)
  2030. {
  2031. u16 vn_max_rate;
  2032. u32 vn_cfg = bp->mf_config[vn];
  2033. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2034. vn_max_rate = 0;
  2035. else {
  2036. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2037. if (IS_MF_SI(bp)) {
  2038. /* maxCfg in percents of linkspeed */
  2039. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2040. } else /* SD modes */
  2041. /* maxCfg is absolute in 100Mb units */
  2042. vn_max_rate = maxCfg * 100;
  2043. }
  2044. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2045. input->vnic_max_rate[vn] = vn_max_rate;
  2046. }
  2047. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2048. {
  2049. if (CHIP_REV_IS_SLOW(bp))
  2050. return CMNG_FNS_NONE;
  2051. if (IS_MF(bp))
  2052. return CMNG_FNS_MINMAX;
  2053. return CMNG_FNS_NONE;
  2054. }
  2055. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2056. {
  2057. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2058. if (BP_NOMCP(bp))
  2059. return; /* what should be the default bvalue in this case */
  2060. /* For 2 port configuration the absolute function number formula
  2061. * is:
  2062. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2063. *
  2064. * and there are 4 functions per port
  2065. *
  2066. * For 4 port configuration it is
  2067. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2068. *
  2069. * and there are 2 functions per port
  2070. */
  2071. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2072. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2073. if (func >= E1H_FUNC_MAX)
  2074. break;
  2075. bp->mf_config[vn] =
  2076. MF_CFG_RD(bp, func_mf_config[func].config);
  2077. }
  2078. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2079. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2080. bp->flags |= MF_FUNC_DIS;
  2081. } else {
  2082. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2083. bp->flags &= ~MF_FUNC_DIS;
  2084. }
  2085. }
  2086. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2087. {
  2088. struct cmng_init_input input;
  2089. memset(&input, 0, sizeof(struct cmng_init_input));
  2090. input.port_rate = bp->link_vars.line_speed;
  2091. if (cmng_type == CMNG_FNS_MINMAX) {
  2092. int vn;
  2093. /* read mf conf from shmem */
  2094. if (read_cfg)
  2095. bnx2x_read_mf_cfg(bp);
  2096. /* vn_weight_sum and enable fairness if not 0 */
  2097. bnx2x_calc_vn_min(bp, &input);
  2098. /* calculate and set min-max rate for each vn */
  2099. if (bp->port.pmf)
  2100. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2101. bnx2x_calc_vn_max(bp, vn, &input);
  2102. /* always enable rate shaping and fairness */
  2103. input.flags.cmng_enables |=
  2104. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2105. bnx2x_init_cmng(&input, &bp->cmng);
  2106. return;
  2107. }
  2108. /* rate shaping and fairness are disabled */
  2109. DP(NETIF_MSG_IFUP,
  2110. "rate shaping and fairness are disabled\n");
  2111. }
  2112. static void storm_memset_cmng(struct bnx2x *bp,
  2113. struct cmng_init *cmng,
  2114. u8 port)
  2115. {
  2116. int vn;
  2117. size_t size = sizeof(struct cmng_struct_per_port);
  2118. u32 addr = BAR_XSTRORM_INTMEM +
  2119. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2120. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2121. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2122. int func = func_by_vn(bp, vn);
  2123. addr = BAR_XSTRORM_INTMEM +
  2124. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2125. size = sizeof(struct rate_shaping_vars_per_vn);
  2126. __storm_memset_struct(bp, addr, size,
  2127. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2128. addr = BAR_XSTRORM_INTMEM +
  2129. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2130. size = sizeof(struct fairness_vars_per_vn);
  2131. __storm_memset_struct(bp, addr, size,
  2132. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2133. }
  2134. }
  2135. /* This function is called upon link interrupt */
  2136. static void bnx2x_link_attn(struct bnx2x *bp)
  2137. {
  2138. /* Make sure that we are synced with the current statistics */
  2139. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2140. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2141. if (bp->link_vars.link_up) {
  2142. /* dropless flow control */
  2143. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2144. int port = BP_PORT(bp);
  2145. u32 pause_enabled = 0;
  2146. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2147. pause_enabled = 1;
  2148. REG_WR(bp, BAR_USTRORM_INTMEM +
  2149. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2150. pause_enabled);
  2151. }
  2152. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2153. struct host_port_stats *pstats;
  2154. pstats = bnx2x_sp(bp, port_stats);
  2155. /* reset old mac stats */
  2156. memset(&(pstats->mac_stx[0]), 0,
  2157. sizeof(struct mac_stx));
  2158. }
  2159. if (bp->state == BNX2X_STATE_OPEN)
  2160. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2161. }
  2162. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2163. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2164. if (cmng_fns != CMNG_FNS_NONE) {
  2165. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2166. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2167. } else
  2168. /* rate shaping and fairness are disabled */
  2169. DP(NETIF_MSG_IFUP,
  2170. "single function mode without fairness\n");
  2171. }
  2172. __bnx2x_link_report(bp);
  2173. if (IS_MF(bp))
  2174. bnx2x_link_sync_notify(bp);
  2175. }
  2176. void bnx2x__link_status_update(struct bnx2x *bp)
  2177. {
  2178. if (bp->state != BNX2X_STATE_OPEN)
  2179. return;
  2180. /* read updated dcb configuration */
  2181. if (IS_PF(bp)) {
  2182. bnx2x_dcbx_pmf_update(bp);
  2183. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2184. if (bp->link_vars.link_up)
  2185. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2186. else
  2187. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2188. /* indicate link status */
  2189. bnx2x_link_report(bp);
  2190. } else { /* VF */
  2191. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2192. SUPPORTED_10baseT_Full |
  2193. SUPPORTED_100baseT_Half |
  2194. SUPPORTED_100baseT_Full |
  2195. SUPPORTED_1000baseT_Full |
  2196. SUPPORTED_2500baseX_Full |
  2197. SUPPORTED_10000baseT_Full |
  2198. SUPPORTED_TP |
  2199. SUPPORTED_FIBRE |
  2200. SUPPORTED_Autoneg |
  2201. SUPPORTED_Pause |
  2202. SUPPORTED_Asym_Pause);
  2203. bp->port.advertising[0] = bp->port.supported[0];
  2204. bp->link_params.bp = bp;
  2205. bp->link_params.port = BP_PORT(bp);
  2206. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2207. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2208. bp->link_params.req_line_speed[0] = SPEED_10000;
  2209. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2210. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2211. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2212. bp->link_vars.line_speed = SPEED_10000;
  2213. bp->link_vars.link_status =
  2214. (LINK_STATUS_LINK_UP |
  2215. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2216. bp->link_vars.link_up = 1;
  2217. bp->link_vars.duplex = DUPLEX_FULL;
  2218. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2219. __bnx2x_link_report(bp);
  2220. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2221. }
  2222. }
  2223. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2224. u16 vlan_val, u8 allowed_prio)
  2225. {
  2226. struct bnx2x_func_state_params func_params = {NULL};
  2227. struct bnx2x_func_afex_update_params *f_update_params =
  2228. &func_params.params.afex_update;
  2229. func_params.f_obj = &bp->func_obj;
  2230. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2231. /* no need to wait for RAMROD completion, so don't
  2232. * set RAMROD_COMP_WAIT flag
  2233. */
  2234. f_update_params->vif_id = vifid;
  2235. f_update_params->afex_default_vlan = vlan_val;
  2236. f_update_params->allowed_priorities = allowed_prio;
  2237. /* if ramrod can not be sent, response to MCP immediately */
  2238. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2239. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2240. return 0;
  2241. }
  2242. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2243. u16 vif_index, u8 func_bit_map)
  2244. {
  2245. struct bnx2x_func_state_params func_params = {NULL};
  2246. struct bnx2x_func_afex_viflists_params *update_params =
  2247. &func_params.params.afex_viflists;
  2248. int rc;
  2249. u32 drv_msg_code;
  2250. /* validate only LIST_SET and LIST_GET are received from switch */
  2251. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2252. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2253. cmd_type);
  2254. func_params.f_obj = &bp->func_obj;
  2255. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2256. /* set parameters according to cmd_type */
  2257. update_params->afex_vif_list_command = cmd_type;
  2258. update_params->vif_list_index = vif_index;
  2259. update_params->func_bit_map =
  2260. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2261. update_params->func_to_clear = 0;
  2262. drv_msg_code =
  2263. (cmd_type == VIF_LIST_RULE_GET) ?
  2264. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2265. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2266. /* if ramrod can not be sent, respond to MCP immediately for
  2267. * SET and GET requests (other are not triggered from MCP)
  2268. */
  2269. rc = bnx2x_func_state_change(bp, &func_params);
  2270. if (rc < 0)
  2271. bnx2x_fw_command(bp, drv_msg_code, 0);
  2272. return 0;
  2273. }
  2274. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2275. {
  2276. struct afex_stats afex_stats;
  2277. u32 func = BP_ABS_FUNC(bp);
  2278. u32 mf_config;
  2279. u16 vlan_val;
  2280. u32 vlan_prio;
  2281. u16 vif_id;
  2282. u8 allowed_prio;
  2283. u8 vlan_mode;
  2284. u32 addr_to_write, vifid, addrs, stats_type, i;
  2285. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2286. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2287. DP(BNX2X_MSG_MCP,
  2288. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2289. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2290. }
  2291. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2292. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2293. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2294. DP(BNX2X_MSG_MCP,
  2295. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2296. vifid, addrs);
  2297. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2298. addrs);
  2299. }
  2300. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2301. addr_to_write = SHMEM2_RD(bp,
  2302. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2303. stats_type = SHMEM2_RD(bp,
  2304. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2305. DP(BNX2X_MSG_MCP,
  2306. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2307. addr_to_write);
  2308. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2309. /* write response to scratchpad, for MCP */
  2310. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2311. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2312. *(((u32 *)(&afex_stats))+i));
  2313. /* send ack message to MCP */
  2314. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2315. }
  2316. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2317. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2318. bp->mf_config[BP_VN(bp)] = mf_config;
  2319. DP(BNX2X_MSG_MCP,
  2320. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2321. mf_config);
  2322. /* if VIF_SET is "enabled" */
  2323. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2324. /* set rate limit directly to internal RAM */
  2325. struct cmng_init_input cmng_input;
  2326. struct rate_shaping_vars_per_vn m_rs_vn;
  2327. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2328. u32 addr = BAR_XSTRORM_INTMEM +
  2329. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2330. bp->mf_config[BP_VN(bp)] = mf_config;
  2331. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2332. m_rs_vn.vn_counter.rate =
  2333. cmng_input.vnic_max_rate[BP_VN(bp)];
  2334. m_rs_vn.vn_counter.quota =
  2335. (m_rs_vn.vn_counter.rate *
  2336. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2337. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2338. /* read relevant values from mf_cfg struct in shmem */
  2339. vif_id =
  2340. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2341. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2342. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2343. vlan_val =
  2344. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2345. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2346. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2347. vlan_prio = (mf_config &
  2348. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2349. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2350. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2351. vlan_mode =
  2352. (MF_CFG_RD(bp,
  2353. func_mf_config[func].afex_config) &
  2354. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2355. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2356. allowed_prio =
  2357. (MF_CFG_RD(bp,
  2358. func_mf_config[func].afex_config) &
  2359. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2360. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2361. /* send ramrod to FW, return in case of failure */
  2362. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2363. allowed_prio))
  2364. return;
  2365. bp->afex_def_vlan_tag = vlan_val;
  2366. bp->afex_vlan_mode = vlan_mode;
  2367. } else {
  2368. /* notify link down because BP->flags is disabled */
  2369. bnx2x_link_report(bp);
  2370. /* send INVALID VIF ramrod to FW */
  2371. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2372. /* Reset the default afex VLAN */
  2373. bp->afex_def_vlan_tag = -1;
  2374. }
  2375. }
  2376. }
  2377. static void bnx2x_pmf_update(struct bnx2x *bp)
  2378. {
  2379. int port = BP_PORT(bp);
  2380. u32 val;
  2381. bp->port.pmf = 1;
  2382. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2383. /*
  2384. * We need the mb() to ensure the ordering between the writing to
  2385. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2386. */
  2387. smp_mb();
  2388. /* queue a periodic task */
  2389. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2390. bnx2x_dcbx_pmf_update(bp);
  2391. /* enable nig attention */
  2392. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2393. if (bp->common.int_block == INT_BLOCK_HC) {
  2394. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2395. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2396. } else if (!CHIP_IS_E1x(bp)) {
  2397. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2398. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2399. }
  2400. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2401. }
  2402. /* end of Link */
  2403. /* slow path */
  2404. /*
  2405. * General service functions
  2406. */
  2407. /* send the MCP a request, block until there is a reply */
  2408. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2409. {
  2410. int mb_idx = BP_FW_MB_IDX(bp);
  2411. u32 seq;
  2412. u32 rc = 0;
  2413. u32 cnt = 1;
  2414. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2415. mutex_lock(&bp->fw_mb_mutex);
  2416. seq = ++bp->fw_seq;
  2417. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2418. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2419. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2420. (command | seq), param);
  2421. do {
  2422. /* let the FW do it's magic ... */
  2423. msleep(delay);
  2424. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2425. /* Give the FW up to 5 second (500*10ms) */
  2426. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2427. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2428. cnt*delay, rc, seq);
  2429. /* is this a reply to our command? */
  2430. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2431. rc &= FW_MSG_CODE_MASK;
  2432. else {
  2433. /* FW BUG! */
  2434. BNX2X_ERR("FW failed to respond!\n");
  2435. bnx2x_fw_dump(bp);
  2436. rc = 0;
  2437. }
  2438. mutex_unlock(&bp->fw_mb_mutex);
  2439. return rc;
  2440. }
  2441. static void storm_memset_func_cfg(struct bnx2x *bp,
  2442. struct tstorm_eth_function_common_config *tcfg,
  2443. u16 abs_fid)
  2444. {
  2445. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2446. u32 addr = BAR_TSTRORM_INTMEM +
  2447. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2448. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2449. }
  2450. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2451. {
  2452. if (CHIP_IS_E1x(bp)) {
  2453. struct tstorm_eth_function_common_config tcfg = {0};
  2454. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2455. }
  2456. /* Enable the function in the FW */
  2457. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2458. storm_memset_func_en(bp, p->func_id, 1);
  2459. /* spq */
  2460. if (p->func_flgs & FUNC_FLG_SPQ) {
  2461. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2462. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2463. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2464. }
  2465. }
  2466. /**
  2467. * bnx2x_get_tx_only_flags - Return common flags
  2468. *
  2469. * @bp device handle
  2470. * @fp queue handle
  2471. * @zero_stats TRUE if statistics zeroing is needed
  2472. *
  2473. * Return the flags that are common for the Tx-only and not normal connections.
  2474. */
  2475. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2476. struct bnx2x_fastpath *fp,
  2477. bool zero_stats)
  2478. {
  2479. unsigned long flags = 0;
  2480. /* PF driver will always initialize the Queue to an ACTIVE state */
  2481. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2482. /* tx only connections collect statistics (on the same index as the
  2483. * parent connection). The statistics are zeroed when the parent
  2484. * connection is initialized.
  2485. */
  2486. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2487. if (zero_stats)
  2488. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &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 classfication ==
  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 reenabled */
  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 explict 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. val = (1UL << 31);
  3041. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  3042. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  3043. if (val & (1L << 31))
  3044. break;
  3045. msleep(5);
  3046. }
  3047. if (!(val & (1L << 31))) {
  3048. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3049. rc = -EBUSY;
  3050. }
  3051. return rc;
  3052. }
  3053. /* release split MCP access lock register */
  3054. static void bnx2x_release_alr(struct bnx2x *bp)
  3055. {
  3056. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  3057. }
  3058. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3059. #define BNX2X_DEF_SB_IDX 0x0002
  3060. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3061. {
  3062. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3063. u16 rc = 0;
  3064. barrier(); /* status block is written to by the chip */
  3065. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3066. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3067. rc |= BNX2X_DEF_SB_ATT_IDX;
  3068. }
  3069. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3070. bp->def_idx = def_sb->sp_sb.running_index;
  3071. rc |= BNX2X_DEF_SB_IDX;
  3072. }
  3073. /* Do not reorder: indecies reading should complete before handling */
  3074. barrier();
  3075. return rc;
  3076. }
  3077. /*
  3078. * slow path service functions
  3079. */
  3080. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3081. {
  3082. int port = BP_PORT(bp);
  3083. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3084. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3085. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3086. NIG_REG_MASK_INTERRUPT_PORT0;
  3087. u32 aeu_mask;
  3088. u32 nig_mask = 0;
  3089. u32 reg_addr;
  3090. if (bp->attn_state & asserted)
  3091. BNX2X_ERR("IGU ERROR\n");
  3092. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3093. aeu_mask = REG_RD(bp, aeu_addr);
  3094. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3095. aeu_mask, asserted);
  3096. aeu_mask &= ~(asserted & 0x3ff);
  3097. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3098. REG_WR(bp, aeu_addr, aeu_mask);
  3099. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3100. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3101. bp->attn_state |= asserted;
  3102. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3103. if (asserted & ATTN_HARD_WIRED_MASK) {
  3104. if (asserted & ATTN_NIG_FOR_FUNC) {
  3105. bnx2x_acquire_phy_lock(bp);
  3106. /* save nig interrupt mask */
  3107. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3108. /* If nig_mask is not set, no need to call the update
  3109. * function.
  3110. */
  3111. if (nig_mask) {
  3112. REG_WR(bp, nig_int_mask_addr, 0);
  3113. bnx2x_link_attn(bp);
  3114. }
  3115. /* handle unicore attn? */
  3116. }
  3117. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3118. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3119. if (asserted & GPIO_2_FUNC)
  3120. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3121. if (asserted & GPIO_3_FUNC)
  3122. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3123. if (asserted & GPIO_4_FUNC)
  3124. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3125. if (port == 0) {
  3126. if (asserted & ATTN_GENERAL_ATTN_1) {
  3127. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3128. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3129. }
  3130. if (asserted & ATTN_GENERAL_ATTN_2) {
  3131. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3132. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3133. }
  3134. if (asserted & ATTN_GENERAL_ATTN_3) {
  3135. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3136. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3137. }
  3138. } else {
  3139. if (asserted & ATTN_GENERAL_ATTN_4) {
  3140. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3141. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3142. }
  3143. if (asserted & ATTN_GENERAL_ATTN_5) {
  3144. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3145. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3146. }
  3147. if (asserted & ATTN_GENERAL_ATTN_6) {
  3148. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3149. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3150. }
  3151. }
  3152. } /* if hardwired */
  3153. if (bp->common.int_block == INT_BLOCK_HC)
  3154. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3155. COMMAND_REG_ATTN_BITS_SET);
  3156. else
  3157. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3158. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3159. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3160. REG_WR(bp, reg_addr, asserted);
  3161. /* now set back the mask */
  3162. if (asserted & ATTN_NIG_FOR_FUNC) {
  3163. /* Verify that IGU ack through BAR was written before restoring
  3164. * NIG mask. This loop should exit after 2-3 iterations max.
  3165. */
  3166. if (bp->common.int_block != INT_BLOCK_HC) {
  3167. u32 cnt = 0, igu_acked;
  3168. do {
  3169. igu_acked = REG_RD(bp,
  3170. IGU_REG_ATTENTION_ACK_BITS);
  3171. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3172. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3173. if (!igu_acked)
  3174. DP(NETIF_MSG_HW,
  3175. "Failed to verify IGU ack on time\n");
  3176. barrier();
  3177. }
  3178. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3179. bnx2x_release_phy_lock(bp);
  3180. }
  3181. }
  3182. static void bnx2x_fan_failure(struct bnx2x *bp)
  3183. {
  3184. int port = BP_PORT(bp);
  3185. u32 ext_phy_config;
  3186. /* mark the failure */
  3187. ext_phy_config =
  3188. SHMEM_RD(bp,
  3189. dev_info.port_hw_config[port].external_phy_config);
  3190. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3191. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3192. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3193. ext_phy_config);
  3194. /* log the failure */
  3195. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3196. "Please contact OEM Support for assistance\n");
  3197. /*
  3198. * Schedule device reset (unload)
  3199. * This is due to some boards consuming sufficient power when driver is
  3200. * up to overheat if fan fails.
  3201. */
  3202. smp_mb__before_clear_bit();
  3203. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3204. smp_mb__after_clear_bit();
  3205. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3206. }
  3207. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3208. {
  3209. int port = BP_PORT(bp);
  3210. int reg_offset;
  3211. u32 val;
  3212. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3213. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3214. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3215. val = REG_RD(bp, reg_offset);
  3216. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3217. REG_WR(bp, reg_offset, val);
  3218. BNX2X_ERR("SPIO5 hw attention\n");
  3219. /* Fan failure attention */
  3220. bnx2x_hw_reset_phy(&bp->link_params);
  3221. bnx2x_fan_failure(bp);
  3222. }
  3223. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3224. bnx2x_acquire_phy_lock(bp);
  3225. bnx2x_handle_module_detect_int(&bp->link_params);
  3226. bnx2x_release_phy_lock(bp);
  3227. }
  3228. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3229. val = REG_RD(bp, reg_offset);
  3230. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3231. REG_WR(bp, reg_offset, val);
  3232. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3233. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3234. bnx2x_panic();
  3235. }
  3236. }
  3237. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3238. {
  3239. u32 val;
  3240. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3241. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3242. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3243. /* DORQ discard attention */
  3244. if (val & 0x2)
  3245. BNX2X_ERR("FATAL error from DORQ\n");
  3246. }
  3247. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3248. int port = BP_PORT(bp);
  3249. int reg_offset;
  3250. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3251. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3252. val = REG_RD(bp, reg_offset);
  3253. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3254. REG_WR(bp, reg_offset, val);
  3255. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3256. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3257. bnx2x_panic();
  3258. }
  3259. }
  3260. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3261. {
  3262. u32 val;
  3263. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3264. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3265. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3266. /* CFC error attention */
  3267. if (val & 0x2)
  3268. BNX2X_ERR("FATAL error from CFC\n");
  3269. }
  3270. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3271. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3272. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3273. /* RQ_USDMDP_FIFO_OVERFLOW */
  3274. if (val & 0x18000)
  3275. BNX2X_ERR("FATAL error from PXP\n");
  3276. if (!CHIP_IS_E1x(bp)) {
  3277. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3278. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3279. }
  3280. }
  3281. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3282. int port = BP_PORT(bp);
  3283. int reg_offset;
  3284. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3285. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3286. val = REG_RD(bp, reg_offset);
  3287. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3288. REG_WR(bp, reg_offset, val);
  3289. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3290. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3291. bnx2x_panic();
  3292. }
  3293. }
  3294. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3295. {
  3296. u32 val;
  3297. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3298. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3299. int func = BP_FUNC(bp);
  3300. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3301. bnx2x_read_mf_cfg(bp);
  3302. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3303. func_mf_config[BP_ABS_FUNC(bp)].config);
  3304. val = SHMEM_RD(bp,
  3305. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3306. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3307. bnx2x_dcc_event(bp,
  3308. (val & DRV_STATUS_DCC_EVENT_MASK));
  3309. if (val & DRV_STATUS_SET_MF_BW)
  3310. bnx2x_set_mf_bw(bp);
  3311. if (val & DRV_STATUS_DRV_INFO_REQ)
  3312. bnx2x_handle_drv_info_req(bp);
  3313. if (val & DRV_STATUS_VF_DISABLED)
  3314. bnx2x_vf_handle_flr_event(bp);
  3315. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3316. bnx2x_pmf_update(bp);
  3317. if (bp->port.pmf &&
  3318. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3319. bp->dcbx_enabled > 0)
  3320. /* start dcbx state machine */
  3321. bnx2x_dcbx_set_params(bp,
  3322. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3323. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3324. bnx2x_handle_afex_cmd(bp,
  3325. val & DRV_STATUS_AFEX_EVENT_MASK);
  3326. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3327. bnx2x_handle_eee_event(bp);
  3328. if (bp->link_vars.periodic_flags &
  3329. PERIODIC_FLAGS_LINK_EVENT) {
  3330. /* sync with link */
  3331. bnx2x_acquire_phy_lock(bp);
  3332. bp->link_vars.periodic_flags &=
  3333. ~PERIODIC_FLAGS_LINK_EVENT;
  3334. bnx2x_release_phy_lock(bp);
  3335. if (IS_MF(bp))
  3336. bnx2x_link_sync_notify(bp);
  3337. bnx2x_link_report(bp);
  3338. }
  3339. /* Always call it here: bnx2x_link_report() will
  3340. * prevent the link indication duplication.
  3341. */
  3342. bnx2x__link_status_update(bp);
  3343. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3344. BNX2X_ERR("MC assert!\n");
  3345. bnx2x_mc_assert(bp);
  3346. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3347. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3348. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3349. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3350. bnx2x_panic();
  3351. } else if (attn & BNX2X_MCP_ASSERT) {
  3352. BNX2X_ERR("MCP assert!\n");
  3353. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3354. bnx2x_fw_dump(bp);
  3355. } else
  3356. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3357. }
  3358. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3359. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3360. if (attn & BNX2X_GRC_TIMEOUT) {
  3361. val = CHIP_IS_E1(bp) ? 0 :
  3362. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3363. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3364. }
  3365. if (attn & BNX2X_GRC_RSV) {
  3366. val = CHIP_IS_E1(bp) ? 0 :
  3367. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3368. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3369. }
  3370. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3371. }
  3372. }
  3373. /*
  3374. * Bits map:
  3375. * 0-7 - Engine0 load counter.
  3376. * 8-15 - Engine1 load counter.
  3377. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3378. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3379. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3380. * on the engine
  3381. * 19 - Engine1 ONE_IS_LOADED.
  3382. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3383. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3384. * just the one belonging to its engine).
  3385. *
  3386. */
  3387. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3388. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3389. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3390. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3391. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3392. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3393. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3394. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3395. /*
  3396. * Set the GLOBAL_RESET bit.
  3397. *
  3398. * Should be run under rtnl lock
  3399. */
  3400. void bnx2x_set_reset_global(struct bnx2x *bp)
  3401. {
  3402. u32 val;
  3403. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3404. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3405. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3406. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3407. }
  3408. /*
  3409. * Clear the GLOBAL_RESET bit.
  3410. *
  3411. * Should be run under rtnl lock
  3412. */
  3413. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3414. {
  3415. u32 val;
  3416. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3417. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3418. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3419. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3420. }
  3421. /*
  3422. * Checks the GLOBAL_RESET bit.
  3423. *
  3424. * should be run under rtnl lock
  3425. */
  3426. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3427. {
  3428. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3429. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3430. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3431. }
  3432. /*
  3433. * Clear RESET_IN_PROGRESS bit for the current engine.
  3434. *
  3435. * Should be run under rtnl lock
  3436. */
  3437. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3438. {
  3439. u32 val;
  3440. u32 bit = BP_PATH(bp) ?
  3441. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3442. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3443. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3444. /* Clear the bit */
  3445. val &= ~bit;
  3446. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3447. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3448. }
  3449. /*
  3450. * Set RESET_IN_PROGRESS for the current engine.
  3451. *
  3452. * should be run under rtnl lock
  3453. */
  3454. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3455. {
  3456. u32 val;
  3457. u32 bit = BP_PATH(bp) ?
  3458. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3459. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3460. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3461. /* Set the bit */
  3462. val |= bit;
  3463. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3464. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3465. }
  3466. /*
  3467. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3468. * should be run under rtnl lock
  3469. */
  3470. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3471. {
  3472. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3473. u32 bit = engine ?
  3474. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3475. /* return false if bit is set */
  3476. return (val & bit) ? false : true;
  3477. }
  3478. /*
  3479. * set pf load for the current pf.
  3480. *
  3481. * should be run under rtnl lock
  3482. */
  3483. void bnx2x_set_pf_load(struct bnx2x *bp)
  3484. {
  3485. u32 val1, val;
  3486. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3487. BNX2X_PATH0_LOAD_CNT_MASK;
  3488. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3489. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3490. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3491. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3492. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3493. /* get the current counter value */
  3494. val1 = (val & mask) >> shift;
  3495. /* set bit of that PF */
  3496. val1 |= (1 << bp->pf_num);
  3497. /* clear the old value */
  3498. val &= ~mask;
  3499. /* set the new one */
  3500. val |= ((val1 << shift) & mask);
  3501. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3502. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3503. }
  3504. /**
  3505. * bnx2x_clear_pf_load - clear pf load mark
  3506. *
  3507. * @bp: driver handle
  3508. *
  3509. * Should be run under rtnl lock.
  3510. * Decrements the load counter for the current engine. Returns
  3511. * whether other functions are still loaded
  3512. */
  3513. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3514. {
  3515. u32 val1, val;
  3516. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3517. BNX2X_PATH0_LOAD_CNT_MASK;
  3518. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3519. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3520. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3521. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3522. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3523. /* get the current counter value */
  3524. val1 = (val & mask) >> shift;
  3525. /* clear bit of that PF */
  3526. val1 &= ~(1 << bp->pf_num);
  3527. /* clear the old value */
  3528. val &= ~mask;
  3529. /* set the new one */
  3530. val |= ((val1 << shift) & mask);
  3531. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3532. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3533. return val1 != 0;
  3534. }
  3535. /*
  3536. * Read the load status for the current engine.
  3537. *
  3538. * should be run under rtnl lock
  3539. */
  3540. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3541. {
  3542. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3543. BNX2X_PATH0_LOAD_CNT_MASK);
  3544. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3545. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3546. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3547. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3548. val = (val & mask) >> shift;
  3549. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3550. engine, val);
  3551. return val != 0;
  3552. }
  3553. static void _print_next_block(int idx, const char *blk)
  3554. {
  3555. pr_cont("%s%s", idx ? ", " : "", blk);
  3556. }
  3557. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3558. bool print)
  3559. {
  3560. int i = 0;
  3561. u32 cur_bit = 0;
  3562. for (i = 0; sig; i++) {
  3563. cur_bit = ((u32)0x1 << i);
  3564. if (sig & cur_bit) {
  3565. switch (cur_bit) {
  3566. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3567. if (print)
  3568. _print_next_block(par_num++, "BRB");
  3569. break;
  3570. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3571. if (print)
  3572. _print_next_block(par_num++, "PARSER");
  3573. break;
  3574. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3575. if (print)
  3576. _print_next_block(par_num++, "TSDM");
  3577. break;
  3578. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3579. if (print)
  3580. _print_next_block(par_num++,
  3581. "SEARCHER");
  3582. break;
  3583. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3584. if (print)
  3585. _print_next_block(par_num++, "TCM");
  3586. break;
  3587. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3588. if (print)
  3589. _print_next_block(par_num++, "TSEMI");
  3590. break;
  3591. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3592. if (print)
  3593. _print_next_block(par_num++, "XPB");
  3594. break;
  3595. }
  3596. /* Clear the bit */
  3597. sig &= ~cur_bit;
  3598. }
  3599. }
  3600. return par_num;
  3601. }
  3602. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3603. bool *global, bool print)
  3604. {
  3605. int i = 0;
  3606. u32 cur_bit = 0;
  3607. for (i = 0; sig; i++) {
  3608. cur_bit = ((u32)0x1 << i);
  3609. if (sig & cur_bit) {
  3610. switch (cur_bit) {
  3611. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3612. if (print)
  3613. _print_next_block(par_num++, "PBF");
  3614. break;
  3615. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3616. if (print)
  3617. _print_next_block(par_num++, "QM");
  3618. break;
  3619. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3620. if (print)
  3621. _print_next_block(par_num++, "TM");
  3622. break;
  3623. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3624. if (print)
  3625. _print_next_block(par_num++, "XSDM");
  3626. break;
  3627. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3628. if (print)
  3629. _print_next_block(par_num++, "XCM");
  3630. break;
  3631. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3632. if (print)
  3633. _print_next_block(par_num++, "XSEMI");
  3634. break;
  3635. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3636. if (print)
  3637. _print_next_block(par_num++,
  3638. "DOORBELLQ");
  3639. break;
  3640. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3641. if (print)
  3642. _print_next_block(par_num++, "NIG");
  3643. break;
  3644. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3645. if (print)
  3646. _print_next_block(par_num++,
  3647. "VAUX PCI CORE");
  3648. *global = true;
  3649. break;
  3650. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3651. if (print)
  3652. _print_next_block(par_num++, "DEBUG");
  3653. break;
  3654. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3655. if (print)
  3656. _print_next_block(par_num++, "USDM");
  3657. break;
  3658. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3659. if (print)
  3660. _print_next_block(par_num++, "UCM");
  3661. break;
  3662. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3663. if (print)
  3664. _print_next_block(par_num++, "USEMI");
  3665. break;
  3666. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3667. if (print)
  3668. _print_next_block(par_num++, "UPB");
  3669. break;
  3670. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3671. if (print)
  3672. _print_next_block(par_num++, "CSDM");
  3673. break;
  3674. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3675. if (print)
  3676. _print_next_block(par_num++, "CCM");
  3677. break;
  3678. }
  3679. /* Clear the bit */
  3680. sig &= ~cur_bit;
  3681. }
  3682. }
  3683. return par_num;
  3684. }
  3685. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3686. bool print)
  3687. {
  3688. int i = 0;
  3689. u32 cur_bit = 0;
  3690. for (i = 0; sig; i++) {
  3691. cur_bit = ((u32)0x1 << i);
  3692. if (sig & cur_bit) {
  3693. switch (cur_bit) {
  3694. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3695. if (print)
  3696. _print_next_block(par_num++, "CSEMI");
  3697. break;
  3698. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3699. if (print)
  3700. _print_next_block(par_num++, "PXP");
  3701. break;
  3702. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3703. if (print)
  3704. _print_next_block(par_num++,
  3705. "PXPPCICLOCKCLIENT");
  3706. break;
  3707. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3708. if (print)
  3709. _print_next_block(par_num++, "CFC");
  3710. break;
  3711. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3712. if (print)
  3713. _print_next_block(par_num++, "CDU");
  3714. break;
  3715. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3716. if (print)
  3717. _print_next_block(par_num++, "DMAE");
  3718. break;
  3719. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3720. if (print)
  3721. _print_next_block(par_num++, "IGU");
  3722. break;
  3723. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3724. if (print)
  3725. _print_next_block(par_num++, "MISC");
  3726. break;
  3727. }
  3728. /* Clear the bit */
  3729. sig &= ~cur_bit;
  3730. }
  3731. }
  3732. return par_num;
  3733. }
  3734. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3735. bool *global, bool print)
  3736. {
  3737. int i = 0;
  3738. u32 cur_bit = 0;
  3739. for (i = 0; sig; i++) {
  3740. cur_bit = ((u32)0x1 << i);
  3741. if (sig & cur_bit) {
  3742. switch (cur_bit) {
  3743. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3744. if (print)
  3745. _print_next_block(par_num++, "MCP ROM");
  3746. *global = true;
  3747. break;
  3748. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3749. if (print)
  3750. _print_next_block(par_num++,
  3751. "MCP UMP RX");
  3752. *global = true;
  3753. break;
  3754. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3755. if (print)
  3756. _print_next_block(par_num++,
  3757. "MCP UMP TX");
  3758. *global = true;
  3759. break;
  3760. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3761. if (print)
  3762. _print_next_block(par_num++,
  3763. "MCP SCPAD");
  3764. *global = true;
  3765. break;
  3766. }
  3767. /* Clear the bit */
  3768. sig &= ~cur_bit;
  3769. }
  3770. }
  3771. return par_num;
  3772. }
  3773. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3774. bool print)
  3775. {
  3776. int i = 0;
  3777. u32 cur_bit = 0;
  3778. for (i = 0; sig; i++) {
  3779. cur_bit = ((u32)0x1 << i);
  3780. if (sig & cur_bit) {
  3781. switch (cur_bit) {
  3782. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3783. if (print)
  3784. _print_next_block(par_num++, "PGLUE_B");
  3785. break;
  3786. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3787. if (print)
  3788. _print_next_block(par_num++, "ATC");
  3789. break;
  3790. }
  3791. /* Clear the bit */
  3792. sig &= ~cur_bit;
  3793. }
  3794. }
  3795. return par_num;
  3796. }
  3797. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3798. u32 *sig)
  3799. {
  3800. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3801. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3802. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3803. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3804. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3805. int par_num = 0;
  3806. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3807. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3808. sig[0] & HW_PRTY_ASSERT_SET_0,
  3809. sig[1] & HW_PRTY_ASSERT_SET_1,
  3810. sig[2] & HW_PRTY_ASSERT_SET_2,
  3811. sig[3] & HW_PRTY_ASSERT_SET_3,
  3812. sig[4] & HW_PRTY_ASSERT_SET_4);
  3813. if (print)
  3814. netdev_err(bp->dev,
  3815. "Parity errors detected in blocks: ");
  3816. par_num = bnx2x_check_blocks_with_parity0(
  3817. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3818. par_num = bnx2x_check_blocks_with_parity1(
  3819. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3820. par_num = bnx2x_check_blocks_with_parity2(
  3821. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3822. par_num = bnx2x_check_blocks_with_parity3(
  3823. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3824. par_num = bnx2x_check_blocks_with_parity4(
  3825. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3826. if (print)
  3827. pr_cont("\n");
  3828. return true;
  3829. } else
  3830. return false;
  3831. }
  3832. /**
  3833. * bnx2x_chk_parity_attn - checks for parity attentions.
  3834. *
  3835. * @bp: driver handle
  3836. * @global: true if there was a global attention
  3837. * @print: show parity attention in syslog
  3838. */
  3839. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3840. {
  3841. struct attn_route attn = { {0} };
  3842. int port = BP_PORT(bp);
  3843. attn.sig[0] = REG_RD(bp,
  3844. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3845. port*4);
  3846. attn.sig[1] = REG_RD(bp,
  3847. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3848. port*4);
  3849. attn.sig[2] = REG_RD(bp,
  3850. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3851. port*4);
  3852. attn.sig[3] = REG_RD(bp,
  3853. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3854. port*4);
  3855. if (!CHIP_IS_E1x(bp))
  3856. attn.sig[4] = REG_RD(bp,
  3857. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3858. port*4);
  3859. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3860. }
  3861. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3862. {
  3863. u32 val;
  3864. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3865. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3866. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3867. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3868. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3869. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3870. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3871. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3872. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3873. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3874. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3875. if (val &
  3876. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3877. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3878. if (val &
  3879. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3880. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3881. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3882. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3883. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3884. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3885. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3886. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3887. }
  3888. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3889. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3890. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3891. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3892. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3893. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3894. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3895. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3896. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3897. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3898. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3899. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3900. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3901. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3902. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3903. }
  3904. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3905. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3906. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3907. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3908. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3909. }
  3910. }
  3911. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3912. {
  3913. struct attn_route attn, *group_mask;
  3914. int port = BP_PORT(bp);
  3915. int index;
  3916. u32 reg_addr;
  3917. u32 val;
  3918. u32 aeu_mask;
  3919. bool global = false;
  3920. /* need to take HW lock because MCP or other port might also
  3921. try to handle this event */
  3922. bnx2x_acquire_alr(bp);
  3923. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3924. #ifndef BNX2X_STOP_ON_ERROR
  3925. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3926. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3927. /* Disable HW interrupts */
  3928. bnx2x_int_disable(bp);
  3929. /* In case of parity errors don't handle attentions so that
  3930. * other function would "see" parity errors.
  3931. */
  3932. #else
  3933. bnx2x_panic();
  3934. #endif
  3935. bnx2x_release_alr(bp);
  3936. return;
  3937. }
  3938. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3939. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3940. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3941. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3942. if (!CHIP_IS_E1x(bp))
  3943. attn.sig[4] =
  3944. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3945. else
  3946. attn.sig[4] = 0;
  3947. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3948. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3949. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3950. if (deasserted & (1 << index)) {
  3951. group_mask = &bp->attn_group[index];
  3952. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3953. index,
  3954. group_mask->sig[0], group_mask->sig[1],
  3955. group_mask->sig[2], group_mask->sig[3],
  3956. group_mask->sig[4]);
  3957. bnx2x_attn_int_deasserted4(bp,
  3958. attn.sig[4] & group_mask->sig[4]);
  3959. bnx2x_attn_int_deasserted3(bp,
  3960. attn.sig[3] & group_mask->sig[3]);
  3961. bnx2x_attn_int_deasserted1(bp,
  3962. attn.sig[1] & group_mask->sig[1]);
  3963. bnx2x_attn_int_deasserted2(bp,
  3964. attn.sig[2] & group_mask->sig[2]);
  3965. bnx2x_attn_int_deasserted0(bp,
  3966. attn.sig[0] & group_mask->sig[0]);
  3967. }
  3968. }
  3969. bnx2x_release_alr(bp);
  3970. if (bp->common.int_block == INT_BLOCK_HC)
  3971. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3972. COMMAND_REG_ATTN_BITS_CLR);
  3973. else
  3974. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3975. val = ~deasserted;
  3976. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3977. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3978. REG_WR(bp, reg_addr, val);
  3979. if (~bp->attn_state & deasserted)
  3980. BNX2X_ERR("IGU ERROR\n");
  3981. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3982. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3983. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3984. aeu_mask = REG_RD(bp, reg_addr);
  3985. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3986. aeu_mask, deasserted);
  3987. aeu_mask |= (deasserted & 0x3ff);
  3988. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3989. REG_WR(bp, reg_addr, aeu_mask);
  3990. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3991. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3992. bp->attn_state &= ~deasserted;
  3993. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3994. }
  3995. static void bnx2x_attn_int(struct bnx2x *bp)
  3996. {
  3997. /* read local copy of bits */
  3998. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3999. attn_bits);
  4000. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4001. attn_bits_ack);
  4002. u32 attn_state = bp->attn_state;
  4003. /* look for changed bits */
  4004. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4005. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4006. DP(NETIF_MSG_HW,
  4007. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4008. attn_bits, attn_ack, asserted, deasserted);
  4009. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4010. BNX2X_ERR("BAD attention state\n");
  4011. /* handle bits that were raised */
  4012. if (asserted)
  4013. bnx2x_attn_int_asserted(bp, asserted);
  4014. if (deasserted)
  4015. bnx2x_attn_int_deasserted(bp, deasserted);
  4016. }
  4017. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4018. u16 index, u8 op, u8 update)
  4019. {
  4020. u32 igu_addr = bp->igu_base_addr;
  4021. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4022. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4023. igu_addr);
  4024. }
  4025. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4026. {
  4027. /* No memory barriers */
  4028. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4029. mmiowb(); /* keep prod updates ordered */
  4030. }
  4031. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4032. union event_ring_elem *elem)
  4033. {
  4034. u8 err = elem->message.error;
  4035. if (!bp->cnic_eth_dev.starting_cid ||
  4036. (cid < bp->cnic_eth_dev.starting_cid &&
  4037. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4038. return 1;
  4039. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4040. if (unlikely(err)) {
  4041. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4042. cid);
  4043. bnx2x_panic_dump(bp, false);
  4044. }
  4045. bnx2x_cnic_cfc_comp(bp, cid, err);
  4046. return 0;
  4047. }
  4048. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4049. {
  4050. struct bnx2x_mcast_ramrod_params rparam;
  4051. int rc;
  4052. memset(&rparam, 0, sizeof(rparam));
  4053. rparam.mcast_obj = &bp->mcast_obj;
  4054. netif_addr_lock_bh(bp->dev);
  4055. /* Clear pending state for the last command */
  4056. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4057. /* If there are pending mcast commands - send them */
  4058. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4059. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4060. if (rc < 0)
  4061. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4062. rc);
  4063. }
  4064. netif_addr_unlock_bh(bp->dev);
  4065. }
  4066. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4067. union event_ring_elem *elem)
  4068. {
  4069. unsigned long ramrod_flags = 0;
  4070. int rc = 0;
  4071. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4072. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4073. /* Always push next commands out, don't wait here */
  4074. __set_bit(RAMROD_CONT, &ramrod_flags);
  4075. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4076. >> BNX2X_SWCID_SHIFT) {
  4077. case BNX2X_FILTER_MAC_PENDING:
  4078. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4079. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4080. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4081. else
  4082. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4083. break;
  4084. case BNX2X_FILTER_MCAST_PENDING:
  4085. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4086. /* This is only relevant for 57710 where multicast MACs are
  4087. * configured as unicast MACs using the same ramrod.
  4088. */
  4089. bnx2x_handle_mcast_eqe(bp);
  4090. return;
  4091. default:
  4092. BNX2X_ERR("Unsupported classification command: %d\n",
  4093. elem->message.data.eth_event.echo);
  4094. return;
  4095. }
  4096. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4097. if (rc < 0)
  4098. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4099. else if (rc > 0)
  4100. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4101. }
  4102. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4103. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4104. {
  4105. netif_addr_lock_bh(bp->dev);
  4106. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4107. /* Send rx_mode command again if was requested */
  4108. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4109. bnx2x_set_storm_rx_mode(bp);
  4110. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4111. &bp->sp_state))
  4112. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4113. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4114. &bp->sp_state))
  4115. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4116. netif_addr_unlock_bh(bp->dev);
  4117. }
  4118. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4119. union event_ring_elem *elem)
  4120. {
  4121. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4122. DP(BNX2X_MSG_SP,
  4123. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4124. elem->message.data.vif_list_event.func_bit_map);
  4125. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4126. elem->message.data.vif_list_event.func_bit_map);
  4127. } else if (elem->message.data.vif_list_event.echo ==
  4128. VIF_LIST_RULE_SET) {
  4129. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4130. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4131. }
  4132. }
  4133. /* called with rtnl_lock */
  4134. static void bnx2x_after_function_update(struct bnx2x *bp)
  4135. {
  4136. int q, rc;
  4137. struct bnx2x_fastpath *fp;
  4138. struct bnx2x_queue_state_params queue_params = {NULL};
  4139. struct bnx2x_queue_update_params *q_update_params =
  4140. &queue_params.params.update;
  4141. /* Send Q update command with afex vlan removal values for all Qs */
  4142. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4143. /* set silent vlan removal values according to vlan mode */
  4144. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4145. &q_update_params->update_flags);
  4146. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4147. &q_update_params->update_flags);
  4148. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4149. /* in access mode mark mask and value are 0 to strip all vlans */
  4150. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4151. q_update_params->silent_removal_value = 0;
  4152. q_update_params->silent_removal_mask = 0;
  4153. } else {
  4154. q_update_params->silent_removal_value =
  4155. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4156. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4157. }
  4158. for_each_eth_queue(bp, q) {
  4159. /* Set the appropriate Queue object */
  4160. fp = &bp->fp[q];
  4161. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4162. /* send the ramrod */
  4163. rc = bnx2x_queue_state_change(bp, &queue_params);
  4164. if (rc < 0)
  4165. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4166. q);
  4167. }
  4168. if (!NO_FCOE(bp)) {
  4169. fp = &bp->fp[FCOE_IDX(bp)];
  4170. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4171. /* clear pending completion bit */
  4172. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4173. /* mark latest Q bit */
  4174. smp_mb__before_clear_bit();
  4175. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4176. smp_mb__after_clear_bit();
  4177. /* send Q update ramrod for FCoE Q */
  4178. rc = bnx2x_queue_state_change(bp, &queue_params);
  4179. if (rc < 0)
  4180. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4181. q);
  4182. } else {
  4183. /* If no FCoE ring - ACK MCP now */
  4184. bnx2x_link_report(bp);
  4185. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4186. }
  4187. }
  4188. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4189. struct bnx2x *bp, u32 cid)
  4190. {
  4191. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4192. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4193. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4194. else
  4195. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4196. }
  4197. static void bnx2x_eq_int(struct bnx2x *bp)
  4198. {
  4199. u16 hw_cons, sw_cons, sw_prod;
  4200. union event_ring_elem *elem;
  4201. u8 echo;
  4202. u32 cid;
  4203. u8 opcode;
  4204. int rc, spqe_cnt = 0;
  4205. struct bnx2x_queue_sp_obj *q_obj;
  4206. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4207. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4208. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4209. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4210. * when we get the the next-page we nned to adjust so the loop
  4211. * condition below will be met. The next element is the size of a
  4212. * regular element and hence incrementing by 1
  4213. */
  4214. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4215. hw_cons++;
  4216. /* This function may never run in parallel with itself for a
  4217. * specific bp, thus there is no need in "paired" read memory
  4218. * barrier here.
  4219. */
  4220. sw_cons = bp->eq_cons;
  4221. sw_prod = bp->eq_prod;
  4222. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4223. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4224. for (; sw_cons != hw_cons;
  4225. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4226. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4227. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4228. if (!rc) {
  4229. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4230. rc);
  4231. goto next_spqe;
  4232. }
  4233. /* elem CID originates from FW; actually LE */
  4234. cid = SW_CID((__force __le32)
  4235. elem->message.data.cfc_del_event.cid);
  4236. opcode = elem->message.opcode;
  4237. /* handle eq element */
  4238. switch (opcode) {
  4239. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4240. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4241. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4242. continue;
  4243. case EVENT_RING_OPCODE_STAT_QUERY:
  4244. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4245. "got statistics comp event %d\n",
  4246. bp->stats_comp++);
  4247. /* nothing to do with stats comp */
  4248. goto next_spqe;
  4249. case EVENT_RING_OPCODE_CFC_DEL:
  4250. /* handle according to cid range */
  4251. /*
  4252. * we may want to verify here that the bp state is
  4253. * HALTING
  4254. */
  4255. DP(BNX2X_MSG_SP,
  4256. "got delete ramrod for MULTI[%d]\n", cid);
  4257. if (CNIC_LOADED(bp) &&
  4258. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4259. goto next_spqe;
  4260. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4261. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4262. break;
  4263. goto next_spqe;
  4264. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4265. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4266. if (f_obj->complete_cmd(bp, f_obj,
  4267. BNX2X_F_CMD_TX_STOP))
  4268. break;
  4269. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4270. goto next_spqe;
  4271. case EVENT_RING_OPCODE_START_TRAFFIC:
  4272. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4273. if (f_obj->complete_cmd(bp, f_obj,
  4274. BNX2X_F_CMD_TX_START))
  4275. break;
  4276. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4277. goto next_spqe;
  4278. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4279. echo = elem->message.data.function_update_event.echo;
  4280. if (echo == SWITCH_UPDATE) {
  4281. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4282. "got FUNC_SWITCH_UPDATE ramrod\n");
  4283. if (f_obj->complete_cmd(
  4284. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4285. break;
  4286. } else {
  4287. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4288. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4289. f_obj->complete_cmd(bp, f_obj,
  4290. BNX2X_F_CMD_AFEX_UPDATE);
  4291. /* We will perform the Queues update from
  4292. * sp_rtnl task as all Queue SP operations
  4293. * should run under rtnl_lock.
  4294. */
  4295. smp_mb__before_clear_bit();
  4296. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4297. &bp->sp_rtnl_state);
  4298. smp_mb__after_clear_bit();
  4299. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4300. }
  4301. goto next_spqe;
  4302. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4303. f_obj->complete_cmd(bp, f_obj,
  4304. BNX2X_F_CMD_AFEX_VIFLISTS);
  4305. bnx2x_after_afex_vif_lists(bp, elem);
  4306. goto next_spqe;
  4307. case EVENT_RING_OPCODE_FUNCTION_START:
  4308. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4309. "got FUNC_START ramrod\n");
  4310. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4311. break;
  4312. goto next_spqe;
  4313. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4314. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4315. "got FUNC_STOP ramrod\n");
  4316. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4317. break;
  4318. goto next_spqe;
  4319. }
  4320. switch (opcode | bp->state) {
  4321. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4322. BNX2X_STATE_OPEN):
  4323. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4324. BNX2X_STATE_OPENING_WAIT4_PORT):
  4325. cid = elem->message.data.eth_event.echo &
  4326. BNX2X_SWCID_MASK;
  4327. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4328. cid);
  4329. rss_raw->clear_pending(rss_raw);
  4330. break;
  4331. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4332. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4333. case (EVENT_RING_OPCODE_SET_MAC |
  4334. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4335. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4336. BNX2X_STATE_OPEN):
  4337. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4338. BNX2X_STATE_DIAG):
  4339. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4340. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4341. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4342. bnx2x_handle_classification_eqe(bp, elem);
  4343. break;
  4344. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4345. BNX2X_STATE_OPEN):
  4346. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4347. BNX2X_STATE_DIAG):
  4348. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4349. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4350. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4351. bnx2x_handle_mcast_eqe(bp);
  4352. break;
  4353. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4354. BNX2X_STATE_OPEN):
  4355. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4356. BNX2X_STATE_DIAG):
  4357. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4358. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4359. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4360. bnx2x_handle_rx_mode_eqe(bp);
  4361. break;
  4362. default:
  4363. /* unknown event log error and continue */
  4364. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4365. elem->message.opcode, bp->state);
  4366. }
  4367. next_spqe:
  4368. spqe_cnt++;
  4369. } /* for */
  4370. smp_mb__before_atomic_inc();
  4371. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4372. bp->eq_cons = sw_cons;
  4373. bp->eq_prod = sw_prod;
  4374. /* Make sure that above mem writes were issued towards the memory */
  4375. smp_wmb();
  4376. /* update producer */
  4377. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4378. }
  4379. static void bnx2x_sp_task(struct work_struct *work)
  4380. {
  4381. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4382. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4383. /* make sure the atomic interupt_occurred has been written */
  4384. smp_rmb();
  4385. if (atomic_read(&bp->interrupt_occurred)) {
  4386. /* what work needs to be performed? */
  4387. u16 status = bnx2x_update_dsb_idx(bp);
  4388. DP(BNX2X_MSG_SP, "status %x\n", status);
  4389. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4390. atomic_set(&bp->interrupt_occurred, 0);
  4391. /* HW attentions */
  4392. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4393. bnx2x_attn_int(bp);
  4394. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4395. }
  4396. /* SP events: STAT_QUERY and others */
  4397. if (status & BNX2X_DEF_SB_IDX) {
  4398. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4399. if (FCOE_INIT(bp) &&
  4400. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4401. /* Prevent local bottom-halves from running as
  4402. * we are going to change the local NAPI list.
  4403. */
  4404. local_bh_disable();
  4405. napi_schedule(&bnx2x_fcoe(bp, napi));
  4406. local_bh_enable();
  4407. }
  4408. /* Handle EQ completions */
  4409. bnx2x_eq_int(bp);
  4410. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4411. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4412. status &= ~BNX2X_DEF_SB_IDX;
  4413. }
  4414. /* if status is non zero then perhaps something went wrong */
  4415. if (unlikely(status))
  4416. DP(BNX2X_MSG_SP,
  4417. "got an unknown interrupt! (status 0x%x)\n", status);
  4418. /* ack status block only if something was actually handled */
  4419. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4420. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4421. }
  4422. /* must be called after the EQ processing (since eq leads to sriov
  4423. * ramrod completion flows).
  4424. * This flow may have been scheduled by the arrival of a ramrod
  4425. * completion, or by the sriov code rescheduling itself.
  4426. */
  4427. bnx2x_iov_sp_task(bp);
  4428. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4429. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4430. &bp->sp_state)) {
  4431. bnx2x_link_report(bp);
  4432. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4433. }
  4434. }
  4435. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4436. {
  4437. struct net_device *dev = dev_instance;
  4438. struct bnx2x *bp = netdev_priv(dev);
  4439. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4440. IGU_INT_DISABLE, 0);
  4441. #ifdef BNX2X_STOP_ON_ERROR
  4442. if (unlikely(bp->panic))
  4443. return IRQ_HANDLED;
  4444. #endif
  4445. if (CNIC_LOADED(bp)) {
  4446. struct cnic_ops *c_ops;
  4447. rcu_read_lock();
  4448. c_ops = rcu_dereference(bp->cnic_ops);
  4449. if (c_ops)
  4450. c_ops->cnic_handler(bp->cnic_data, NULL);
  4451. rcu_read_unlock();
  4452. }
  4453. /* schedule sp task to perform default status block work, ack
  4454. * attentions and enable interrupts.
  4455. */
  4456. bnx2x_schedule_sp_task(bp);
  4457. return IRQ_HANDLED;
  4458. }
  4459. /* end of slow path */
  4460. void bnx2x_drv_pulse(struct bnx2x *bp)
  4461. {
  4462. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4463. bp->fw_drv_pulse_wr_seq);
  4464. }
  4465. static void bnx2x_timer(unsigned long data)
  4466. {
  4467. struct bnx2x *bp = (struct bnx2x *) data;
  4468. if (!netif_running(bp->dev))
  4469. return;
  4470. if (IS_PF(bp) &&
  4471. !BP_NOMCP(bp)) {
  4472. int mb_idx = BP_FW_MB_IDX(bp);
  4473. u32 drv_pulse;
  4474. u32 mcp_pulse;
  4475. ++bp->fw_drv_pulse_wr_seq;
  4476. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4477. /* TBD - add SYSTEM_TIME */
  4478. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4479. bnx2x_drv_pulse(bp);
  4480. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4481. MCP_PULSE_SEQ_MASK);
  4482. /* The delta between driver pulse and mcp response
  4483. * should be 1 (before mcp response) or 0 (after mcp response)
  4484. */
  4485. if ((drv_pulse != mcp_pulse) &&
  4486. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4487. /* someone lost a heartbeat... */
  4488. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4489. drv_pulse, mcp_pulse);
  4490. }
  4491. }
  4492. if (bp->state == BNX2X_STATE_OPEN)
  4493. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4494. /* sample pf vf bulletin board for new posts from pf */
  4495. if (IS_VF(bp))
  4496. bnx2x_sample_bulletin(bp);
  4497. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4498. }
  4499. /* end of Statistics */
  4500. /* nic init */
  4501. /*
  4502. * nic init service functions
  4503. */
  4504. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4505. {
  4506. u32 i;
  4507. if (!(len%4) && !(addr%4))
  4508. for (i = 0; i < len; i += 4)
  4509. REG_WR(bp, addr + i, fill);
  4510. else
  4511. for (i = 0; i < len; i++)
  4512. REG_WR8(bp, addr + i, fill);
  4513. }
  4514. /* helper: writes FP SP data to FW - data_size in dwords */
  4515. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4516. int fw_sb_id,
  4517. u32 *sb_data_p,
  4518. u32 data_size)
  4519. {
  4520. int index;
  4521. for (index = 0; index < data_size; index++)
  4522. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4523. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4524. sizeof(u32)*index,
  4525. *(sb_data_p + index));
  4526. }
  4527. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4528. {
  4529. u32 *sb_data_p;
  4530. u32 data_size = 0;
  4531. struct hc_status_block_data_e2 sb_data_e2;
  4532. struct hc_status_block_data_e1x sb_data_e1x;
  4533. /* disable the function first */
  4534. if (!CHIP_IS_E1x(bp)) {
  4535. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4536. sb_data_e2.common.state = SB_DISABLED;
  4537. sb_data_e2.common.p_func.vf_valid = false;
  4538. sb_data_p = (u32 *)&sb_data_e2;
  4539. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4540. } else {
  4541. memset(&sb_data_e1x, 0,
  4542. sizeof(struct hc_status_block_data_e1x));
  4543. sb_data_e1x.common.state = SB_DISABLED;
  4544. sb_data_e1x.common.p_func.vf_valid = false;
  4545. sb_data_p = (u32 *)&sb_data_e1x;
  4546. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4547. }
  4548. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4549. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4550. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4551. CSTORM_STATUS_BLOCK_SIZE);
  4552. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4553. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4554. CSTORM_SYNC_BLOCK_SIZE);
  4555. }
  4556. /* helper: writes SP SB data to FW */
  4557. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4558. struct hc_sp_status_block_data *sp_sb_data)
  4559. {
  4560. int func = BP_FUNC(bp);
  4561. int i;
  4562. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4563. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4564. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4565. i*sizeof(u32),
  4566. *((u32 *)sp_sb_data + i));
  4567. }
  4568. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4569. {
  4570. int func = BP_FUNC(bp);
  4571. struct hc_sp_status_block_data sp_sb_data;
  4572. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4573. sp_sb_data.state = SB_DISABLED;
  4574. sp_sb_data.p_func.vf_valid = false;
  4575. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4576. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4577. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4578. CSTORM_SP_STATUS_BLOCK_SIZE);
  4579. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4580. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4581. CSTORM_SP_SYNC_BLOCK_SIZE);
  4582. }
  4583. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4584. int igu_sb_id, int igu_seg_id)
  4585. {
  4586. hc_sm->igu_sb_id = igu_sb_id;
  4587. hc_sm->igu_seg_id = igu_seg_id;
  4588. hc_sm->timer_value = 0xFF;
  4589. hc_sm->time_to_expire = 0xFFFFFFFF;
  4590. }
  4591. /* allocates state machine ids. */
  4592. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4593. {
  4594. /* zero out state machine indices */
  4595. /* rx indices */
  4596. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4597. /* tx indices */
  4598. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4599. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4600. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4601. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4602. /* map indices */
  4603. /* rx indices */
  4604. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4605. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4606. /* tx indices */
  4607. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4608. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4609. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4610. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4611. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4612. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4613. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4614. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4615. }
  4616. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4617. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4618. {
  4619. int igu_seg_id;
  4620. struct hc_status_block_data_e2 sb_data_e2;
  4621. struct hc_status_block_data_e1x sb_data_e1x;
  4622. struct hc_status_block_sm *hc_sm_p;
  4623. int data_size;
  4624. u32 *sb_data_p;
  4625. if (CHIP_INT_MODE_IS_BC(bp))
  4626. igu_seg_id = HC_SEG_ACCESS_NORM;
  4627. else
  4628. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4629. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4630. if (!CHIP_IS_E1x(bp)) {
  4631. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4632. sb_data_e2.common.state = SB_ENABLED;
  4633. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4634. sb_data_e2.common.p_func.vf_id = vfid;
  4635. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4636. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4637. sb_data_e2.common.same_igu_sb_1b = true;
  4638. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4639. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4640. hc_sm_p = sb_data_e2.common.state_machine;
  4641. sb_data_p = (u32 *)&sb_data_e2;
  4642. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4643. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4644. } else {
  4645. memset(&sb_data_e1x, 0,
  4646. sizeof(struct hc_status_block_data_e1x));
  4647. sb_data_e1x.common.state = SB_ENABLED;
  4648. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4649. sb_data_e1x.common.p_func.vf_id = 0xff;
  4650. sb_data_e1x.common.p_func.vf_valid = false;
  4651. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4652. sb_data_e1x.common.same_igu_sb_1b = true;
  4653. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4654. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4655. hc_sm_p = sb_data_e1x.common.state_machine;
  4656. sb_data_p = (u32 *)&sb_data_e1x;
  4657. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4658. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4659. }
  4660. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4661. igu_sb_id, igu_seg_id);
  4662. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4663. igu_sb_id, igu_seg_id);
  4664. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4665. /* write indices to HW - PCI guarantees endianity of regpairs */
  4666. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4667. }
  4668. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4669. u16 tx_usec, u16 rx_usec)
  4670. {
  4671. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4672. false, rx_usec);
  4673. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4674. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4675. tx_usec);
  4676. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4677. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4678. tx_usec);
  4679. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4680. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4681. tx_usec);
  4682. }
  4683. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4684. {
  4685. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4686. dma_addr_t mapping = bp->def_status_blk_mapping;
  4687. int igu_sp_sb_index;
  4688. int igu_seg_id;
  4689. int port = BP_PORT(bp);
  4690. int func = BP_FUNC(bp);
  4691. int reg_offset, reg_offset_en5;
  4692. u64 section;
  4693. int index;
  4694. struct hc_sp_status_block_data sp_sb_data;
  4695. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4696. if (CHIP_INT_MODE_IS_BC(bp)) {
  4697. igu_sp_sb_index = DEF_SB_IGU_ID;
  4698. igu_seg_id = HC_SEG_ACCESS_DEF;
  4699. } else {
  4700. igu_sp_sb_index = bp->igu_dsb_id;
  4701. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4702. }
  4703. /* ATTN */
  4704. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4705. atten_status_block);
  4706. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4707. bp->attn_state = 0;
  4708. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4709. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4710. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4711. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4712. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4713. int sindex;
  4714. /* take care of sig[0]..sig[4] */
  4715. for (sindex = 0; sindex < 4; sindex++)
  4716. bp->attn_group[index].sig[sindex] =
  4717. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4718. if (!CHIP_IS_E1x(bp))
  4719. /*
  4720. * enable5 is separate from the rest of the registers,
  4721. * and therefore the address skip is 4
  4722. * and not 16 between the different groups
  4723. */
  4724. bp->attn_group[index].sig[4] = REG_RD(bp,
  4725. reg_offset_en5 + 0x4*index);
  4726. else
  4727. bp->attn_group[index].sig[4] = 0;
  4728. }
  4729. if (bp->common.int_block == INT_BLOCK_HC) {
  4730. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4731. HC_REG_ATTN_MSG0_ADDR_L);
  4732. REG_WR(bp, reg_offset, U64_LO(section));
  4733. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4734. } else if (!CHIP_IS_E1x(bp)) {
  4735. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4736. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4737. }
  4738. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4739. sp_sb);
  4740. bnx2x_zero_sp_sb(bp);
  4741. /* PCI guarantees endianity of regpairs */
  4742. sp_sb_data.state = SB_ENABLED;
  4743. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4744. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4745. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4746. sp_sb_data.igu_seg_id = igu_seg_id;
  4747. sp_sb_data.p_func.pf_id = func;
  4748. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4749. sp_sb_data.p_func.vf_id = 0xff;
  4750. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4751. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4752. }
  4753. void bnx2x_update_coalesce(struct bnx2x *bp)
  4754. {
  4755. int i;
  4756. for_each_eth_queue(bp, i)
  4757. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4758. bp->tx_ticks, bp->rx_ticks);
  4759. }
  4760. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4761. {
  4762. spin_lock_init(&bp->spq_lock);
  4763. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4764. bp->spq_prod_idx = 0;
  4765. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4766. bp->spq_prod_bd = bp->spq;
  4767. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4768. }
  4769. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4770. {
  4771. int i;
  4772. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4773. union event_ring_elem *elem =
  4774. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4775. elem->next_page.addr.hi =
  4776. cpu_to_le32(U64_HI(bp->eq_mapping +
  4777. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4778. elem->next_page.addr.lo =
  4779. cpu_to_le32(U64_LO(bp->eq_mapping +
  4780. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4781. }
  4782. bp->eq_cons = 0;
  4783. bp->eq_prod = NUM_EQ_DESC;
  4784. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4785. /* we want a warning message before it gets rought... */
  4786. atomic_set(&bp->eq_spq_left,
  4787. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4788. }
  4789. /* called with netif_addr_lock_bh() */
  4790. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4791. unsigned long rx_mode_flags,
  4792. unsigned long rx_accept_flags,
  4793. unsigned long tx_accept_flags,
  4794. unsigned long ramrod_flags)
  4795. {
  4796. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4797. int rc;
  4798. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4799. /* Prepare ramrod parameters */
  4800. ramrod_param.cid = 0;
  4801. ramrod_param.cl_id = cl_id;
  4802. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4803. ramrod_param.func_id = BP_FUNC(bp);
  4804. ramrod_param.pstate = &bp->sp_state;
  4805. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4806. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4807. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4808. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4809. ramrod_param.ramrod_flags = ramrod_flags;
  4810. ramrod_param.rx_mode_flags = rx_mode_flags;
  4811. ramrod_param.rx_accept_flags = rx_accept_flags;
  4812. ramrod_param.tx_accept_flags = tx_accept_flags;
  4813. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4814. if (rc < 0) {
  4815. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4816. return rc;
  4817. }
  4818. return 0;
  4819. }
  4820. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4821. unsigned long *rx_accept_flags,
  4822. unsigned long *tx_accept_flags)
  4823. {
  4824. /* Clear the flags first */
  4825. *rx_accept_flags = 0;
  4826. *tx_accept_flags = 0;
  4827. switch (rx_mode) {
  4828. case BNX2X_RX_MODE_NONE:
  4829. /*
  4830. * 'drop all' supersedes any accept flags that may have been
  4831. * passed to the function.
  4832. */
  4833. break;
  4834. case BNX2X_RX_MODE_NORMAL:
  4835. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4836. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4837. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4838. /* internal switching mode */
  4839. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4840. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4841. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4842. break;
  4843. case BNX2X_RX_MODE_ALLMULTI:
  4844. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4845. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4846. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4847. /* internal switching mode */
  4848. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4849. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4850. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4851. break;
  4852. case BNX2X_RX_MODE_PROMISC:
  4853. /* According to deffinition of SI mode, iface in promisc mode
  4854. * should receive matched and unmatched (in resolution of port)
  4855. * unicast packets.
  4856. */
  4857. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  4858. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4859. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4860. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4861. /* internal switching mode */
  4862. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4863. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4864. if (IS_MF_SI(bp))
  4865. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  4866. else
  4867. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4868. break;
  4869. default:
  4870. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  4871. return -EINVAL;
  4872. }
  4873. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  4874. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4875. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  4876. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  4877. }
  4878. return 0;
  4879. }
  4880. /* called with netif_addr_lock_bh() */
  4881. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4882. {
  4883. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4884. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4885. int rc;
  4886. if (!NO_FCOE(bp))
  4887. /* Configure rx_mode of FCoE Queue */
  4888. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4889. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  4890. &tx_accept_flags);
  4891. if (rc)
  4892. return rc;
  4893. __set_bit(RAMROD_RX, &ramrod_flags);
  4894. __set_bit(RAMROD_TX, &ramrod_flags);
  4895. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  4896. rx_accept_flags, tx_accept_flags,
  4897. ramrod_flags);
  4898. }
  4899. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4900. {
  4901. int i;
  4902. if (IS_MF_SI(bp))
  4903. /*
  4904. * In switch independent mode, the TSTORM needs to accept
  4905. * packets that failed classification, since approximate match
  4906. * mac addresses aren't written to NIG LLH
  4907. */
  4908. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4909. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4910. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4911. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4912. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4913. /* Zero this manually as its initialization is
  4914. currently missing in the initTool */
  4915. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4916. REG_WR(bp, BAR_USTRORM_INTMEM +
  4917. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4918. if (!CHIP_IS_E1x(bp)) {
  4919. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4920. CHIP_INT_MODE_IS_BC(bp) ?
  4921. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4922. }
  4923. }
  4924. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4925. {
  4926. switch (load_code) {
  4927. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4928. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4929. bnx2x_init_internal_common(bp);
  4930. /* no break */
  4931. case FW_MSG_CODE_DRV_LOAD_PORT:
  4932. /* nothing to do */
  4933. /* no break */
  4934. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4935. /* internal memory per function is
  4936. initialized inside bnx2x_pf_init */
  4937. break;
  4938. default:
  4939. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4940. break;
  4941. }
  4942. }
  4943. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4944. {
  4945. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4946. }
  4947. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4948. {
  4949. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4950. }
  4951. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4952. {
  4953. if (CHIP_IS_E1x(fp->bp))
  4954. return BP_L_ID(fp->bp) + fp->index;
  4955. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4956. return bnx2x_fp_igu_sb_id(fp);
  4957. }
  4958. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4959. {
  4960. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4961. u8 cos;
  4962. unsigned long q_type = 0;
  4963. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4964. fp->rx_queue = fp_idx;
  4965. fp->cid = fp_idx;
  4966. fp->cl_id = bnx2x_fp_cl_id(fp);
  4967. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4968. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4969. /* qZone id equals to FW (per path) client id */
  4970. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4971. /* init shortcut */
  4972. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4973. /* Setup SB indicies */
  4974. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4975. /* Configure Queue State object */
  4976. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4977. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4978. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4979. /* init tx data */
  4980. for_each_cos_in_tx_queue(fp, cos) {
  4981. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4982. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4983. FP_COS_TO_TXQ(fp, cos, bp),
  4984. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4985. cids[cos] = fp->txdata_ptr[cos]->cid;
  4986. }
  4987. /* nothing more for vf to do here */
  4988. if (IS_VF(bp))
  4989. return;
  4990. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4991. fp->fw_sb_id, fp->igu_sb_id);
  4992. bnx2x_update_fpsb_idx(fp);
  4993. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4994. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4995. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4996. /**
  4997. * Configure classification DBs: Always enable Tx switching
  4998. */
  4999. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5000. DP(NETIF_MSG_IFUP,
  5001. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5002. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5003. fp->igu_sb_id);
  5004. }
  5005. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5006. {
  5007. int i;
  5008. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5009. struct eth_tx_next_bd *tx_next_bd =
  5010. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5011. tx_next_bd->addr_hi =
  5012. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5013. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5014. tx_next_bd->addr_lo =
  5015. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5016. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5017. }
  5018. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5019. txdata->tx_db.data.zero_fill1 = 0;
  5020. txdata->tx_db.data.prod = 0;
  5021. txdata->tx_pkt_prod = 0;
  5022. txdata->tx_pkt_cons = 0;
  5023. txdata->tx_bd_prod = 0;
  5024. txdata->tx_bd_cons = 0;
  5025. txdata->tx_pkt = 0;
  5026. }
  5027. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5028. {
  5029. int i;
  5030. for_each_tx_queue_cnic(bp, i)
  5031. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5032. }
  5033. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5034. {
  5035. int i;
  5036. u8 cos;
  5037. for_each_eth_queue(bp, i)
  5038. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5039. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5040. }
  5041. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5042. {
  5043. if (!NO_FCOE(bp))
  5044. bnx2x_init_fcoe_fp(bp);
  5045. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5046. BNX2X_VF_ID_INVALID, false,
  5047. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5048. /* ensure status block indices were read */
  5049. rmb();
  5050. bnx2x_init_rx_rings_cnic(bp);
  5051. bnx2x_init_tx_rings_cnic(bp);
  5052. /* flush all */
  5053. mb();
  5054. mmiowb();
  5055. }
  5056. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  5057. {
  5058. int i;
  5059. for_each_eth_queue(bp, i)
  5060. bnx2x_init_eth_fp(bp, i);
  5061. /* ensure status block indices were read */
  5062. rmb();
  5063. bnx2x_init_rx_rings(bp);
  5064. bnx2x_init_tx_rings(bp);
  5065. if (IS_VF(bp))
  5066. return;
  5067. /* Initialize MOD_ABS interrupts */
  5068. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5069. bp->common.shmem_base, bp->common.shmem2_base,
  5070. BP_PORT(bp));
  5071. bnx2x_init_def_sb(bp);
  5072. bnx2x_update_dsb_idx(bp);
  5073. bnx2x_init_sp_ring(bp);
  5074. bnx2x_init_eq_ring(bp);
  5075. bnx2x_init_internal(bp, load_code);
  5076. bnx2x_pf_init(bp);
  5077. bnx2x_stats_init(bp);
  5078. /* flush all before enabling interrupts */
  5079. mb();
  5080. mmiowb();
  5081. bnx2x_int_enable(bp);
  5082. /* Check for SPIO5 */
  5083. bnx2x_attn_int_deasserted0(bp,
  5084. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5085. AEU_INPUTS_ATTN_BITS_SPIO5);
  5086. }
  5087. /* end of nic init */
  5088. /*
  5089. * gzip service functions
  5090. */
  5091. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5092. {
  5093. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5094. &bp->gunzip_mapping, GFP_KERNEL);
  5095. if (bp->gunzip_buf == NULL)
  5096. goto gunzip_nomem1;
  5097. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5098. if (bp->strm == NULL)
  5099. goto gunzip_nomem2;
  5100. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5101. if (bp->strm->workspace == NULL)
  5102. goto gunzip_nomem3;
  5103. return 0;
  5104. gunzip_nomem3:
  5105. kfree(bp->strm);
  5106. bp->strm = NULL;
  5107. gunzip_nomem2:
  5108. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5109. bp->gunzip_mapping);
  5110. bp->gunzip_buf = NULL;
  5111. gunzip_nomem1:
  5112. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5113. return -ENOMEM;
  5114. }
  5115. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5116. {
  5117. if (bp->strm) {
  5118. vfree(bp->strm->workspace);
  5119. kfree(bp->strm);
  5120. bp->strm = NULL;
  5121. }
  5122. if (bp->gunzip_buf) {
  5123. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5124. bp->gunzip_mapping);
  5125. bp->gunzip_buf = NULL;
  5126. }
  5127. }
  5128. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5129. {
  5130. int n, rc;
  5131. /* check gzip header */
  5132. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5133. BNX2X_ERR("Bad gzip header\n");
  5134. return -EINVAL;
  5135. }
  5136. n = 10;
  5137. #define FNAME 0x8
  5138. if (zbuf[3] & FNAME)
  5139. while ((zbuf[n++] != 0) && (n < len));
  5140. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5141. bp->strm->avail_in = len - n;
  5142. bp->strm->next_out = bp->gunzip_buf;
  5143. bp->strm->avail_out = FW_BUF_SIZE;
  5144. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5145. if (rc != Z_OK)
  5146. return rc;
  5147. rc = zlib_inflate(bp->strm, Z_FINISH);
  5148. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5149. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5150. bp->strm->msg);
  5151. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5152. if (bp->gunzip_outlen & 0x3)
  5153. netdev_err(bp->dev,
  5154. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5155. bp->gunzip_outlen);
  5156. bp->gunzip_outlen >>= 2;
  5157. zlib_inflateEnd(bp->strm);
  5158. if (rc == Z_STREAM_END)
  5159. return 0;
  5160. return rc;
  5161. }
  5162. /* nic load/unload */
  5163. /*
  5164. * General service functions
  5165. */
  5166. /* send a NIG loopback debug packet */
  5167. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5168. {
  5169. u32 wb_write[3];
  5170. /* Ethernet source and destination addresses */
  5171. wb_write[0] = 0x55555555;
  5172. wb_write[1] = 0x55555555;
  5173. wb_write[2] = 0x20; /* SOP */
  5174. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5175. /* NON-IP protocol */
  5176. wb_write[0] = 0x09000000;
  5177. wb_write[1] = 0x55555555;
  5178. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5179. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5180. }
  5181. /* some of the internal memories
  5182. * are not directly readable from the driver
  5183. * to test them we send debug packets
  5184. */
  5185. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5186. {
  5187. int factor;
  5188. int count, i;
  5189. u32 val = 0;
  5190. if (CHIP_REV_IS_FPGA(bp))
  5191. factor = 120;
  5192. else if (CHIP_REV_IS_EMUL(bp))
  5193. factor = 200;
  5194. else
  5195. factor = 1;
  5196. /* Disable inputs of parser neighbor blocks */
  5197. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5198. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5199. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5200. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5201. /* Write 0 to parser credits for CFC search request */
  5202. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5203. /* send Ethernet packet */
  5204. bnx2x_lb_pckt(bp);
  5205. /* TODO do i reset NIG statistic? */
  5206. /* Wait until NIG register shows 1 packet of size 0x10 */
  5207. count = 1000 * factor;
  5208. while (count) {
  5209. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5210. val = *bnx2x_sp(bp, wb_data[0]);
  5211. if (val == 0x10)
  5212. break;
  5213. msleep(10);
  5214. count--;
  5215. }
  5216. if (val != 0x10) {
  5217. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5218. return -1;
  5219. }
  5220. /* Wait until PRS register shows 1 packet */
  5221. count = 1000 * factor;
  5222. while (count) {
  5223. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5224. if (val == 1)
  5225. break;
  5226. msleep(10);
  5227. count--;
  5228. }
  5229. if (val != 0x1) {
  5230. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5231. return -2;
  5232. }
  5233. /* Reset and init BRB, PRS */
  5234. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5235. msleep(50);
  5236. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5237. msleep(50);
  5238. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5239. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5240. DP(NETIF_MSG_HW, "part2\n");
  5241. /* Disable inputs of parser neighbor blocks */
  5242. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5243. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5244. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5245. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5246. /* Write 0 to parser credits for CFC search request */
  5247. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5248. /* send 10 Ethernet packets */
  5249. for (i = 0; i < 10; i++)
  5250. bnx2x_lb_pckt(bp);
  5251. /* Wait until NIG register shows 10 + 1
  5252. packets of size 11*0x10 = 0xb0 */
  5253. count = 1000 * factor;
  5254. while (count) {
  5255. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5256. val = *bnx2x_sp(bp, wb_data[0]);
  5257. if (val == 0xb0)
  5258. break;
  5259. msleep(10);
  5260. count--;
  5261. }
  5262. if (val != 0xb0) {
  5263. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5264. return -3;
  5265. }
  5266. /* Wait until PRS register shows 2 packets */
  5267. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5268. if (val != 2)
  5269. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5270. /* Write 1 to parser credits for CFC search request */
  5271. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5272. /* Wait until PRS register shows 3 packets */
  5273. msleep(10 * factor);
  5274. /* Wait until NIG register shows 1 packet of size 0x10 */
  5275. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5276. if (val != 3)
  5277. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5278. /* clear NIG EOP FIFO */
  5279. for (i = 0; i < 11; i++)
  5280. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5281. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5282. if (val != 1) {
  5283. BNX2X_ERR("clear of NIG failed\n");
  5284. return -4;
  5285. }
  5286. /* Reset and init BRB, PRS, NIG */
  5287. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5288. msleep(50);
  5289. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5290. msleep(50);
  5291. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5292. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5293. if (!CNIC_SUPPORT(bp))
  5294. /* set NIC mode */
  5295. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5296. /* Enable inputs of parser neighbor blocks */
  5297. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5298. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5299. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5300. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5301. DP(NETIF_MSG_HW, "done\n");
  5302. return 0; /* OK */
  5303. }
  5304. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5305. {
  5306. u32 val;
  5307. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5308. if (!CHIP_IS_E1x(bp))
  5309. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5310. else
  5311. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5312. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5313. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5314. /*
  5315. * mask read length error interrupts in brb for parser
  5316. * (parsing unit and 'checksum and crc' unit)
  5317. * these errors are legal (PU reads fixed length and CAC can cause
  5318. * read length error on truncated packets)
  5319. */
  5320. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5321. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5322. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5323. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5324. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5325. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5326. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5327. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5328. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5329. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5330. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5331. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5332. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5333. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5334. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5335. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5336. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5337. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5338. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5339. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5340. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5341. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5342. if (!CHIP_IS_E1x(bp))
  5343. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5344. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5345. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5346. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5347. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5348. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5349. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5350. if (!CHIP_IS_E1x(bp))
  5351. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5352. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5353. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5354. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5355. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5356. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5357. }
  5358. static void bnx2x_reset_common(struct bnx2x *bp)
  5359. {
  5360. u32 val = 0x1400;
  5361. /* reset_common */
  5362. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5363. 0xd3ffff7f);
  5364. if (CHIP_IS_E3(bp)) {
  5365. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5366. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5367. }
  5368. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5369. }
  5370. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5371. {
  5372. bp->dmae_ready = 0;
  5373. spin_lock_init(&bp->dmae_lock);
  5374. }
  5375. static void bnx2x_init_pxp(struct bnx2x *bp)
  5376. {
  5377. u16 devctl;
  5378. int r_order, w_order;
  5379. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5380. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5381. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5382. if (bp->mrrs == -1)
  5383. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5384. else {
  5385. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5386. r_order = bp->mrrs;
  5387. }
  5388. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5389. }
  5390. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5391. {
  5392. int is_required;
  5393. u32 val;
  5394. int port;
  5395. if (BP_NOMCP(bp))
  5396. return;
  5397. is_required = 0;
  5398. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5399. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5400. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5401. is_required = 1;
  5402. /*
  5403. * The fan failure mechanism is usually related to the PHY type since
  5404. * the power consumption of the board is affected by the PHY. Currently,
  5405. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5406. */
  5407. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5408. for (port = PORT_0; port < PORT_MAX; port++) {
  5409. is_required |=
  5410. bnx2x_fan_failure_det_req(
  5411. bp,
  5412. bp->common.shmem_base,
  5413. bp->common.shmem2_base,
  5414. port);
  5415. }
  5416. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5417. if (is_required == 0)
  5418. return;
  5419. /* Fan failure is indicated by SPIO 5 */
  5420. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5421. /* set to active low mode */
  5422. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5423. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5424. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5425. /* enable interrupt to signal the IGU */
  5426. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5427. val |= MISC_SPIO_SPIO5;
  5428. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5429. }
  5430. void bnx2x_pf_disable(struct bnx2x *bp)
  5431. {
  5432. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5433. val &= ~IGU_PF_CONF_FUNC_EN;
  5434. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5435. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5436. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5437. }
  5438. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5439. {
  5440. u32 shmem_base[2], shmem2_base[2];
  5441. /* Avoid common init in case MFW supports LFA */
  5442. if (SHMEM2_RD(bp, size) >
  5443. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5444. return;
  5445. shmem_base[0] = bp->common.shmem_base;
  5446. shmem2_base[0] = bp->common.shmem2_base;
  5447. if (!CHIP_IS_E1x(bp)) {
  5448. shmem_base[1] =
  5449. SHMEM2_RD(bp, other_shmem_base_addr);
  5450. shmem2_base[1] =
  5451. SHMEM2_RD(bp, other_shmem2_base_addr);
  5452. }
  5453. bnx2x_acquire_phy_lock(bp);
  5454. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5455. bp->common.chip_id);
  5456. bnx2x_release_phy_lock(bp);
  5457. }
  5458. /**
  5459. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5460. *
  5461. * @bp: driver handle
  5462. */
  5463. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5464. {
  5465. u32 val;
  5466. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5467. /*
  5468. * take the RESET lock to protect undi_unload flow from accessing
  5469. * registers while we're resetting the chip
  5470. */
  5471. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5472. bnx2x_reset_common(bp);
  5473. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5474. val = 0xfffc;
  5475. if (CHIP_IS_E3(bp)) {
  5476. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5477. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5478. }
  5479. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5480. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5481. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5482. if (!CHIP_IS_E1x(bp)) {
  5483. u8 abs_func_id;
  5484. /**
  5485. * 4-port mode or 2-port mode we need to turn of master-enable
  5486. * for everyone, after that, turn it back on for self.
  5487. * so, we disregard multi-function or not, and always disable
  5488. * for all functions on the given path, this means 0,2,4,6 for
  5489. * path 0 and 1,3,5,7 for path 1
  5490. */
  5491. for (abs_func_id = BP_PATH(bp);
  5492. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5493. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5494. REG_WR(bp,
  5495. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5496. 1);
  5497. continue;
  5498. }
  5499. bnx2x_pretend_func(bp, abs_func_id);
  5500. /* clear pf enable */
  5501. bnx2x_pf_disable(bp);
  5502. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5503. }
  5504. }
  5505. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5506. if (CHIP_IS_E1(bp)) {
  5507. /* enable HW interrupt from PXP on USDM overflow
  5508. bit 16 on INT_MASK_0 */
  5509. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5510. }
  5511. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5512. bnx2x_init_pxp(bp);
  5513. #ifdef __BIG_ENDIAN
  5514. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5515. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5516. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5517. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5518. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5519. /* make sure this value is 0 */
  5520. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5521. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5522. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5523. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5524. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5525. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5526. #endif
  5527. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5528. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5529. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5530. /* let the HW do it's magic ... */
  5531. msleep(100);
  5532. /* finish PXP init */
  5533. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5534. if (val != 1) {
  5535. BNX2X_ERR("PXP2 CFG failed\n");
  5536. return -EBUSY;
  5537. }
  5538. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5539. if (val != 1) {
  5540. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5541. return -EBUSY;
  5542. }
  5543. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5544. * have entries with value "0" and valid bit on.
  5545. * This needs to be done by the first PF that is loaded in a path
  5546. * (i.e. common phase)
  5547. */
  5548. if (!CHIP_IS_E1x(bp)) {
  5549. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5550. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5551. * This occurs when a different function (func2,3) is being marked
  5552. * as "scan-off". Real-life scenario for example: if a driver is being
  5553. * load-unloaded while func6,7 are down. This will cause the timer to access
  5554. * the ilt, translate to a logical address and send a request to read/write.
  5555. * Since the ilt for the function that is down is not valid, this will cause
  5556. * a translation error which is unrecoverable.
  5557. * The Workaround is intended to make sure that when this happens nothing fatal
  5558. * will occur. The workaround:
  5559. * 1. First PF driver which loads on a path will:
  5560. * a. After taking the chip out of reset, by using pretend,
  5561. * it will write "0" to the following registers of
  5562. * the other vnics.
  5563. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5564. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5565. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5566. * And for itself it will write '1' to
  5567. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5568. * dmae-operations (writing to pram for example.)
  5569. * note: can be done for only function 6,7 but cleaner this
  5570. * way.
  5571. * b. Write zero+valid to the entire ILT.
  5572. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5573. * VNIC3 (of that port). The range allocated will be the
  5574. * entire ILT. This is needed to prevent ILT range error.
  5575. * 2. Any PF driver load flow:
  5576. * a. ILT update with the physical addresses of the allocated
  5577. * logical pages.
  5578. * b. Wait 20msec. - note that this timeout is needed to make
  5579. * sure there are no requests in one of the PXP internal
  5580. * queues with "old" ILT addresses.
  5581. * c. PF enable in the PGLC.
  5582. * d. Clear the was_error of the PF in the PGLC. (could have
  5583. * occurred while driver was down)
  5584. * e. PF enable in the CFC (WEAK + STRONG)
  5585. * f. Timers scan enable
  5586. * 3. PF driver unload flow:
  5587. * a. Clear the Timers scan_en.
  5588. * b. Polling for scan_on=0 for that PF.
  5589. * c. Clear the PF enable bit in the PXP.
  5590. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5591. * e. Write zero+valid to all ILT entries (The valid bit must
  5592. * stay set)
  5593. * f. If this is VNIC 3 of a port then also init
  5594. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5595. * to the last enrty in the ILT.
  5596. *
  5597. * Notes:
  5598. * Currently the PF error in the PGLC is non recoverable.
  5599. * In the future the there will be a recovery routine for this error.
  5600. * Currently attention is masked.
  5601. * Having an MCP lock on the load/unload process does not guarantee that
  5602. * there is no Timer disable during Func6/7 enable. This is because the
  5603. * Timers scan is currently being cleared by the MCP on FLR.
  5604. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5605. * there is error before clearing it. But the flow above is simpler and
  5606. * more general.
  5607. * All ILT entries are written by zero+valid and not just PF6/7
  5608. * ILT entries since in the future the ILT entries allocation for
  5609. * PF-s might be dynamic.
  5610. */
  5611. struct ilt_client_info ilt_cli;
  5612. struct bnx2x_ilt ilt;
  5613. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5614. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5615. /* initialize dummy TM client */
  5616. ilt_cli.start = 0;
  5617. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5618. ilt_cli.client_num = ILT_CLIENT_TM;
  5619. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5620. * Step 2: set the timers first/last ilt entry to point
  5621. * to the entire range to prevent ILT range error for 3rd/4th
  5622. * vnic (this code assumes existence of the vnic)
  5623. *
  5624. * both steps performed by call to bnx2x_ilt_client_init_op()
  5625. * with dummy TM client
  5626. *
  5627. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5628. * and his brother are split registers
  5629. */
  5630. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5631. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5632. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5633. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5634. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5635. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5636. }
  5637. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5638. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5639. if (!CHIP_IS_E1x(bp)) {
  5640. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5641. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5642. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5643. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5644. /* let the HW do it's magic ... */
  5645. do {
  5646. msleep(200);
  5647. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5648. } while (factor-- && (val != 1));
  5649. if (val != 1) {
  5650. BNX2X_ERR("ATC_INIT failed\n");
  5651. return -EBUSY;
  5652. }
  5653. }
  5654. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5655. bnx2x_iov_init_dmae(bp);
  5656. /* clean the DMAE memory */
  5657. bp->dmae_ready = 1;
  5658. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5659. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5660. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5661. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5662. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5663. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5664. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5665. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5666. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5667. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5668. /* QM queues pointers table */
  5669. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5670. /* soft reset pulse */
  5671. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5672. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5673. if (CNIC_SUPPORT(bp))
  5674. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5675. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5676. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5677. if (!CHIP_REV_IS_SLOW(bp))
  5678. /* enable hw interrupt from doorbell Q */
  5679. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5680. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5681. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5682. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5683. if (!CHIP_IS_E1(bp))
  5684. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5685. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5686. if (IS_MF_AFEX(bp)) {
  5687. /* configure that VNTag and VLAN headers must be
  5688. * received in afex mode
  5689. */
  5690. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5691. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5692. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5693. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5694. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5695. } else {
  5696. /* Bit-map indicating which L2 hdrs may appear
  5697. * after the basic Ethernet header
  5698. */
  5699. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5700. bp->path_has_ovlan ? 7 : 6);
  5701. }
  5702. }
  5703. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5704. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5705. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5706. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5707. if (!CHIP_IS_E1x(bp)) {
  5708. /* reset VFC memories */
  5709. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5710. VFC_MEMORIES_RST_REG_CAM_RST |
  5711. VFC_MEMORIES_RST_REG_RAM_RST);
  5712. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5713. VFC_MEMORIES_RST_REG_CAM_RST |
  5714. VFC_MEMORIES_RST_REG_RAM_RST);
  5715. msleep(20);
  5716. }
  5717. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5718. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5719. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5720. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5721. /* sync semi rtc */
  5722. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5723. 0x80000000);
  5724. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5725. 0x80000000);
  5726. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5727. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5728. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5729. if (!CHIP_IS_E1x(bp)) {
  5730. if (IS_MF_AFEX(bp)) {
  5731. /* configure that VNTag and VLAN headers must be
  5732. * sent in afex mode
  5733. */
  5734. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5735. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5736. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5737. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5738. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5739. } else {
  5740. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5741. bp->path_has_ovlan ? 7 : 6);
  5742. }
  5743. }
  5744. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5745. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5746. if (CNIC_SUPPORT(bp)) {
  5747. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5748. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5749. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5750. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5751. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5752. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5753. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5754. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5755. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5756. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5757. }
  5758. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5759. if (sizeof(union cdu_context) != 1024)
  5760. /* we currently assume that a context is 1024 bytes */
  5761. dev_alert(&bp->pdev->dev,
  5762. "please adjust the size of cdu_context(%ld)\n",
  5763. (long)sizeof(union cdu_context));
  5764. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5765. val = (4 << 24) + (0 << 12) + 1024;
  5766. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5767. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5768. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5769. /* enable context validation interrupt from CFC */
  5770. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5771. /* set the thresholds to prevent CFC/CDU race */
  5772. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5773. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5774. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5775. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5776. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5777. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5778. /* Reset PCIE errors for debug */
  5779. REG_WR(bp, 0x2814, 0xffffffff);
  5780. REG_WR(bp, 0x3820, 0xffffffff);
  5781. if (!CHIP_IS_E1x(bp)) {
  5782. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5783. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5784. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5785. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5786. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5787. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5788. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5789. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5790. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5791. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5792. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5793. }
  5794. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5795. if (!CHIP_IS_E1(bp)) {
  5796. /* in E3 this done in per-port section */
  5797. if (!CHIP_IS_E3(bp))
  5798. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5799. }
  5800. if (CHIP_IS_E1H(bp))
  5801. /* not applicable for E2 (and above ...) */
  5802. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5803. if (CHIP_REV_IS_SLOW(bp))
  5804. msleep(200);
  5805. /* finish CFC init */
  5806. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5807. if (val != 1) {
  5808. BNX2X_ERR("CFC LL_INIT failed\n");
  5809. return -EBUSY;
  5810. }
  5811. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5812. if (val != 1) {
  5813. BNX2X_ERR("CFC AC_INIT failed\n");
  5814. return -EBUSY;
  5815. }
  5816. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5817. if (val != 1) {
  5818. BNX2X_ERR("CFC CAM_INIT failed\n");
  5819. return -EBUSY;
  5820. }
  5821. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5822. if (CHIP_IS_E1(bp)) {
  5823. /* read NIG statistic
  5824. to see if this is our first up since powerup */
  5825. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5826. val = *bnx2x_sp(bp, wb_data[0]);
  5827. /* do internal memory self test */
  5828. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5829. BNX2X_ERR("internal mem self test failed\n");
  5830. return -EBUSY;
  5831. }
  5832. }
  5833. bnx2x_setup_fan_failure_detection(bp);
  5834. /* clear PXP2 attentions */
  5835. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5836. bnx2x_enable_blocks_attention(bp);
  5837. bnx2x_enable_blocks_parity(bp);
  5838. if (!BP_NOMCP(bp)) {
  5839. if (CHIP_IS_E1x(bp))
  5840. bnx2x__common_init_phy(bp);
  5841. } else
  5842. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5843. return 0;
  5844. }
  5845. /**
  5846. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5847. *
  5848. * @bp: driver handle
  5849. */
  5850. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5851. {
  5852. int rc = bnx2x_init_hw_common(bp);
  5853. if (rc)
  5854. return rc;
  5855. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5856. if (!BP_NOMCP(bp))
  5857. bnx2x__common_init_phy(bp);
  5858. return 0;
  5859. }
  5860. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5861. {
  5862. int port = BP_PORT(bp);
  5863. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5864. u32 low, high;
  5865. u32 val;
  5866. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5867. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5868. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5869. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5870. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5871. /* Timers bug workaround: disables the pf_master bit in pglue at
  5872. * common phase, we need to enable it here before any dmae access are
  5873. * attempted. Therefore we manually added the enable-master to the
  5874. * port phase (it also happens in the function phase)
  5875. */
  5876. if (!CHIP_IS_E1x(bp))
  5877. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5878. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5879. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5880. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5881. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5882. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5883. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5884. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5885. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5886. /* QM cid (connection) count */
  5887. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5888. if (CNIC_SUPPORT(bp)) {
  5889. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5890. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5891. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5892. }
  5893. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5894. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5895. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5896. if (IS_MF(bp))
  5897. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5898. else if (bp->dev->mtu > 4096) {
  5899. if (bp->flags & ONE_PORT_FLAG)
  5900. low = 160;
  5901. else {
  5902. val = bp->dev->mtu;
  5903. /* (24*1024 + val*4)/256 */
  5904. low = 96 + (val/64) +
  5905. ((val % 64) ? 1 : 0);
  5906. }
  5907. } else
  5908. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5909. high = low + 56; /* 14*1024/256 */
  5910. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5911. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5912. }
  5913. if (CHIP_MODE_IS_4_PORT(bp))
  5914. REG_WR(bp, (BP_PORT(bp) ?
  5915. BRB1_REG_MAC_GUARANTIED_1 :
  5916. BRB1_REG_MAC_GUARANTIED_0), 40);
  5917. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5918. if (CHIP_IS_E3B0(bp)) {
  5919. if (IS_MF_AFEX(bp)) {
  5920. /* configure headers for AFEX mode */
  5921. REG_WR(bp, BP_PORT(bp) ?
  5922. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5923. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5924. REG_WR(bp, BP_PORT(bp) ?
  5925. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5926. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5927. REG_WR(bp, BP_PORT(bp) ?
  5928. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5929. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5930. } else {
  5931. /* Ovlan exists only if we are in multi-function +
  5932. * switch-dependent mode, in switch-independent there
  5933. * is no ovlan headers
  5934. */
  5935. REG_WR(bp, BP_PORT(bp) ?
  5936. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5937. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5938. (bp->path_has_ovlan ? 7 : 6));
  5939. }
  5940. }
  5941. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5942. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5943. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5944. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5945. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5946. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5947. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5948. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5949. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5950. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5951. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5952. if (CHIP_IS_E1x(bp)) {
  5953. /* configure PBF to work without PAUSE mtu 9000 */
  5954. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5955. /* update threshold */
  5956. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5957. /* update init credit */
  5958. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5959. /* probe changes */
  5960. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5961. udelay(50);
  5962. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5963. }
  5964. if (CNIC_SUPPORT(bp))
  5965. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5966. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5967. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5968. if (CHIP_IS_E1(bp)) {
  5969. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5970. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5971. }
  5972. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5973. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5974. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5975. /* init aeu_mask_attn_func_0/1:
  5976. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5977. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5978. * bits 4-7 are used for "per vn group attention" */
  5979. val = IS_MF(bp) ? 0xF7 : 0x7;
  5980. /* Enable DCBX attention for all but E1 */
  5981. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5982. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5983. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5984. if (!CHIP_IS_E1x(bp)) {
  5985. /* Bit-map indicating which L2 hdrs may appear after the
  5986. * basic Ethernet header
  5987. */
  5988. if (IS_MF_AFEX(bp))
  5989. REG_WR(bp, BP_PORT(bp) ?
  5990. NIG_REG_P1_HDRS_AFTER_BASIC :
  5991. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5992. else
  5993. REG_WR(bp, BP_PORT(bp) ?
  5994. NIG_REG_P1_HDRS_AFTER_BASIC :
  5995. NIG_REG_P0_HDRS_AFTER_BASIC,
  5996. IS_MF_SD(bp) ? 7 : 6);
  5997. if (CHIP_IS_E3(bp))
  5998. REG_WR(bp, BP_PORT(bp) ?
  5999. NIG_REG_LLH1_MF_MODE :
  6000. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6001. }
  6002. if (!CHIP_IS_E3(bp))
  6003. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6004. if (!CHIP_IS_E1(bp)) {
  6005. /* 0x2 disable mf_ov, 0x1 enable */
  6006. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6007. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6008. if (!CHIP_IS_E1x(bp)) {
  6009. val = 0;
  6010. switch (bp->mf_mode) {
  6011. case MULTI_FUNCTION_SD:
  6012. val = 1;
  6013. break;
  6014. case MULTI_FUNCTION_SI:
  6015. case MULTI_FUNCTION_AFEX:
  6016. val = 2;
  6017. break;
  6018. }
  6019. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6020. NIG_REG_LLH0_CLS_TYPE), val);
  6021. }
  6022. {
  6023. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6024. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6025. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6026. }
  6027. }
  6028. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6029. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6030. if (val & MISC_SPIO_SPIO5) {
  6031. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6032. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6033. val = REG_RD(bp, reg_addr);
  6034. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6035. REG_WR(bp, reg_addr, val);
  6036. }
  6037. return 0;
  6038. }
  6039. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6040. {
  6041. int reg;
  6042. u32 wb_write[2];
  6043. if (CHIP_IS_E1(bp))
  6044. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6045. else
  6046. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6047. wb_write[0] = ONCHIP_ADDR1(addr);
  6048. wb_write[1] = ONCHIP_ADDR2(addr);
  6049. REG_WR_DMAE(bp, reg, wb_write, 2);
  6050. }
  6051. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6052. {
  6053. u32 data, ctl, cnt = 100;
  6054. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6055. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6056. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6057. u32 sb_bit = 1 << (idu_sb_id%32);
  6058. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6059. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6060. /* Not supported in BC mode */
  6061. if (CHIP_INT_MODE_IS_BC(bp))
  6062. return;
  6063. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6064. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6065. IGU_REGULAR_CLEANUP_SET |
  6066. IGU_REGULAR_BCLEANUP;
  6067. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6068. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6069. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6070. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6071. data, igu_addr_data);
  6072. REG_WR(bp, igu_addr_data, data);
  6073. mmiowb();
  6074. barrier();
  6075. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6076. ctl, igu_addr_ctl);
  6077. REG_WR(bp, igu_addr_ctl, ctl);
  6078. mmiowb();
  6079. barrier();
  6080. /* wait for clean up to finish */
  6081. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6082. msleep(20);
  6083. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6084. DP(NETIF_MSG_HW,
  6085. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6086. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6087. }
  6088. }
  6089. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6090. {
  6091. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6092. }
  6093. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6094. {
  6095. u32 i, base = FUNC_ILT_BASE(func);
  6096. for (i = base; i < base + ILT_PER_FUNC; i++)
  6097. bnx2x_ilt_wr(bp, i, 0);
  6098. }
  6099. static void bnx2x_init_searcher(struct bnx2x *bp)
  6100. {
  6101. int port = BP_PORT(bp);
  6102. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6103. /* T1 hash bits value determines the T1 number of entries */
  6104. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6105. }
  6106. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6107. {
  6108. int rc;
  6109. struct bnx2x_func_state_params func_params = {NULL};
  6110. struct bnx2x_func_switch_update_params *switch_update_params =
  6111. &func_params.params.switch_update;
  6112. /* Prepare parameters for function state transitions */
  6113. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6114. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6115. func_params.f_obj = &bp->func_obj;
  6116. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6117. /* Function parameters */
  6118. switch_update_params->suspend = suspend;
  6119. rc = bnx2x_func_state_change(bp, &func_params);
  6120. return rc;
  6121. }
  6122. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6123. {
  6124. int rc, i, port = BP_PORT(bp);
  6125. int vlan_en = 0, mac_en[NUM_MACS];
  6126. /* Close input from network */
  6127. if (bp->mf_mode == SINGLE_FUNCTION) {
  6128. bnx2x_set_rx_filter(&bp->link_params, 0);
  6129. } else {
  6130. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6131. NIG_REG_LLH0_FUNC_EN);
  6132. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6133. NIG_REG_LLH0_FUNC_EN, 0);
  6134. for (i = 0; i < NUM_MACS; i++) {
  6135. mac_en[i] = REG_RD(bp, port ?
  6136. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6137. 4 * i) :
  6138. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6139. 4 * i));
  6140. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6141. 4 * i) :
  6142. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6143. }
  6144. }
  6145. /* Close BMC to host */
  6146. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6147. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6148. /* Suspend Tx switching to the PF. Completion of this ramrod
  6149. * further guarantees that all the packets of that PF / child
  6150. * VFs in BRB were processed by the Parser, so it is safe to
  6151. * change the NIC_MODE register.
  6152. */
  6153. rc = bnx2x_func_switch_update(bp, 1);
  6154. if (rc) {
  6155. BNX2X_ERR("Can't suspend tx-switching!\n");
  6156. return rc;
  6157. }
  6158. /* Change NIC_MODE register */
  6159. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6160. /* Open input from network */
  6161. if (bp->mf_mode == SINGLE_FUNCTION) {
  6162. bnx2x_set_rx_filter(&bp->link_params, 1);
  6163. } else {
  6164. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6165. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6166. for (i = 0; i < NUM_MACS; i++) {
  6167. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6168. 4 * i) :
  6169. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6170. mac_en[i]);
  6171. }
  6172. }
  6173. /* Enable BMC to host */
  6174. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6175. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6176. /* Resume Tx switching to the PF */
  6177. rc = bnx2x_func_switch_update(bp, 0);
  6178. if (rc) {
  6179. BNX2X_ERR("Can't resume tx-switching!\n");
  6180. return rc;
  6181. }
  6182. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6183. return 0;
  6184. }
  6185. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6186. {
  6187. int rc;
  6188. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6189. if (CONFIGURE_NIC_MODE(bp)) {
  6190. /* Configrue searcher as part of function hw init */
  6191. bnx2x_init_searcher(bp);
  6192. /* Reset NIC mode */
  6193. rc = bnx2x_reset_nic_mode(bp);
  6194. if (rc)
  6195. BNX2X_ERR("Can't change NIC mode!\n");
  6196. return rc;
  6197. }
  6198. return 0;
  6199. }
  6200. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6201. {
  6202. int port = BP_PORT(bp);
  6203. int func = BP_FUNC(bp);
  6204. int init_phase = PHASE_PF0 + func;
  6205. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6206. u16 cdu_ilt_start;
  6207. u32 addr, val;
  6208. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6209. int i, main_mem_width, rc;
  6210. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6211. /* FLR cleanup - hmmm */
  6212. if (!CHIP_IS_E1x(bp)) {
  6213. rc = bnx2x_pf_flr_clnup(bp);
  6214. if (rc) {
  6215. bnx2x_fw_dump(bp);
  6216. return rc;
  6217. }
  6218. }
  6219. /* set MSI reconfigure capability */
  6220. if (bp->common.int_block == INT_BLOCK_HC) {
  6221. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6222. val = REG_RD(bp, addr);
  6223. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6224. REG_WR(bp, addr, val);
  6225. }
  6226. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6227. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6228. ilt = BP_ILT(bp);
  6229. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6230. if (IS_SRIOV(bp))
  6231. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6232. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6233. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6234. * those of the VFs, so start line should be reset
  6235. */
  6236. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6237. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6238. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6239. ilt->lines[cdu_ilt_start + i].page_mapping =
  6240. bp->context[i].cxt_mapping;
  6241. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6242. }
  6243. bnx2x_ilt_init_op(bp, INITOP_SET);
  6244. if (!CONFIGURE_NIC_MODE(bp)) {
  6245. bnx2x_init_searcher(bp);
  6246. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6247. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6248. } else {
  6249. /* Set NIC mode */
  6250. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6251. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6252. }
  6253. if (!CHIP_IS_E1x(bp)) {
  6254. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6255. /* Turn on a single ISR mode in IGU if driver is going to use
  6256. * INT#x or MSI
  6257. */
  6258. if (!(bp->flags & USING_MSIX_FLAG))
  6259. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6260. /*
  6261. * Timers workaround bug: function init part.
  6262. * Need to wait 20msec after initializing ILT,
  6263. * needed to make sure there are no requests in
  6264. * one of the PXP internal queues with "old" ILT addresses
  6265. */
  6266. msleep(20);
  6267. /*
  6268. * Master enable - Due to WB DMAE writes performed before this
  6269. * register is re-initialized as part of the regular function
  6270. * init
  6271. */
  6272. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6273. /* Enable the function in IGU */
  6274. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6275. }
  6276. bp->dmae_ready = 1;
  6277. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6278. if (!CHIP_IS_E1x(bp))
  6279. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6280. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6281. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6282. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6283. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6284. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6285. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6286. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6287. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6288. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6289. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6290. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6291. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6292. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6293. if (!CHIP_IS_E1x(bp))
  6294. REG_WR(bp, QM_REG_PF_EN, 1);
  6295. if (!CHIP_IS_E1x(bp)) {
  6296. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6297. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6298. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6299. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6300. }
  6301. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6302. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6303. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6304. bnx2x_iov_init_dq(bp);
  6305. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6306. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6307. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6308. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6309. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6310. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6311. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6312. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6313. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6314. if (!CHIP_IS_E1x(bp))
  6315. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6316. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6317. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6318. if (!CHIP_IS_E1x(bp))
  6319. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6320. if (IS_MF(bp)) {
  6321. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6322. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6323. }
  6324. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6325. /* HC init per function */
  6326. if (bp->common.int_block == INT_BLOCK_HC) {
  6327. if (CHIP_IS_E1H(bp)) {
  6328. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6329. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6330. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6331. }
  6332. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6333. } else {
  6334. int num_segs, sb_idx, prod_offset;
  6335. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6336. if (!CHIP_IS_E1x(bp)) {
  6337. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6338. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6339. }
  6340. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6341. if (!CHIP_IS_E1x(bp)) {
  6342. int dsb_idx = 0;
  6343. /**
  6344. * Producer memory:
  6345. * E2 mode: address 0-135 match to the mapping memory;
  6346. * 136 - PF0 default prod; 137 - PF1 default prod;
  6347. * 138 - PF2 default prod; 139 - PF3 default prod;
  6348. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6349. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6350. * 144-147 reserved.
  6351. *
  6352. * E1.5 mode - In backward compatible mode;
  6353. * for non default SB; each even line in the memory
  6354. * holds the U producer and each odd line hold
  6355. * the C producer. The first 128 producers are for
  6356. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6357. * producers are for the DSB for each PF.
  6358. * Each PF has five segments: (the order inside each
  6359. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6360. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6361. * 144-147 attn prods;
  6362. */
  6363. /* non-default-status-blocks */
  6364. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6365. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6366. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6367. prod_offset = (bp->igu_base_sb + sb_idx) *
  6368. num_segs;
  6369. for (i = 0; i < num_segs; i++) {
  6370. addr = IGU_REG_PROD_CONS_MEMORY +
  6371. (prod_offset + i) * 4;
  6372. REG_WR(bp, addr, 0);
  6373. }
  6374. /* send consumer update with value 0 */
  6375. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6376. USTORM_ID, 0, IGU_INT_NOP, 1);
  6377. bnx2x_igu_clear_sb(bp,
  6378. bp->igu_base_sb + sb_idx);
  6379. }
  6380. /* default-status-blocks */
  6381. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6382. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6383. if (CHIP_MODE_IS_4_PORT(bp))
  6384. dsb_idx = BP_FUNC(bp);
  6385. else
  6386. dsb_idx = BP_VN(bp);
  6387. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6388. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6389. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6390. /*
  6391. * igu prods come in chunks of E1HVN_MAX (4) -
  6392. * does not matters what is the current chip mode
  6393. */
  6394. for (i = 0; i < (num_segs * E1HVN_MAX);
  6395. i += E1HVN_MAX) {
  6396. addr = IGU_REG_PROD_CONS_MEMORY +
  6397. (prod_offset + i)*4;
  6398. REG_WR(bp, addr, 0);
  6399. }
  6400. /* send consumer update with 0 */
  6401. if (CHIP_INT_MODE_IS_BC(bp)) {
  6402. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6403. USTORM_ID, 0, IGU_INT_NOP, 1);
  6404. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6405. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6406. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6407. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6408. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6409. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6410. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6411. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6412. } else {
  6413. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6414. USTORM_ID, 0, IGU_INT_NOP, 1);
  6415. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6416. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6417. }
  6418. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6419. /* !!! these should become driver const once
  6420. rf-tool supports split-68 const */
  6421. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6422. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6423. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6424. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6425. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6426. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6427. }
  6428. }
  6429. /* Reset PCIE errors for debug */
  6430. REG_WR(bp, 0x2114, 0xffffffff);
  6431. REG_WR(bp, 0x2120, 0xffffffff);
  6432. if (CHIP_IS_E1x(bp)) {
  6433. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6434. main_mem_base = HC_REG_MAIN_MEMORY +
  6435. BP_PORT(bp) * (main_mem_size * 4);
  6436. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6437. main_mem_width = 8;
  6438. val = REG_RD(bp, main_mem_prty_clr);
  6439. if (val)
  6440. DP(NETIF_MSG_HW,
  6441. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6442. val);
  6443. /* Clear "false" parity errors in MSI-X table */
  6444. for (i = main_mem_base;
  6445. i < main_mem_base + main_mem_size * 4;
  6446. i += main_mem_width) {
  6447. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6448. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6449. i, main_mem_width / 4);
  6450. }
  6451. /* Clear HC parity attention */
  6452. REG_RD(bp, main_mem_prty_clr);
  6453. }
  6454. #ifdef BNX2X_STOP_ON_ERROR
  6455. /* Enable STORMs SP logging */
  6456. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6457. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6458. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6459. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6460. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6461. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6462. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6463. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6464. #endif
  6465. bnx2x_phy_probe(&bp->link_params);
  6466. return 0;
  6467. }
  6468. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6469. {
  6470. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6471. if (!CHIP_IS_E1x(bp))
  6472. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6473. sizeof(struct host_hc_status_block_e2));
  6474. else
  6475. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6476. sizeof(struct host_hc_status_block_e1x));
  6477. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6478. }
  6479. void bnx2x_free_mem(struct bnx2x *bp)
  6480. {
  6481. int i;
  6482. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6483. sizeof(struct host_sp_status_block));
  6484. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6485. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6486. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6487. sizeof(struct bnx2x_slowpath));
  6488. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6489. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6490. bp->context[i].size);
  6491. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6492. BNX2X_FREE(bp->ilt->lines);
  6493. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6494. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6495. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6496. bnx2x_iov_free_mem(bp);
  6497. }
  6498. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6499. {
  6500. if (!CHIP_IS_E1x(bp))
  6501. /* size = the status block + ramrod buffers */
  6502. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6503. sizeof(struct host_hc_status_block_e2));
  6504. else
  6505. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6506. &bp->cnic_sb_mapping,
  6507. sizeof(struct
  6508. host_hc_status_block_e1x));
  6509. if (CONFIGURE_NIC_MODE(bp))
  6510. /* allocate searcher T2 table, as it wan't allocated before */
  6511. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6512. /* write address to which L5 should insert its values */
  6513. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6514. &bp->slowpath->drv_info_to_mcp;
  6515. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6516. goto alloc_mem_err;
  6517. return 0;
  6518. alloc_mem_err:
  6519. bnx2x_free_mem_cnic(bp);
  6520. BNX2X_ERR("Can't allocate memory\n");
  6521. return -ENOMEM;
  6522. }
  6523. int bnx2x_alloc_mem(struct bnx2x *bp)
  6524. {
  6525. int i, allocated, context_size;
  6526. if (!CONFIGURE_NIC_MODE(bp))
  6527. /* allocate searcher T2 table */
  6528. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6529. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6530. sizeof(struct host_sp_status_block));
  6531. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6532. sizeof(struct bnx2x_slowpath));
  6533. /* Allocate memory for CDU context:
  6534. * This memory is allocated separately and not in the generic ILT
  6535. * functions because CDU differs in few aspects:
  6536. * 1. There are multiple entities allocating memory for context -
  6537. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6538. * its own ILT lines.
  6539. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6540. * for the other ILT clients), to be efficient we want to support
  6541. * allocation of sub-page-size in the last entry.
  6542. * 3. Context pointers are used by the driver to pass to FW / update
  6543. * the context (for the other ILT clients the pointers are used just to
  6544. * free the memory during unload).
  6545. */
  6546. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6547. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6548. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6549. (context_size - allocated));
  6550. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6551. &bp->context[i].cxt_mapping,
  6552. bp->context[i].size);
  6553. allocated += bp->context[i].size;
  6554. }
  6555. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6556. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6557. goto alloc_mem_err;
  6558. if (bnx2x_iov_alloc_mem(bp))
  6559. goto alloc_mem_err;
  6560. /* Slow path ring */
  6561. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6562. /* EQ */
  6563. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6564. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6565. return 0;
  6566. alloc_mem_err:
  6567. bnx2x_free_mem(bp);
  6568. BNX2X_ERR("Can't allocate memory\n");
  6569. return -ENOMEM;
  6570. }
  6571. /*
  6572. * Init service functions
  6573. */
  6574. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6575. struct bnx2x_vlan_mac_obj *obj, bool set,
  6576. int mac_type, unsigned long *ramrod_flags)
  6577. {
  6578. int rc;
  6579. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6580. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6581. /* Fill general parameters */
  6582. ramrod_param.vlan_mac_obj = obj;
  6583. ramrod_param.ramrod_flags = *ramrod_flags;
  6584. /* Fill a user request section if needed */
  6585. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6586. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6587. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6588. /* Set the command: ADD or DEL */
  6589. if (set)
  6590. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6591. else
  6592. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6593. }
  6594. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6595. if (rc == -EEXIST) {
  6596. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6597. /* do not treat adding same MAC as error */
  6598. rc = 0;
  6599. } else if (rc < 0)
  6600. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6601. return rc;
  6602. }
  6603. int bnx2x_del_all_macs(struct bnx2x *bp,
  6604. struct bnx2x_vlan_mac_obj *mac_obj,
  6605. int mac_type, bool wait_for_comp)
  6606. {
  6607. int rc;
  6608. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6609. /* Wait for completion of requested */
  6610. if (wait_for_comp)
  6611. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6612. /* Set the mac type of addresses we want to clear */
  6613. __set_bit(mac_type, &vlan_mac_flags);
  6614. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6615. if (rc < 0)
  6616. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6617. return rc;
  6618. }
  6619. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6620. {
  6621. unsigned long ramrod_flags = 0;
  6622. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6623. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6624. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6625. "Ignoring Zero MAC for STORAGE SD mode\n");
  6626. return 0;
  6627. }
  6628. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6629. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6630. /* Eth MAC is set on RSS leading client (fp[0]) */
  6631. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6632. set, BNX2X_ETH_MAC, &ramrod_flags);
  6633. }
  6634. int bnx2x_setup_leading(struct bnx2x *bp)
  6635. {
  6636. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6637. }
  6638. /**
  6639. * bnx2x_set_int_mode - configure interrupt mode
  6640. *
  6641. * @bp: driver handle
  6642. *
  6643. * In case of MSI-X it will also try to enable MSI-X.
  6644. */
  6645. int bnx2x_set_int_mode(struct bnx2x *bp)
  6646. {
  6647. int rc = 0;
  6648. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6649. return -EINVAL;
  6650. switch (int_mode) {
  6651. case BNX2X_INT_MODE_MSIX:
  6652. /* attempt to enable msix */
  6653. rc = bnx2x_enable_msix(bp);
  6654. /* msix attained */
  6655. if (!rc)
  6656. return 0;
  6657. /* vfs use only msix */
  6658. if (rc && IS_VF(bp))
  6659. return rc;
  6660. /* failed to enable multiple MSI-X */
  6661. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6662. bp->num_queues,
  6663. 1 + bp->num_cnic_queues);
  6664. /* falling through... */
  6665. case BNX2X_INT_MODE_MSI:
  6666. bnx2x_enable_msi(bp);
  6667. /* falling through... */
  6668. case BNX2X_INT_MODE_INTX:
  6669. bp->num_ethernet_queues = 1;
  6670. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6671. BNX2X_DEV_INFO("set number of queues to 1\n");
  6672. break;
  6673. default:
  6674. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6675. return -EINVAL;
  6676. }
  6677. return 0;
  6678. }
  6679. /* must be called prior to any HW initializations */
  6680. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6681. {
  6682. if (IS_SRIOV(bp))
  6683. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6684. return L2_ILT_LINES(bp);
  6685. }
  6686. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6687. {
  6688. struct ilt_client_info *ilt_client;
  6689. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6690. u16 line = 0;
  6691. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6692. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6693. /* CDU */
  6694. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6695. ilt_client->client_num = ILT_CLIENT_CDU;
  6696. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6697. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6698. ilt_client->start = line;
  6699. line += bnx2x_cid_ilt_lines(bp);
  6700. if (CNIC_SUPPORT(bp))
  6701. line += CNIC_ILT_LINES;
  6702. ilt_client->end = line - 1;
  6703. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6704. ilt_client->start,
  6705. ilt_client->end,
  6706. ilt_client->page_size,
  6707. ilt_client->flags,
  6708. ilog2(ilt_client->page_size >> 12));
  6709. /* QM */
  6710. if (QM_INIT(bp->qm_cid_count)) {
  6711. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6712. ilt_client->client_num = ILT_CLIENT_QM;
  6713. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6714. ilt_client->flags = 0;
  6715. ilt_client->start = line;
  6716. /* 4 bytes for each cid */
  6717. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6718. QM_ILT_PAGE_SZ);
  6719. ilt_client->end = line - 1;
  6720. DP(NETIF_MSG_IFUP,
  6721. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6722. ilt_client->start,
  6723. ilt_client->end,
  6724. ilt_client->page_size,
  6725. ilt_client->flags,
  6726. ilog2(ilt_client->page_size >> 12));
  6727. }
  6728. if (CNIC_SUPPORT(bp)) {
  6729. /* SRC */
  6730. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6731. ilt_client->client_num = ILT_CLIENT_SRC;
  6732. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6733. ilt_client->flags = 0;
  6734. ilt_client->start = line;
  6735. line += SRC_ILT_LINES;
  6736. ilt_client->end = line - 1;
  6737. DP(NETIF_MSG_IFUP,
  6738. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6739. ilt_client->start,
  6740. ilt_client->end,
  6741. ilt_client->page_size,
  6742. ilt_client->flags,
  6743. ilog2(ilt_client->page_size >> 12));
  6744. /* TM */
  6745. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6746. ilt_client->client_num = ILT_CLIENT_TM;
  6747. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6748. ilt_client->flags = 0;
  6749. ilt_client->start = line;
  6750. line += TM_ILT_LINES;
  6751. ilt_client->end = line - 1;
  6752. DP(NETIF_MSG_IFUP,
  6753. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6754. ilt_client->start,
  6755. ilt_client->end,
  6756. ilt_client->page_size,
  6757. ilt_client->flags,
  6758. ilog2(ilt_client->page_size >> 12));
  6759. }
  6760. BUG_ON(line > ILT_MAX_LINES);
  6761. }
  6762. /**
  6763. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6764. *
  6765. * @bp: driver handle
  6766. * @fp: pointer to fastpath
  6767. * @init_params: pointer to parameters structure
  6768. *
  6769. * parameters configured:
  6770. * - HC configuration
  6771. * - Queue's CDU context
  6772. */
  6773. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6774. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6775. {
  6776. u8 cos;
  6777. int cxt_index, cxt_offset;
  6778. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6779. if (!IS_FCOE_FP(fp)) {
  6780. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6781. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6782. /* If HC is supporterd, enable host coalescing in the transition
  6783. * to INIT state.
  6784. */
  6785. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6786. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6787. /* HC rate */
  6788. init_params->rx.hc_rate = bp->rx_ticks ?
  6789. (1000000 / bp->rx_ticks) : 0;
  6790. init_params->tx.hc_rate = bp->tx_ticks ?
  6791. (1000000 / bp->tx_ticks) : 0;
  6792. /* FW SB ID */
  6793. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6794. fp->fw_sb_id;
  6795. /*
  6796. * CQ index among the SB indices: FCoE clients uses the default
  6797. * SB, therefore it's different.
  6798. */
  6799. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6800. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6801. }
  6802. /* set maximum number of COSs supported by this queue */
  6803. init_params->max_cos = fp->max_cos;
  6804. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6805. fp->index, init_params->max_cos);
  6806. /* set the context pointers queue object */
  6807. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6808. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6809. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6810. ILT_PAGE_CIDS);
  6811. init_params->cxts[cos] =
  6812. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6813. }
  6814. }
  6815. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6816. struct bnx2x_queue_state_params *q_params,
  6817. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6818. int tx_index, bool leading)
  6819. {
  6820. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6821. /* Set the command */
  6822. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6823. /* Set tx-only QUEUE flags: don't zero statistics */
  6824. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6825. /* choose the index of the cid to send the slow path on */
  6826. tx_only_params->cid_index = tx_index;
  6827. /* Set general TX_ONLY_SETUP parameters */
  6828. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6829. /* Set Tx TX_ONLY_SETUP parameters */
  6830. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6831. DP(NETIF_MSG_IFUP,
  6832. "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",
  6833. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6834. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6835. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6836. /* send the ramrod */
  6837. return bnx2x_queue_state_change(bp, q_params);
  6838. }
  6839. /**
  6840. * bnx2x_setup_queue - setup queue
  6841. *
  6842. * @bp: driver handle
  6843. * @fp: pointer to fastpath
  6844. * @leading: is leading
  6845. *
  6846. * This function performs 2 steps in a Queue state machine
  6847. * actually: 1) RESET->INIT 2) INIT->SETUP
  6848. */
  6849. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6850. bool leading)
  6851. {
  6852. struct bnx2x_queue_state_params q_params = {NULL};
  6853. struct bnx2x_queue_setup_params *setup_params =
  6854. &q_params.params.setup;
  6855. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6856. &q_params.params.tx_only;
  6857. int rc;
  6858. u8 tx_index;
  6859. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6860. /* reset IGU state skip FCoE L2 queue */
  6861. if (!IS_FCOE_FP(fp))
  6862. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6863. IGU_INT_ENABLE, 0);
  6864. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6865. /* We want to wait for completion in this context */
  6866. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6867. /* Prepare the INIT parameters */
  6868. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6869. /* Set the command */
  6870. q_params.cmd = BNX2X_Q_CMD_INIT;
  6871. /* Change the state to INIT */
  6872. rc = bnx2x_queue_state_change(bp, &q_params);
  6873. if (rc) {
  6874. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6875. return rc;
  6876. }
  6877. DP(NETIF_MSG_IFUP, "init complete\n");
  6878. /* Now move the Queue to the SETUP state... */
  6879. memset(setup_params, 0, sizeof(*setup_params));
  6880. /* Set QUEUE flags */
  6881. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6882. /* Set general SETUP parameters */
  6883. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6884. FIRST_TX_COS_INDEX);
  6885. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6886. &setup_params->rxq_params);
  6887. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6888. FIRST_TX_COS_INDEX);
  6889. /* Set the command */
  6890. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6891. if (IS_FCOE_FP(fp))
  6892. bp->fcoe_init = true;
  6893. /* Change the state to SETUP */
  6894. rc = bnx2x_queue_state_change(bp, &q_params);
  6895. if (rc) {
  6896. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6897. return rc;
  6898. }
  6899. /* loop through the relevant tx-only indices */
  6900. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6901. tx_index < fp->max_cos;
  6902. tx_index++) {
  6903. /* prepare and send tx-only ramrod*/
  6904. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6905. tx_only_params, tx_index, leading);
  6906. if (rc) {
  6907. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6908. fp->index, tx_index);
  6909. return rc;
  6910. }
  6911. }
  6912. return rc;
  6913. }
  6914. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6915. {
  6916. struct bnx2x_fastpath *fp = &bp->fp[index];
  6917. struct bnx2x_fp_txdata *txdata;
  6918. struct bnx2x_queue_state_params q_params = {NULL};
  6919. int rc, tx_index;
  6920. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6921. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6922. /* We want to wait for completion in this context */
  6923. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6924. /* close tx-only connections */
  6925. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6926. tx_index < fp->max_cos;
  6927. tx_index++){
  6928. /* ascertain this is a normal queue*/
  6929. txdata = fp->txdata_ptr[tx_index];
  6930. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6931. txdata->txq_index);
  6932. /* send halt terminate on tx-only connection */
  6933. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6934. memset(&q_params.params.terminate, 0,
  6935. sizeof(q_params.params.terminate));
  6936. q_params.params.terminate.cid_index = tx_index;
  6937. rc = bnx2x_queue_state_change(bp, &q_params);
  6938. if (rc)
  6939. return rc;
  6940. /* send halt terminate on tx-only connection */
  6941. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6942. memset(&q_params.params.cfc_del, 0,
  6943. sizeof(q_params.params.cfc_del));
  6944. q_params.params.cfc_del.cid_index = tx_index;
  6945. rc = bnx2x_queue_state_change(bp, &q_params);
  6946. if (rc)
  6947. return rc;
  6948. }
  6949. /* Stop the primary connection: */
  6950. /* ...halt the connection */
  6951. q_params.cmd = BNX2X_Q_CMD_HALT;
  6952. rc = bnx2x_queue_state_change(bp, &q_params);
  6953. if (rc)
  6954. return rc;
  6955. /* ...terminate the connection */
  6956. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6957. memset(&q_params.params.terminate, 0,
  6958. sizeof(q_params.params.terminate));
  6959. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6960. rc = bnx2x_queue_state_change(bp, &q_params);
  6961. if (rc)
  6962. return rc;
  6963. /* ...delete cfc entry */
  6964. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6965. memset(&q_params.params.cfc_del, 0,
  6966. sizeof(q_params.params.cfc_del));
  6967. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6968. return bnx2x_queue_state_change(bp, &q_params);
  6969. }
  6970. static void bnx2x_reset_func(struct bnx2x *bp)
  6971. {
  6972. int port = BP_PORT(bp);
  6973. int func = BP_FUNC(bp);
  6974. int i;
  6975. /* Disable the function in the FW */
  6976. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6977. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6978. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6979. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6980. /* FP SBs */
  6981. for_each_eth_queue(bp, i) {
  6982. struct bnx2x_fastpath *fp = &bp->fp[i];
  6983. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6984. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6985. SB_DISABLED);
  6986. }
  6987. if (CNIC_LOADED(bp))
  6988. /* CNIC SB */
  6989. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6990. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6991. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6992. /* SP SB */
  6993. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6994. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6995. SB_DISABLED);
  6996. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6997. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6998. 0);
  6999. /* Configure IGU */
  7000. if (bp->common.int_block == INT_BLOCK_HC) {
  7001. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7002. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7003. } else {
  7004. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7005. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7006. }
  7007. if (CNIC_LOADED(bp)) {
  7008. /* Disable Timer scan */
  7009. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7010. /*
  7011. * Wait for at least 10ms and up to 2 second for the timers
  7012. * scan to complete
  7013. */
  7014. for (i = 0; i < 200; i++) {
  7015. msleep(10);
  7016. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7017. break;
  7018. }
  7019. }
  7020. /* Clear ILT */
  7021. bnx2x_clear_func_ilt(bp, func);
  7022. /* Timers workaround bug for E2: if this is vnic-3,
  7023. * we need to set the entire ilt range for this timers.
  7024. */
  7025. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7026. struct ilt_client_info ilt_cli;
  7027. /* use dummy TM client */
  7028. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7029. ilt_cli.start = 0;
  7030. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7031. ilt_cli.client_num = ILT_CLIENT_TM;
  7032. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7033. }
  7034. /* this assumes that reset_port() called before reset_func()*/
  7035. if (!CHIP_IS_E1x(bp))
  7036. bnx2x_pf_disable(bp);
  7037. bp->dmae_ready = 0;
  7038. }
  7039. static void bnx2x_reset_port(struct bnx2x *bp)
  7040. {
  7041. int port = BP_PORT(bp);
  7042. u32 val;
  7043. /* Reset physical Link */
  7044. bnx2x__link_reset(bp);
  7045. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7046. /* Do not rcv packets to BRB */
  7047. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7048. /* Do not direct rcv packets that are not for MCP to the BRB */
  7049. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7050. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7051. /* Configure AEU */
  7052. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7053. msleep(100);
  7054. /* Check for BRB port occupancy */
  7055. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7056. if (val)
  7057. DP(NETIF_MSG_IFDOWN,
  7058. "BRB1 is not empty %d blocks are occupied\n", val);
  7059. /* TODO: Close Doorbell port? */
  7060. }
  7061. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7062. {
  7063. struct bnx2x_func_state_params func_params = {NULL};
  7064. /* Prepare parameters for function state transitions */
  7065. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7066. func_params.f_obj = &bp->func_obj;
  7067. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7068. func_params.params.hw_init.load_phase = load_code;
  7069. return bnx2x_func_state_change(bp, &func_params);
  7070. }
  7071. static int bnx2x_func_stop(struct bnx2x *bp)
  7072. {
  7073. struct bnx2x_func_state_params func_params = {NULL};
  7074. int rc;
  7075. /* Prepare parameters for function state transitions */
  7076. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7077. func_params.f_obj = &bp->func_obj;
  7078. func_params.cmd = BNX2X_F_CMD_STOP;
  7079. /*
  7080. * Try to stop the function the 'good way'. If fails (in case
  7081. * of a parity error during bnx2x_chip_cleanup()) and we are
  7082. * not in a debug mode, perform a state transaction in order to
  7083. * enable further HW_RESET transaction.
  7084. */
  7085. rc = bnx2x_func_state_change(bp, &func_params);
  7086. if (rc) {
  7087. #ifdef BNX2X_STOP_ON_ERROR
  7088. return rc;
  7089. #else
  7090. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7091. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7092. return bnx2x_func_state_change(bp, &func_params);
  7093. #endif
  7094. }
  7095. return 0;
  7096. }
  7097. /**
  7098. * bnx2x_send_unload_req - request unload mode from the MCP.
  7099. *
  7100. * @bp: driver handle
  7101. * @unload_mode: requested function's unload mode
  7102. *
  7103. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7104. */
  7105. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7106. {
  7107. u32 reset_code = 0;
  7108. int port = BP_PORT(bp);
  7109. /* Select the UNLOAD request mode */
  7110. if (unload_mode == UNLOAD_NORMAL)
  7111. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7112. else if (bp->flags & NO_WOL_FLAG)
  7113. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7114. else if (bp->wol) {
  7115. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7116. u8 *mac_addr = bp->dev->dev_addr;
  7117. u32 val;
  7118. u16 pmc;
  7119. /* The mac address is written to entries 1-4 to
  7120. * preserve entry 0 which is used by the PMF
  7121. */
  7122. u8 entry = (BP_VN(bp) + 1)*8;
  7123. val = (mac_addr[0] << 8) | mac_addr[1];
  7124. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7125. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7126. (mac_addr[4] << 8) | mac_addr[5];
  7127. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7128. /* Enable the PME and clear the status */
  7129. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7130. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7131. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7132. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7133. } else
  7134. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7135. /* Send the request to the MCP */
  7136. if (!BP_NOMCP(bp))
  7137. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7138. else {
  7139. int path = BP_PATH(bp);
  7140. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7141. path, load_count[path][0], load_count[path][1],
  7142. load_count[path][2]);
  7143. load_count[path][0]--;
  7144. load_count[path][1 + port]--;
  7145. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7146. path, load_count[path][0], load_count[path][1],
  7147. load_count[path][2]);
  7148. if (load_count[path][0] == 0)
  7149. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7150. else if (load_count[path][1 + port] == 0)
  7151. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7152. else
  7153. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7154. }
  7155. return reset_code;
  7156. }
  7157. /**
  7158. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7159. *
  7160. * @bp: driver handle
  7161. * @keep_link: true iff link should be kept up
  7162. */
  7163. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7164. {
  7165. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7166. /* Report UNLOAD_DONE to MCP */
  7167. if (!BP_NOMCP(bp))
  7168. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7169. }
  7170. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7171. {
  7172. int tout = 50;
  7173. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7174. if (!bp->port.pmf)
  7175. return 0;
  7176. /*
  7177. * (assumption: No Attention from MCP at this stage)
  7178. * PMF probably in the middle of TXdisable/enable transaction
  7179. * 1. Sync IRS for default SB
  7180. * 2. Sync SP queue - this guarantes us that attention handling started
  7181. * 3. Wait, that TXdisable/enable transaction completes
  7182. *
  7183. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7184. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7185. * received complettion for the transaction the state is TX_STOPPED.
  7186. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7187. * transaction.
  7188. */
  7189. /* make sure default SB ISR is done */
  7190. if (msix)
  7191. synchronize_irq(bp->msix_table[0].vector);
  7192. else
  7193. synchronize_irq(bp->pdev->irq);
  7194. flush_workqueue(bnx2x_wq);
  7195. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7196. BNX2X_F_STATE_STARTED && tout--)
  7197. msleep(20);
  7198. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7199. BNX2X_F_STATE_STARTED) {
  7200. #ifdef BNX2X_STOP_ON_ERROR
  7201. BNX2X_ERR("Wrong function state\n");
  7202. return -EBUSY;
  7203. #else
  7204. /*
  7205. * Failed to complete the transaction in a "good way"
  7206. * Force both transactions with CLR bit
  7207. */
  7208. struct bnx2x_func_state_params func_params = {NULL};
  7209. DP(NETIF_MSG_IFDOWN,
  7210. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7211. func_params.f_obj = &bp->func_obj;
  7212. __set_bit(RAMROD_DRV_CLR_ONLY,
  7213. &func_params.ramrod_flags);
  7214. /* STARTED-->TX_ST0PPED */
  7215. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7216. bnx2x_func_state_change(bp, &func_params);
  7217. /* TX_ST0PPED-->STARTED */
  7218. func_params.cmd = BNX2X_F_CMD_TX_START;
  7219. return bnx2x_func_state_change(bp, &func_params);
  7220. #endif
  7221. }
  7222. return 0;
  7223. }
  7224. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7225. {
  7226. int port = BP_PORT(bp);
  7227. int i, rc = 0;
  7228. u8 cos;
  7229. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7230. u32 reset_code;
  7231. /* Wait until tx fastpath tasks complete */
  7232. for_each_tx_queue(bp, i) {
  7233. struct bnx2x_fastpath *fp = &bp->fp[i];
  7234. for_each_cos_in_tx_queue(fp, cos)
  7235. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7236. #ifdef BNX2X_STOP_ON_ERROR
  7237. if (rc)
  7238. return;
  7239. #endif
  7240. }
  7241. /* Give HW time to discard old tx messages */
  7242. usleep_range(1000, 2000);
  7243. /* Clean all ETH MACs */
  7244. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7245. false);
  7246. if (rc < 0)
  7247. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7248. /* Clean up UC list */
  7249. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7250. true);
  7251. if (rc < 0)
  7252. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7253. rc);
  7254. /* Disable LLH */
  7255. if (!CHIP_IS_E1(bp))
  7256. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7257. /* Set "drop all" (stop Rx).
  7258. * We need to take a netif_addr_lock() here in order to prevent
  7259. * a race between the completion code and this code.
  7260. */
  7261. netif_addr_lock_bh(bp->dev);
  7262. /* Schedule the rx_mode command */
  7263. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7264. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7265. else
  7266. bnx2x_set_storm_rx_mode(bp);
  7267. /* Cleanup multicast configuration */
  7268. rparam.mcast_obj = &bp->mcast_obj;
  7269. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7270. if (rc < 0)
  7271. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7272. netif_addr_unlock_bh(bp->dev);
  7273. bnx2x_iov_chip_cleanup(bp);
  7274. /*
  7275. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7276. * this function should perform FUNC, PORT or COMMON HW
  7277. * reset.
  7278. */
  7279. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7280. /*
  7281. * (assumption: No Attention from MCP at this stage)
  7282. * PMF probably in the middle of TXdisable/enable transaction
  7283. */
  7284. rc = bnx2x_func_wait_started(bp);
  7285. if (rc) {
  7286. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7287. #ifdef BNX2X_STOP_ON_ERROR
  7288. return;
  7289. #endif
  7290. }
  7291. /* Close multi and leading connections
  7292. * Completions for ramrods are collected in a synchronous way
  7293. */
  7294. for_each_eth_queue(bp, i)
  7295. if (bnx2x_stop_queue(bp, i))
  7296. #ifdef BNX2X_STOP_ON_ERROR
  7297. return;
  7298. #else
  7299. goto unload_error;
  7300. #endif
  7301. if (CNIC_LOADED(bp)) {
  7302. for_each_cnic_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. }
  7310. /* If SP settings didn't get completed so far - something
  7311. * very wrong has happen.
  7312. */
  7313. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7314. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7315. #ifndef BNX2X_STOP_ON_ERROR
  7316. unload_error:
  7317. #endif
  7318. rc = bnx2x_func_stop(bp);
  7319. if (rc) {
  7320. BNX2X_ERR("Function stop failed!\n");
  7321. #ifdef BNX2X_STOP_ON_ERROR
  7322. return;
  7323. #endif
  7324. }
  7325. /* Disable HW interrupts, NAPI */
  7326. bnx2x_netif_stop(bp, 1);
  7327. /* Delete all NAPI objects */
  7328. bnx2x_del_all_napi(bp);
  7329. if (CNIC_LOADED(bp))
  7330. bnx2x_del_all_napi_cnic(bp);
  7331. /* Release IRQs */
  7332. bnx2x_free_irq(bp);
  7333. /* Reset the chip */
  7334. rc = bnx2x_reset_hw(bp, reset_code);
  7335. if (rc)
  7336. BNX2X_ERR("HW_RESET failed\n");
  7337. /* Report UNLOAD_DONE to MCP */
  7338. bnx2x_send_unload_done(bp, keep_link);
  7339. }
  7340. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7341. {
  7342. u32 val;
  7343. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7344. if (CHIP_IS_E1(bp)) {
  7345. int port = BP_PORT(bp);
  7346. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7347. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7348. val = REG_RD(bp, addr);
  7349. val &= ~(0x300);
  7350. REG_WR(bp, addr, val);
  7351. } else {
  7352. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7353. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7354. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7355. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7356. }
  7357. }
  7358. /* Close gates #2, #3 and #4: */
  7359. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7360. {
  7361. u32 val;
  7362. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7363. if (!CHIP_IS_E1(bp)) {
  7364. /* #4 */
  7365. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7366. /* #2 */
  7367. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7368. }
  7369. /* #3 */
  7370. if (CHIP_IS_E1x(bp)) {
  7371. /* Prevent interrupts from HC on both ports */
  7372. val = REG_RD(bp, HC_REG_CONFIG_1);
  7373. REG_WR(bp, HC_REG_CONFIG_1,
  7374. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7375. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7376. val = REG_RD(bp, HC_REG_CONFIG_0);
  7377. REG_WR(bp, HC_REG_CONFIG_0,
  7378. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7379. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7380. } else {
  7381. /* Prevent incoming interrupts in IGU */
  7382. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7383. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7384. (!close) ?
  7385. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7386. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7387. }
  7388. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7389. close ? "closing" : "opening");
  7390. mmiowb();
  7391. }
  7392. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7393. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7394. {
  7395. /* Do some magic... */
  7396. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7397. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7398. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7399. }
  7400. /**
  7401. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7402. *
  7403. * @bp: driver handle
  7404. * @magic_val: old value of the `magic' bit.
  7405. */
  7406. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7407. {
  7408. /* Restore the `magic' bit value... */
  7409. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7410. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7411. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7412. }
  7413. /**
  7414. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7415. *
  7416. * @bp: driver handle
  7417. * @magic_val: old value of 'magic' bit.
  7418. *
  7419. * Takes care of CLP configurations.
  7420. */
  7421. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7422. {
  7423. u32 shmem;
  7424. u32 validity_offset;
  7425. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7426. /* Set `magic' bit in order to save MF config */
  7427. if (!CHIP_IS_E1(bp))
  7428. bnx2x_clp_reset_prep(bp, magic_val);
  7429. /* Get shmem offset */
  7430. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7431. validity_offset =
  7432. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7433. /* Clear validity map flags */
  7434. if (shmem > 0)
  7435. REG_WR(bp, shmem + validity_offset, 0);
  7436. }
  7437. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7438. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7439. /**
  7440. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7441. *
  7442. * @bp: driver handle
  7443. */
  7444. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7445. {
  7446. /* special handling for emulation and FPGA,
  7447. wait 10 times longer */
  7448. if (CHIP_REV_IS_SLOW(bp))
  7449. msleep(MCP_ONE_TIMEOUT*10);
  7450. else
  7451. msleep(MCP_ONE_TIMEOUT);
  7452. }
  7453. /*
  7454. * initializes bp->common.shmem_base and waits for validity signature to appear
  7455. */
  7456. static int bnx2x_init_shmem(struct bnx2x *bp)
  7457. {
  7458. int cnt = 0;
  7459. u32 val = 0;
  7460. do {
  7461. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7462. if (bp->common.shmem_base) {
  7463. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7464. if (val & SHR_MEM_VALIDITY_MB)
  7465. return 0;
  7466. }
  7467. bnx2x_mcp_wait_one(bp);
  7468. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7469. BNX2X_ERR("BAD MCP validity signature\n");
  7470. return -ENODEV;
  7471. }
  7472. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7473. {
  7474. int rc = bnx2x_init_shmem(bp);
  7475. /* Restore the `magic' bit value */
  7476. if (!CHIP_IS_E1(bp))
  7477. bnx2x_clp_reset_done(bp, magic_val);
  7478. return rc;
  7479. }
  7480. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7481. {
  7482. if (!CHIP_IS_E1(bp)) {
  7483. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7484. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7485. mmiowb();
  7486. }
  7487. }
  7488. /*
  7489. * Reset the whole chip except for:
  7490. * - PCIE core
  7491. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7492. * one reset bit)
  7493. * - IGU
  7494. * - MISC (including AEU)
  7495. * - GRC
  7496. * - RBCN, RBCP
  7497. */
  7498. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7499. {
  7500. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7501. u32 global_bits2, stay_reset2;
  7502. /*
  7503. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7504. * (per chip) blocks.
  7505. */
  7506. global_bits2 =
  7507. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7508. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7509. /* Don't reset the following blocks.
  7510. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7511. * reset, as in 4 port device they might still be owned
  7512. * by the MCP (there is only one leader per path).
  7513. */
  7514. not_reset_mask1 =
  7515. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7516. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7517. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7518. not_reset_mask2 =
  7519. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7520. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7521. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7522. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7523. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7524. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7525. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7526. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7527. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7528. MISC_REGISTERS_RESET_REG_2_PGLC |
  7529. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7530. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7531. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7532. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7533. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7534. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7535. /*
  7536. * Keep the following blocks in reset:
  7537. * - all xxMACs are handled by the bnx2x_link code.
  7538. */
  7539. stay_reset2 =
  7540. MISC_REGISTERS_RESET_REG_2_XMAC |
  7541. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7542. /* Full reset masks according to the chip */
  7543. reset_mask1 = 0xffffffff;
  7544. if (CHIP_IS_E1(bp))
  7545. reset_mask2 = 0xffff;
  7546. else if (CHIP_IS_E1H(bp))
  7547. reset_mask2 = 0x1ffff;
  7548. else if (CHIP_IS_E2(bp))
  7549. reset_mask2 = 0xfffff;
  7550. else /* CHIP_IS_E3 */
  7551. reset_mask2 = 0x3ffffff;
  7552. /* Don't reset global blocks unless we need to */
  7553. if (!global)
  7554. reset_mask2 &= ~global_bits2;
  7555. /*
  7556. * In case of attention in the QM, we need to reset PXP
  7557. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7558. * because otherwise QM reset would release 'close the gates' shortly
  7559. * before resetting the PXP, then the PSWRQ would send a write
  7560. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7561. * read the payload data from PSWWR, but PSWWR would not
  7562. * respond. The write queue in PGLUE would stuck, dmae commands
  7563. * would not return. Therefore it's important to reset the second
  7564. * reset register (containing the
  7565. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7566. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7567. * bit).
  7568. */
  7569. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7570. reset_mask2 & (~not_reset_mask2));
  7571. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7572. reset_mask1 & (~not_reset_mask1));
  7573. barrier();
  7574. mmiowb();
  7575. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7576. reset_mask2 & (~stay_reset2));
  7577. barrier();
  7578. mmiowb();
  7579. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7580. mmiowb();
  7581. }
  7582. /**
  7583. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7584. * It should get cleared in no more than 1s.
  7585. *
  7586. * @bp: driver handle
  7587. *
  7588. * It should get cleared in no more than 1s. Returns 0 if
  7589. * pending writes bit gets cleared.
  7590. */
  7591. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7592. {
  7593. u32 cnt = 1000;
  7594. u32 pend_bits = 0;
  7595. do {
  7596. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7597. if (pend_bits == 0)
  7598. break;
  7599. usleep_range(1000, 2000);
  7600. } while (cnt-- > 0);
  7601. if (cnt <= 0) {
  7602. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7603. pend_bits);
  7604. return -EBUSY;
  7605. }
  7606. return 0;
  7607. }
  7608. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7609. {
  7610. int cnt = 1000;
  7611. u32 val = 0;
  7612. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7613. u32 tags_63_32 = 0;
  7614. /* Empty the Tetris buffer, wait for 1s */
  7615. do {
  7616. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7617. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7618. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7619. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7620. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7621. if (CHIP_IS_E3(bp))
  7622. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7623. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7624. ((port_is_idle_0 & 0x1) == 0x1) &&
  7625. ((port_is_idle_1 & 0x1) == 0x1) &&
  7626. (pgl_exp_rom2 == 0xffffffff) &&
  7627. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7628. break;
  7629. usleep_range(1000, 2000);
  7630. } while (cnt-- > 0);
  7631. if (cnt <= 0) {
  7632. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7633. 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",
  7634. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7635. pgl_exp_rom2);
  7636. return -EAGAIN;
  7637. }
  7638. barrier();
  7639. /* Close gates #2, #3 and #4 */
  7640. bnx2x_set_234_gates(bp, true);
  7641. /* Poll for IGU VQs for 57712 and newer chips */
  7642. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7643. return -EAGAIN;
  7644. /* TBD: Indicate that "process kill" is in progress to MCP */
  7645. /* Clear "unprepared" bit */
  7646. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7647. barrier();
  7648. /* Make sure all is written to the chip before the reset */
  7649. mmiowb();
  7650. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7651. * PSWHST, GRC and PSWRD Tetris buffer.
  7652. */
  7653. usleep_range(1000, 2000);
  7654. /* Prepare to chip reset: */
  7655. /* MCP */
  7656. if (global)
  7657. bnx2x_reset_mcp_prep(bp, &val);
  7658. /* PXP */
  7659. bnx2x_pxp_prep(bp);
  7660. barrier();
  7661. /* reset the chip */
  7662. bnx2x_process_kill_chip_reset(bp, global);
  7663. barrier();
  7664. /* Recover after reset: */
  7665. /* MCP */
  7666. if (global && bnx2x_reset_mcp_comp(bp, val))
  7667. return -EAGAIN;
  7668. /* TBD: Add resetting the NO_MCP mode DB here */
  7669. /* Open the gates #2, #3 and #4 */
  7670. bnx2x_set_234_gates(bp, false);
  7671. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7672. * reset state, re-enable attentions. */
  7673. return 0;
  7674. }
  7675. static int bnx2x_leader_reset(struct bnx2x *bp)
  7676. {
  7677. int rc = 0;
  7678. bool global = bnx2x_reset_is_global(bp);
  7679. u32 load_code;
  7680. /* if not going to reset MCP - load "fake" driver to reset HW while
  7681. * driver is owner of the HW
  7682. */
  7683. if (!global && !BP_NOMCP(bp)) {
  7684. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7685. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7686. if (!load_code) {
  7687. BNX2X_ERR("MCP response failure, aborting\n");
  7688. rc = -EAGAIN;
  7689. goto exit_leader_reset;
  7690. }
  7691. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7692. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7693. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7694. rc = -EAGAIN;
  7695. goto exit_leader_reset2;
  7696. }
  7697. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7698. if (!load_code) {
  7699. BNX2X_ERR("MCP response failure, aborting\n");
  7700. rc = -EAGAIN;
  7701. goto exit_leader_reset2;
  7702. }
  7703. }
  7704. /* Try to recover after the failure */
  7705. if (bnx2x_process_kill(bp, global)) {
  7706. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7707. BP_PATH(bp));
  7708. rc = -EAGAIN;
  7709. goto exit_leader_reset2;
  7710. }
  7711. /*
  7712. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7713. * state.
  7714. */
  7715. bnx2x_set_reset_done(bp);
  7716. if (global)
  7717. bnx2x_clear_reset_global(bp);
  7718. exit_leader_reset2:
  7719. /* unload "fake driver" if it was loaded */
  7720. if (!global && !BP_NOMCP(bp)) {
  7721. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7722. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7723. }
  7724. exit_leader_reset:
  7725. bp->is_leader = 0;
  7726. bnx2x_release_leader_lock(bp);
  7727. smp_mb();
  7728. return rc;
  7729. }
  7730. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7731. {
  7732. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7733. /* Disconnect this device */
  7734. netif_device_detach(bp->dev);
  7735. /*
  7736. * Block ifup for all function on this engine until "process kill"
  7737. * or power cycle.
  7738. */
  7739. bnx2x_set_reset_in_progress(bp);
  7740. /* Shut down the power */
  7741. bnx2x_set_power_state(bp, PCI_D3hot);
  7742. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7743. smp_mb();
  7744. }
  7745. /*
  7746. * Assumption: runs under rtnl lock. This together with the fact
  7747. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7748. * will never be called when netif_running(bp->dev) is false.
  7749. */
  7750. static void bnx2x_parity_recover(struct bnx2x *bp)
  7751. {
  7752. bool global = false;
  7753. u32 error_recovered, error_unrecovered;
  7754. bool is_parity;
  7755. DP(NETIF_MSG_HW, "Handling parity\n");
  7756. while (1) {
  7757. switch (bp->recovery_state) {
  7758. case BNX2X_RECOVERY_INIT:
  7759. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7760. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7761. WARN_ON(!is_parity);
  7762. /* Try to get a LEADER_LOCK HW lock */
  7763. if (bnx2x_trylock_leader_lock(bp)) {
  7764. bnx2x_set_reset_in_progress(bp);
  7765. /*
  7766. * Check if there is a global attention and if
  7767. * there was a global attention, set the global
  7768. * reset bit.
  7769. */
  7770. if (global)
  7771. bnx2x_set_reset_global(bp);
  7772. bp->is_leader = 1;
  7773. }
  7774. /* Stop the driver */
  7775. /* If interface has been removed - break */
  7776. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7777. return;
  7778. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7779. /* Ensure "is_leader", MCP command sequence and
  7780. * "recovery_state" update values are seen on other
  7781. * CPUs.
  7782. */
  7783. smp_mb();
  7784. break;
  7785. case BNX2X_RECOVERY_WAIT:
  7786. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7787. if (bp->is_leader) {
  7788. int other_engine = BP_PATH(bp) ? 0 : 1;
  7789. bool other_load_status =
  7790. bnx2x_get_load_status(bp, other_engine);
  7791. bool load_status =
  7792. bnx2x_get_load_status(bp, BP_PATH(bp));
  7793. global = bnx2x_reset_is_global(bp);
  7794. /*
  7795. * In case of a parity in a global block, let
  7796. * the first leader that performs a
  7797. * leader_reset() reset the global blocks in
  7798. * order to clear global attentions. Otherwise
  7799. * the the gates will remain closed for that
  7800. * engine.
  7801. */
  7802. if (load_status ||
  7803. (global && other_load_status)) {
  7804. /* Wait until all other functions get
  7805. * down.
  7806. */
  7807. schedule_delayed_work(&bp->sp_rtnl_task,
  7808. HZ/10);
  7809. return;
  7810. } else {
  7811. /* If all other functions got down -
  7812. * try to bring the chip back to
  7813. * normal. In any case it's an exit
  7814. * point for a leader.
  7815. */
  7816. if (bnx2x_leader_reset(bp)) {
  7817. bnx2x_recovery_failed(bp);
  7818. return;
  7819. }
  7820. /* If we are here, means that the
  7821. * leader has succeeded and doesn't
  7822. * want to be a leader any more. Try
  7823. * to continue as a none-leader.
  7824. */
  7825. break;
  7826. }
  7827. } else { /* non-leader */
  7828. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7829. /* Try to get a LEADER_LOCK HW lock as
  7830. * long as a former leader may have
  7831. * been unloaded by the user or
  7832. * released a leadership by another
  7833. * reason.
  7834. */
  7835. if (bnx2x_trylock_leader_lock(bp)) {
  7836. /* I'm a leader now! Restart a
  7837. * switch case.
  7838. */
  7839. bp->is_leader = 1;
  7840. break;
  7841. }
  7842. schedule_delayed_work(&bp->sp_rtnl_task,
  7843. HZ/10);
  7844. return;
  7845. } else {
  7846. /*
  7847. * If there was a global attention, wait
  7848. * for it to be cleared.
  7849. */
  7850. if (bnx2x_reset_is_global(bp)) {
  7851. schedule_delayed_work(
  7852. &bp->sp_rtnl_task,
  7853. HZ/10);
  7854. return;
  7855. }
  7856. error_recovered =
  7857. bp->eth_stats.recoverable_error;
  7858. error_unrecovered =
  7859. bp->eth_stats.unrecoverable_error;
  7860. bp->recovery_state =
  7861. BNX2X_RECOVERY_NIC_LOADING;
  7862. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7863. error_unrecovered++;
  7864. netdev_err(bp->dev,
  7865. "Recovery failed. Power cycle needed\n");
  7866. /* Disconnect this device */
  7867. netif_device_detach(bp->dev);
  7868. /* Shut down the power */
  7869. bnx2x_set_power_state(
  7870. bp, PCI_D3hot);
  7871. smp_mb();
  7872. } else {
  7873. bp->recovery_state =
  7874. BNX2X_RECOVERY_DONE;
  7875. error_recovered++;
  7876. smp_mb();
  7877. }
  7878. bp->eth_stats.recoverable_error =
  7879. error_recovered;
  7880. bp->eth_stats.unrecoverable_error =
  7881. error_unrecovered;
  7882. return;
  7883. }
  7884. }
  7885. default:
  7886. return;
  7887. }
  7888. }
  7889. }
  7890. static int bnx2x_close(struct net_device *dev);
  7891. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7892. * scheduled on a general queue in order to prevent a dead lock.
  7893. */
  7894. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7895. {
  7896. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7897. rtnl_lock();
  7898. if (!netif_running(bp->dev)) {
  7899. rtnl_unlock();
  7900. return;
  7901. }
  7902. /* if stop on error is defined no recovery flows should be executed */
  7903. #ifdef BNX2X_STOP_ON_ERROR
  7904. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7905. "you will need to reboot when done\n");
  7906. goto sp_rtnl_not_reset;
  7907. #endif
  7908. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7909. /*
  7910. * Clear all pending SP commands as we are going to reset the
  7911. * function anyway.
  7912. */
  7913. bp->sp_rtnl_state = 0;
  7914. smp_mb();
  7915. bnx2x_parity_recover(bp);
  7916. rtnl_unlock();
  7917. return;
  7918. }
  7919. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7920. /*
  7921. * Clear all pending SP commands as we are going to reset the
  7922. * function anyway.
  7923. */
  7924. bp->sp_rtnl_state = 0;
  7925. smp_mb();
  7926. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7927. bnx2x_nic_load(bp, LOAD_NORMAL);
  7928. rtnl_unlock();
  7929. return;
  7930. }
  7931. #ifdef BNX2X_STOP_ON_ERROR
  7932. sp_rtnl_not_reset:
  7933. #endif
  7934. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7935. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7936. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7937. bnx2x_after_function_update(bp);
  7938. /*
  7939. * in case of fan failure we need to reset id if the "stop on error"
  7940. * debug flag is set, since we trying to prevent permanent overheating
  7941. * damage
  7942. */
  7943. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7944. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7945. netif_device_detach(bp->dev);
  7946. bnx2x_close(bp->dev);
  7947. rtnl_unlock();
  7948. return;
  7949. }
  7950. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7951. DP(BNX2X_MSG_SP,
  7952. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7953. bnx2x_vfpf_set_mcast(bp->dev);
  7954. }
  7955. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7956. &bp->sp_rtnl_state)) {
  7957. DP(BNX2X_MSG_SP,
  7958. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7959. bnx2x_vfpf_storm_rx_mode(bp);
  7960. }
  7961. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  7962. &bp->sp_rtnl_state))
  7963. bnx2x_pf_set_vfs_vlan(bp);
  7964. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  7965. * can be called from other contexts as well)
  7966. */
  7967. rtnl_unlock();
  7968. /* enable SR-IOV if applicable */
  7969. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  7970. &bp->sp_rtnl_state)) {
  7971. bnx2x_disable_sriov(bp);
  7972. bnx2x_enable_sriov(bp);
  7973. }
  7974. }
  7975. static void bnx2x_period_task(struct work_struct *work)
  7976. {
  7977. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7978. if (!netif_running(bp->dev))
  7979. goto period_task_exit;
  7980. if (CHIP_REV_IS_SLOW(bp)) {
  7981. BNX2X_ERR("period task called on emulation, ignoring\n");
  7982. goto period_task_exit;
  7983. }
  7984. bnx2x_acquire_phy_lock(bp);
  7985. /*
  7986. * The barrier is needed to ensure the ordering between the writing to
  7987. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7988. * the reading here.
  7989. */
  7990. smp_mb();
  7991. if (bp->port.pmf) {
  7992. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7993. /* Re-queue task in 1 sec */
  7994. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7995. }
  7996. bnx2x_release_phy_lock(bp);
  7997. period_task_exit:
  7998. return;
  7999. }
  8000. /*
  8001. * Init service functions
  8002. */
  8003. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8004. {
  8005. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8006. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8007. return base + (BP_ABS_FUNC(bp)) * stride;
  8008. }
  8009. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8010. struct bnx2x_mac_vals *vals)
  8011. {
  8012. u32 val, base_addr, offset, mask, reset_reg;
  8013. bool mac_stopped = false;
  8014. u8 port = BP_PORT(bp);
  8015. /* reset addresses as they also mark which values were changed */
  8016. vals->bmac_addr = 0;
  8017. vals->umac_addr = 0;
  8018. vals->xmac_addr = 0;
  8019. vals->emac_addr = 0;
  8020. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8021. if (!CHIP_IS_E3(bp)) {
  8022. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8023. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8024. if ((mask & reset_reg) && val) {
  8025. u32 wb_data[2];
  8026. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8027. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8028. : NIG_REG_INGRESS_BMAC0_MEM;
  8029. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8030. : BIGMAC_REGISTER_BMAC_CONTROL;
  8031. /*
  8032. * use rd/wr since we cannot use dmae. This is safe
  8033. * since MCP won't access the bus due to the request
  8034. * to unload, and no function on the path can be
  8035. * loaded at this time.
  8036. */
  8037. wb_data[0] = REG_RD(bp, base_addr + offset);
  8038. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8039. vals->bmac_addr = base_addr + offset;
  8040. vals->bmac_val[0] = wb_data[0];
  8041. vals->bmac_val[1] = wb_data[1];
  8042. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8043. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8044. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8045. }
  8046. BNX2X_DEV_INFO("Disable emac Rx\n");
  8047. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8048. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8049. REG_WR(bp, vals->emac_addr, 0);
  8050. mac_stopped = true;
  8051. } else {
  8052. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8053. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8054. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8055. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8056. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8057. val & ~(1 << 1));
  8058. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8059. val | (1 << 1));
  8060. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8061. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8062. REG_WR(bp, vals->xmac_addr, 0);
  8063. mac_stopped = true;
  8064. }
  8065. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8066. if (mask & reset_reg) {
  8067. BNX2X_DEV_INFO("Disable umac Rx\n");
  8068. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8069. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8070. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8071. REG_WR(bp, vals->umac_addr, 0);
  8072. mac_stopped = true;
  8073. }
  8074. }
  8075. if (mac_stopped)
  8076. msleep(20);
  8077. }
  8078. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8079. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8080. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8081. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8082. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8083. {
  8084. u16 rcq, bd;
  8085. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8086. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8087. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8088. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8089. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8090. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8091. port, bd, rcq);
  8092. }
  8093. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8094. {
  8095. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8096. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8097. if (!rc) {
  8098. BNX2X_ERR("MCP response failure, aborting\n");
  8099. return -EBUSY;
  8100. }
  8101. return 0;
  8102. }
  8103. static struct bnx2x_prev_path_list *
  8104. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8105. {
  8106. struct bnx2x_prev_path_list *tmp_list;
  8107. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8108. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8109. bp->pdev->bus->number == tmp_list->bus &&
  8110. BP_PATH(bp) == tmp_list->path)
  8111. return tmp_list;
  8112. return NULL;
  8113. }
  8114. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8115. {
  8116. struct bnx2x_prev_path_list *tmp_list;
  8117. int rc = false;
  8118. if (down_trylock(&bnx2x_prev_sem))
  8119. return false;
  8120. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  8121. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8122. bp->pdev->bus->number == tmp_list->bus &&
  8123. BP_PATH(bp) == tmp_list->path) {
  8124. rc = true;
  8125. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8126. BP_PATH(bp));
  8127. break;
  8128. }
  8129. }
  8130. up(&bnx2x_prev_sem);
  8131. return rc;
  8132. }
  8133. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8134. {
  8135. struct bnx2x_prev_path_list *tmp_list;
  8136. int rc;
  8137. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8138. if (!tmp_list) {
  8139. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8140. return -ENOMEM;
  8141. }
  8142. tmp_list->bus = bp->pdev->bus->number;
  8143. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8144. tmp_list->path = BP_PATH(bp);
  8145. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8146. rc = down_interruptible(&bnx2x_prev_sem);
  8147. if (rc) {
  8148. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8149. kfree(tmp_list);
  8150. } else {
  8151. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  8152. BP_PATH(bp));
  8153. list_add(&tmp_list->list, &bnx2x_prev_list);
  8154. up(&bnx2x_prev_sem);
  8155. }
  8156. return rc;
  8157. }
  8158. static int bnx2x_do_flr(struct bnx2x *bp)
  8159. {
  8160. int i;
  8161. u16 status;
  8162. struct pci_dev *dev = bp->pdev;
  8163. if (CHIP_IS_E1x(bp)) {
  8164. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8165. return -EINVAL;
  8166. }
  8167. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8168. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8169. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8170. bp->common.bc_ver);
  8171. return -EINVAL;
  8172. }
  8173. /* Wait for Transaction Pending bit clean */
  8174. for (i = 0; i < 4; i++) {
  8175. if (i)
  8176. msleep((1 << (i - 1)) * 100);
  8177. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8178. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8179. goto clear;
  8180. }
  8181. dev_err(&dev->dev,
  8182. "transaction is not cleared; proceeding with reset anyway\n");
  8183. clear:
  8184. BNX2X_DEV_INFO("Initiating FLR\n");
  8185. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8186. return 0;
  8187. }
  8188. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8189. {
  8190. int rc;
  8191. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8192. /* Test if previous unload process was already finished for this path */
  8193. if (bnx2x_prev_is_path_marked(bp))
  8194. return bnx2x_prev_mcp_done(bp);
  8195. BNX2X_DEV_INFO("Path is unmarked\n");
  8196. /* If function has FLR capabilities, and existing FW version matches
  8197. * the one required, then FLR will be sufficient to clean any residue
  8198. * left by previous driver
  8199. */
  8200. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8201. if (!rc) {
  8202. /* fw version is good */
  8203. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8204. rc = bnx2x_do_flr(bp);
  8205. }
  8206. if (!rc) {
  8207. /* FLR was performed */
  8208. BNX2X_DEV_INFO("FLR successful\n");
  8209. return 0;
  8210. }
  8211. BNX2X_DEV_INFO("Could not FLR\n");
  8212. /* Close the MCP request, return failure*/
  8213. rc = bnx2x_prev_mcp_done(bp);
  8214. if (!rc)
  8215. rc = BNX2X_PREV_WAIT_NEEDED;
  8216. return rc;
  8217. }
  8218. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8219. {
  8220. u32 reset_reg, tmp_reg = 0, rc;
  8221. bool prev_undi = false;
  8222. struct bnx2x_mac_vals mac_vals;
  8223. /* It is possible a previous function received 'common' answer,
  8224. * but hasn't loaded yet, therefore creating a scenario of
  8225. * multiple functions receiving 'common' on the same path.
  8226. */
  8227. BNX2X_DEV_INFO("Common unload Flow\n");
  8228. memset(&mac_vals, 0, sizeof(mac_vals));
  8229. if (bnx2x_prev_is_path_marked(bp))
  8230. return bnx2x_prev_mcp_done(bp);
  8231. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8232. /* Reset should be performed after BRB is emptied */
  8233. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8234. u32 timer_count = 1000;
  8235. /* Close the MAC Rx to prevent BRB from filling up */
  8236. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8237. /* close LLH filters towards the BRB */
  8238. bnx2x_set_rx_filter(&bp->link_params, 0);
  8239. /* Check if the UNDI driver was previously loaded
  8240. * UNDI driver initializes CID offset for normal bell to 0x7
  8241. */
  8242. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8243. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8244. if (tmp_reg == 0x7) {
  8245. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8246. prev_undi = true;
  8247. /* clear the UNDI indication */
  8248. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8249. /* clear possible idle check errors */
  8250. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8251. }
  8252. }
  8253. /* wait until BRB is empty */
  8254. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8255. while (timer_count) {
  8256. u32 prev_brb = tmp_reg;
  8257. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8258. if (!tmp_reg)
  8259. break;
  8260. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8261. /* reset timer as long as BRB actually gets emptied */
  8262. if (prev_brb > tmp_reg)
  8263. timer_count = 1000;
  8264. else
  8265. timer_count--;
  8266. /* If UNDI resides in memory, manually increment it */
  8267. if (prev_undi)
  8268. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8269. udelay(10);
  8270. }
  8271. if (!timer_count)
  8272. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8273. }
  8274. /* No packets are in the pipeline, path is ready for reset */
  8275. bnx2x_reset_common(bp);
  8276. if (mac_vals.xmac_addr)
  8277. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8278. if (mac_vals.umac_addr)
  8279. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8280. if (mac_vals.emac_addr)
  8281. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8282. if (mac_vals.bmac_addr) {
  8283. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8284. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8285. }
  8286. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8287. if (rc) {
  8288. bnx2x_prev_mcp_done(bp);
  8289. return rc;
  8290. }
  8291. return bnx2x_prev_mcp_done(bp);
  8292. }
  8293. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8294. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8295. * the addresses of the transaction, resulting in was-error bit set in the pci
  8296. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8297. * to clear the interrupt which detected this from the pglueb and the was done
  8298. * bit
  8299. */
  8300. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8301. {
  8302. if (!CHIP_IS_E1x(bp)) {
  8303. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8304. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8305. DP(BNX2X_MSG_SP,
  8306. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8307. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8308. 1 << BP_FUNC(bp));
  8309. }
  8310. }
  8311. }
  8312. static int bnx2x_prev_unload(struct bnx2x *bp)
  8313. {
  8314. int time_counter = 10;
  8315. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8316. struct bnx2x_prev_path_list *prev_list;
  8317. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8318. /* clear hw from errors which may have resulted from an interrupted
  8319. * dmae transaction.
  8320. */
  8321. bnx2x_prev_interrupted_dmae(bp);
  8322. /* Release previously held locks */
  8323. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8324. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8325. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8326. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8327. if (hw_lock_val) {
  8328. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8329. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8330. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8331. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8332. }
  8333. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8334. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8335. } else
  8336. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8337. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8338. BNX2X_DEV_INFO("Release previously held alr\n");
  8339. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8340. }
  8341. do {
  8342. /* Lock MCP using an unload request */
  8343. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8344. if (!fw) {
  8345. BNX2X_ERR("MCP response failure, aborting\n");
  8346. rc = -EBUSY;
  8347. break;
  8348. }
  8349. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8350. rc = bnx2x_prev_unload_common(bp);
  8351. break;
  8352. }
  8353. /* non-common reply from MCP night require looping */
  8354. rc = bnx2x_prev_unload_uncommon(bp);
  8355. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8356. break;
  8357. msleep(20);
  8358. } while (--time_counter);
  8359. if (!time_counter || rc) {
  8360. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8361. rc = -EBUSY;
  8362. }
  8363. /* Mark function if its port was used to boot from SAN */
  8364. prev_list = bnx2x_prev_path_get_entry(bp);
  8365. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8366. bp->link_params.feature_config_flags |=
  8367. FEATURE_CONFIG_BOOT_FROM_SAN;
  8368. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8369. return rc;
  8370. }
  8371. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8372. {
  8373. u32 val, val2, val3, val4, id, boot_mode;
  8374. u16 pmc;
  8375. /* Get the chip revision id and number. */
  8376. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8377. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8378. id = ((val & 0xffff) << 16);
  8379. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8380. id |= ((val & 0xf) << 12);
  8381. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8382. * the configuration space (so we need to reg_rd)
  8383. */
  8384. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8385. id |= (((val >> 24) & 0xf) << 4);
  8386. val = REG_RD(bp, MISC_REG_BOND_ID);
  8387. id |= (val & 0xf);
  8388. bp->common.chip_id = id;
  8389. /* force 57811 according to MISC register */
  8390. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8391. if (CHIP_IS_57810(bp))
  8392. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8393. (bp->common.chip_id & 0x0000FFFF);
  8394. else if (CHIP_IS_57810_MF(bp))
  8395. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8396. (bp->common.chip_id & 0x0000FFFF);
  8397. bp->common.chip_id |= 0x1;
  8398. }
  8399. /* Set doorbell size */
  8400. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8401. if (!CHIP_IS_E1x(bp)) {
  8402. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8403. if ((val & 1) == 0)
  8404. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8405. else
  8406. val = (val >> 1) & 1;
  8407. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8408. "2_PORT_MODE");
  8409. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8410. CHIP_2_PORT_MODE;
  8411. if (CHIP_MODE_IS_4_PORT(bp))
  8412. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8413. else
  8414. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8415. } else {
  8416. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8417. bp->pfid = bp->pf_num; /* 0..7 */
  8418. }
  8419. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8420. bp->link_params.chip_id = bp->common.chip_id;
  8421. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8422. val = (REG_RD(bp, 0x2874) & 0x55);
  8423. if ((bp->common.chip_id & 0x1) ||
  8424. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8425. bp->flags |= ONE_PORT_FLAG;
  8426. BNX2X_DEV_INFO("single port device\n");
  8427. }
  8428. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8429. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8430. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8431. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8432. bp->common.flash_size, bp->common.flash_size);
  8433. bnx2x_init_shmem(bp);
  8434. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8435. MISC_REG_GENERIC_CR_1 :
  8436. MISC_REG_GENERIC_CR_0));
  8437. bp->link_params.shmem_base = bp->common.shmem_base;
  8438. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8439. if (SHMEM2_RD(bp, size) >
  8440. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8441. bp->link_params.lfa_base =
  8442. REG_RD(bp, bp->common.shmem2_base +
  8443. (u32)offsetof(struct shmem2_region,
  8444. lfa_host_addr[BP_PORT(bp)]));
  8445. else
  8446. bp->link_params.lfa_base = 0;
  8447. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8448. bp->common.shmem_base, bp->common.shmem2_base);
  8449. if (!bp->common.shmem_base) {
  8450. BNX2X_DEV_INFO("MCP not active\n");
  8451. bp->flags |= NO_MCP_FLAG;
  8452. return;
  8453. }
  8454. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8455. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8456. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8457. SHARED_HW_CFG_LED_MODE_MASK) >>
  8458. SHARED_HW_CFG_LED_MODE_SHIFT);
  8459. bp->link_params.feature_config_flags = 0;
  8460. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8461. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8462. bp->link_params.feature_config_flags |=
  8463. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8464. else
  8465. bp->link_params.feature_config_flags &=
  8466. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8467. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8468. bp->common.bc_ver = val;
  8469. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8470. if (val < BNX2X_BC_VER) {
  8471. /* for now only warn
  8472. * later we might need to enforce this */
  8473. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8474. BNX2X_BC_VER, val);
  8475. }
  8476. bp->link_params.feature_config_flags |=
  8477. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8478. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8479. bp->link_params.feature_config_flags |=
  8480. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8481. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8482. bp->link_params.feature_config_flags |=
  8483. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8484. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8485. bp->link_params.feature_config_flags |=
  8486. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8487. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8488. bp->link_params.feature_config_flags |=
  8489. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8490. FEATURE_CONFIG_MT_SUPPORT : 0;
  8491. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8492. BC_SUPPORTS_PFC_STATS : 0;
  8493. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8494. BC_SUPPORTS_FCOE_FEATURES : 0;
  8495. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8496. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8497. boot_mode = SHMEM_RD(bp,
  8498. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8499. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8500. switch (boot_mode) {
  8501. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8502. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8503. break;
  8504. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8505. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8506. break;
  8507. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8508. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8509. break;
  8510. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8511. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8512. break;
  8513. }
  8514. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8515. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8516. BNX2X_DEV_INFO("%sWoL capable\n",
  8517. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8518. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8519. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8520. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8521. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8522. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8523. val, val2, val3, val4);
  8524. }
  8525. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8526. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8527. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8528. {
  8529. int pfid = BP_FUNC(bp);
  8530. int igu_sb_id;
  8531. u32 val;
  8532. u8 fid, igu_sb_cnt = 0;
  8533. bp->igu_base_sb = 0xff;
  8534. if (CHIP_INT_MODE_IS_BC(bp)) {
  8535. int vn = BP_VN(bp);
  8536. igu_sb_cnt = bp->igu_sb_cnt;
  8537. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8538. FP_SB_MAX_E1x;
  8539. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8540. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8541. return 0;
  8542. }
  8543. /* IGU in normal mode - read CAM */
  8544. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8545. igu_sb_id++) {
  8546. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8547. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8548. continue;
  8549. fid = IGU_FID(val);
  8550. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8551. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8552. continue;
  8553. if (IGU_VEC(val) == 0)
  8554. /* default status block */
  8555. bp->igu_dsb_id = igu_sb_id;
  8556. else {
  8557. if (bp->igu_base_sb == 0xff)
  8558. bp->igu_base_sb = igu_sb_id;
  8559. igu_sb_cnt++;
  8560. }
  8561. }
  8562. }
  8563. #ifdef CONFIG_PCI_MSI
  8564. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8565. * optional that number of CAM entries will not be equal to the value
  8566. * advertised in PCI.
  8567. * Driver should use the minimal value of both as the actual status
  8568. * block count
  8569. */
  8570. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8571. #endif
  8572. if (igu_sb_cnt == 0) {
  8573. BNX2X_ERR("CAM configuration error\n");
  8574. return -EINVAL;
  8575. }
  8576. return 0;
  8577. }
  8578. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8579. {
  8580. int cfg_size = 0, idx, port = BP_PORT(bp);
  8581. /* Aggregation of supported attributes of all external phys */
  8582. bp->port.supported[0] = 0;
  8583. bp->port.supported[1] = 0;
  8584. switch (bp->link_params.num_phys) {
  8585. case 1:
  8586. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8587. cfg_size = 1;
  8588. break;
  8589. case 2:
  8590. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8591. cfg_size = 1;
  8592. break;
  8593. case 3:
  8594. if (bp->link_params.multi_phy_config &
  8595. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8596. bp->port.supported[1] =
  8597. bp->link_params.phy[EXT_PHY1].supported;
  8598. bp->port.supported[0] =
  8599. bp->link_params.phy[EXT_PHY2].supported;
  8600. } else {
  8601. bp->port.supported[0] =
  8602. bp->link_params.phy[EXT_PHY1].supported;
  8603. bp->port.supported[1] =
  8604. bp->link_params.phy[EXT_PHY2].supported;
  8605. }
  8606. cfg_size = 2;
  8607. break;
  8608. }
  8609. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8610. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8611. SHMEM_RD(bp,
  8612. dev_info.port_hw_config[port].external_phy_config),
  8613. SHMEM_RD(bp,
  8614. dev_info.port_hw_config[port].external_phy_config2));
  8615. return;
  8616. }
  8617. if (CHIP_IS_E3(bp))
  8618. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8619. else {
  8620. switch (switch_cfg) {
  8621. case SWITCH_CFG_1G:
  8622. bp->port.phy_addr = REG_RD(
  8623. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8624. break;
  8625. case SWITCH_CFG_10G:
  8626. bp->port.phy_addr = REG_RD(
  8627. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8628. break;
  8629. default:
  8630. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8631. bp->port.link_config[0]);
  8632. return;
  8633. }
  8634. }
  8635. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8636. /* mask what we support according to speed_cap_mask per configuration */
  8637. for (idx = 0; idx < cfg_size; idx++) {
  8638. if (!(bp->link_params.speed_cap_mask[idx] &
  8639. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8640. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8641. if (!(bp->link_params.speed_cap_mask[idx] &
  8642. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8643. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8644. if (!(bp->link_params.speed_cap_mask[idx] &
  8645. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8646. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8647. if (!(bp->link_params.speed_cap_mask[idx] &
  8648. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8649. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8650. if (!(bp->link_params.speed_cap_mask[idx] &
  8651. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8652. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8653. SUPPORTED_1000baseT_Full);
  8654. if (!(bp->link_params.speed_cap_mask[idx] &
  8655. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8656. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8657. if (!(bp->link_params.speed_cap_mask[idx] &
  8658. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8659. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8660. }
  8661. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8662. bp->port.supported[1]);
  8663. }
  8664. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8665. {
  8666. u32 link_config, idx, cfg_size = 0;
  8667. bp->port.advertising[0] = 0;
  8668. bp->port.advertising[1] = 0;
  8669. switch (bp->link_params.num_phys) {
  8670. case 1:
  8671. case 2:
  8672. cfg_size = 1;
  8673. break;
  8674. case 3:
  8675. cfg_size = 2;
  8676. break;
  8677. }
  8678. for (idx = 0; idx < cfg_size; idx++) {
  8679. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8680. link_config = bp->port.link_config[idx];
  8681. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8682. case PORT_FEATURE_LINK_SPEED_AUTO:
  8683. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8684. bp->link_params.req_line_speed[idx] =
  8685. SPEED_AUTO_NEG;
  8686. bp->port.advertising[idx] |=
  8687. bp->port.supported[idx];
  8688. if (bp->link_params.phy[EXT_PHY1].type ==
  8689. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8690. bp->port.advertising[idx] |=
  8691. (SUPPORTED_100baseT_Half |
  8692. SUPPORTED_100baseT_Full);
  8693. } else {
  8694. /* force 10G, no AN */
  8695. bp->link_params.req_line_speed[idx] =
  8696. SPEED_10000;
  8697. bp->port.advertising[idx] |=
  8698. (ADVERTISED_10000baseT_Full |
  8699. ADVERTISED_FIBRE);
  8700. continue;
  8701. }
  8702. break;
  8703. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8704. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8705. bp->link_params.req_line_speed[idx] =
  8706. SPEED_10;
  8707. bp->port.advertising[idx] |=
  8708. (ADVERTISED_10baseT_Full |
  8709. ADVERTISED_TP);
  8710. } else {
  8711. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8712. link_config,
  8713. bp->link_params.speed_cap_mask[idx]);
  8714. return;
  8715. }
  8716. break;
  8717. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8718. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8719. bp->link_params.req_line_speed[idx] =
  8720. SPEED_10;
  8721. bp->link_params.req_duplex[idx] =
  8722. DUPLEX_HALF;
  8723. bp->port.advertising[idx] |=
  8724. (ADVERTISED_10baseT_Half |
  8725. ADVERTISED_TP);
  8726. } else {
  8727. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8728. link_config,
  8729. bp->link_params.speed_cap_mask[idx]);
  8730. return;
  8731. }
  8732. break;
  8733. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8734. if (bp->port.supported[idx] &
  8735. SUPPORTED_100baseT_Full) {
  8736. bp->link_params.req_line_speed[idx] =
  8737. SPEED_100;
  8738. bp->port.advertising[idx] |=
  8739. (ADVERTISED_100baseT_Full |
  8740. ADVERTISED_TP);
  8741. } else {
  8742. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8743. link_config,
  8744. bp->link_params.speed_cap_mask[idx]);
  8745. return;
  8746. }
  8747. break;
  8748. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8749. if (bp->port.supported[idx] &
  8750. SUPPORTED_100baseT_Half) {
  8751. bp->link_params.req_line_speed[idx] =
  8752. SPEED_100;
  8753. bp->link_params.req_duplex[idx] =
  8754. DUPLEX_HALF;
  8755. bp->port.advertising[idx] |=
  8756. (ADVERTISED_100baseT_Half |
  8757. ADVERTISED_TP);
  8758. } else {
  8759. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8760. link_config,
  8761. bp->link_params.speed_cap_mask[idx]);
  8762. return;
  8763. }
  8764. break;
  8765. case PORT_FEATURE_LINK_SPEED_1G:
  8766. if (bp->port.supported[idx] &
  8767. SUPPORTED_1000baseT_Full) {
  8768. bp->link_params.req_line_speed[idx] =
  8769. SPEED_1000;
  8770. bp->port.advertising[idx] |=
  8771. (ADVERTISED_1000baseT_Full |
  8772. ADVERTISED_TP);
  8773. } else {
  8774. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8775. link_config,
  8776. bp->link_params.speed_cap_mask[idx]);
  8777. return;
  8778. }
  8779. break;
  8780. case PORT_FEATURE_LINK_SPEED_2_5G:
  8781. if (bp->port.supported[idx] &
  8782. SUPPORTED_2500baseX_Full) {
  8783. bp->link_params.req_line_speed[idx] =
  8784. SPEED_2500;
  8785. bp->port.advertising[idx] |=
  8786. (ADVERTISED_2500baseX_Full |
  8787. ADVERTISED_TP);
  8788. } else {
  8789. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8790. link_config,
  8791. bp->link_params.speed_cap_mask[idx]);
  8792. return;
  8793. }
  8794. break;
  8795. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8796. if (bp->port.supported[idx] &
  8797. SUPPORTED_10000baseT_Full) {
  8798. bp->link_params.req_line_speed[idx] =
  8799. SPEED_10000;
  8800. bp->port.advertising[idx] |=
  8801. (ADVERTISED_10000baseT_Full |
  8802. ADVERTISED_FIBRE);
  8803. } else {
  8804. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8805. link_config,
  8806. bp->link_params.speed_cap_mask[idx]);
  8807. return;
  8808. }
  8809. break;
  8810. case PORT_FEATURE_LINK_SPEED_20G:
  8811. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8812. break;
  8813. default:
  8814. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8815. link_config);
  8816. bp->link_params.req_line_speed[idx] =
  8817. SPEED_AUTO_NEG;
  8818. bp->port.advertising[idx] =
  8819. bp->port.supported[idx];
  8820. break;
  8821. }
  8822. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8823. PORT_FEATURE_FLOW_CONTROL_MASK);
  8824. if (bp->link_params.req_flow_ctrl[idx] ==
  8825. BNX2X_FLOW_CTRL_AUTO) {
  8826. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8827. bp->link_params.req_flow_ctrl[idx] =
  8828. BNX2X_FLOW_CTRL_NONE;
  8829. else
  8830. bnx2x_set_requested_fc(bp);
  8831. }
  8832. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8833. bp->link_params.req_line_speed[idx],
  8834. bp->link_params.req_duplex[idx],
  8835. bp->link_params.req_flow_ctrl[idx],
  8836. bp->port.advertising[idx]);
  8837. }
  8838. }
  8839. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8840. {
  8841. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  8842. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  8843. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  8844. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  8845. }
  8846. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8847. {
  8848. int port = BP_PORT(bp);
  8849. u32 config;
  8850. u32 ext_phy_type, ext_phy_config, eee_mode;
  8851. bp->link_params.bp = bp;
  8852. bp->link_params.port = port;
  8853. bp->link_params.lane_config =
  8854. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8855. bp->link_params.speed_cap_mask[0] =
  8856. SHMEM_RD(bp,
  8857. dev_info.port_hw_config[port].speed_capability_mask);
  8858. bp->link_params.speed_cap_mask[1] =
  8859. SHMEM_RD(bp,
  8860. dev_info.port_hw_config[port].speed_capability_mask2);
  8861. bp->port.link_config[0] =
  8862. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8863. bp->port.link_config[1] =
  8864. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8865. bp->link_params.multi_phy_config =
  8866. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8867. /* If the device is capable of WoL, set the default state according
  8868. * to the HW
  8869. */
  8870. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8871. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8872. (config & PORT_FEATURE_WOL_ENABLED));
  8873. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8874. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  8875. bp->flags |= NO_ISCSI_FLAG;
  8876. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8877. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  8878. bp->flags |= NO_FCOE_FLAG;
  8879. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8880. bp->link_params.lane_config,
  8881. bp->link_params.speed_cap_mask[0],
  8882. bp->port.link_config[0]);
  8883. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8884. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8885. bnx2x_phy_probe(&bp->link_params);
  8886. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8887. bnx2x_link_settings_requested(bp);
  8888. /*
  8889. * If connected directly, work with the internal PHY, otherwise, work
  8890. * with the external PHY
  8891. */
  8892. ext_phy_config =
  8893. SHMEM_RD(bp,
  8894. dev_info.port_hw_config[port].external_phy_config);
  8895. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8896. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8897. bp->mdio.prtad = bp->port.phy_addr;
  8898. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8899. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8900. bp->mdio.prtad =
  8901. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8902. /* Configure link feature according to nvram value */
  8903. eee_mode = (((SHMEM_RD(bp, dev_info.
  8904. port_feature_config[port].eee_power_mode)) &
  8905. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8906. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8907. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8908. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8909. EEE_MODE_ENABLE_LPI |
  8910. EEE_MODE_OUTPUT_TIME;
  8911. } else {
  8912. bp->link_params.eee_mode = 0;
  8913. }
  8914. }
  8915. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8916. {
  8917. u32 no_flags = NO_ISCSI_FLAG;
  8918. int port = BP_PORT(bp);
  8919. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8920. drv_lic_key[port].max_iscsi_conn);
  8921. if (!CNIC_SUPPORT(bp)) {
  8922. bp->flags |= no_flags;
  8923. return;
  8924. }
  8925. /* Get the number of maximum allowed iSCSI connections */
  8926. bp->cnic_eth_dev.max_iscsi_conn =
  8927. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8928. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8929. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8930. bp->cnic_eth_dev.max_iscsi_conn);
  8931. /*
  8932. * If maximum allowed number of connections is zero -
  8933. * disable the feature.
  8934. */
  8935. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8936. bp->flags |= no_flags;
  8937. }
  8938. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8939. {
  8940. /* Port info */
  8941. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8942. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8943. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8944. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8945. /* Node info */
  8946. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8947. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8948. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8949. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8950. }
  8951. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8952. {
  8953. int port = BP_PORT(bp);
  8954. int func = BP_ABS_FUNC(bp);
  8955. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8956. drv_lic_key[port].max_fcoe_conn);
  8957. if (!CNIC_SUPPORT(bp)) {
  8958. bp->flags |= NO_FCOE_FLAG;
  8959. return;
  8960. }
  8961. /* Get the number of maximum allowed FCoE connections */
  8962. bp->cnic_eth_dev.max_fcoe_conn =
  8963. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8964. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8965. /* Read the WWN: */
  8966. if (!IS_MF(bp)) {
  8967. /* Port info */
  8968. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8969. SHMEM_RD(bp,
  8970. dev_info.port_hw_config[port].
  8971. fcoe_wwn_port_name_upper);
  8972. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8973. SHMEM_RD(bp,
  8974. dev_info.port_hw_config[port].
  8975. fcoe_wwn_port_name_lower);
  8976. /* Node info */
  8977. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8978. SHMEM_RD(bp,
  8979. dev_info.port_hw_config[port].
  8980. fcoe_wwn_node_name_upper);
  8981. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8982. SHMEM_RD(bp,
  8983. dev_info.port_hw_config[port].
  8984. fcoe_wwn_node_name_lower);
  8985. } else if (!IS_MF_SD(bp)) {
  8986. /*
  8987. * Read the WWN info only if the FCoE feature is enabled for
  8988. * this function.
  8989. */
  8990. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8991. bnx2x_get_ext_wwn_info(bp, func);
  8992. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8993. bnx2x_get_ext_wwn_info(bp, func);
  8994. }
  8995. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8996. /*
  8997. * If maximum allowed number of connections is zero -
  8998. * disable the feature.
  8999. */
  9000. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9001. bp->flags |= NO_FCOE_FLAG;
  9002. }
  9003. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9004. {
  9005. /*
  9006. * iSCSI may be dynamically disabled but reading
  9007. * info here we will decrease memory usage by driver
  9008. * if the feature is disabled for good
  9009. */
  9010. bnx2x_get_iscsi_info(bp);
  9011. bnx2x_get_fcoe_info(bp);
  9012. }
  9013. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9014. {
  9015. u32 val, val2;
  9016. int func = BP_ABS_FUNC(bp);
  9017. int port = BP_PORT(bp);
  9018. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9019. u8 *fip_mac = bp->fip_mac;
  9020. if (IS_MF(bp)) {
  9021. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9022. * FCoE MAC then the appropriate feature should be disabled.
  9023. * In non SD mode features configuration comes from struct
  9024. * func_ext_config.
  9025. */
  9026. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9027. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9028. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9029. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9030. iscsi_mac_addr_upper);
  9031. val = MF_CFG_RD(bp, func_ext_config[func].
  9032. iscsi_mac_addr_lower);
  9033. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9034. BNX2X_DEV_INFO
  9035. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9036. } else {
  9037. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9038. }
  9039. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9040. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9041. fcoe_mac_addr_upper);
  9042. val = MF_CFG_RD(bp, func_ext_config[func].
  9043. fcoe_mac_addr_lower);
  9044. bnx2x_set_mac_buf(fip_mac, val, val2);
  9045. BNX2X_DEV_INFO
  9046. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9047. } else {
  9048. bp->flags |= NO_FCOE_FLAG;
  9049. }
  9050. bp->mf_ext_config = cfg;
  9051. } else { /* SD MODE */
  9052. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9053. /* use primary mac as iscsi mac */
  9054. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9055. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9056. BNX2X_DEV_INFO
  9057. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9058. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9059. /* use primary mac as fip mac */
  9060. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9061. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9062. BNX2X_DEV_INFO
  9063. ("Read FIP MAC: %pM\n", fip_mac);
  9064. }
  9065. }
  9066. if (IS_MF_STORAGE_SD(bp))
  9067. /* Zero primary MAC configuration */
  9068. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9069. if (IS_MF_FCOE_AFEX(bp) || IS_MF_FCOE_SD(bp))
  9070. /* use FIP MAC as primary MAC */
  9071. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9072. } else {
  9073. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9074. iscsi_mac_upper);
  9075. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9076. iscsi_mac_lower);
  9077. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9078. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9079. fcoe_fip_mac_upper);
  9080. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9081. fcoe_fip_mac_lower);
  9082. bnx2x_set_mac_buf(fip_mac, val, val2);
  9083. }
  9084. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9085. if (!is_valid_ether_addr(iscsi_mac)) {
  9086. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9087. memset(iscsi_mac, 0, ETH_ALEN);
  9088. }
  9089. /* Disable FCoE if MAC configuration is invalid. */
  9090. if (!is_valid_ether_addr(fip_mac)) {
  9091. bp->flags |= NO_FCOE_FLAG;
  9092. memset(bp->fip_mac, 0, ETH_ALEN);
  9093. }
  9094. }
  9095. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9096. {
  9097. u32 val, val2;
  9098. int func = BP_ABS_FUNC(bp);
  9099. int port = BP_PORT(bp);
  9100. /* Zero primary MAC configuration */
  9101. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9102. if (BP_NOMCP(bp)) {
  9103. BNX2X_ERROR("warning: random MAC workaround active\n");
  9104. eth_hw_addr_random(bp->dev);
  9105. } else if (IS_MF(bp)) {
  9106. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9107. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9108. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9109. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9110. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9111. if (CNIC_SUPPORT(bp))
  9112. bnx2x_get_cnic_mac_hwinfo(bp);
  9113. } else {
  9114. /* in SF read MACs from port configuration */
  9115. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9116. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9117. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9118. if (CNIC_SUPPORT(bp))
  9119. bnx2x_get_cnic_mac_hwinfo(bp);
  9120. }
  9121. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9122. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9123. dev_err(&bp->pdev->dev,
  9124. "bad Ethernet MAC address configuration: %pM\n"
  9125. "change it manually before bringing up the appropriate network interface\n",
  9126. bp->dev->dev_addr);
  9127. }
  9128. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9129. {
  9130. int tmp;
  9131. u32 cfg;
  9132. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9133. /* Take function: tmp = func */
  9134. tmp = BP_ABS_FUNC(bp);
  9135. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9136. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9137. } else {
  9138. /* Take port: tmp = port */
  9139. tmp = BP_PORT(bp);
  9140. cfg = SHMEM_RD(bp,
  9141. dev_info.port_hw_config[tmp].generic_features);
  9142. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9143. }
  9144. return cfg;
  9145. }
  9146. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9147. {
  9148. int /*abs*/func = BP_ABS_FUNC(bp);
  9149. int vn;
  9150. u32 val = 0;
  9151. int rc = 0;
  9152. bnx2x_get_common_hwinfo(bp);
  9153. /*
  9154. * initialize IGU parameters
  9155. */
  9156. if (CHIP_IS_E1x(bp)) {
  9157. bp->common.int_block = INT_BLOCK_HC;
  9158. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9159. bp->igu_base_sb = 0;
  9160. } else {
  9161. bp->common.int_block = INT_BLOCK_IGU;
  9162. /* do not allow device reset during IGU info preocessing */
  9163. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9164. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9165. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9166. int tout = 5000;
  9167. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9168. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9169. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9170. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9171. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9172. tout--;
  9173. usleep_range(1000, 2000);
  9174. }
  9175. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9176. dev_err(&bp->pdev->dev,
  9177. "FORCING Normal Mode failed!!!\n");
  9178. bnx2x_release_hw_lock(bp,
  9179. HW_LOCK_RESOURCE_RESET);
  9180. return -EPERM;
  9181. }
  9182. }
  9183. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9184. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9185. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9186. } else
  9187. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9188. rc = bnx2x_get_igu_cam_info(bp);
  9189. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9190. if (rc)
  9191. return rc;
  9192. }
  9193. /*
  9194. * set base FW non-default (fast path) status block id, this value is
  9195. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9196. * determine the id used by the FW.
  9197. */
  9198. if (CHIP_IS_E1x(bp))
  9199. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9200. else /*
  9201. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9202. * the same queue are indicated on the same IGU SB). So we prefer
  9203. * FW and IGU SBs to be the same value.
  9204. */
  9205. bp->base_fw_ndsb = bp->igu_base_sb;
  9206. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9207. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9208. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9209. /*
  9210. * Initialize MF configuration
  9211. */
  9212. bp->mf_ov = 0;
  9213. bp->mf_mode = 0;
  9214. vn = BP_VN(bp);
  9215. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9216. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9217. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9218. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9219. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9220. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9221. else
  9222. bp->common.mf_cfg_base = bp->common.shmem_base +
  9223. offsetof(struct shmem_region, func_mb) +
  9224. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9225. /*
  9226. * get mf configuration:
  9227. * 1. existence of MF configuration
  9228. * 2. MAC address must be legal (check only upper bytes)
  9229. * for Switch-Independent mode;
  9230. * OVLAN must be legal for Switch-Dependent mode
  9231. * 3. SF_MODE configures specific MF mode
  9232. */
  9233. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9234. /* get mf configuration */
  9235. val = SHMEM_RD(bp,
  9236. dev_info.shared_feature_config.config);
  9237. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9238. switch (val) {
  9239. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9240. val = MF_CFG_RD(bp, func_mf_config[func].
  9241. mac_upper);
  9242. /* check for legal mac (upper bytes)*/
  9243. if (val != 0xffff) {
  9244. bp->mf_mode = MULTI_FUNCTION_SI;
  9245. bp->mf_config[vn] = MF_CFG_RD(bp,
  9246. func_mf_config[func].config);
  9247. } else
  9248. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9249. break;
  9250. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9251. if ((!CHIP_IS_E1x(bp)) &&
  9252. (MF_CFG_RD(bp, func_mf_config[func].
  9253. mac_upper) != 0xffff) &&
  9254. (SHMEM2_HAS(bp,
  9255. afex_driver_support))) {
  9256. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9257. bp->mf_config[vn] = MF_CFG_RD(bp,
  9258. func_mf_config[func].config);
  9259. } else {
  9260. BNX2X_DEV_INFO("can not configure afex mode\n");
  9261. }
  9262. break;
  9263. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9264. /* get OV configuration */
  9265. val = MF_CFG_RD(bp,
  9266. func_mf_config[FUNC_0].e1hov_tag);
  9267. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9268. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9269. bp->mf_mode = MULTI_FUNCTION_SD;
  9270. bp->mf_config[vn] = MF_CFG_RD(bp,
  9271. func_mf_config[func].config);
  9272. } else
  9273. BNX2X_DEV_INFO("illegal OV for SD\n");
  9274. break;
  9275. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9276. bp->mf_config[vn] = 0;
  9277. break;
  9278. default:
  9279. /* Unknown configuration: reset mf_config */
  9280. bp->mf_config[vn] = 0;
  9281. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9282. }
  9283. }
  9284. BNX2X_DEV_INFO("%s function mode\n",
  9285. IS_MF(bp) ? "multi" : "single");
  9286. switch (bp->mf_mode) {
  9287. case MULTI_FUNCTION_SD:
  9288. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9289. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9290. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9291. bp->mf_ov = val;
  9292. bp->path_has_ovlan = true;
  9293. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9294. func, bp->mf_ov, bp->mf_ov);
  9295. } else {
  9296. dev_err(&bp->pdev->dev,
  9297. "No valid MF OV for func %d, aborting\n",
  9298. func);
  9299. return -EPERM;
  9300. }
  9301. break;
  9302. case MULTI_FUNCTION_AFEX:
  9303. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9304. break;
  9305. case MULTI_FUNCTION_SI:
  9306. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9307. func);
  9308. break;
  9309. default:
  9310. if (vn) {
  9311. dev_err(&bp->pdev->dev,
  9312. "VN %d is in a single function mode, aborting\n",
  9313. vn);
  9314. return -EPERM;
  9315. }
  9316. break;
  9317. }
  9318. /* check if other port on the path needs ovlan:
  9319. * Since MF configuration is shared between ports
  9320. * Possible mixed modes are only
  9321. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9322. */
  9323. if (CHIP_MODE_IS_4_PORT(bp) &&
  9324. !bp->path_has_ovlan &&
  9325. !IS_MF(bp) &&
  9326. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9327. u8 other_port = !BP_PORT(bp);
  9328. u8 other_func = BP_PATH(bp) + 2*other_port;
  9329. val = MF_CFG_RD(bp,
  9330. func_mf_config[other_func].e1hov_tag);
  9331. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9332. bp->path_has_ovlan = true;
  9333. }
  9334. }
  9335. /* adjust igu_sb_cnt to MF for E1x */
  9336. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9337. bp->igu_sb_cnt /= E1HVN_MAX;
  9338. /* port info */
  9339. bnx2x_get_port_hwinfo(bp);
  9340. /* Get MAC addresses */
  9341. bnx2x_get_mac_hwinfo(bp);
  9342. bnx2x_get_cnic_info(bp);
  9343. return rc;
  9344. }
  9345. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9346. {
  9347. int cnt, i, block_end, rodi;
  9348. char vpd_start[BNX2X_VPD_LEN+1];
  9349. char str_id_reg[VENDOR_ID_LEN+1];
  9350. char str_id_cap[VENDOR_ID_LEN+1];
  9351. char *vpd_data;
  9352. char *vpd_extended_data = NULL;
  9353. u8 len;
  9354. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9355. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9356. if (cnt < BNX2X_VPD_LEN)
  9357. goto out_not_found;
  9358. /* VPD RO tag should be first tag after identifier string, hence
  9359. * we should be able to find it in first BNX2X_VPD_LEN chars
  9360. */
  9361. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9362. PCI_VPD_LRDT_RO_DATA);
  9363. if (i < 0)
  9364. goto out_not_found;
  9365. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9366. pci_vpd_lrdt_size(&vpd_start[i]);
  9367. i += PCI_VPD_LRDT_TAG_SIZE;
  9368. if (block_end > BNX2X_VPD_LEN) {
  9369. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9370. if (vpd_extended_data == NULL)
  9371. goto out_not_found;
  9372. /* read rest of vpd image into vpd_extended_data */
  9373. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9374. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9375. block_end - BNX2X_VPD_LEN,
  9376. vpd_extended_data + BNX2X_VPD_LEN);
  9377. if (cnt < (block_end - BNX2X_VPD_LEN))
  9378. goto out_not_found;
  9379. vpd_data = vpd_extended_data;
  9380. } else
  9381. vpd_data = vpd_start;
  9382. /* now vpd_data holds full vpd content in both cases */
  9383. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9384. PCI_VPD_RO_KEYWORD_MFR_ID);
  9385. if (rodi < 0)
  9386. goto out_not_found;
  9387. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9388. if (len != VENDOR_ID_LEN)
  9389. goto out_not_found;
  9390. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9391. /* vendor specific info */
  9392. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9393. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9394. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9395. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9396. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9397. PCI_VPD_RO_KEYWORD_VENDOR0);
  9398. if (rodi >= 0) {
  9399. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9400. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9401. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9402. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9403. bp->fw_ver[len] = ' ';
  9404. }
  9405. }
  9406. kfree(vpd_extended_data);
  9407. return;
  9408. }
  9409. out_not_found:
  9410. kfree(vpd_extended_data);
  9411. return;
  9412. }
  9413. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9414. {
  9415. u32 flags = 0;
  9416. if (CHIP_REV_IS_FPGA(bp))
  9417. SET_FLAGS(flags, MODE_FPGA);
  9418. else if (CHIP_REV_IS_EMUL(bp))
  9419. SET_FLAGS(flags, MODE_EMUL);
  9420. else
  9421. SET_FLAGS(flags, MODE_ASIC);
  9422. if (CHIP_MODE_IS_4_PORT(bp))
  9423. SET_FLAGS(flags, MODE_PORT4);
  9424. else
  9425. SET_FLAGS(flags, MODE_PORT2);
  9426. if (CHIP_IS_E2(bp))
  9427. SET_FLAGS(flags, MODE_E2);
  9428. else if (CHIP_IS_E3(bp)) {
  9429. SET_FLAGS(flags, MODE_E3);
  9430. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9431. SET_FLAGS(flags, MODE_E3_A0);
  9432. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9433. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9434. }
  9435. if (IS_MF(bp)) {
  9436. SET_FLAGS(flags, MODE_MF);
  9437. switch (bp->mf_mode) {
  9438. case MULTI_FUNCTION_SD:
  9439. SET_FLAGS(flags, MODE_MF_SD);
  9440. break;
  9441. case MULTI_FUNCTION_SI:
  9442. SET_FLAGS(flags, MODE_MF_SI);
  9443. break;
  9444. case MULTI_FUNCTION_AFEX:
  9445. SET_FLAGS(flags, MODE_MF_AFEX);
  9446. break;
  9447. }
  9448. } else
  9449. SET_FLAGS(flags, MODE_SF);
  9450. #if defined(__LITTLE_ENDIAN)
  9451. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9452. #else /*(__BIG_ENDIAN)*/
  9453. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9454. #endif
  9455. INIT_MODE_FLAGS(bp) = flags;
  9456. }
  9457. static int bnx2x_init_bp(struct bnx2x *bp)
  9458. {
  9459. int func;
  9460. int rc;
  9461. mutex_init(&bp->port.phy_mutex);
  9462. mutex_init(&bp->fw_mb_mutex);
  9463. spin_lock_init(&bp->stats_lock);
  9464. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9465. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9466. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9467. if (IS_PF(bp)) {
  9468. rc = bnx2x_get_hwinfo(bp);
  9469. if (rc)
  9470. return rc;
  9471. } else {
  9472. random_ether_addr(bp->dev->dev_addr);
  9473. }
  9474. bnx2x_set_modes_bitmap(bp);
  9475. rc = bnx2x_alloc_mem_bp(bp);
  9476. if (rc)
  9477. return rc;
  9478. bnx2x_read_fwinfo(bp);
  9479. func = BP_FUNC(bp);
  9480. /* need to reset chip if undi was active */
  9481. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9482. /* init fw_seq */
  9483. bp->fw_seq =
  9484. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9485. DRV_MSG_SEQ_NUMBER_MASK;
  9486. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9487. bnx2x_prev_unload(bp);
  9488. }
  9489. if (CHIP_REV_IS_FPGA(bp))
  9490. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9491. if (BP_NOMCP(bp) && (func == 0))
  9492. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9493. bp->disable_tpa = disable_tpa;
  9494. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9495. /* Set TPA flags */
  9496. if (bp->disable_tpa) {
  9497. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9498. bp->dev->features &= ~NETIF_F_LRO;
  9499. } else {
  9500. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9501. bp->dev->features |= NETIF_F_LRO;
  9502. }
  9503. if (CHIP_IS_E1(bp))
  9504. bp->dropless_fc = 0;
  9505. else
  9506. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9507. bp->mrrs = mrrs;
  9508. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9509. if (IS_VF(bp))
  9510. bp->rx_ring_size = MAX_RX_AVAIL;
  9511. /* make sure that the numbers are in the right granularity */
  9512. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9513. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9514. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9515. init_timer(&bp->timer);
  9516. bp->timer.expires = jiffies + bp->current_interval;
  9517. bp->timer.data = (unsigned long) bp;
  9518. bp->timer.function = bnx2x_timer;
  9519. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9520. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9521. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9522. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9523. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9524. bnx2x_dcbx_init_params(bp);
  9525. } else {
  9526. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9527. }
  9528. if (CHIP_IS_E1x(bp))
  9529. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9530. else
  9531. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9532. /* multiple tx priority */
  9533. if (IS_VF(bp))
  9534. bp->max_cos = 1;
  9535. else if (CHIP_IS_E1x(bp))
  9536. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9537. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9538. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9539. else if (CHIP_IS_E3B0(bp))
  9540. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9541. else
  9542. BNX2X_ERR("unknown chip %x revision %x\n",
  9543. CHIP_NUM(bp), CHIP_REV(bp));
  9544. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9545. /* We need at least one default status block for slow-path events,
  9546. * second status block for the L2 queue, and a third status block for
  9547. * CNIC if supproted.
  9548. */
  9549. if (CNIC_SUPPORT(bp))
  9550. bp->min_msix_vec_cnt = 3;
  9551. else
  9552. bp->min_msix_vec_cnt = 2;
  9553. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9554. return rc;
  9555. }
  9556. /****************************************************************************
  9557. * General service functions
  9558. ****************************************************************************/
  9559. /*
  9560. * net_device service functions
  9561. */
  9562. /* called with rtnl_lock */
  9563. static int bnx2x_open(struct net_device *dev)
  9564. {
  9565. struct bnx2x *bp = netdev_priv(dev);
  9566. bool global = false;
  9567. int other_engine = BP_PATH(bp) ? 0 : 1;
  9568. bool other_load_status, load_status;
  9569. int rc;
  9570. bp->stats_init = true;
  9571. netif_carrier_off(dev);
  9572. bnx2x_set_power_state(bp, PCI_D0);
  9573. /* If parity had happen during the unload, then attentions
  9574. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9575. * want the first function loaded on the current engine to
  9576. * complete the recovery.
  9577. * Parity recovery is only relevant for PF driver.
  9578. */
  9579. if (IS_PF(bp)) {
  9580. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9581. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9582. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9583. bnx2x_chk_parity_attn(bp, &global, true)) {
  9584. do {
  9585. /* If there are attentions and they are in a
  9586. * global blocks, set the GLOBAL_RESET bit
  9587. * regardless whether it will be this function
  9588. * that will complete the recovery or not.
  9589. */
  9590. if (global)
  9591. bnx2x_set_reset_global(bp);
  9592. /* Only the first function on the current
  9593. * engine should try to recover in open. In case
  9594. * of attentions in global blocks only the first
  9595. * in the chip should try to recover.
  9596. */
  9597. if ((!load_status &&
  9598. (!global || !other_load_status)) &&
  9599. bnx2x_trylock_leader_lock(bp) &&
  9600. !bnx2x_leader_reset(bp)) {
  9601. netdev_info(bp->dev,
  9602. "Recovered in open\n");
  9603. break;
  9604. }
  9605. /* recovery has failed... */
  9606. bnx2x_set_power_state(bp, PCI_D3hot);
  9607. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9608. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9609. "If you still see this message after a few retries then power cycle is required.\n");
  9610. return -EAGAIN;
  9611. } while (0);
  9612. }
  9613. }
  9614. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9615. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9616. if (rc)
  9617. return rc;
  9618. return bnx2x_open_epilog(bp);
  9619. }
  9620. /* called with rtnl_lock */
  9621. static int bnx2x_close(struct net_device *dev)
  9622. {
  9623. struct bnx2x *bp = netdev_priv(dev);
  9624. /* Unload the driver, release IRQs */
  9625. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9626. /* Power off */
  9627. bnx2x_set_power_state(bp, PCI_D3hot);
  9628. return 0;
  9629. }
  9630. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9631. struct bnx2x_mcast_ramrod_params *p)
  9632. {
  9633. int mc_count = netdev_mc_count(bp->dev);
  9634. struct bnx2x_mcast_list_elem *mc_mac =
  9635. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9636. struct netdev_hw_addr *ha;
  9637. if (!mc_mac)
  9638. return -ENOMEM;
  9639. INIT_LIST_HEAD(&p->mcast_list);
  9640. netdev_for_each_mc_addr(ha, bp->dev) {
  9641. mc_mac->mac = bnx2x_mc_addr(ha);
  9642. list_add_tail(&mc_mac->link, &p->mcast_list);
  9643. mc_mac++;
  9644. }
  9645. p->mcast_list_len = mc_count;
  9646. return 0;
  9647. }
  9648. static void bnx2x_free_mcast_macs_list(
  9649. struct bnx2x_mcast_ramrod_params *p)
  9650. {
  9651. struct bnx2x_mcast_list_elem *mc_mac =
  9652. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9653. link);
  9654. WARN_ON(!mc_mac);
  9655. kfree(mc_mac);
  9656. }
  9657. /**
  9658. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9659. *
  9660. * @bp: driver handle
  9661. *
  9662. * We will use zero (0) as a MAC type for these MACs.
  9663. */
  9664. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9665. {
  9666. int rc;
  9667. struct net_device *dev = bp->dev;
  9668. struct netdev_hw_addr *ha;
  9669. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9670. unsigned long ramrod_flags = 0;
  9671. /* First schedule a cleanup up of old configuration */
  9672. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9673. if (rc < 0) {
  9674. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9675. return rc;
  9676. }
  9677. netdev_for_each_uc_addr(ha, dev) {
  9678. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9679. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9680. if (rc == -EEXIST) {
  9681. DP(BNX2X_MSG_SP,
  9682. "Failed to schedule ADD operations: %d\n", rc);
  9683. /* do not treat adding same MAC as error */
  9684. rc = 0;
  9685. } else if (rc < 0) {
  9686. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9687. rc);
  9688. return rc;
  9689. }
  9690. }
  9691. /* Execute the pending commands */
  9692. __set_bit(RAMROD_CONT, &ramrod_flags);
  9693. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9694. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9695. }
  9696. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9697. {
  9698. struct net_device *dev = bp->dev;
  9699. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9700. int rc = 0;
  9701. rparam.mcast_obj = &bp->mcast_obj;
  9702. /* first, clear all configured multicast MACs */
  9703. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9704. if (rc < 0) {
  9705. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9706. return rc;
  9707. }
  9708. /* then, configure a new MACs list */
  9709. if (netdev_mc_count(dev)) {
  9710. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9711. if (rc) {
  9712. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9713. rc);
  9714. return rc;
  9715. }
  9716. /* Now add the new MACs */
  9717. rc = bnx2x_config_mcast(bp, &rparam,
  9718. BNX2X_MCAST_CMD_ADD);
  9719. if (rc < 0)
  9720. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9721. rc);
  9722. bnx2x_free_mcast_macs_list(&rparam);
  9723. }
  9724. return rc;
  9725. }
  9726. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9727. void bnx2x_set_rx_mode(struct net_device *dev)
  9728. {
  9729. struct bnx2x *bp = netdev_priv(dev);
  9730. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9731. if (bp->state != BNX2X_STATE_OPEN) {
  9732. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9733. return;
  9734. }
  9735. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9736. if (dev->flags & IFF_PROMISC)
  9737. rx_mode = BNX2X_RX_MODE_PROMISC;
  9738. else if ((dev->flags & IFF_ALLMULTI) ||
  9739. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9740. CHIP_IS_E1(bp)))
  9741. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9742. else {
  9743. if (IS_PF(bp)) {
  9744. /* some multicasts */
  9745. if (bnx2x_set_mc_list(bp) < 0)
  9746. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9747. if (bnx2x_set_uc_list(bp) < 0)
  9748. rx_mode = BNX2X_RX_MODE_PROMISC;
  9749. } else {
  9750. /* configuring mcast to a vf involves sleeping (when we
  9751. * wait for the pf's response). Since this function is
  9752. * called from non sleepable context we must schedule
  9753. * a work item for this purpose
  9754. */
  9755. smp_mb__before_clear_bit();
  9756. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9757. &bp->sp_rtnl_state);
  9758. smp_mb__after_clear_bit();
  9759. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9760. }
  9761. }
  9762. bp->rx_mode = rx_mode;
  9763. /* handle ISCSI SD mode */
  9764. if (IS_MF_ISCSI_SD(bp))
  9765. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9766. /* Schedule the rx_mode command */
  9767. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9768. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9769. return;
  9770. }
  9771. if (IS_PF(bp)) {
  9772. bnx2x_set_storm_rx_mode(bp);
  9773. } else {
  9774. /* configuring rx mode to storms in a vf involves sleeping (when
  9775. * we wait for the pf's response). Since this function is
  9776. * called from non sleepable context we must schedule
  9777. * a work item for this purpose
  9778. */
  9779. smp_mb__before_clear_bit();
  9780. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9781. &bp->sp_rtnl_state);
  9782. smp_mb__after_clear_bit();
  9783. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9784. }
  9785. }
  9786. /* called with rtnl_lock */
  9787. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9788. int devad, u16 addr)
  9789. {
  9790. struct bnx2x *bp = netdev_priv(netdev);
  9791. u16 value;
  9792. int rc;
  9793. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9794. prtad, devad, addr);
  9795. /* The HW expects different devad if CL22 is used */
  9796. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9797. bnx2x_acquire_phy_lock(bp);
  9798. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9799. bnx2x_release_phy_lock(bp);
  9800. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9801. if (!rc)
  9802. rc = value;
  9803. return rc;
  9804. }
  9805. /* called with rtnl_lock */
  9806. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9807. u16 addr, u16 value)
  9808. {
  9809. struct bnx2x *bp = netdev_priv(netdev);
  9810. int rc;
  9811. DP(NETIF_MSG_LINK,
  9812. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9813. prtad, devad, addr, value);
  9814. /* The HW expects different devad if CL22 is used */
  9815. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9816. bnx2x_acquire_phy_lock(bp);
  9817. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9818. bnx2x_release_phy_lock(bp);
  9819. return rc;
  9820. }
  9821. /* called with rtnl_lock */
  9822. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9823. {
  9824. struct bnx2x *bp = netdev_priv(dev);
  9825. struct mii_ioctl_data *mdio = if_mii(ifr);
  9826. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9827. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9828. if (!netif_running(dev))
  9829. return -EAGAIN;
  9830. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9831. }
  9832. #ifdef CONFIG_NET_POLL_CONTROLLER
  9833. static void poll_bnx2x(struct net_device *dev)
  9834. {
  9835. struct bnx2x *bp = netdev_priv(dev);
  9836. int i;
  9837. for_each_eth_queue(bp, i) {
  9838. struct bnx2x_fastpath *fp = &bp->fp[i];
  9839. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9840. }
  9841. }
  9842. #endif
  9843. static int bnx2x_validate_addr(struct net_device *dev)
  9844. {
  9845. struct bnx2x *bp = netdev_priv(dev);
  9846. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9847. BNX2X_ERR("Non-valid Ethernet address\n");
  9848. return -EADDRNOTAVAIL;
  9849. }
  9850. return 0;
  9851. }
  9852. static const struct net_device_ops bnx2x_netdev_ops = {
  9853. .ndo_open = bnx2x_open,
  9854. .ndo_stop = bnx2x_close,
  9855. .ndo_start_xmit = bnx2x_start_xmit,
  9856. .ndo_select_queue = bnx2x_select_queue,
  9857. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9858. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9859. .ndo_validate_addr = bnx2x_validate_addr,
  9860. .ndo_do_ioctl = bnx2x_ioctl,
  9861. .ndo_change_mtu = bnx2x_change_mtu,
  9862. .ndo_fix_features = bnx2x_fix_features,
  9863. .ndo_set_features = bnx2x_set_features,
  9864. .ndo_tx_timeout = bnx2x_tx_timeout,
  9865. #ifdef CONFIG_NET_POLL_CONTROLLER
  9866. .ndo_poll_controller = poll_bnx2x,
  9867. #endif
  9868. .ndo_setup_tc = bnx2x_setup_tc,
  9869. #ifdef CONFIG_BNX2X_SRIOV
  9870. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  9871. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  9872. .ndo_get_vf_config = bnx2x_get_vf_config,
  9873. #endif
  9874. #ifdef NETDEV_FCOE_WWNN
  9875. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9876. #endif
  9877. };
  9878. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9879. {
  9880. struct device *dev = &bp->pdev->dev;
  9881. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9882. bp->flags |= USING_DAC_FLAG;
  9883. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9884. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9885. return -EIO;
  9886. }
  9887. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9888. dev_err(dev, "System does not support DMA, aborting\n");
  9889. return -EIO;
  9890. }
  9891. return 0;
  9892. }
  9893. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9894. struct net_device *dev, unsigned long board_type)
  9895. {
  9896. int rc;
  9897. u32 pci_cfg_dword;
  9898. bool chip_is_e1x = (board_type == BCM57710 ||
  9899. board_type == BCM57711 ||
  9900. board_type == BCM57711E);
  9901. SET_NETDEV_DEV(dev, &pdev->dev);
  9902. bp->dev = dev;
  9903. bp->pdev = pdev;
  9904. rc = pci_enable_device(pdev);
  9905. if (rc) {
  9906. dev_err(&bp->pdev->dev,
  9907. "Cannot enable PCI device, aborting\n");
  9908. goto err_out;
  9909. }
  9910. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9911. dev_err(&bp->pdev->dev,
  9912. "Cannot find PCI device base address, aborting\n");
  9913. rc = -ENODEV;
  9914. goto err_out_disable;
  9915. }
  9916. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9917. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9918. rc = -ENODEV;
  9919. goto err_out_disable;
  9920. }
  9921. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9922. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9923. PCICFG_REVESION_ID_ERROR_VAL) {
  9924. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9925. rc = -ENODEV;
  9926. goto err_out_disable;
  9927. }
  9928. if (atomic_read(&pdev->enable_cnt) == 1) {
  9929. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9930. if (rc) {
  9931. dev_err(&bp->pdev->dev,
  9932. "Cannot obtain PCI resources, aborting\n");
  9933. goto err_out_disable;
  9934. }
  9935. pci_set_master(pdev);
  9936. pci_save_state(pdev);
  9937. }
  9938. if (IS_PF(bp)) {
  9939. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9940. if (bp->pm_cap == 0) {
  9941. dev_err(&bp->pdev->dev,
  9942. "Cannot find power management capability, aborting\n");
  9943. rc = -EIO;
  9944. goto err_out_release;
  9945. }
  9946. }
  9947. if (!pci_is_pcie(pdev)) {
  9948. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9949. rc = -EIO;
  9950. goto err_out_release;
  9951. }
  9952. rc = bnx2x_set_coherency_mask(bp);
  9953. if (rc)
  9954. goto err_out_release;
  9955. dev->mem_start = pci_resource_start(pdev, 0);
  9956. dev->base_addr = dev->mem_start;
  9957. dev->mem_end = pci_resource_end(pdev, 0);
  9958. dev->irq = pdev->irq;
  9959. bp->regview = pci_ioremap_bar(pdev, 0);
  9960. if (!bp->regview) {
  9961. dev_err(&bp->pdev->dev,
  9962. "Cannot map register space, aborting\n");
  9963. rc = -ENOMEM;
  9964. goto err_out_release;
  9965. }
  9966. /* In E1/E1H use pci device function given by kernel.
  9967. * In E2/E3 read physical function from ME register since these chips
  9968. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9969. * (depending on hypervisor).
  9970. */
  9971. if (chip_is_e1x) {
  9972. bp->pf_num = PCI_FUNC(pdev->devfn);
  9973. } else {
  9974. /* chip is E2/3*/
  9975. pci_read_config_dword(bp->pdev,
  9976. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9977. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9978. ME_REG_ABS_PF_NUM_SHIFT);
  9979. }
  9980. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9981. bnx2x_set_power_state(bp, PCI_D0);
  9982. /* clean indirect addresses */
  9983. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9984. PCICFG_VENDOR_ID_OFFSET);
  9985. /*
  9986. * Clean the following indirect addresses for all functions since it
  9987. * is not used by the driver.
  9988. */
  9989. if (IS_PF(bp)) {
  9990. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9991. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9992. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9993. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9994. if (chip_is_e1x) {
  9995. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9996. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9997. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9998. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9999. }
  10000. /* Enable internal target-read (in case we are probed after PF
  10001. * FLR). Must be done prior to any BAR read access. Only for
  10002. * 57712 and up
  10003. */
  10004. if (!chip_is_e1x)
  10005. REG_WR(bp,
  10006. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10007. }
  10008. dev->watchdog_timeo = TX_TIMEOUT;
  10009. dev->netdev_ops = &bnx2x_netdev_ops;
  10010. bnx2x_set_ethtool_ops(bp, dev);
  10011. dev->priv_flags |= IFF_UNICAST_FLT;
  10012. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10013. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10014. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10015. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  10016. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10017. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10018. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  10019. if (bp->flags & USING_DAC_FLAG)
  10020. dev->features |= NETIF_F_HIGHDMA;
  10021. /* Add Loopback capability to the device */
  10022. dev->hw_features |= NETIF_F_LOOPBACK;
  10023. #ifdef BCM_DCBNL
  10024. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10025. #endif
  10026. /* get_port_hwinfo() will set prtad and mmds properly */
  10027. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10028. bp->mdio.mmds = 0;
  10029. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10030. bp->mdio.dev = dev;
  10031. bp->mdio.mdio_read = bnx2x_mdio_read;
  10032. bp->mdio.mdio_write = bnx2x_mdio_write;
  10033. return 0;
  10034. err_out_release:
  10035. if (atomic_read(&pdev->enable_cnt) == 1)
  10036. pci_release_regions(pdev);
  10037. err_out_disable:
  10038. pci_disable_device(pdev);
  10039. pci_set_drvdata(pdev, NULL);
  10040. err_out:
  10041. return rc;
  10042. }
  10043. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  10044. {
  10045. u32 val = 0;
  10046. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10047. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10048. /* return value of 1=2.5GHz 2=5GHz */
  10049. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10050. }
  10051. static int bnx2x_check_firmware(struct bnx2x *bp)
  10052. {
  10053. const struct firmware *firmware = bp->firmware;
  10054. struct bnx2x_fw_file_hdr *fw_hdr;
  10055. struct bnx2x_fw_file_section *sections;
  10056. u32 offset, len, num_ops;
  10057. __be16 *ops_offsets;
  10058. int i;
  10059. const u8 *fw_ver;
  10060. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10061. BNX2X_ERR("Wrong FW size\n");
  10062. return -EINVAL;
  10063. }
  10064. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10065. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10066. /* Make sure none of the offsets and sizes make us read beyond
  10067. * the end of the firmware data */
  10068. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10069. offset = be32_to_cpu(sections[i].offset);
  10070. len = be32_to_cpu(sections[i].len);
  10071. if (offset + len > firmware->size) {
  10072. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10073. return -EINVAL;
  10074. }
  10075. }
  10076. /* Likewise for the init_ops offsets */
  10077. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10078. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10079. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10080. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10081. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10082. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10083. return -EINVAL;
  10084. }
  10085. }
  10086. /* Check FW version */
  10087. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10088. fw_ver = firmware->data + offset;
  10089. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10090. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10091. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10092. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10093. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10094. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10095. BCM_5710_FW_MAJOR_VERSION,
  10096. BCM_5710_FW_MINOR_VERSION,
  10097. BCM_5710_FW_REVISION_VERSION,
  10098. BCM_5710_FW_ENGINEERING_VERSION);
  10099. return -EINVAL;
  10100. }
  10101. return 0;
  10102. }
  10103. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10104. {
  10105. const __be32 *source = (const __be32 *)_source;
  10106. u32 *target = (u32 *)_target;
  10107. u32 i;
  10108. for (i = 0; i < n/4; i++)
  10109. target[i] = be32_to_cpu(source[i]);
  10110. }
  10111. /*
  10112. Ops array is stored in the following format:
  10113. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10114. */
  10115. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10116. {
  10117. const __be32 *source = (const __be32 *)_source;
  10118. struct raw_op *target = (struct raw_op *)_target;
  10119. u32 i, j, tmp;
  10120. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10121. tmp = be32_to_cpu(source[j]);
  10122. target[i].op = (tmp >> 24) & 0xff;
  10123. target[i].offset = tmp & 0xffffff;
  10124. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10125. }
  10126. }
  10127. /* IRO array is stored in the following format:
  10128. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10129. */
  10130. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10131. {
  10132. const __be32 *source = (const __be32 *)_source;
  10133. struct iro *target = (struct iro *)_target;
  10134. u32 i, j, tmp;
  10135. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10136. target[i].base = be32_to_cpu(source[j]);
  10137. j++;
  10138. tmp = be32_to_cpu(source[j]);
  10139. target[i].m1 = (tmp >> 16) & 0xffff;
  10140. target[i].m2 = tmp & 0xffff;
  10141. j++;
  10142. tmp = be32_to_cpu(source[j]);
  10143. target[i].m3 = (tmp >> 16) & 0xffff;
  10144. target[i].size = tmp & 0xffff;
  10145. j++;
  10146. }
  10147. }
  10148. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10149. {
  10150. const __be16 *source = (const __be16 *)_source;
  10151. u16 *target = (u16 *)_target;
  10152. u32 i;
  10153. for (i = 0; i < n/2; i++)
  10154. target[i] = be16_to_cpu(source[i]);
  10155. }
  10156. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10157. do { \
  10158. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10159. bp->arr = kmalloc(len, GFP_KERNEL); \
  10160. if (!bp->arr) \
  10161. goto lbl; \
  10162. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10163. (u8 *)bp->arr, len); \
  10164. } while (0)
  10165. static int bnx2x_init_firmware(struct bnx2x *bp)
  10166. {
  10167. const char *fw_file_name;
  10168. struct bnx2x_fw_file_hdr *fw_hdr;
  10169. int rc;
  10170. if (bp->firmware)
  10171. return 0;
  10172. if (CHIP_IS_E1(bp))
  10173. fw_file_name = FW_FILE_NAME_E1;
  10174. else if (CHIP_IS_E1H(bp))
  10175. fw_file_name = FW_FILE_NAME_E1H;
  10176. else if (!CHIP_IS_E1x(bp))
  10177. fw_file_name = FW_FILE_NAME_E2;
  10178. else {
  10179. BNX2X_ERR("Unsupported chip revision\n");
  10180. return -EINVAL;
  10181. }
  10182. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10183. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10184. if (rc) {
  10185. BNX2X_ERR("Can't load firmware file %s\n",
  10186. fw_file_name);
  10187. goto request_firmware_exit;
  10188. }
  10189. rc = bnx2x_check_firmware(bp);
  10190. if (rc) {
  10191. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10192. goto request_firmware_exit;
  10193. }
  10194. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10195. /* Initialize the pointers to the init arrays */
  10196. /* Blob */
  10197. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10198. /* Opcodes */
  10199. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10200. /* Offsets */
  10201. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10202. be16_to_cpu_n);
  10203. /* STORMs firmware */
  10204. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10205. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10206. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10207. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10208. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10209. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10210. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10211. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10212. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10213. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10214. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10215. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10216. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10217. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10218. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10219. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10220. /* IRO */
  10221. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10222. return 0;
  10223. iro_alloc_err:
  10224. kfree(bp->init_ops_offsets);
  10225. init_offsets_alloc_err:
  10226. kfree(bp->init_ops);
  10227. init_ops_alloc_err:
  10228. kfree(bp->init_data);
  10229. request_firmware_exit:
  10230. release_firmware(bp->firmware);
  10231. bp->firmware = NULL;
  10232. return rc;
  10233. }
  10234. static void bnx2x_release_firmware(struct bnx2x *bp)
  10235. {
  10236. kfree(bp->init_ops_offsets);
  10237. kfree(bp->init_ops);
  10238. kfree(bp->init_data);
  10239. release_firmware(bp->firmware);
  10240. bp->firmware = NULL;
  10241. }
  10242. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10243. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10244. .init_hw_cmn = bnx2x_init_hw_common,
  10245. .init_hw_port = bnx2x_init_hw_port,
  10246. .init_hw_func = bnx2x_init_hw_func,
  10247. .reset_hw_cmn = bnx2x_reset_common,
  10248. .reset_hw_port = bnx2x_reset_port,
  10249. .reset_hw_func = bnx2x_reset_func,
  10250. .gunzip_init = bnx2x_gunzip_init,
  10251. .gunzip_end = bnx2x_gunzip_end,
  10252. .init_fw = bnx2x_init_firmware,
  10253. .release_fw = bnx2x_release_firmware,
  10254. };
  10255. void bnx2x__init_func_obj(struct bnx2x *bp)
  10256. {
  10257. /* Prepare DMAE related driver resources */
  10258. bnx2x_setup_dmae(bp);
  10259. bnx2x_init_func_obj(bp, &bp->func_obj,
  10260. bnx2x_sp(bp, func_rdata),
  10261. bnx2x_sp_mapping(bp, func_rdata),
  10262. bnx2x_sp(bp, func_afex_rdata),
  10263. bnx2x_sp_mapping(bp, func_afex_rdata),
  10264. &bnx2x_func_sp_drv);
  10265. }
  10266. /* must be called after sriov-enable */
  10267. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10268. {
  10269. int cid_count = BNX2X_L2_MAX_CID(bp);
  10270. if (IS_SRIOV(bp))
  10271. cid_count += BNX2X_VF_CIDS;
  10272. if (CNIC_SUPPORT(bp))
  10273. cid_count += CNIC_CID_MAX;
  10274. return roundup(cid_count, QM_CID_ROUND);
  10275. }
  10276. /**
  10277. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10278. *
  10279. * @dev: pci device
  10280. *
  10281. */
  10282. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10283. int cnic_cnt, bool is_vf)
  10284. {
  10285. int pos, index;
  10286. u16 control = 0;
  10287. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10288. /*
  10289. * If MSI-X is not supported - return number of SBs needed to support
  10290. * one fast path queue: one FP queue + SB for CNIC
  10291. */
  10292. if (!pos) {
  10293. dev_info(&pdev->dev, "no msix capability found\n");
  10294. return 1 + cnic_cnt;
  10295. }
  10296. dev_info(&pdev->dev, "msix capability found\n");
  10297. /*
  10298. * The value in the PCI configuration space is the index of the last
  10299. * entry, namely one less than the actual size of the table, which is
  10300. * exactly what we want to return from this function: number of all SBs
  10301. * without the default SB.
  10302. * For VFs there is no default SB, then we return (index+1).
  10303. */
  10304. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10305. index = control & PCI_MSIX_FLAGS_QSIZE;
  10306. return is_vf ? index + 1 : index;
  10307. }
  10308. static int set_max_cos_est(int chip_id)
  10309. {
  10310. switch (chip_id) {
  10311. case BCM57710:
  10312. case BCM57711:
  10313. case BCM57711E:
  10314. return BNX2X_MULTI_TX_COS_E1X;
  10315. case BCM57712:
  10316. case BCM57712_MF:
  10317. case BCM57712_VF:
  10318. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10319. case BCM57800:
  10320. case BCM57800_MF:
  10321. case BCM57800_VF:
  10322. case BCM57810:
  10323. case BCM57810_MF:
  10324. case BCM57840_4_10:
  10325. case BCM57840_2_20:
  10326. case BCM57840_O:
  10327. case BCM57840_MFO:
  10328. case BCM57810_VF:
  10329. case BCM57840_MF:
  10330. case BCM57840_VF:
  10331. case BCM57811:
  10332. case BCM57811_MF:
  10333. case BCM57811_VF:
  10334. return BNX2X_MULTI_TX_COS_E3B0;
  10335. return 1;
  10336. default:
  10337. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10338. return -ENODEV;
  10339. }
  10340. }
  10341. static int set_is_vf(int chip_id)
  10342. {
  10343. switch (chip_id) {
  10344. case BCM57712_VF:
  10345. case BCM57800_VF:
  10346. case BCM57810_VF:
  10347. case BCM57840_VF:
  10348. case BCM57811_VF:
  10349. return true;
  10350. default:
  10351. return false;
  10352. }
  10353. }
  10354. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10355. static int bnx2x_init_one(struct pci_dev *pdev,
  10356. const struct pci_device_id *ent)
  10357. {
  10358. struct net_device *dev = NULL;
  10359. struct bnx2x *bp;
  10360. int pcie_width, pcie_speed;
  10361. int rc, max_non_def_sbs;
  10362. int rx_count, tx_count, rss_count, doorbell_size;
  10363. int max_cos_est;
  10364. bool is_vf;
  10365. int cnic_cnt;
  10366. /* An estimated maximum supported CoS number according to the chip
  10367. * version.
  10368. * We will try to roughly estimate the maximum number of CoSes this chip
  10369. * may support in order to minimize the memory allocated for Tx
  10370. * netdev_queue's. This number will be accurately calculated during the
  10371. * initialization of bp->max_cos based on the chip versions AND chip
  10372. * revision in the bnx2x_init_bp().
  10373. */
  10374. max_cos_est = set_max_cos_est(ent->driver_data);
  10375. if (max_cos_est < 0)
  10376. return max_cos_est;
  10377. is_vf = set_is_vf(ent->driver_data);
  10378. cnic_cnt = is_vf ? 0 : 1;
  10379. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10380. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10381. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10382. if (rss_count < 1)
  10383. return -EINVAL;
  10384. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10385. rx_count = rss_count + cnic_cnt;
  10386. /* Maximum number of netdev Tx queues:
  10387. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10388. */
  10389. tx_count = rss_count * max_cos_est + cnic_cnt;
  10390. /* dev zeroed in init_etherdev */
  10391. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10392. if (!dev)
  10393. return -ENOMEM;
  10394. bp = netdev_priv(dev);
  10395. bp->flags = 0;
  10396. if (is_vf)
  10397. bp->flags |= IS_VF_FLAG;
  10398. bp->igu_sb_cnt = max_non_def_sbs;
  10399. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10400. bp->msg_enable = debug;
  10401. bp->cnic_support = cnic_cnt;
  10402. bp->cnic_probe = bnx2x_cnic_probe;
  10403. pci_set_drvdata(pdev, dev);
  10404. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10405. if (rc < 0) {
  10406. free_netdev(dev);
  10407. return rc;
  10408. }
  10409. BNX2X_DEV_INFO("This is a %s function\n",
  10410. IS_PF(bp) ? "physical" : "virtual");
  10411. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10412. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10413. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10414. tx_count, rx_count);
  10415. rc = bnx2x_init_bp(bp);
  10416. if (rc)
  10417. goto init_one_exit;
  10418. /* Map doorbells here as we need the real value of bp->max_cos which
  10419. * is initialized in bnx2x_init_bp() to determine the number of
  10420. * l2 connections.
  10421. */
  10422. if (IS_VF(bp)) {
  10423. bnx2x_vf_map_doorbells(bp);
  10424. rc = bnx2x_vf_pci_alloc(bp);
  10425. if (rc)
  10426. goto init_one_exit;
  10427. } else {
  10428. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10429. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10430. dev_err(&bp->pdev->dev,
  10431. "Cannot map doorbells, bar size too small, aborting\n");
  10432. rc = -ENOMEM;
  10433. goto init_one_exit;
  10434. }
  10435. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10436. doorbell_size);
  10437. }
  10438. if (!bp->doorbells) {
  10439. dev_err(&bp->pdev->dev,
  10440. "Cannot map doorbell space, aborting\n");
  10441. rc = -ENOMEM;
  10442. goto init_one_exit;
  10443. }
  10444. if (IS_VF(bp)) {
  10445. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10446. if (rc)
  10447. goto init_one_exit;
  10448. }
  10449. /* Enable SRIOV if capability found in configuration space */
  10450. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10451. if (rc)
  10452. goto init_one_exit;
  10453. /* calc qm_cid_count */
  10454. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10455. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10456. /* disable FCOE L2 queue for E1x*/
  10457. if (CHIP_IS_E1x(bp))
  10458. bp->flags |= NO_FCOE_FLAG;
  10459. /* disable FCOE for 57840 device, until FW supports it */
  10460. switch (ent->driver_data) {
  10461. case BCM57840_O:
  10462. case BCM57840_4_10:
  10463. case BCM57840_2_20:
  10464. case BCM57840_MFO:
  10465. case BCM57840_MF:
  10466. bp->flags |= NO_FCOE_FLAG;
  10467. }
  10468. /* Set bp->num_queues for MSI-X mode*/
  10469. bnx2x_set_num_queues(bp);
  10470. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10471. * needed.
  10472. */
  10473. rc = bnx2x_set_int_mode(bp);
  10474. if (rc) {
  10475. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10476. goto init_one_exit;
  10477. }
  10478. BNX2X_DEV_INFO("set interrupts successfully\n");
  10479. /* register the net device */
  10480. rc = register_netdev(dev);
  10481. if (rc) {
  10482. dev_err(&pdev->dev, "Cannot register net device\n");
  10483. goto init_one_exit;
  10484. }
  10485. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10486. if (!NO_FCOE(bp)) {
  10487. /* Add storage MAC address */
  10488. rtnl_lock();
  10489. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10490. rtnl_unlock();
  10491. }
  10492. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10493. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10494. pcie_width, pcie_speed);
  10495. BNX2X_DEV_INFO(
  10496. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10497. board_info[ent->driver_data].name,
  10498. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10499. pcie_width,
  10500. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10501. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10502. "5GHz (Gen2)" : "2.5GHz",
  10503. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10504. return 0;
  10505. init_one_exit:
  10506. if (bp->regview)
  10507. iounmap(bp->regview);
  10508. if (IS_PF(bp) && bp->doorbells)
  10509. iounmap(bp->doorbells);
  10510. free_netdev(dev);
  10511. if (atomic_read(&pdev->enable_cnt) == 1)
  10512. pci_release_regions(pdev);
  10513. pci_disable_device(pdev);
  10514. pci_set_drvdata(pdev, NULL);
  10515. return rc;
  10516. }
  10517. static void bnx2x_remove_one(struct pci_dev *pdev)
  10518. {
  10519. struct net_device *dev = pci_get_drvdata(pdev);
  10520. struct bnx2x *bp;
  10521. if (!dev) {
  10522. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10523. return;
  10524. }
  10525. bp = netdev_priv(dev);
  10526. /* Delete storage MAC address */
  10527. if (!NO_FCOE(bp)) {
  10528. rtnl_lock();
  10529. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10530. rtnl_unlock();
  10531. }
  10532. #ifdef BCM_DCBNL
  10533. /* Delete app tlvs from dcbnl */
  10534. bnx2x_dcbnl_update_applist(bp, true);
  10535. #endif
  10536. unregister_netdev(dev);
  10537. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10538. if (IS_PF(bp))
  10539. bnx2x_set_power_state(bp, PCI_D0);
  10540. /* Disable MSI/MSI-X */
  10541. bnx2x_disable_msi(bp);
  10542. /* Power off */
  10543. if (IS_PF(bp))
  10544. bnx2x_set_power_state(bp, PCI_D3hot);
  10545. /* Make sure RESET task is not scheduled before continuing */
  10546. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10547. bnx2x_iov_remove_one(bp);
  10548. /* send message via vfpf channel to release the resources of this vf */
  10549. if (IS_VF(bp))
  10550. bnx2x_vfpf_release(bp);
  10551. if (bp->regview)
  10552. iounmap(bp->regview);
  10553. /* for vf doorbells are part of the regview and were unmapped along with
  10554. * it. FW is only loaded by PF.
  10555. */
  10556. if (IS_PF(bp)) {
  10557. if (bp->doorbells)
  10558. iounmap(bp->doorbells);
  10559. bnx2x_release_firmware(bp);
  10560. }
  10561. bnx2x_free_mem_bp(bp);
  10562. free_netdev(dev);
  10563. if (atomic_read(&pdev->enable_cnt) == 1)
  10564. pci_release_regions(pdev);
  10565. pci_disable_device(pdev);
  10566. pci_set_drvdata(pdev, NULL);
  10567. }
  10568. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10569. {
  10570. int i;
  10571. bp->state = BNX2X_STATE_ERROR;
  10572. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10573. if (CNIC_LOADED(bp))
  10574. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10575. /* Stop Tx */
  10576. bnx2x_tx_disable(bp);
  10577. bnx2x_netif_stop(bp, 0);
  10578. /* Delete all NAPI objects */
  10579. bnx2x_del_all_napi(bp);
  10580. if (CNIC_LOADED(bp))
  10581. bnx2x_del_all_napi_cnic(bp);
  10582. del_timer_sync(&bp->timer);
  10583. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10584. /* Release IRQs */
  10585. bnx2x_free_irq(bp);
  10586. /* Free SKBs, SGEs, TPA pool and driver internals */
  10587. bnx2x_free_skbs(bp);
  10588. for_each_rx_queue(bp, i)
  10589. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10590. bnx2x_free_mem(bp);
  10591. bp->state = BNX2X_STATE_CLOSED;
  10592. netif_carrier_off(bp->dev);
  10593. return 0;
  10594. }
  10595. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10596. {
  10597. u32 val;
  10598. mutex_init(&bp->port.phy_mutex);
  10599. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10600. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10601. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10602. BNX2X_ERR("BAD MCP validity signature\n");
  10603. }
  10604. /**
  10605. * bnx2x_io_error_detected - called when PCI error is detected
  10606. * @pdev: Pointer to PCI device
  10607. * @state: The current pci connection state
  10608. *
  10609. * This function is called after a PCI bus error affecting
  10610. * this device has been detected.
  10611. */
  10612. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10613. pci_channel_state_t state)
  10614. {
  10615. struct net_device *dev = pci_get_drvdata(pdev);
  10616. struct bnx2x *bp = netdev_priv(dev);
  10617. rtnl_lock();
  10618. netif_device_detach(dev);
  10619. if (state == pci_channel_io_perm_failure) {
  10620. rtnl_unlock();
  10621. return PCI_ERS_RESULT_DISCONNECT;
  10622. }
  10623. if (netif_running(dev))
  10624. bnx2x_eeh_nic_unload(bp);
  10625. pci_disable_device(pdev);
  10626. rtnl_unlock();
  10627. /* Request a slot reset */
  10628. return PCI_ERS_RESULT_NEED_RESET;
  10629. }
  10630. /**
  10631. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10632. * @pdev: Pointer to PCI device
  10633. *
  10634. * Restart the card from scratch, as if from a cold-boot.
  10635. */
  10636. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10637. {
  10638. struct net_device *dev = pci_get_drvdata(pdev);
  10639. struct bnx2x *bp = netdev_priv(dev);
  10640. rtnl_lock();
  10641. if (pci_enable_device(pdev)) {
  10642. dev_err(&pdev->dev,
  10643. "Cannot re-enable PCI device after reset\n");
  10644. rtnl_unlock();
  10645. return PCI_ERS_RESULT_DISCONNECT;
  10646. }
  10647. pci_set_master(pdev);
  10648. pci_restore_state(pdev);
  10649. if (netif_running(dev))
  10650. bnx2x_set_power_state(bp, PCI_D0);
  10651. rtnl_unlock();
  10652. return PCI_ERS_RESULT_RECOVERED;
  10653. }
  10654. /**
  10655. * bnx2x_io_resume - called when traffic can start flowing again
  10656. * @pdev: Pointer to PCI device
  10657. *
  10658. * This callback is called when the error recovery driver tells us that
  10659. * its OK to resume normal operation.
  10660. */
  10661. static void bnx2x_io_resume(struct pci_dev *pdev)
  10662. {
  10663. struct net_device *dev = pci_get_drvdata(pdev);
  10664. struct bnx2x *bp = netdev_priv(dev);
  10665. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10666. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10667. return;
  10668. }
  10669. rtnl_lock();
  10670. bnx2x_eeh_recover(bp);
  10671. if (netif_running(dev))
  10672. bnx2x_nic_load(bp, LOAD_NORMAL);
  10673. netif_device_attach(dev);
  10674. rtnl_unlock();
  10675. }
  10676. static const struct pci_error_handlers bnx2x_err_handler = {
  10677. .error_detected = bnx2x_io_error_detected,
  10678. .slot_reset = bnx2x_io_slot_reset,
  10679. .resume = bnx2x_io_resume,
  10680. };
  10681. static struct pci_driver bnx2x_pci_driver = {
  10682. .name = DRV_MODULE_NAME,
  10683. .id_table = bnx2x_pci_tbl,
  10684. .probe = bnx2x_init_one,
  10685. .remove = bnx2x_remove_one,
  10686. .suspend = bnx2x_suspend,
  10687. .resume = bnx2x_resume,
  10688. .err_handler = &bnx2x_err_handler,
  10689. #ifdef CONFIG_BNX2X_SRIOV
  10690. .sriov_configure = bnx2x_sriov_configure,
  10691. #endif
  10692. };
  10693. static int __init bnx2x_init(void)
  10694. {
  10695. int ret;
  10696. pr_info("%s", version);
  10697. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10698. if (bnx2x_wq == NULL) {
  10699. pr_err("Cannot create workqueue\n");
  10700. return -ENOMEM;
  10701. }
  10702. ret = pci_register_driver(&bnx2x_pci_driver);
  10703. if (ret) {
  10704. pr_err("Cannot register driver\n");
  10705. destroy_workqueue(bnx2x_wq);
  10706. }
  10707. return ret;
  10708. }
  10709. static void __exit bnx2x_cleanup(void)
  10710. {
  10711. struct list_head *pos, *q;
  10712. pci_unregister_driver(&bnx2x_pci_driver);
  10713. destroy_workqueue(bnx2x_wq);
  10714. /* Free globablly allocated resources */
  10715. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10716. struct bnx2x_prev_path_list *tmp =
  10717. list_entry(pos, struct bnx2x_prev_path_list, list);
  10718. list_del(pos);
  10719. kfree(tmp);
  10720. }
  10721. }
  10722. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10723. {
  10724. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10725. }
  10726. module_init(bnx2x_init);
  10727. module_exit(bnx2x_cleanup);
  10728. /**
  10729. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10730. *
  10731. * @bp: driver handle
  10732. * @set: set or clear the CAM entry
  10733. *
  10734. * This function will wait until the ramdord completion returns.
  10735. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10736. */
  10737. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10738. {
  10739. unsigned long ramrod_flags = 0;
  10740. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10741. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10742. &bp->iscsi_l2_mac_obj, true,
  10743. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10744. }
  10745. /* count denotes the number of new completions we have seen */
  10746. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10747. {
  10748. struct eth_spe *spe;
  10749. int cxt_index, cxt_offset;
  10750. #ifdef BNX2X_STOP_ON_ERROR
  10751. if (unlikely(bp->panic))
  10752. return;
  10753. #endif
  10754. spin_lock_bh(&bp->spq_lock);
  10755. BUG_ON(bp->cnic_spq_pending < count);
  10756. bp->cnic_spq_pending -= count;
  10757. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10758. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10759. & SPE_HDR_CONN_TYPE) >>
  10760. SPE_HDR_CONN_TYPE_SHIFT;
  10761. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10762. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10763. /* Set validation for iSCSI L2 client before sending SETUP
  10764. * ramrod
  10765. */
  10766. if (type == ETH_CONNECTION_TYPE) {
  10767. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10768. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10769. ILT_PAGE_CIDS;
  10770. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10771. (cxt_index * ILT_PAGE_CIDS);
  10772. bnx2x_set_ctx_validation(bp,
  10773. &bp->context[cxt_index].
  10774. vcxt[cxt_offset].eth,
  10775. BNX2X_ISCSI_ETH_CID(bp));
  10776. }
  10777. }
  10778. /*
  10779. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10780. * and in the air. We also check that number of outstanding
  10781. * COMMON ramrods is not more than the EQ and SPQ can
  10782. * accommodate.
  10783. */
  10784. if (type == ETH_CONNECTION_TYPE) {
  10785. if (!atomic_read(&bp->cq_spq_left))
  10786. break;
  10787. else
  10788. atomic_dec(&bp->cq_spq_left);
  10789. } else if (type == NONE_CONNECTION_TYPE) {
  10790. if (!atomic_read(&bp->eq_spq_left))
  10791. break;
  10792. else
  10793. atomic_dec(&bp->eq_spq_left);
  10794. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10795. (type == FCOE_CONNECTION_TYPE)) {
  10796. if (bp->cnic_spq_pending >=
  10797. bp->cnic_eth_dev.max_kwqe_pending)
  10798. break;
  10799. else
  10800. bp->cnic_spq_pending++;
  10801. } else {
  10802. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10803. bnx2x_panic();
  10804. break;
  10805. }
  10806. spe = bnx2x_sp_get_next(bp);
  10807. *spe = *bp->cnic_kwq_cons;
  10808. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10809. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10810. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10811. bp->cnic_kwq_cons = bp->cnic_kwq;
  10812. else
  10813. bp->cnic_kwq_cons++;
  10814. }
  10815. bnx2x_sp_prod_update(bp);
  10816. spin_unlock_bh(&bp->spq_lock);
  10817. }
  10818. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10819. struct kwqe_16 *kwqes[], u32 count)
  10820. {
  10821. struct bnx2x *bp = netdev_priv(dev);
  10822. int i;
  10823. #ifdef BNX2X_STOP_ON_ERROR
  10824. if (unlikely(bp->panic)) {
  10825. BNX2X_ERR("Can't post to SP queue while panic\n");
  10826. return -EIO;
  10827. }
  10828. #endif
  10829. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10830. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10831. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10832. return -EAGAIN;
  10833. }
  10834. spin_lock_bh(&bp->spq_lock);
  10835. for (i = 0; i < count; i++) {
  10836. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10837. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10838. break;
  10839. *bp->cnic_kwq_prod = *spe;
  10840. bp->cnic_kwq_pending++;
  10841. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10842. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10843. spe->data.update_data_addr.hi,
  10844. spe->data.update_data_addr.lo,
  10845. bp->cnic_kwq_pending);
  10846. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10847. bp->cnic_kwq_prod = bp->cnic_kwq;
  10848. else
  10849. bp->cnic_kwq_prod++;
  10850. }
  10851. spin_unlock_bh(&bp->spq_lock);
  10852. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10853. bnx2x_cnic_sp_post(bp, 0);
  10854. return i;
  10855. }
  10856. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10857. {
  10858. struct cnic_ops *c_ops;
  10859. int rc = 0;
  10860. mutex_lock(&bp->cnic_mutex);
  10861. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10862. lockdep_is_held(&bp->cnic_mutex));
  10863. if (c_ops)
  10864. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10865. mutex_unlock(&bp->cnic_mutex);
  10866. return rc;
  10867. }
  10868. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10869. {
  10870. struct cnic_ops *c_ops;
  10871. int rc = 0;
  10872. rcu_read_lock();
  10873. c_ops = rcu_dereference(bp->cnic_ops);
  10874. if (c_ops)
  10875. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10876. rcu_read_unlock();
  10877. return rc;
  10878. }
  10879. /*
  10880. * for commands that have no data
  10881. */
  10882. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10883. {
  10884. struct cnic_ctl_info ctl = {0};
  10885. ctl.cmd = cmd;
  10886. return bnx2x_cnic_ctl_send(bp, &ctl);
  10887. }
  10888. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10889. {
  10890. struct cnic_ctl_info ctl = {0};
  10891. /* first we tell CNIC and only then we count this as a completion */
  10892. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10893. ctl.data.comp.cid = cid;
  10894. ctl.data.comp.error = err;
  10895. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10896. bnx2x_cnic_sp_post(bp, 0);
  10897. }
  10898. /* Called with netif_addr_lock_bh() taken.
  10899. * Sets an rx_mode config for an iSCSI ETH client.
  10900. * Doesn't block.
  10901. * Completion should be checked outside.
  10902. */
  10903. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10904. {
  10905. unsigned long accept_flags = 0, ramrod_flags = 0;
  10906. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10907. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10908. if (start) {
  10909. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10910. * because it's the only way for UIO Queue to accept
  10911. * multicasts (in non-promiscuous mode only one Queue per
  10912. * function will receive multicast packets (leading in our
  10913. * case).
  10914. */
  10915. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10916. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10917. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10918. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10919. /* Clear STOP_PENDING bit if START is requested */
  10920. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10921. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10922. } else
  10923. /* Clear START_PENDING bit if STOP is requested */
  10924. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10925. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10926. set_bit(sched_state, &bp->sp_state);
  10927. else {
  10928. __set_bit(RAMROD_RX, &ramrod_flags);
  10929. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10930. ramrod_flags);
  10931. }
  10932. }
  10933. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10934. {
  10935. struct bnx2x *bp = netdev_priv(dev);
  10936. int rc = 0;
  10937. switch (ctl->cmd) {
  10938. case DRV_CTL_CTXTBL_WR_CMD: {
  10939. u32 index = ctl->data.io.offset;
  10940. dma_addr_t addr = ctl->data.io.dma_addr;
  10941. bnx2x_ilt_wr(bp, index, addr);
  10942. break;
  10943. }
  10944. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10945. int count = ctl->data.credit.credit_count;
  10946. bnx2x_cnic_sp_post(bp, count);
  10947. break;
  10948. }
  10949. /* rtnl_lock is held. */
  10950. case DRV_CTL_START_L2_CMD: {
  10951. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10952. unsigned long sp_bits = 0;
  10953. /* Configure the iSCSI classification object */
  10954. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10955. cp->iscsi_l2_client_id,
  10956. cp->iscsi_l2_cid, BP_FUNC(bp),
  10957. bnx2x_sp(bp, mac_rdata),
  10958. bnx2x_sp_mapping(bp, mac_rdata),
  10959. BNX2X_FILTER_MAC_PENDING,
  10960. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10961. &bp->macs_pool);
  10962. /* Set iSCSI MAC address */
  10963. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10964. if (rc)
  10965. break;
  10966. mmiowb();
  10967. barrier();
  10968. /* Start accepting on iSCSI L2 ring */
  10969. netif_addr_lock_bh(dev);
  10970. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10971. netif_addr_unlock_bh(dev);
  10972. /* bits to wait on */
  10973. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10974. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10975. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10976. BNX2X_ERR("rx_mode completion timed out!\n");
  10977. break;
  10978. }
  10979. /* rtnl_lock is held. */
  10980. case DRV_CTL_STOP_L2_CMD: {
  10981. unsigned long sp_bits = 0;
  10982. /* Stop accepting on iSCSI L2 ring */
  10983. netif_addr_lock_bh(dev);
  10984. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10985. netif_addr_unlock_bh(dev);
  10986. /* bits to wait on */
  10987. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10988. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10989. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10990. BNX2X_ERR("rx_mode completion timed out!\n");
  10991. mmiowb();
  10992. barrier();
  10993. /* Unset iSCSI L2 MAC */
  10994. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10995. BNX2X_ISCSI_ETH_MAC, true);
  10996. break;
  10997. }
  10998. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10999. int count = ctl->data.credit.credit_count;
  11000. smp_mb__before_atomic_inc();
  11001. atomic_add(count, &bp->cq_spq_left);
  11002. smp_mb__after_atomic_inc();
  11003. break;
  11004. }
  11005. case DRV_CTL_ULP_REGISTER_CMD: {
  11006. int ulp_type = ctl->data.register_data.ulp_type;
  11007. if (CHIP_IS_E3(bp)) {
  11008. int idx = BP_FW_MB_IDX(bp);
  11009. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11010. int path = BP_PATH(bp);
  11011. int port = BP_PORT(bp);
  11012. int i;
  11013. u32 scratch_offset;
  11014. u32 *host_addr;
  11015. /* first write capability to shmem2 */
  11016. if (ulp_type == CNIC_ULP_ISCSI)
  11017. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11018. else if (ulp_type == CNIC_ULP_FCOE)
  11019. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11020. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11021. if ((ulp_type != CNIC_ULP_FCOE) ||
  11022. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11023. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11024. break;
  11025. /* if reached here - should write fcoe capabilities */
  11026. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11027. if (!scratch_offset)
  11028. break;
  11029. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11030. fcoe_features[path][port]);
  11031. host_addr = (u32 *) &(ctl->data.register_data.
  11032. fcoe_features);
  11033. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11034. i += 4)
  11035. REG_WR(bp, scratch_offset + i,
  11036. *(host_addr + i/4));
  11037. }
  11038. break;
  11039. }
  11040. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11041. int ulp_type = ctl->data.ulp_type;
  11042. if (CHIP_IS_E3(bp)) {
  11043. int idx = BP_FW_MB_IDX(bp);
  11044. u32 cap;
  11045. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11046. if (ulp_type == CNIC_ULP_ISCSI)
  11047. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11048. else if (ulp_type == CNIC_ULP_FCOE)
  11049. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11050. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11051. }
  11052. break;
  11053. }
  11054. default:
  11055. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11056. rc = -EINVAL;
  11057. }
  11058. return rc;
  11059. }
  11060. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11061. {
  11062. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11063. if (bp->flags & USING_MSIX_FLAG) {
  11064. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11065. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11066. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11067. } else {
  11068. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11069. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11070. }
  11071. if (!CHIP_IS_E1x(bp))
  11072. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11073. else
  11074. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11075. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11076. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11077. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11078. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11079. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11080. cp->num_irq = 2;
  11081. }
  11082. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11083. {
  11084. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11085. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11086. bnx2x_cid_ilt_lines(bp);
  11087. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11088. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11089. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11090. if (NO_ISCSI_OOO(bp))
  11091. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11092. }
  11093. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11094. void *data)
  11095. {
  11096. struct bnx2x *bp = netdev_priv(dev);
  11097. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11098. int rc;
  11099. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11100. if (ops == NULL) {
  11101. BNX2X_ERR("NULL ops received\n");
  11102. return -EINVAL;
  11103. }
  11104. if (!CNIC_SUPPORT(bp)) {
  11105. BNX2X_ERR("Can't register CNIC when not supported\n");
  11106. return -EOPNOTSUPP;
  11107. }
  11108. if (!CNIC_LOADED(bp)) {
  11109. rc = bnx2x_load_cnic(bp);
  11110. if (rc) {
  11111. BNX2X_ERR("CNIC-related load failed\n");
  11112. return rc;
  11113. }
  11114. }
  11115. bp->cnic_enabled = true;
  11116. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11117. if (!bp->cnic_kwq)
  11118. return -ENOMEM;
  11119. bp->cnic_kwq_cons = bp->cnic_kwq;
  11120. bp->cnic_kwq_prod = bp->cnic_kwq;
  11121. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11122. bp->cnic_spq_pending = 0;
  11123. bp->cnic_kwq_pending = 0;
  11124. bp->cnic_data = data;
  11125. cp->num_irq = 0;
  11126. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11127. cp->iro_arr = bp->iro_arr;
  11128. bnx2x_setup_cnic_irq_info(bp);
  11129. rcu_assign_pointer(bp->cnic_ops, ops);
  11130. return 0;
  11131. }
  11132. static int bnx2x_unregister_cnic(struct net_device *dev)
  11133. {
  11134. struct bnx2x *bp = netdev_priv(dev);
  11135. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11136. mutex_lock(&bp->cnic_mutex);
  11137. cp->drv_state = 0;
  11138. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11139. mutex_unlock(&bp->cnic_mutex);
  11140. synchronize_rcu();
  11141. kfree(bp->cnic_kwq);
  11142. bp->cnic_kwq = NULL;
  11143. return 0;
  11144. }
  11145. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11146. {
  11147. struct bnx2x *bp = netdev_priv(dev);
  11148. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11149. /* If both iSCSI and FCoE are disabled - return NULL in
  11150. * order to indicate CNIC that it should not try to work
  11151. * with this device.
  11152. */
  11153. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11154. return NULL;
  11155. cp->drv_owner = THIS_MODULE;
  11156. cp->chip_id = CHIP_ID(bp);
  11157. cp->pdev = bp->pdev;
  11158. cp->io_base = bp->regview;
  11159. cp->io_base2 = bp->doorbells;
  11160. cp->max_kwqe_pending = 8;
  11161. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11162. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11163. bnx2x_cid_ilt_lines(bp);
  11164. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11165. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11166. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11167. cp->drv_ctl = bnx2x_drv_ctl;
  11168. cp->drv_register_cnic = bnx2x_register_cnic;
  11169. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11170. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11171. cp->iscsi_l2_client_id =
  11172. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11173. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11174. if (NO_ISCSI_OOO(bp))
  11175. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11176. if (NO_ISCSI(bp))
  11177. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11178. if (NO_FCOE(bp))
  11179. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11180. BNX2X_DEV_INFO(
  11181. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11182. cp->ctx_blk_size,
  11183. cp->ctx_tbl_offset,
  11184. cp->ctx_tbl_len,
  11185. cp->starting_cid);
  11186. return cp;
  11187. }
  11188. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11189. {
  11190. struct bnx2x *bp = fp->bp;
  11191. u32 offset = BAR_USTRORM_INTMEM;
  11192. if (IS_VF(bp))
  11193. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11194. else if (!CHIP_IS_E1x(bp))
  11195. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11196. else
  11197. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11198. return offset;
  11199. }
  11200. /* called only on E1H or E2.
  11201. * When pretending to be PF, the pretend value is the function number 0...7
  11202. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11203. * combination
  11204. */
  11205. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11206. {
  11207. u32 pretend_reg;
  11208. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11209. return -1;
  11210. /* get my own pretend register */
  11211. pretend_reg = bnx2x_get_pretend_reg(bp);
  11212. REG_WR(bp, pretend_reg, pretend_func_val);
  11213. REG_RD(bp, pretend_reg);
  11214. return 0;
  11215. }